Skip to content

fix(apply): prevent exact review publication memory exhaustion - #980

Merged
vincentkoc merged 1 commit into
mainfrom
fix/bounded-exact-publication
Aug 1, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/bounded-exact-publication

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where exact-review publication could exhaust the Node heap after a review completed because a one-item run hydrated and rescanned the full canonical review corpus. The deferred publisher could repeat the same full hydration when direct publication or lifecycle finalization fell back to the queued path.

Why This Change Was Made

Direct and deferred exact-event publication now hydrate only the requested canonical record and carry the same bounded item set through report discovery and final-state reads. Broad apply modes keep their existing full-corpus behavior.

User Impact

Exact ClawSweeper reviews can publish without memory use scaling with every historical review record, including the queued fallback path. There is no user-facing configuration change.

Evidence

  • Live failure before the fix: https://github.com/openclaw/clawsweeper/actions/runs/30652803108 reached roughly 1.95 GB heap after hydrating about 49,000 revisions, then queued the fallback publication path.
  • Live linked observation: https://github.com/openclaw/clawsweeper/actions/runs/30680211674 completed review generation quickly but spent about 12 minutes in state setup/publication before the durable comment appeared.
  • pnpm run build:all
  • node --test test/sweep-workflow.test.ts test/apply-cursor-trace.test.ts test/repair/exact-review-batch-workflow.test.ts
  • Result: 115 tests passed.
  • Formatting and git diff --check passed.
  • Fresh uncommitted and committed-branch autoreview: no accepted or actionable findings.
  • Production-scale local A/B fixture: 50,000 canonical records at 8,873 bytes each, with the same exact-event command run against base 16f01b29508632ab3a904087191e39b20968ab68 and fixed head 093ffeeb6d84deba015a309750dc343f1799bb74.
  • Base: exact apply selected item 20 in 4,056 ms and peaked at 1,109,803,008 bytes RSS (1,058.4 MiB).
  • Fixed: exact apply selected item 20 in 149 ms and peaked at 113,999,872 bytes RSS (108.7 MiB).
  • Delta: 96.3% lower exact-apply latency and 89.7% lower peak RSS on the same corpus.

Real Behavior Proof

  • Claim: an exact-event apply reads only its requested canonical record, does not touch unrelated dangling records, and both direct and deferred publication hydrate that exact record rather than the full repository corpus.
  • Exercised surface: exact review setup-state hydration, deferred publication setup-state hydration, report discovery, apply finalization, and workflow wiring.
  • Scenario: the regression fixture provides item 20 plus an unrelated unreadable 999.md record. The scale fixture provides 50,000 valid 8,873-byte canonical records and requests only item 20. Workflow assertions bind both direct and deferred setup-state calls to their exact item-number outputs.
  • Command and environment: Node 26.4.0 on macOS. A controlled canonical-record directory was executed through the built production CLI as node dist/clawsweeper.js apply-decisions --target-repo openclaw/openclaw --items-dir <fixture>/items --closed-dir <fixture>/closed --plans-dir <fixture>/plans --report-path <fixture>/apply-report.json --item-numbers 20 --exact-event-publication --limit 1 --processed-limit 1 --close-delay-ms 0. The same /usr/bin/time -l invocation ran against both measured heads.
  • Observed result: the unreadable-neighbor fixture completed without opening item 999; all 115 focused tests passed. On the 50,000-record fixture, the base used 1,058.4 MiB RSS and 4,056 ms while the fixed head used 108.7 MiB RSS and 149 ms.
  • Trace: the workflow tests verify records-item-number is bound to the exact target for both direct and deferred publication; the behavior test verifies bounded discovery and rereads; the scale run reports selected item, apply elapsed time, and process peak RSS.
  • Limits: the scale measurement is a production-sized local corpus rather than the live canonical Worker store. The first post-land exact publication should still be observed operationally, but the before/after read amplification and memory claim are directly measured.

Redacted production-CLI transcript:

base=16f01b29508632ab3a904087191e39b20968ab68
{"corpus_records":50000,"record_bytes":8873,"outcome":"success","selected":20,"apply_elapsed_ms":4056}
1109803008 maximum resident set size

head=093ffeeb6d84deba015a309750dc343f1799bb74
{"corpus_records":50000,"record_bytes":8873,"outcome":"success","selected":20,"apply_elapsed_ms":149}
113999872 maximum resident set size

ClawSweeper Review Disposition - August 1, 2026

  • Removed the release-owned CHANGELOG.md entry requested by the exact-head review; release context remains in this PR body.

  • Rebased onto current main at b07ab751813c722d45f07ef955a8b5752ebbbb19.

  • The direct and deferred one-item publication paths both pass records-item-number through the existing focused hydration contract.

  • Step-specific workflow assertions cover both paths; the focused suite passes 115 tests.

  • The existing corpus-scale proof remains applicable to the bounded apply/read path. The deferred workflow correction closes the remaining sibling setup-state gap found during review.

  • The prior rank-up move remains post-land operational monitoring: observe the first canonical Worker publication and retain a redacted result if it differs from the fixture outcome.

@clawsweeper clawsweeper Bot added 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. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 11:06 PM ET / August 1, 2026, 03:06 UTC.

ClawSweeper review

What this changes

The PR limits exact-event review publication to the requested canonical record and adds regression assertions for direct and deferred state setup.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This PR is a focused, evidence-backed fix for exact-review publication reading the whole canonical corpus. The current head filters records before Markdown reads, keeps the broad apply path unchanged, and wires the exact item number through both direct and deferred publication; keep it open for normal member-authored maintainer landing after the remaining required check completes.

Priority: P2
Reviewed head: ee154dd1d9debe4bc7a286262c8dd12fede40313

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) This is a focused, well-covered reliability patch with strong real CLI proof; remaining confidence work is limited to normal current-head checks and first-production observation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides a redacted built-CLI before/after scale measurement, a concrete unreadable-neighbor regression scenario, and focused workflow-path assertions; it directly demonstrates the claimed bounded read and memory improvement.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides a redacted built-CLI before/after scale measurement, a concrete unreadable-neighbor regression scenario, and focused workflow-path assertions; it directly demonstrates the claimed bounded read and memory improvement.
Evidence reviewed 6 items Focused record reads: The PR extends the report reader with an optional item-number set and applies it before reading Markdown, so an exact requested item does not hydrate unrelated canonical records.
Exact-mode counterpart and final-state bounds: Only exact-event publication with requested item numbers substitutes the selected entries for the open-record map and filters final item/closed rereads; non-exact paths retain their full-corpus behavior.
Direct and deferred workflow wiring: Both exact-review setup-state steps pass their resolved item number to the existing focused hydration input, avoiding an unbounded canonical snapshot in either publication path.
Findings None None.
Security None None.

How this fits together

ClawSweeper’s apply lane turns a reviewed record into durable state and GitHub effects. Exact-event publication handles one leased review item, while normal apply modes can still inspect the broader repository corpus when their safety checks need it.

flowchart LR
  A[Exact review event] --> B[Selected canonical item]
  B --> C[Focused state hydration]
  C --> D[Apply decision publication]
  D --> E[Durable review record]
  D --> F[Deferred publication fallback]
  F --> C
Loading

Before merge

  • Resolve merge risk (P1) - Exact-event publication is a production automation path; the corpus-scale proof is strong but uses a controlled local canonical-record corpus rather than the live Worker, so retain a redacted observation from the first production publication.
  • Resolve merge risk (P1) - The provided check snapshot still shows pnpm check in progress; do not land until the current-head required checks complete successfully.
  • Complete next step (P2) - No mechanical repair remains: this member-authored PR has no actionable review finding and needs normal maintainer landing review after its in-progress check completes.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch scope 5 files affected; 93 added, 17 removed The change is limited to the apply reader, two workflow bindings, and focused regression tests.
Publication paths 2 state-setup bindings added Both direct and deferred exact publication now use the selected-item hydration contract.
Scale proof 50,000 records; 89.7% lower peak RSS The supplied real CLI benchmark directly measures the memory-regression claim.

Merge-risk options

Maintainer options:

  1. Land with first-run observation (recommended)
    After the current-head required check passes, merge the bounded path and retain a redacted result from the first live exact publication to validate the Worker-backed operational path.
  2. Hold for an additional live canary
    Keep the PR open until a maintainer chooses to run and inspect a production exact-event canary before landing.

Technical review

Best possible solution:

Land the bounded exact-event path after the current-head check completes, then retain a redacted first-production publication result to confirm Worker-scale behavior matches the measured fixture.

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

Yes, with high confidence from source and supplied proof: the prior path enumerated and read all canonical reports, while the PR gives a deterministic built-CLI 50,000-record reproduction and an unreadable-neighbor regression case. This review did not execute the fixture because the target checkout is read-only.

Is this the best way to solve the issue?

Yes. Filtering before Markdown reads and limiting the exact-event-only counterpart/final-state paths fixes the amplification without changing broad apply behavior, and both direct and deferred workflow entry points use the existing focused hydration interface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b07ab751813c.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a redacted built-CLI before/after scale measurement, a concrete unreadable-neighbor regression scenario, and focused workflow-path assertions; it directly demonstrates the claimed bounded read and memory improvement.

Label justifications:

  • P2: This is a concrete reliability and latency regression in one-item review publication with a bounded operational blast radius.
  • merge-risk: 🚨 availability: A mistake in the selected-record bounds could prevent an exact review from publishing its durable result.
  • merge-risk: 🚨 automation: The PR changes inputs to two sweep workflow state-setup steps.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides a redacted built-CLI before/after scale measurement, a concrete unreadable-neighbor regression scenario, and focused workflow-path assertions; it directly demonstrates the claimed bounded read and memory improvement.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a redacted built-CLI before/after scale measurement, a concrete unreadable-neighbor regression scenario, and focused workflow-path assertions; it directly demonstrates the claimed bounded read and memory improvement.

Evidence

What I checked:

  • Focused record reads: The PR extends the report reader with an optional item-number set and applies it before reading Markdown, so an exact requested item does not hydrate unrelated canonical records. (src/clawsweeper.ts:23463, ee154dd1d9de)
  • Exact-mode counterpart and final-state bounds: Only exact-event publication with requested item numbers substitutes the selected entries for the open-record map and filters final item/closed rereads; non-exact paths retain their full-corpus behavior. (src/clawsweeper.ts:23536, ee154dd1d9de)
  • Direct and deferred workflow wiring: Both exact-review setup-state steps pass their resolved item number to the existing focused hydration input, avoiding an unbounded canonical snapshot in either publication path. (.github/workflows/sweep.yml:1292, ee154dd1d9de)
  • Focused regression coverage: The new apply test places an unreadable unrelated record beside the requested report and asserts exact-event apply completes for the selected item; workflow tests assert both setup-state bindings. (test/apply-cursor-trace.test.ts:62, ee154dd1d9de)
  • Feature provenance: The parent current-main commit introduced exact review lifecycle projection, making it the immediate feature-history anchor for the workflow this patch narrows. (.github/workflows/sweep.yml:1284, b07ab751813c)
  • Real behavior proof: The PR body records a redacted built-CLI A/B run on 50,000 canonical records: the pre-fix path reached 1,058.4 MiB RSS in 4,056 ms, while the fixed head reached 108.7 MiB in 149 ms, plus an unreadable-neighbor scenario and 115 focused passing tests. (ee154dd1d9de)

Likely related people:

  • Martin Cleary: Authored the current-main exact review lifecycle projection that established the direct publication workflow this patch adjusts. (role: exact-review lifecycle feature author; confidence: high; commits: b07ab751813c; files: .github/workflows/sweep.yml)
  • Peter Steinberger: Recent current-main history shows substantial ownership of the apply and review-runtime path, including the read-only modularization and recovery behavior adjacent to this change. (role: recent apply-path contributor; confidence: high; commits: 16f01b295086, ec2f84cc3f00; files: src/clawsweeper.ts)
  • Vincent Koc: Has a prior merged current-main change in the same central source file and authored this focused repair. (role: recent adjacent contributor; confidence: medium; commits: 2e6bacee3813, ee154dd1d9de; files: src/clawsweeper.ts, test/apply-cursor-trace.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for the current-head pnpm check result before landing.
  • Retain a redacted first live exact-publication result after merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-31T18:43:10.296Z sha c168f76 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T19:48:31.856Z sha 093ffee :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T20:41:25.747Z sha 093ffee :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T20:51:04.667Z sha 093ffee :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T02:58:23.647Z sha a3d2086 :: needs changes before merge. :: [P3] Remove the release-owned changelog entry

@vincentkoc
vincentkoc force-pushed the fix/bounded-exact-publication branch from c168f76 to 093ffee Compare July 31, 2026 19:43
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 31, 2026
@vincentkoc
vincentkoc force-pushed the fix/bounded-exact-publication branch from 093ffee to a3d2086 Compare August 1, 2026 02:53
@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the proof: sufficient Contributor real behavior proof is sufficient. label Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the fix/bounded-exact-publication branch from a3d2086 to ee154dd Compare August 1, 2026 03:00
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient Contributor real behavior proof is sufficient. label Aug 1, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 1, 2026 03:08
@vincentkoc
vincentkoc requested a review from a team as a code owner August 1, 2026 03:08
@vincentkoc
vincentkoc merged commit 0925eca into main Aug 1, 2026
12 checks passed
@vincentkoc
vincentkoc deleted the fix/bounded-exact-publication branch August 1, 2026 03:08
azaj01 pushed a commit to azaj01/clawsweeper that referenced this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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