Skip to content

perf(agents): release caller contexts from custody abort reasons - #185647

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-subagent-custody-abort-reason-stacks-20261027
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-subagent-custody-abort-reason-stacks-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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 materializeErrorStack helper. 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.ts invokes the real SessionFollowupCompletion.bind/close owner, holds requests through a three-deep AbortSignal.any chain, and creates Errors inside an assertDispatchCurrent-style closure. Four forced GCs test whether transient caller payloads survive. Baseline is 0957af25689d833a3afe685f0c723c77a1c68e78 with only import relocation for loading the exact baseline owner.

Owner measurement Base Candidate
Retained heap, 16 × 7 MiB caller contexts 117,514,384 B 57,384 B
Retained heap per held reason 7,344,649 B 3,587 B
Caller payloads surviving GC 16 0
Process CPU per lifecycle operation 19.457 µs 29.987 µs
Sampled allocation per lifecycle operation 10,305 B 14,171 B

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-released retention assertion fails on baseline (16 surviving payloads) and passes on the candidate (zero). The regression in session-followup-completion.test.ts also 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):

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-custody-abort-retention.ts --owner /absolute/baseline-owner.ts --mode retention --operations 16 --expect-released
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-custody-abort-retention.ts --mode retention --operations 16 --expect-released
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-custody-abort-retention.ts --mode timing --operations 5000
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-custody-abort-retention.ts --mode allocation --operations 5000

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:

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.

@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-27T07:59:16.906242Z 1d3027a New commits
ℹ️ 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 scripts Repository scripts agents Agent runtime and tooling size: M 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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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 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.

  • Before: All 16 caller payloads survive garbage collection.
  • After: Zero caller payloads survive, while cancellation preserves the original Error identity.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with useful owner-level measurements; proof remains below the shipped entry point and exact-head CI is pending.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied owner measurements exercise bind/close with composed abort signals and show payload release, without claiming whole-Gateway coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Finished or cancelled subagent work can keep otherwise-unused caller contexts alive.
Reason: Measured retention release supports the narrow fix, and the maintainer-authored PR explicitly accepts the additional failure-path CPU and allocation cost.

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
Reviewed head: 1d3027ad32a926e71624dfeb97142a3e6e85d521

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises the real completion owner rather than a shipped Gateway cancellation flow.
Agent review details

How this fits together

Subagent 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]
Loading

Technical review

Best 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

  • Announcement deadline keeps the original intent (7a168d3: Private completion handoffs separated observer deadlines from underlying admitted work.)
  • Announcement admission and execution revocation keeps the original intent (36e277d: Session-controller ownership retained cancellation and source checks around admission and execution.)
  • Followup result custody keeps the original intent (a94ad94: Followup completion moved from Tasks into the session/subagent owner while preserving result custody and cancellation.)
  • Announcement cleanup expiry keeps the original intent (d8e684e: Lifecycle consolidation preserved existing delivery deadlines and cleanup ownership.)
  • Recovered requester revocation keeps the original intent (674cebf: Recovered channel children retain exact-session authority, with replaced requester sessions remaining terminal.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +18, Tests +93, Other +157. Total +268 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 27 9 +18
Tests 2 93 0 +93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 157 0 +157
Total 7 277 9 +268

Review metrics

Metric Value Why it matters
Runtime versus regression coverage Runtime +27/−9 lines; tests +93/−0 lines Runtime growth formats existing reason objects before publication; regressions cover owner cancellation and three distinct announcement abort triggers.

Labels

Label changes:

  • 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.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Retained cancellation reasons can prolong caller-context memory use, with no demonstrated outage or urgent user-facing regression.
  • 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.

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 (1 earlier review cycle)
  • reviewed 2026-10-27T07:54:31.521Z sha 14213d1b3266e25193518002b76e85f1ffa51fdc :: needs changes before merge. :: [P2] Assert the existing lifecycle error message | [P2] Account for the probe's new lint suppression

Reviewed October 27, 2026, 4:04 AM ET / 08:04 UTC (Revision 2).

@steipete
steipete force-pushed the steipete/perf-subagent-custody-abort-reason-stacks-20261027 branch from 14213d1 to 1d3027a Compare October 27, 2026 07:57
@steipete

Copy link
Copy Markdown
Contributor Author

Fixed both findings on 1d3027ad32a926e71624dfeb97142a3e6e85d521: the tests assert the existing complete lifecycle message, and the probe uses Array.from without a lint suppression. Also corrected the probe type to use the public bind() factory. The suppression guard (14 tests), scripts typecheck, and independent follow-up review pass. Both benchmark arms were remeasured and the PR evidence is current; replacement-head CI is running.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landing at exact head 1d3027a over two pre-existing red shards, unrelated to this change.

checks-node-changed-compact-small-8 and -11 fail in src/agents/subagents/registry/subagent-control.worker.test.ts (four "subagent progress drafts" cases: expected 0 calls, got 1) and src/agents/subagents/announce/subagent-announce.requester-settle-dispatch.test.ts ("one undelivered, NO_REPLY"). The same cases fail on scheduled main run 40463504008 at 9b7db694b593, before this PR. This change only materializes abort-reason stacks before abort()/reject() at six producer sites; identity, messages and cancellation behavior are unchanged.

No reruns. The main-side failures get their own root-cause fix.

@steipete
steipete merged commit 7c1971c into main Oct 27, 2026
154 of 158 checks passed
@steipete
steipete deleted the steipete/perf-subagent-custody-abort-reason-stacks-20261027 branch October 27, 2026 08:13
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…nclaw#185647)

* perf(agents): release caller contexts from custody abort reasons

* test(agents): fix custody abort retention proof checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. 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