Skip to content

perf(process): release contexts retained by long-lived error stacks - #185584

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-long-lived-error-stack-retention-20261027
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-long-lived-error-stack-retention-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Long-lived process cleanup failures and revoked automation capabilities can keep expired execution contexts reachable through V8's unformatted Error stack frames.

User Impact

Releases those otherwise-unused contexts while preserving the original error object, error class, message, code/status, cause, and shutdown/abort behavior. No configuration or migration is required.

Why This Change Was Made

Materialize stacks at the supervisor cleanup-failure holders and cron capability abort boundary using the existing infrastructure helper. Keep formatting best-effort for immutable errors and opaque diagnostic getters so diagnostic work cannot replace a cleanup failure or prevent revocation. The prepared-model-runtime detached snapshot serves a different contract (dropping plugin prototypes and cause graphs) and remains unchanged.

This is a retained-memory tradeoff: eager formatting adds work on failure/revocation, with no change to the successful process or active-authority paths. Production runtime code grows by 13 net lines to cover the missing retention boundaries while preserving error identity; no cache, copied error representation, or competing owner is added.

Evidence

Node 26 owner harness, synthetic 10,000-session/40-plugin closure contexts; actual production owners with a synthetic child-process I/O adapter. Baseline: 2f81eacee9b2f91906265280897d4997960d440d. Five alternating base/candidate runs, 3,000 iterations per arm per run (15,000 per arm total); timing and sampled allocation run separately. Heap runs hold 16 independently-created contexts per arm and collect after stack frames unwind.

Owner / metric Base Candidate
Supervisor retained bytes / held error 1,702,256 3,887
Cron retained bytes / held reason 1,700,022 749
Supervisor contexts still reachable 16 / 16 0 / 16
Cron contexts still reachable 16 / 16 0 / 16
Supervisor CPU, median µs / operation 39.38 63.26
Cron CPU, median µs / operation 6.54 22.62
Supervisor sampled allocation, median bytes / operation 32,026 35,926
Cron sampled allocation, median bytes / operation 4,400 10,511

CPU ranges were 38.43–52.17 → 55.48–82.06 µs (supervisor), and 5.47–7.42 → 21.29–27.12 µs (cron). Host one-minute load ranged 56–84 across arms. This does not establish a whole-Gateway CPU or latency gain: it exchanges about 16–24 µs and 4–6 KB per failure/revocation for releasing the expired contexts. The retained-byte result depends on the size of the caller's context. Uses the lane's cold-owner fast-path proof exception; no live server load test was run.

Reproduce with the usage in scripts/perf/long-lived-error-stacks-measure.ts (--owner supervisor|cron, --mode timing|allocation|heap, --base-dir for saved baseline owner sources). Formatting a small standalone held Error also changes a WeakRef payload from retained to collected.

Two owner GC regressions exercise real lifecycle boundaries and preserve error identity/type/status; a formatter regression covers immutable/opaque diagnostics. Focused Node validation passes all 76 tests (supervisor 39, cron grants 28, error helper 9); test-file durations 3.41 s, 7.00 s, and 1.57 s respectively. Scoped oxfmt/oxlint, the export-name collision guard, and both import-closure files pass (29 closure tests, 245.89 s test duration). Independent subagent review (autoreview route unavailable) is scoped-clean at P2. The final two GC regressions and immutable-diagnostic regression all fail on the saved baseline source for the intended reasons and pass on the candidate. Exact-head CI is tracked in the PR workflow. PR CI owns broad validation.

@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.

@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-27T06:42:37.757428Z c648145 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.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: c648145253468b6e15dbecfd4150e89747fef3f0
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/cron-creator-authority-grant.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete
steipete merged commit c579c55 into main Oct 27, 2026
140 of 142 checks passed
@steipete
steipete deleted the steipete/perf-long-lived-error-stack-retention-20261027 branch October 27, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant