Skip to content

fix(agents): release prompt diagnostics for retired sessions - #177614

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-retained-growth-diagnostic-buffers-20260919
Oct 19, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-retained-growth-diagnostic-buffers-20260919

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Releases prompt-cache diagnostic history when its conversation retires or its one-off Skill Workshop review finishes.

User Impact

Session reset, deletion, automatic rotation, shutdown, and completed Workshop reviews release their diagnostic fingerprints. Active conversations keep cross-turn cache-hit and history-rewrite comparisons. No configuration or migration is required.

Why This Change Was Made

The diagnostic tracker map had a 512-entry count limit but no session-lifecycle cleanup. Its key includes the session ID, so a retired session's baseline could never be reused. Two hour-long synthetic Gateway snapshots contained 84 trackers each (14.52 and 14.55 MiB), despite only four active workload children. Identity analysis also identified the legitimate parent conversation and one-off Workshop reviews; at least two of three retained reviews were obsolete because the scheduler permits only one review at a time.

The existing diagnostics owner now clears every affinity for a retired session through the session-resource cleanup registry. Automatic reply-session rotation calls that same owner, and the Workshop terminal owner releases its session resources. Provider resources are selected by exact session ID, preserving other conversations that share provider affinity. Detached persistence alone does not imply a disposable identity, so ordinary reusable detached callers retain their existing contract.

The production delta is +20 lines: the missing retirement operation and three lifecycle connections. No cache, timer, option, index, or duplicate tracking owner was added. Removing the baseline itself would break active conversations' documented diagnostic comparisons.

Evidence

The session cleanup and automatic-rotation regressions fail on the base (old 8,000-token baseline instead of null); the Workshop success/failure cases fail without its terminal cleanup. With the complete fix, the previously run owner/history/reset files pass 78 tests, and the Workshop file passes 12 tests. The owner/history/reset runner took 28.39 seconds; Workshop took 55.05 seconds wall time (34.61 seconds Vitest, using the existing persistence/admission integration fixture). Changed-file formatting and type-aware lint pass. The two import-closure files pass 22 tests. No Testbox/Crabbox lease was used.

Fresh independent Codex review of the complete seven-file patch is clean through P2. In CI run 39320492713 for exact head 733da4b85a62d0274014ce8fc1c2d880be02960e, all functional jobs passed. Two static-analysis jobs failed on the unchanged src/gateway/local-http-probe.test.ts; the aggregate gate reports those failures. No CI rerun was requested.

The inherited-failure exception is supported by the same diagnostics on the exact baseline 0548086d6a95525d7bad7f1905d2ae8c8d2de3ef in scheduled main run 39320267109:

Check PR job Baseline job Matching failure
check-test-types-core-4 118294934551 118292687907 Line 154: missing createDeferredCore (TS2304); line 178: implicit any (TS7006)
check-lint-core-1 118294934557 118292687840 Line 178: typescript(prefer-promise-reject-errors)

The affected test has identical blob cb50eabba3e6638baad1a3860e8f602449757f75 on the baseline, PR head, and inspected current main. The automatic summary labels these as new against the older completed run 39311481040; the newer exact-parent run above independently reproduces both failures. All four job logs were fetched once and their diagnostics compared. The changed code and focused regression/import-closure proofs remain green.

Gateway measurement

The committed memory-soak harness from #177548 runs a real Gateway, streamed responses from a synthetic provider, real tool execution, and eight viewers against a synthetic 5,000-session/6,000-run fixture. It uses synthetic transcript payloads, not production-sized transcript data, and Node 26.8.2. Each final pair uses one minute of warmup plus four measured minutes, four workload children, 100 streamed chunks at 10 ms, a three-second requested cohort cadence, and resets every two cohorts. Two baseline/candidate runs execute concurrently under an exclusive measurement lock; the CPU halves swap for pair two. The baseline is 0548086d6a95525d7bad7f1905d2ae8c8d2de3ef; candidate is 733da4b85a62d0274014ce8fc1c2d880be02960e.

Acceptance was recorded before these runs: equal completed turns/tool results, no retired workload generations, preservation of current child/parent baselines, and no completed Workshop review baselines. The initial exactly-four-total-trackers assumption was corrected after inspecting identities: the parent is legitimate, while completed one-off reviews require cleanup. A genuinely live review is allowed.

Both pairs completed equal work with zero errors: 61/60 cohorts per side, 244/240 turns and tool results, 156/152 resets, and 881/863 model requests. The request totals include equal foreground, tool continuation, and utility work within each pair.

Metric Pair 1: baseline → fix Pair 2: baseline → fix
Completed turns and tool results 244 → 244 240 → 240
Settled heap growth (MiB) 68.335 → 69.788 56.161 → 51.393
External growth (MiB) 1.841 → 1.775 1.530 → 1.471
ArrayBuffer growth (MiB) 1.846 → 1.780 1.549 → 1.490
RSS growth (MiB) 530.109 → 562.656 487.297 → 564.867
Sampled surviving prompt-diagnostic allocations (MiB) 1.566 → 0.141 1.596 → 0.063
All sampled surviving allocations (MiB) 70.363 → 72.692 57.824 → 55.681
Cohort completion p50 (ms) 2044.80 → 2035.29 2081.10 → 2090.79
Cohort completion p95 (ms) 2157.67 → 2147.44 2272.49 → 2272.48
Cohort completion p99 (ms) 2429.49 → 2355.43 2498.83 → 2425.12
sessions.list p50 (ms) 21.30 → 20.86 22.81 → 23.55
sessions.list p95 (ms) 43.44 → 39.58 45.49 → 48.24
sessions.list p99 (ms) 66.56 → 52.71 62.16 → 68.98
Process CPU (s) 158.90 → 160.06 162.49 → 171.02
Main-thread CPU (s) 71.31 → 70.74 74.97 → 75.69

The paired fixed-minus-baseline heap-growth differences are +1.45 and −4.77 MiB (mean −1.66 MiB): neutral overall. RSS growth increased by 32.55 and 77.57 MiB; final RSS was 0.5% and 2.3% higher, so this is not an RSS improvement. Process CPU moved +0.7%/+5.2%, and latency tails moved in both directions. The consistent win is lifecycle ownership: sampled prompt-diagnostic survivors fell by 91%/96%, and both final snapshots contain exactly five legitimate trackers (four current children plus their parent), retaining 93,272/163,096 bytes. No retired child generations or completed Workshop review trackers remain. The fixed code preserves active diagnostic behavior and releases obsolete state without a new retention policy.

This is a targeted ownership/retention fix. The earlier hour-long campaign did not reproduce the reported approximately 1 GiB growth in 90 minutes, and this short comparison does not establish overall one-hour memory flatness or explain all native allocations. No production deployment or restart is part of this PR.

@clawsweeper

clawsweeper Bot commented Oct 19, 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.

@steipete
steipete marked this pull request as ready for review October 19, 2026 19:03
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T20:38:28.883581Z 733da4b 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.

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Release retired sessions’ prompt-cache diagnostic baselines through existing session cleanup paths.

Example: Reset a session holding two cache-affinity baselines measured at 8,000 cached tokens.

  • Before: Both retired baselines remain retained until count-based eviction.
  • After: Both retired baselines are removed while another active session’s baseline remains available.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified defect, but the required after-fix performance evidence is not yet posted.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Repeated conversation retirement leaves unnecessary diagnostic history occupying Gateway memory.
Reason: The maintainer-authored direction repairs a demonstrated lifecycle omission while preserving active diagnostics and provider behavior.

Merge readiness

✅ Ready for maintainer review

This PR fixes a source-confirmed diagnostic retention bug with a focused change; no introduced correctness or security defects were found.

Priority: P2
Reviewed head: 3430586e98ba3c1f4f7e6f9092ac4e13ab36d0e5

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The declared post-fix Gateway comparison must show only four current-session trackers after repeated resets, preserved workload completion, and the paired memory results.
Agent review details

How this fits together

The embedded runner retains request fingerprints and cache telemetry for cross-turn diagnostics; session retirement now releases those process-local observations.

flowchart TD
 A[Model requests] --> B[Prompt diagnostic owner]
 B --> C[Session affinity baselines]
 D[Session reset or deletion] --> E[Existing cleanup paths]
 F[Gateway shutdown] --> E
 E --> B
Loading

Technical review

Best possible solution:

Keep this focused owner-held cleanup and complete its declared Gateway retention acceptance comparison.

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

Current-main source confirms retained tracker entries survive retirement until count-based eviction; the author also reports a Gateway reproduction, which this read-only review did not rerun.

Is this the best way to solve the issue?

The patch restores the missing lifecycle invariant at the existing diagnostics owner and connects both retirement paths without unnecessary architecture.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 18d7b2bf9be2.

Provenance checked

  • Retained diagnostic baselines keeps the original intent (c76646a: Introduce bounded cross-turn prompt-cache diagnostics without changing provider payload semantics.)
  • Diagnostic session identity keeps the original intent (8fb756e: Keep foreground and background request usage isolated by execution session even when provider affinity is shared.)
  • Reply-session resource retirement keeps the original intent (164bd67: Release retained fork context when its owning session retires; the patch adds diagnostics to that same lifecycle boundary.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ea7604a adds src/auto-reply/reply/session-reset-cleanup.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ea7604ac5f30; files: src/auto-reply/reply/session-reset-cleanup.ts)
  • Vincent Koc: Raw commit c76646a adds src/agents/pi-embedded-runner/prompt-cache-observability.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c76646adb135; files: src/agents/pi-embedded-runner/prompt-cache-observability.ts)
  • Ayaan Zaidi: Raw commit 164bd67 adds src/auto-reply/reply/session-reset-cleanup.ts:168 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 164bd6756af1; files: src/auto-reply/reply/session-reset-cleanup.ts)

PR surface

Source +18, Tests +51, Docs 0. Total +69 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 18 0 +18
Tests 2 51 0 +51
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 70 1 +69

Review metrics

Metric Value Why it matters
Production versus test growth Production +18 lines; tests +51 lines. Growth implements the missing lifecycle operation and covers two distinct retirement paths without new caches, timers, or indexes.

Labels

Label changes:

  • add P2: Retired diagnostic histories consume unnecessary Gateway memory, but the report establishes neither an outage nor unbounded growth beyond the existing tracker cap.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Retired diagnostic histories consume unnecessary Gateway memory, but the report establishes neither an outage nor unbounded growth beyond the existing tracker cap.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Post the declared baseline/candidate Gateway comparison results, redacting IPs, credentials, and non-public endpoints.

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.

Reviewed October 19, 2026, 3:21 PM ET / 19:21 UTC.

Release every cache-affinity baseline when its session resets, is deleted, or shuts down; automatic reply-session rotation uses the same owner. Preserve cross-turn diagnostics for active sessions.
@steipete
steipete force-pushed the steipete/perf-micro-retained-growth-diagnostic-buffers-20260919 branch from 3430586 to 733da4b Compare October 19, 2026 20:34
@steipete
steipete merged commit b61b080 into main Oct 19, 2026
137 of 143 checks passed
@steipete
steipete deleted the steipete/perf-micro-retained-growth-diagnostic-buffers-20260919 branch October 19, 2026 21:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged as b61b0809c63792c23df5ef68bc303882e146c134 under the authorized inherited-failure exception, with exact reviewed head 733da4b85a62d0274014ce8fc1c2d880be02960e.

All functional jobs passed. The two static-analysis failures in src/gateway/local-http-probe.test.ts reproduce on the exact parent in scheduled main run 39320267109: typecheck 118292687907 has the same TS2304/TS7006 diagnostics, and lint 118292687840 has the same prefer-promise-reject-errors error. The failing source blob is identical on base and PR. The automatic classifier used an older completed main run; the newer exact-parent evidence establishes inheritance. Full links and details are in the PR body. Security/dependency review passed, independent review was clean, and no CI rerun was requested.

The final paired Gateway results are now in the body: five legitimate trackers, zero retired child generations or completed Workshop review trackers, and 91%/96% fewer sampled prompt-diagnostic survivors. Total heap growth was neutral; no RSS improvement or one-hour flatness claim is made. The older review's pending measurement note is superseded by these results, including the legitimate parent-session baseline. No production deployment or restart was performed.

The native wrapper stopped before submission because its extra PR-review worktree was absent; the lane forbids additional worktrees, so the explicitly authorized exact-head REST fallback was used. Merge state and ancestry on main are verified.

vincentkoc added a commit that referenced this pull request Oct 19, 2026
* commit '08e32fdb4df002c9d4eea158b855d6521dd1e916': (52 commits)
  test(gateway): restore local probe deferred import
  fix(agents): release prompt diagnostics for retired sessions (#177614)
  fix(release): tag restart plugin cohorts consistently (#177725)
  refactor(ui): inline single-caller detail requests (#177705)
  chore(i18n): refresh native locales (#177721)
  refactor(codex): drop unread private runtime reports (#177689)
  refactor(ui): consolidate static artwork registries (#177692)
  refactor(ui): derive settings schema analysis in the view (#177624)
  refactor(media): consolidate capability defaults and compression grids (#177665)
  refactor(auth): bind OAuth managers to native provider operations (#177676)
  refactor(ui): remove redundant component rendering layers (#177607)
  fix(ios): model sign-in is a permanent row under the composer instead of an item in the model menu (#166082)
  fix(agents): report failed secret input prompt delivery (#177688)
  refactor(ui): share chat message render contracts (#177668)
  fix(ui): settle model status after overlapping publication (#177667)
  refactor(gateway): reuse native workspace and lifecycle facts (#177670)
  refactor(runtime): rely on canonical async lifecycle owners (#177635)
  refactor: fold private operation helpers into their callers (#177655)
  refactor(ui): remove unused chat leaf element adapters (#177582)
  perf(talk): use published authority for foreign voice writes (#177533)
  ...
vincentkoc added a commit that referenced this pull request Oct 19, 2026
#167350)

* fix(pr): retain the admitted workflow across maintainer commands

* fix: refresh the reviewed correction baseline

Baseline-Refresh: a89bd166b79d54b343b93ad374f8ebfa4f3d1163

* fix(pr): preserve cold workflow admission and repository identity

* chore(pr): integrate canonical main CI repair

* commit '08e32fdb4df002c9d4eea158b855d6521dd1e916': (52 commits)
  test(gateway): restore local probe deferred import
  fix(agents): release prompt diagnostics for retired sessions (#177614)
  fix(release): tag restart plugin cohorts consistently (#177725)
  refactor(ui): inline single-caller detail requests (#177705)
  chore(i18n): refresh native locales (#177721)
  refactor(codex): drop unread private runtime reports (#177689)
  refactor(ui): consolidate static artwork registries (#177692)
  refactor(ui): derive settings schema analysis in the view (#177624)
  refactor(media): consolidate capability defaults and compression grids (#177665)
  refactor(auth): bind OAuth managers to native provider operations (#177676)
  refactor(ui): remove redundant component rendering layers (#177607)
  fix(ios): model sign-in is a permanent row under the composer instead of an item in the model menu (#166082)
  fix(agents): report failed secret input prompt delivery (#177688)
  refactor(ui): share chat message render contracts (#177668)
  fix(ui): settle model status after overlapping publication (#177667)
  refactor(gateway): reuse native workspace and lifecycle facts (#177670)
  refactor(runtime): rely on canonical async lifecycle owners (#177635)
  refactor: fold private operation helpers into their callers (#177655)
  refactor(ui): remove unused chat leaf element adapters (#177582)
  perf(talk): use published authority for foreign voice writes (#177533)
  ...

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…w#177614)

* fix(agents): release prompt diagnostics for retired sessions

Release every cache-affinity baseline when its session resets, is deleted, or shuts down; automatic reply-session rotation uses the same owner. Preserve cross-turn diagnostics for active sessions.

* fix(skills): release completed review session resources
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
openclaw#167350)

* fix(pr): retain the admitted workflow across maintainer commands

* fix: refresh the reviewed correction baseline

Baseline-Refresh: a89bd166b79d54b343b93ad374f8ebfa4f3d1163

* fix(pr): preserve cold workflow admission and repository identity

* chore(pr): integrate canonical main CI repair

* commit '4f8617589b6c71d754171052b603fe534901bfa1': (52 commits)
  test(gateway): restore local probe deferred import
  fix(agents): release prompt diagnostics for retired sessions (openclaw#177614)
  fix(release): tag restart plugin cohorts consistently (openclaw#177725)
  refactor(ui): inline single-caller detail requests (openclaw#177705)
  chore(i18n): refresh native locales (openclaw#177721)
  refactor(codex): drop unread private runtime reports (openclaw#177689)
  refactor(ui): consolidate static artwork registries (openclaw#177692)
  refactor(ui): derive settings schema analysis in the view (openclaw#177624)
  refactor(media): consolidate capability defaults and compression grids (openclaw#177665)
  refactor(auth): bind OAuth managers to native provider operations (openclaw#177676)
  refactor(ui): remove redundant component rendering layers (openclaw#177607)
  fix(ios): model sign-in is a permanent row under the composer instead of an item in the model menu (openclaw#166082)
  fix(agents): report failed secret input prompt delivery (openclaw#177688)
  refactor(ui): share chat message render contracts (openclaw#177668)
  fix(ui): settle model status after overlapping publication (openclaw#177667)
  refactor(gateway): reuse native workspace and lifecycle facts (openclaw#177670)
  refactor(runtime): rely on canonical async lifecycle owners (openclaw#177635)
  refactor: fold private operation helpers into their callers (openclaw#177655)
  refactor(ui): remove unused chat leaf element adapters (openclaw#177582)
  perf(talk): use published authority for foreign voice writes (openclaw#177533)
  ...

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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