Repository navigation
perf(agents): release caller contexts from custody abort reasons - #185647
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR materializes retained cancellation Error stacks at existing subagent completion producers. Example: The supplied owner benchmark holds 16 cancellation reasons created inside 7 MiB caller contexts.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a focused retention fix that current main still needs; both previous findings are resolved, and no new actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSubagent completion owners receive cancellation, authority-revocation, and deadline events and publish abort reasons or rejected results to waiting callers. flowchart LR
A[Cancellation or deadline] --> B[Existing completion owner]
B --> C[Materialize Error stack]
C --> D[Abort signal or rejected result]
D --> E[Waiting caller]
C --> F[Caller context can be collected]
Technical reviewBest possible solution: Materialize retained reasons at their existing producers while preserving cancellation identity, settlement, and authority checks. Do we have a high-confidence way to reproduce the issue? Current main retains unformatted Errors in abort signals and rejected results; the supplied baseline owner measurement reproduces retained caller payloads, but this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes retention at existing producers using the established helper, without adding a cancellation owner or changing dispatch policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aedd9f3f5658. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +18, Tests +93, Other +157. Total +268 across 7 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 HistoryReview history (1 earlier review cycle)
Reviewed October 27, 2026, 4:04 AM ET / 08:04 UTC (Revision 2). |
14213d1 to
1d3027a
Compare
|
Fixed both findings on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landing at exact head 1d3027a over two pre-existing red shards, unrelated to this change.
No reruns. The main-side failures get their own root-cause fix. |
…nclaw#185647) * perf(agents): release caller contexts from custody abort reasons * test(agents): fix custody abort retention proof checks
What Problem This Solves
Aborted subagent completion custody can retain an entire caller context through V8's lazy Error stack, even after the caller has finished.
User Impact
Subagent cancellation and expired completion delivery release captured caller state while preserving the same Error objects, messages, cancellation signals, and authority checks. No configuration or migration is required.
Why This Change Was Made
Materialize retained reasons at the six custody/deadline abort producers using the existing
materializeErrorStackhelper. Also materialize the followup owner's rejected result, preserving the two distinct default Error objects. This completes the subagent abort paths without introducing another cancellation owner or changing dispatch assertions.Runtime production code grows by 27 insertions / 9 deletions (net +18 lines; the standalone benchmark adds 157 lines): each existing producer must keep its reason object while formatting it before publication. This is a retention fix with an explicit CPU/allocation tradeoff, not a reduction in per-abort work.
Related: #185584. There is a same-file overlap with #184243's announcement dispatch wrapper; this PR only adds materialization at its abort producers.
Evidence
Final head:
1d3027ad32a926e71624dfeb97142a3e6e85d521. Exact-head CI run 40470284236 is complete: this PR's corrected announcement tests, suppression guard, typechecks, and lint pass. CI remains red solely for the two inherited sibling-test shards documented below. Independent review is clean; the PR is ready and unmerged.The committed
scripts/perf/subagent-custody-abort-retention.tsinvokes the realSessionFollowupCompletion.bind/closeowner, holds requests through a three-deepAbortSignal.anychain, and creates Errors inside anassertDispatchCurrent-style closure. Four forced GCs test whether transient caller payloads survive. Baseline is0957af25689d833a3afe685f0c723c77a1c68e78with only import relocation for loading the exact baseline owner.Timing and allocation each use five counterbalanced pairs, 5,000 operations per arm per pair (25,000 per revision per mode), with 100 warmup operations. Allocation uses separate inspector passes at a 1 KiB interval. CPU and allocation include owner binding, a small synthetic context, cancellation, signal composition, and identity checks. Eager formatting costs +10.530 µs CPU and +3,866 B temporary allocation per operation, releasing about 7 MiB of retained caller payload in the retention fixture. Host one-minute load ranged 50–59; each arm records host load and RSS. These are owner measurements, not whole-Gateway CPU or latency claims.
The
--expect-releasedretention assertion fails on baseline (16 surviving payloads) and passes on the candidate (zero). The regression insession-followup-completion.test.tsalso fails on main before materialization and checks that cancellation observers see formatted reasons while identity, cause, message, and release behavior remain intact. Announcement tests cover deadline expiry, admission rejection, and execution-time revocation.Commands (baseline owner uses its original source with imports relocated to the checkout):
Independent subagent review (autoreview route unavailable): clean, no actionable P0–P2 findings. The configured Codex autoreview route was refused because it did not match the operator configuration; the authorized fresh-context review fallback was used. Targeted core and scripts typechecks and changed-file lint/format pass. The baseline owner regression failed as expected; the candidate owner file passed all 11 tests (new regression: 5 ms) before a separate announcement artifact check invalidated that combined invocation. The two closure guard files passed all 29 tests (264.6 seconds wall on this busy host), the suppression guard passed all 14 tests (91.2 seconds), and the export-name guard passed. Subsequent Bun and Node owner/lifecycle reruns stalled without an assertion failure and were stopped; the completed exact-head CI run supplies the final validation. An earlier combined invocation was invalidated by source formatting during compilation, and was not counted as a passing run. No Testbox was allocated. The owner proof establishes the retention mechanism, but cannot uniquely identify the abort origin in a deleted heap snapshot. No live deployment was touched. Whole-Gateway stress was omitted for this terminal-retention change; server handler latency, event-loop p99, and GC s/min are not measured here.
Initial CI caught the benchmark's suppression and private-constructor type and an abbreviated expected error message in the new test; all three proof-only defects were corrected, and both arms were remeasured with the final benchmark. Production cancellation behavior was unchanged by those corrections.
Inherited CI failures
The first PR run also reproduced five pre-existing assertions in two sibling files. Scheduled main run 40463504008, head
9b7db694b593cd2b498d704611414a8659fe7ffb, has matching failures:subagent-control.worker.test.ts, job 122053694079: four progress-card/result-recovery cases, identical expected-zero/actual-one assertions at lines 616 and 686.subagent-announce.requester-settle-dispatch.test.ts, job 122053694034: the “one undelivered, NO_REPLY” case, identical expected-false/actual-true assertion at line 316.That main head is an ancestor of the first PR base; both failing tests and the relevant completion-policy owners are unchanged between them. The nearby intervening spawn change only moves storage-acquisition imports. These are not classified from job names alone. The repaired head reproduces exactly the same five assertion signatures in job 122076075207 and job 122076075272. All other CI test shards and static checks pass. No CI reruns were requested to chase these inherited failures.