Skip to content

fix(workspace): release completed mutation captures - #185354

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-local-workspace-failure-retention
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-local-workspace-failure-retention

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #185256

What Problem This Solves

Completed workspace writes can keep large mutation payloads and prior rows reachable when a caller retains their finished admission handle, including after failed writes.

User Impact

Releases completed workspace payloads and publication callbacks while preserving native write settlement, authority checks, and recovery when a committed write loses its reply. This is bounded retention cleanup; it does not establish the root of a production memory-growth incident.

Why This Change Was Made

Finished admissions retained their commit observers, request observer, and database authority. Workspace observer and execution closures shared captured mutation inputs; ended store custody also left its current row reachable. Clear those references at their existing lifecycle boundaries and keep only the native receipt sequence needed for duplicate detection.

Committed/settlement facts deliberately remain available: the broker finishes admission before resolving or rejecting its caller, and production recovery consumers read those facts afterward. Removing them here would lose known committed outcomes. Workspace receipts contain only an ID/revision (or deletion result), not the large workspace payload. A broader receipt-consumer migration is outside this bounded cleanup.

Runtime source grows by 23 lines to end payload/callback lifetimes explicitly while retaining receipt recovery and failed-lease cleanup. The existing harness grows by 319 lines for fault injection and retention/port measurements; no production test seam, dependency, config option, schema change, or shared perf README change is introduced.

Evidence

Baseline owner sources are pinned to ce503a58dad3b06cfba1cc357bab3e5a0435f024; candidate source hashes match the pushed head after rebase. Both use the same real-worker harness and synthetic fixtures.

Acceptance: after each settled failure batch, live admission ports return to their warmed baseline; released scopes retain no mutation payloads or prior rows. Even deliberately retained finished admissions must release those captures. Accepted writes interrupted by cancellation, reply loss, or caller abandonment must remain recoverable without replay.

  • Direct owner regression retains 1,000 finished admissions: baseline retains 1,000 observer snapshots, candidate retains zero. Queued publications still arrive in order, including reentrant finish, and recovery facts remain available.
  • Real-worker regression: 1,000 stale-revision failures, synthetic 1,000-path checkpoints, and 1,000 deliberately retained finished admission handles. Both versions finished every admission; live ports stayed 4→4. Baseline retained 1,000 payloads + 1,000 prior rows and fails the final GC assertion; candidate retained zero of either and passes. Settled old space fell 176.655→114.731 MB, a 61.925 MB (35.1%) reduction. Heap fell 182.243→120.311 MB. Both retain 2,027 reachable port wrappers because the fixture deliberately holds the closed admission objects; these are not open ports. Retained-handle bookkeeping still occupies memory, so this is not a claim that deliberately retaining arbitrary handles has constant heap.
  • Focused checks: 77 tests passed across four files (workspace store 18; admission, native deadlines and broker cleanup 59). The wrapper took 357.97 seconds, including cold worker-fixture compilation; the new 1,000-admission GC regression itself took 45 ms. The native timeout file covers refusal before use, delayed transaction/commit grants, and deadlines crossed during policy preparation.
  • Ordinary real-worker failures with 1,000 updates × 100,000 paths, without deliberately held handles: both baseline and candidate finished 1,000/1,000 admissions, released all observed admissions/rows/payloads, and kept live ports at 4 and reachable wrappers at 27. Settled old space was 50.550→50.553 MB. The ordinary baseline is already flat; no skipped-finish leak was reproduced.
  • Candidate commit-stage cancellation, supersession, predispatch caller deadline, abandoned accepted result, and lost reply: 100 iterations each, zero retained rows/payloads and flat live ports. Each admission-producing case finished 100/100; the already-expired caller deadline created zero admissions. Accepted cancellation/abandonment/reply loss preserved exact revisions and payloads without replay. Supersession refused the write. Native admission deadlines are covered by the focused timeout tests above.
  • Large-filesystem diagnostic: 100,000 actual files with a sparse 64 MiB + 1 byte artifact passed two oversized-error checkpoints. Prior rows were collectible, live ports stayed at 5, and old space was 91.352 then 91.378 MB (91.624 MB after preparation). Artifact, pending recovery state, and canonical contents were preserved. This ten-cycle diagnostic was intentionally interrupted after two checkpoints because each cycle took minutes under host load; it is not a completed ten-cycle result. This diagnostic is reported separately from the completed matched case below.
  • Matched oversized-error case: 1,000 actual files, ten cycles per arm, with the same sparse 64 MiB + 1 byte artifact. Both arms pass all preservation checks and collect every observed prior row. Live ports plateau at 7 and reachable wrappers at 40. Settled old space is 88.197→88.232 MB; heap 96.963→97.058 MB, RSS 1,030.041→1,051.818 MB. Main-thread CPU is 445.7→423.9 ms, write wall time 33.736→32.647 s, natural GC 40.89→83.75 ms (43→44 collections; maximum 4.41→34.18 ms). These short, single-arm timings are context, not a controlled performance verdict; the GC change is inconclusive, with no A/A-based adverse conclusion. Host load at the first/last recovery samples was 77.34→72.51 for baseline and 71.45→76.84 for candidate. This mode observes ports/rows and recovery invariants, not admission-finish counters.
  • Healthy owner timing, 1,000 accepted updates × 10,000 paths: main-thread CPU 1.040799→1.114838 s (+74.039 ms total, +7.1%); write wall time 6.656→10.949 s. Natural GC 14.083→14.442 ms (7→9 collections; max 6.425→4.302 ms), a +0.359 ms total difference. Both collect all historical rows. Settled old space 47.841→47.768 MB, heap 53.300→53.097 MB, RSS 694.449→676.442 MB. Load at warm/settled samples: baseline 69.41→72.82, candidate 70.08→70.35. This is one short sequential pair on a loaded host, not a controlled speedup or regression claim. The bounded retained-memory result above is the purpose of the change. A separate allocation pair sampled 438,658,184→438,618,120 bytes total (438,658→438,618 bytes/update; −40,064 bytes, −0.009%, effectively neutral); warm/settled host load was 67.55→65.46 for baseline and 64.48→67.17 for candidate.
  • Autoreview preflight refused the configured provider mismatch; operator configuration was left unchanged. Independent subagent review (autoreview route unavailable): scoped clean, no actionable P0–P2 findings, under the authorized fallback. ClawSweeper and the GitHub Codex review also reported no findings.
  • Exact-head PR CI passed on e603fabce6db7c5728fb5399c0af9e4fe03e2f79, including the required CI gate. Changed-file formatting and lint passed.

The existing standalone harness now exercises failures through the real store/worker boundary, tracks close events for unreferenced ports, and uses forced GC/WeakRefs plus a MessagePort heap census. No production load or state mutation is used. Whole-Gateway stress is omitted under the authorized fast-path policy.

Clear finished admission observers and ended workspace payloads while preserving committed facts for lost-reply recovery. Cover retained-handle GC and failure-path port lifetimes.
@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T02:51:16.345600Z e603fab PR opened
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: L labels Oct 27, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR releases completed workspace mutation captures and admission callbacks while preserving committed facts for recovery.

Example: Retain finished admission handles after 1,000 stale-revision workspace writes with 1,000-path checkpoints.

  • Before: The reported baseline retains 1,000 mutation payloads and 1,000 prior rows.
  • After: The reported candidate retains neither payloads nor prior rows, while live ports remain at the warmed baseline of four.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful lifecycle repair with no actionable findings; proof is bounded to the real-worker harness rather than a shipped Gateway entry point.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied isolated real-worker run exercises the changed store and admission owners through the production worker transport: 1,000 stale-revision failures with retained finished handles release all observed payloads and prior rows while live ports remain four. This supports the bounded retention repair, without establishing whole-Gateway performance or a production memory-growth root cause.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Completed workspace writes can retain large payloads and previous rows when callers keep finished admission handles.
Reason: The maintainer-authored direction addresses a measured lifetime defect without changing stored data, configuration, permissions, or workspace behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a concrete retention path still present on current main; no actionable correctness or security findings were identified.

Priority: P2
Reviewed head: e603fabce6db7c5728fb5399c0af9e4fe03e2f79

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway workspace store submits mutations through lease-bound SQLite worker admissions; native commit receipts support publication and lost-reply recovery before completed operations release their captures.

flowchart LR
  A[Workspace caller] --> B[Local workspace store]
  B --> C[Lease-bound admission]
  C --> D[SQLite worker]
  D --> E[Commit receipts]
  E --> B
  B --> F[Recovery and acknowledgement]
  F --> G[Release completed captures]
Loading

Technical review

Best possible solution:

Release payload and callback references at the existing completion boundaries while retaining committed evidence until recovery consumers finish.

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

The base source retains publication callbacks and their workspace captures through finished admission handles, and the PR reports a matching red-on-base real-worker reproduction; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs the existing lifecycle owners directly, preserves recovery evidence and failed-lease cleanup, and adds no competing storage or execution path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Workspace mutation ownership and recovery keeps the original intent (perf(workspace): avoid copying owned projection mutations #185256: Owner-created mutations are reused through settlement to avoid a second full payload copy; earlier recovery work preserves native committed outcomes after reply loss.)
  • Multiple commit observers keeps the original intent (4466c0d: Worker-backed state consumers share committed-receipt publication through multiple observers in the original owner context.)
  • Native receipt retention keeps the original intent (da67a08: Retained committed facts preserve known write outcomes when publication or reply delivery fails; sequence numbers suppress duplicate receipts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Reviewed introduction: The pinned merge-base-to-head diff confines production changes to workspace capture lifetimes and admission cleanup; base movement is separate. (e603fabce6db)
  • Cleanup preserves publication ordering: Admission finish closes authority, drains queued receipts, preserves an active observer iteration, clears callbacks, and retains database authority only when lease release failed. (src/infra/sqlite-worker-operation-admission.ts:675, e603fabce6db)
  • Recovery precedes capture release: Workspace mutations clear pending payloads after acknowledgement or settlement-based recovery, and the store clears its row when custody ends. (src/gateway/worker-environments/local-workspace-store.ts:251, e603fabce6db)
  • Committed facts remain necessary: The broker finishes admission before resolving or rejecting its caller; workspace recovery subsequently reads admission.committed, so clearing those facts would break known-outcome recovery. (src/infra/sqlite-worker-broker-reply.ts:667, e603fabce6db)
  • Supplied real-worker comparison: The fully read PR body reports zero retained payloads and prior rows after 1,000 stale-revision failures, unchanged live-port counts, and a failing baseline retention assertion; the committed harness uses the real store and worker transport. The captured body identity is 35c035454e58934a41984d514d8fd14cc02ee15bd6aa27462251bc040cc0c10e. (scripts/perf/local-workspace-retention.ts:497, e603fabce6db)
  • Current main still needs the cleanup: Fetched main retains the original observer array, database-authority reference, and workspace mutation captures without these lifecycle releases. (src/infra/sqlite-worker-operation-admission.ts:181, b3fa02e99b72)

PR surface

Source +23, Tests +45, Docs +6, Other +319. Total +393 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 36 13 +23
Tests 1 51 6 +45
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 391 72 +319
Total 5 484 91 +393

Review metrics

Metric Value Why it matters
Production versus test and proof growth Production +36/-13 lines; tests and executable proof +442/-78 lines. The production growth explicitly ends existing capture lifetimes; most supporting growth extends the existing harness with fault injection, port accounting, and retention checks.

Labels

Label changes:

  • add P2: The demonstrated retention affects completed workspace operations with retained handles; no production outage or unbounded production memory-growth incident is established.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The demonstrated retention affects completed workspace operations with retained handles; no production outage or unbounded production memory-growth incident is established.
  • 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.

Reviewed October 26, 2026, 11:04 PM ET / October 27, 2026, 03:04 UTC.

@steipete
steipete merged commit 6592064 into main Oct 27, 2026
173 of 176 checks passed
@steipete
steipete deleted the steipete/perf-local-workspace-failure-retention branch October 27, 2026 03:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
Clear finished admission observers and ended workspace payloads while preserving committed facts for lost-reply recovery. Cover retained-handle GC and failure-path port lifetimes.
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 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: L 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