Skip to content

fix(workspaces): let checkpoints progress during manifest sweeps - #198157

Merged
steipete merged 2 commits into
mainfrom
fix/workspace-sweep-read-holds-2437
Nov 13, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/workspace-sweep-read-holds-2437

Conversation

@steipete

@steipete steipete commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: workspace maintenance pins a SQLite read transaction throughout a large manifest sweep, preventing checkpoints from completing between its graph reads.

User Impact

Maintenance releases each metadata read after at most 256 rows. Accepted trees, pending checkpoints and content reused or published during the sweep remain protected by the existing preparation epochs and deletion checks. No configuration, schema or retention-window change.

Why This Change Was Made

The existing projection is already narrow. Most IO comes from reaching child metadata and epochs stored after large pack payloads; selecting fewer columns cannot remove those overflow-page reads. This change removes the handler-wide read snapshot and pages roots and candidate scans using existing primary keys. Graph reads were already bounded. It relieves long checkpoint holds without claiming to eliminate the underlying multi-GB IO.

Production delta: +38 lines, needed for three bounded keyset scans; no cache, additional owner or durable cursor. The existing GC regression now checks an actual WAL checkpoint from another connection and concurrent publication/reuse. The old snapshot wrapper is removed.

Evidence

The regression fails on exact parent 1110e81c7b93da2eb1a8b3ba26f70cf4a9660553: the checkpoint reports busy=1. With the fix it reports busy=0 and all 12 CAS tests pass, including preservation of accepted, pending, newly published and reused content. Independent Codex review found no actionable P0–P2 findings. All 45 focused CAS/store/manifest tests and the full build pass. pnpm check:changed passed its selected type, schema, database, format and boundary guards. Its new callback-shadow lint error is fixed and final focused lint passes. The remaining dead-export failure (sharedThemeProjection) also reproduces in both scans on the exact parent; 18872ea508b988daae6e641e79b95ab10fe885ad / #197549 removed its final consumer. This is a recorded main regression, not a new failure dismissed as noise. No UI-imported module is changed.

Measurements and full build use 8f05cb9b9d733b202c5b60bb80c3a333592fc23c; the final source changes only a callback parameter name to satisfy lint, preserving SQL, types and control flow. That final delta has its own clean Codex review. Exact-head PR CI remains a landing gate.

Acceptance rule, recorded before the paired campaign: warm production-handler sweep over a new synthetic ~6 GB state database, 10,000 projection rows and distinct 62,000-file manifests, stored at epoch 2 and swept at epoch 4. Two parent A/A controls, then five serial interleaved parent/candidate pairs each for timing, allocation and logical pager reads. Require identical candidate digests, at least 90% lower longest read hold, and no >20% adverse movement in paired wall/CPU/allocation medians; report p95, ranges and adverse cells. This is the existing state-owner workload, not a copied 35 GiB agent database or whole-Gateway transport test. Setup and warmup are excluded.

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/local-workspace-manifest-read.ts \
  62000 1 timing /path/to/new-synthetic.sqlite --sweep --sweep-epoch=4 --target-bytes=6000000000
# Subsequent arms: --reuse --sweep --sweep-epoch=4; allocation uses the allocation mode.

Prior retained evidence from #191779 attributes most native reads to child metadata after record payloads. Its synthetic covering child+epoch index experiment reduced logical pager bytes 3.808 GB → 0.155 GB, but the initial timing experiment was adverse and confounded. That is a proposal for separate schema-owner review, not justification to add an index here. No index experiment is repeated or shipped in this PR.

Completed sweep measurements

The fixture is 6,008,033,280 bytes: 234 accepted 62,000-file manifests, 145,548 packs and 10,000 projections. All 36 measured invocations returned the identical candidate digest and zero garbage, as expected for the all-live large fixture; the regression separately checks nonempty garbage and concurrent reuse/publication. Each mode has two parent A/A controls and five interleaved pairs. Values below are median / empirical p95 (maximum at n=5).

Metric Parent Bounded reads
Longest SQLite read hold, ms 3,537.9 / 5,832.9 63.7 / 447.6
Owner wall, ms 3,541.5 / 5,833.6 4,611.2 / 8,063.1
Owner CPU, ms 3,163.6 / 3,301.2 3,750.8 / 3,952.6
Sampled V8 allocation, MB, separate pass 300.69 / 309.51 303.39 / 308.64
Logical pager bytes, GB, separate pass 12.588 / 12.588 13.122 / 13.122
Read statements 572 1,179
Largest returned page, rows 145,548 256

Read-hold median improves 98.2%; all statements return at most 256 rows. The tradeoff is explicit: timing median worsens 30.2%, p95 38.2%, CPU median 18.6%, allocation median 0.9%, logical reads 4.23%, and more statements replace the long scans. Owner-accepted tradeoff (November 13, 2026): Peter explicitly accepts this cost and directs landing. The production problem is a 28–32 second read-transaction hold on the shared state database on each maintenance pass, obstructing checkpoint progress. Reducing the fixture median hold from 3,537.9 ms to 63.7 ms is worth increasing total sweep time from 3,541.5 ms to 4,611.2 ms (+30.2%) and worker CPU from 3,163.6 ms to 3,750.8 ms (+18.6%), once per background pass. The remaining logical read volume is a separate follow-up; this acceptance does not claim lower IO or authorize a schema change.

Timing A/A wall was 3,071 / 3,044 ms and CPU 3,129 / 3,090 ms. All paired timing observations are retained: wall parent 3,119–5,834 ms, candidate 3,610–8,063 ms. The shared host was busy; the separate pager pass later measured wall medians 3,109 → 3,605 ms and CPU 3,169 → 3,663 ms. Those diagnostic runs do not replace the adverse untraced timing campaign. Native query execution dominates both separately captured CPU profiles; no compilation-cache fix or schema change is inferred.

Node 26.12.1 / SQLite 3.54.1 on macOS/APFS; logical pager counts use the retained native CACHE_MISS probe, 2 MiB cache and mmap disabled. Logical pager bytes are not physical disk bytes. This exercises the production read handler in-process, not Gateway scheduling, btrfs commits or chat latency. Real maintenance executes this operation in its existing read worker.

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: M labels Nov 13, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces the manifest sweep’s long SQLite read snapshot with reads bounded to 256 rows.

Example: Workspace maintenance scans the reported 6.0 GB synthetic state database.

  • Before: The median longest SQLite read hold is 3,537.9 ms.
  • After: The median longest read hold is 63.7 ms, allowing checkpoints between reads.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct repair with real SQLite owner-level evidence, passing exact-head gates, and an accepted performance tradeoff; proof remains in process rather than through a running Gateway.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied macOS/APFS campaign exercises the production sweep read handler against real SQLite with a 6.0 GB synthetic database, showing shorter read holds and retaining adverse metrics; the regression exercises a separate WAL-checkpoint connection and content preservation, without claiming Gateway scheduling or chat-latency coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Large workspace maintenance sweeps hold a shared-state SQLite read transaction long enough to obstruct checkpoints.
Reason: The existing workspace owner explicitly accepts the measured background overhead for substantially shorter read holds, resolving the sole prior blocker.

Merge readiness

✅ Ready for maintainer review

This PR is ready for landing consideration: no actionable findings remain, exact-head CI gates pass, and the owner explicitly accepted the measured performance tradeoff that blocked the previous review.

Priority: P2
Reviewed head: e552124d795a1bfb066e6bddb424d48e4b474946

Before merge

None.

Findings

None.

Agent review details

How this fits together

The workspace maintenance owner advances the sweep epoch, asks the existing read worker to discover unreachable manifest content, and sends candidates to the writer for epoch-checked deletion.

flowchart TD
  A[Workspace maintenance] --> B[Advance sweep epoch]
  B --> C[Existing read worker]
  C --> D[Bounded root and graph reads]
  D --> E[Unreachable content candidates]
  E --> F[Epoch checked writer deletion]
Loading

Technical review

Best possible solution:

Land the bounded reads in the existing sweep owner with its unchanged epoch safeguards and the explicitly accepted background performance cost.

Do we have a high-confidence way to reproduce the issue?

Current main visibly holds one read snapshot throughout discovery, and the supplied regression reports busy=1 on the exact parent versus busy=0 after the fix; this review executed no target code.

Is this the best way to solve the issue?

The patch is a focused repair: it removes the long snapshot, bounds existing scans by their primary keys, and preserves the existing publication and deletion owners without adding durable state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3370acfc7477.

Provenance checked

  • Sweep-wide read snapshot and candidate discovery changes intended behavior with a stated reason (a25b072: Content-addressed workspace storage used a coherent snapshot to mark retained roots and discover unreachable packs.)
  • Preparation epochs and publication safety keeps the original intent (e69b382: Reject publication after prepared content becomes collectible, preventing references to missing baseline data.)
  • Sweep traversal allocation and measurement tooling keeps the original intent (9a0a5e6: Bound temporary frontier allocation and measure actual native reader work without claiming lower database I/O.)
  • Deduplicated graph traversal keeps the original intent (c9b46d8: Avoid returning known digests and allocating redundant traversal sets while preserving missing-pack detection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit a25b072 adds src/gateway/worker-environments/local-workspace-cas.kernel.ts:180 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a25b072d1684; files: src/gateway/worker-environments/local-workspace-cas.kernel.ts)

PR surface

Source +38, Tests +25, Docs +3, Other +48. Total +114 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 87 49 +38
Tests 1 36 11 +25
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 57 9 +48
Total 5 185 71 +114

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The change addresses background maintenance obstructing SQLite checkpoints with a focused repair.
  • merge-risk: 🚨 other: Total sweep wall time increases 30.2% and worker CPU increases 18.6% in the reported campaign; the workspace owner explicitly accepted this performance cost.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-13T07:27:08.205Z sha 8f05cb9 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-13T08:21:57.087Z sha e552124 :: blocked before merge. :: none

Reviewed November 13, 2026, 5:56 AM ET / 10:56 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review November 13, 2026 08:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T08:03:28.438723Z e552124 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

The completed 6.0 GB synthetic campaign is now in the PR body: median read hold 3,537.9 → 63.7 ms, with the measured total-time/CPU/read overhead retained and explicitly awaiting owner acceptance. All final-head CI checks passed in run 43389843075. Final head e552124 changes only a shadowed callback name after the reviewed implementation. There were no numbered open findings in the previous review.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the sole open review item on final head e552124d795a1bfb066e6bddb424d48e4b474946:

  1. Owner acceptance — resolved. Peter explicitly accepts the measured tradeoff and directs landing. The bounded root/candidate reads (CAS owner, lines 220–360) and removal of the operation-wide snapshot (read handler, line 261) reduce median longest hold from 3,537.9 ms to 63.7 ms. The owner accepts total time 3,541.5 → 4,611.2 ms (+30.2%) and worker CPU 3,163.6 → 3,750.8 ms (+18.6%) once per background pass, because production holds the shared-state read transaction for 28–32 seconds and obstructs checkpoints. The PR body now records that decision and retains all adverse metrics and fixture limitations. Read-volume reduction remains separate; no schema change is authorized or included.

Code and head are unchanged; the existing exact-head CI and independent Codex review still apply.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 13, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 13, 2026
@steipete
steipete merged commit 3e01309 into main Nov 13, 2026
237 of 240 checks passed
@steipete
steipete deleted the fix/workspace-sweep-read-holds-2437 branch November 13, 2026 11:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…nclaw#198157)

* fix(workspaces): release sweep reads between bounded pages

* style(workspaces): avoid shadowing the sweep query helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant