feat(storage): reclaim context-offload SQLite free pages in Host maintenance #5855
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 637 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5855"
general
weight: 0.35
liugddx
Summary
context-offload.sqliteis created withauto_vacuum = INCREMENTAL(sqlite-context-offload-schema.ts), but nothing onmainever ranincremental_vacuum. Garbage collection freed pages logically, and the file never shrank. This PR adds that reclamation as a bounded lane in the existingHostStorageMaintenanceloop, so freed pages go back to the filesystem after Ready.SqliteContextOffloadStore.reclaimFreePages({ maxPages }):- It first reads
freelist_countin a read transaction, so an idle tick never takes the write lock.- It then runs one
PRAGMA incremental_vacuum(min(maxPages, freelist))inside the store's write transaction.- It follows a productive batch with a
PASSIVEWAL checkpoint, which never waits on readers.- It returns
{ reclaimedPages, hasMore }.collectGarbage.context-offload page reclamation, runs 64 pages per batch. It uses the existing active and idle cadence: 100 ms while work remains, otherwise 60 s. It runs beside the existing GC lane and the archive-retention lane from #5902.Scope: this PR covers only the context-offload lane. It adds no protocol operation, no epoch bump and no UI. M1's
context_offloadfootprint (#5832) already shows the file shrinking. Convertingruntime.sqliteto incremental vacuum still needs a decision on where its one fullVACUUMruns, so it moves to a follow-up issue rather than living here.Part of #5825.
Review focus
This head supersedes the earlier revisions. It takes the 2026-10-01 review on top of @garvit-arora's lane:
main. The only conflict wasstorage-maintenance.tsagainst #5902's retention lane. Both lanes are kept, and the reclamation lane now declaresactiveDelay/idleDelay, which #5902 made required.reclaimedBytesremoved. Nothing consumed it, and the main/WAL/SHM file-set delta measured checkpoint timing rather than reclamation: the first tick reported 0 bytes for 64 freed pages. With it go thestatcalls and the duplicatereadSqliteDatabaseFileSetBytes(a copy ofstorage-footprint.ts's privatefileSetBytes), sosqlite-file-set.tsis unchanged frommain.sqlite-page-reclamation.tsand its test folded into the store. The per-batchauto_vacuumreader is dropped, because the schema already refuses to open a non-incremental database. So are the second and third copies of themaxPages, empty-freelist and:memory:checks. A guard againstincremental_vacuum(0)stays, since a zero argument would free every page.- The first batch frees exactly 64 pages, and
freelist_countdrops by 64.- Before any external checkpoint, the main file has already shrunk, which pins the store's PASSIVE checkpoint.
- Draining until
!hasMoreempties the freelist, its batch totals equal the freed pages, andpage_countand the file shrink.- A further call is a no-op.
hasMorerequires progress (after < before). A batch that frees nothing cannot spin the lane. The schema already makes this unreachable today, so it is a guard, not a fix.An independent review of the follow-up found the PASSIVE checkpoint and the always-
truelane uncovered. I confirmed both with mutants. With the second follow-up commit (47acd335d), each mutant now fails its test.Verification
npm --workspacebuilds of@maka/core,@maka/storage,@maka/mcp,@maka/runtimeand@maka/runtime-hostpass.storage-maintenance.test.js: 6/6 pass, including the reclamation lane and #5902's retention lane. The rewrittenreclaimFreePagesstore test passes 3/3 repeated runs. Mutants that drop the PASSIVE checkpoint, or make the lane always report more work, each fail. In the fullsqlite-context-offload-store.test.json Windows, 16/25 pass. The other 9 are untouched tests that fail withEBUSY ... unlinkduring temp-dir cleanup, the same Windows handle artefact recorded in the previous review.biome formatandbiome linton the changed files, the@maka/storageand@maka/runtime-hosttypechecks, andnpm run windows:inventoryall pass.AI use
Select exactly one:
Tool(s) and scope: the original lane came from @garvit-arora's revisions. Claude Code did the rebase onto
main, the review follow-up (thereclaimFreePagessimplification and removal of the duplicate helpers) and the rewritten store test.Checklist
Does this PR entail a change in behavior?