Skip to content

fix(store): persist periodic SQLite cleanup and retry failed deletes #2343

Description

@DeliciousBuding

Summary

The SQLite periodic cleanup loop calls the in-memory Store.CleanupRuns directly and never commits the resulting deletes. On source base 49078e7adce93c8ed61108c6f427782f475cfc2c, a real timer tick removes an expired run and its evidence from memory, but all six durable rows remain. Reopening without the final Close/Flush persist restores the run and checkpoint. This is a deterministic local SQLite reproduction, not a production load or process-kill claim.

The prior historical tracker #2154 mentioned cleanup-loop shutdown, but its text incorrectly treated s.store.CleanupRuns as a persistence call. This issue uses the current code and a real durable-reopen failure instead of reopening that catch-all tracker.

Scope / file ownership

One writer in an isolated task worktree. Allowed files:

  • edge-server/internal/store/sqlite_store.go: commit periodic deletions, retain pending persistence for retry after transient failure, and stop/join owned background loops before final shutdown persistence. Tests use testing/synctest to advance the actual constructor-owned loops at production cadence; no shortened interval seam is added.
  • edge-server/internal/store/sqlite_periodic_cleanup_test.go: real database, actual timer/constructor, fault-recovery and shutdown coverage.
  • docs/architecture/02-edge-server.md: align the stable persistence/lifecycle description if needed.

Interfaces / invariants / exclusions

Public APIs, 5-minute cadence, 24-hour terminal TTL, 50-per-thread cap, selected terminal states and cascade membership stay unchanged. Preserve the existing explicit-write failure policy: memory may change on a failed durable commit and LastPersistError reports that failure. No schema, connection-pool, PRAGMA, WAL policy, settings, runtime configuration or deployment changes. No new verifier or broad storage abstraction; no actual workspace files are deleted by run retention.

Acceptance

  • Reproduce periodic memory/disk divergence and reopen restoration on the unchanged production base.
  • Actual periodic cleanup durably deletes the run and associated evidence before final close; unrelated queued data remains.
  • A recoverable SQL delete failure is observable and the next timer cycle can commit pending deletes without a new business write.
  • Owned background tasks finish before final close persistence and database closure; shutdown can flush pending cleanup without requiring another tick.
  • Complete store/API Windows and Linux race tests, vet/staticcheck and existing document validation.
  • PR required checks pass for the final head.
  • Merge, source-only owner-document synchronization and cleanup of the completed task branch/worktree.

Initial failing regression: go test ./internal/store -run TestSQLitePeriodicCleanupIsDurableBeforeClose -count=1 -v from edge-server with CGO_ENABLED=0 on Windows. The test explicitly bypasses final persistence so shutdown cannot hide the missing periodic write.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions