Repository navigation
fix(agents): release prompt history after completed runs - #176804
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7c833b53e
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a8e54d3 to
9604071
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9604071c12
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: needs maintainer review before merge. What this changesThis PR releases completed recovery payloads and retires attempt callbacks after accepted transcript writes drain. Example: An agent completes repeated image-bearing runs with three read tools and an output-limit recovery.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a demonstrated retention path still present on main; no introduced correctness defect was verified. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded runner carries recovery history between attempts, while session-manager guards transform and persist messages; cleanup must release completed history without interrupting accepted writes. flowchart TD
A[Agent RPC] --> B[Logical run prompt state]
B --> C[Embedded attempt]
C --> D[Guarded session manager]
D --> E[Transcript persistence]
C --> F[Transcript lifecycle drain]
F --> G[Release attempt callbacks]
B --> H[Release completed recovery payloads]
Technical reviewBest possible solution: Release recovery payloads at the logical-run owner and retire callback bindings only after their accepted writes settle. Do we have a high-confidence way to reproduce the issue? Source identifies the retained continuation and closure paths, supported by supplied baseline/fixed GC regressions and Gateway snapshot results; this review executed no reproduction. Is this the best way to solve the issue? The change uses the existing logical-run, session-manager, and transcript-drain owners without adding a competing cleanup manager, and preserves active recovery history. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 918a379c89cb. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +88, Tests +203, Docs +20, Other +169. Total +480 across 19 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 18, 2026, 10:59 PM ET / October 19, 2026, 02:59 UTC. |
9604071 to
1f2fe8e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f2fe8e391
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Release run-owned continuation history and per-attempt callback bindings without interrupting accepted transcript writes. Narrow retained writer and cache-touch callback scopes, and refresh callbacks when session managers are reused. Regression proof: three 20-attempt WeakRef checks fail on the base and collect every completed continuation with the fix. Add a synthetic image/tool/recovery Gateway workload for retained-heap measurements.
1f2fe8e to
907e353
Compare
|
Final head: 907e353. The final two swapped-core pairs and snapshot are in the PR body: 40 completed continuation envelopes retain zero prompt/messages; median cohort times are about 2.5% slower, with overlapping spread and mixed p95/CPU results. No speedup is claimed. Independent review is clean. The only underlying CI failure is checks-fast-baseline-ratchets at test/scripts/ci-node-test-plan.test.ts:3297 (ci-test-timings mock). The PR head, tested merge ff2b76604b05b5669cca5a15a78c28101f37a713, and main parent de561f3 have identical test/ledger blobs. Scoped reproduction using the actual native parser, scanner, and ledger predicate fails identically on all three with fingerprint 8c74b1e63618912d9ac86d6697e483f02edeae751b9edb61b44c668c7f9db59c. Its aggregate gates are the only other red checks; the remaining checks, including final test types and security review, passed or were intentionally skipped. Landing uses the standing inherited-failure exception; no CI rerun was requested. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…6804) * fix(agents): release prompt history after completed runs Release run-owned continuation history and per-attempt callback bindings without interrupting accepted transcript writes. Narrow retained writer and cache-touch callback scopes, and refresh callbacks when session managers are reused. Regression proof: three 20-attempt WeakRef checks fail on the base and collect every completed continuation with the fix. Add a synthetic image/tool/recovery Gateway workload for retained-heap measurements. * fix(agents): bind accepted transcript writes to their callbacks * fix(agents): release continuation payloads at their run owner * fix(agents): preserve run context for queued transcript writes * test(agents): use typed assistant fixture for retired cleanup
Merges upstream main at b90b2cf. - scripts/pr-lib/wrapper-components.txt: keep main's new inventory entries and this branch's 18 reference-collector imports; no entry is duplicated. - src/agents/embedded-agent-tool-media.ts: keep main's pushUniqueMessagingMediaUrl return value (openclaw#175022). collectStructuredMedia keeps this branch's capped, acceptMediaUrl-gated push, which already keys attachment metadata by the normalized accepted URL. - src/agents/session-tool-result-guard-wrapper.ts: main's openclaw#176804 gives each run its own transcript context and rebuilds it when a guarded manager is reused. The local-media trust set now lives on that context: the trustedLocalMediaToolNames option seeds it, setTrustedLocalMediaToolNames replaces it on the current context, and a reuse that passes no set inherits the previous context's, so a same-run helper keeps the run's trust and an accepted write keeps the set of the context it captured.
What Problem This Solves
Fixes heap growth when completed tool-heavy agent runs leave their full recovery prompts reachable through retained attempt callbacks and copied harness parameters.
User Impact
Completed runs release temporary recovery history. Active retries preserve their accumulated messages, and accepted transcript writes finish with the original run's prepared message, visibility, attribution, and callbacks. No configuration, schema, stored-transcript, or prompt-prefix change is required.
Why This Change Was Made
The logical run now releases the borrowed prompt/message payload when replacing a continuation and at disposal, including copies of its envelope retained by outer harness layers. Transcript preparation captures only needed fields; cache-touch completion captures only its timestamp.
A reused session manager captures one run context before append admission. That context owns transformations, callbacks, prepared user state, run ID, and persistence mode. Its cleanup runs after the actual transcript drain, including drains that outlast the bounded teardown wait. Old cleanup and old mode setters cannot mutate a newer run. Callback retirement preserves visibility and attribution needed for synthetic-result cleanup.
The change removes whole-attempt closure capture, shared mutable run policy, the positional rebinding API, and the callback-generation counter. Runtime code grows by 89 lines to preserve the accepted-write and retry-history contracts at these lifetime boundaries. The existing benchmark grows by 169 tooling lines plus 13 README lines to exercise tools, images, recovery, and post-GC resources; no new benchmark entry point or runtime manager is added.
Evidence
The original GC regressions retained all 20 continuations on baseline
c2549f8295d09f520f119de44d77e1c7dc25779a, while an unowned control collected. Each fixed regression retains zero:A separate regression keeps copies of completed attempt parameters alive: reachable message arrays fall from 40/40 to 0/40. It also protects message order and identity, caller-owned arrays, and recovery calls that omit new messages.
Delayed-write regressions failed before their corresponding fixes. They now prove that in-flight and queued writes retain the accepting run's callbacks, prepared envelopes, private visibility, assistant preparation, and run ID across rebinding. Other focused tests cover context-bound mode setters, synthetic cleanup after retirement, success/abort cleanup, prompt-prefix stability, and the benchmark protocol. The final context correction passed 113 tests across five guard/lifecycle files; its final fixture correction passed all 18 wrapper tests. Changed-file formatting/lint and independent review passed. The one permitted local core typecheck (native tsrs) passed before the final refinements; exact-head PR CI supplies the broad and final type proof. No Testbox/Crabbox validation lease or CI rerun was used.
Paired Gateway measurements
Acceptance rule: identical completed synthetic workloads and tool/recovery counts; collectible callback-owned continuations with a live GC control; no completed-continuation prompt payloads; no heap/timing regression beyond run variation. Two concurrent A/B pairs run under an exclusive lock on separate 16-core halves, swapping halves in pair 2. Compare candidate minus baseline within each pair.
Each side completes 110 runs (10 warmup and 100 measured, in cohorts of 10), with 300 read calls/results, 100 output-limit continuations/recoveries, and 300 image-bearing requests. Each synthetic fixture has 5,000 sessions, 6,000 retained runs, 200 approvals, 100 cron jobs, and 12 projects; its databases total 91,033,600 bytes (86.82 MiB).
Median cohort time increased about 2.5% in both pairs. Individual cohort times overlapped broadly (roughly 4.6–6.2 seconds); nearest-rank p95 shifted −0.87% / +0.90% (10 cohorts per side, so p95 equals the maximum). CPU changed −0.02% / +3.60%. These measurements do not establish a speedup or a material latency regression; the landing evidence is removal of retained continuation payloads. Other post-warmup heap growth remains.
Workload command, run concurrently for the two isolated artifacts under the CPU/lock rule above:
The final candidate side also used
--heap-snapshot.The final snapshot contains 40 reachable continuation envelopes from completed run IDs, all with empty message arrays and empty prompts. None of the five reported callback paths remains. An equivalent baseline snapshot from the prior identical-source/workload campaign had 37 nonempty envelopes with seven messages each. Unique string self bytes reachable through continuation payloads fall from 15,331,224 to zero. This is reachability accounting, not dominator-retained bytes or a claim that every byte was uniquely owned by those envelopes.
The runtime artifacts compare pinned baseline
c2549f8295d09f520f119de44d77e1c7dc25779aagainst that baseline with eight runtime source files captured from final head907e3536079ad39524c15bfd5fc2a852e5c6b249; all source hashes match. This isolates the selected files, not a full latest-main performance comparison. The workload uses real isolated Gateway RPCs with a synthetic HTTP model, ten reused child-session IDs, tools, and PNG input. It does not measure live-model or model-driven subagent spawning behavior.Build limitation: filtered runtime preparation hit unrelated Canvas-asset and baseline CLI-packaging checks. Both sides then used identical targeted runtime compilation/postbuild commands; no failed full build is represented as passing. A port-conflicted setup attempt was discarded and fresh fixtures used. Snapshot diagnostics retain their 30-second deadline; much larger snapshots can fail explicitly with a timeout.
PR CI
Final-head CI completed on
907e3536079ad39524c15bfd5fc2a852e5c6b249. Core/test types, focused owning lanes, and security review passed. The only underlying failure is the mock-export ratchet, plus its aggregate gates:test/scripts/ci-node-test-plan.test.ts:3297mocks../../scripts/lib/ci-test-timings.mtswithout pass-through/isolation annotation.This is inherited. The PR head, tested merge
ff2b76604b05b5669cca5a15a78c28101f37a713, and its main parentde561f3ea0b2f69dfacea6d3b4d67ca3e4989634have identical test and ledger blobs (8c5a6d152b15828c44931615b4102534aa2f1d29andd9c221e0b548925364ff34fdcba83f559008928f). A scoped reproduction on the benchmark host used the actual native parser, mock scanner, and ledger predicate on only that reported file/module: all three revisions exit 1 with the identical missing-factory fingerprint8c74b1e63618912d9ac86d6697e483f02edeae751b9edb61b44c668c7f9db59c. No full suite or global ratchet was run for attribution. The operator-authorized inherited-failure exception applies; no CI rerun or rebase was performed to chase green.The earlier PR-caused fixture type error was corrected using the existing typed assistant fixture and is green on this head. Independent reviews are clean; the two queued-write ownership findings are fixed. The optional larger-snapshot timeout suggestion is deferred with the limitation documented above.