Skip to content

fix: release retired session metadata after short listings - #136567

Merged
steipete merged 1 commit into
mainfrom
codex/gateway-memory-ownership
Sep 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/gateway-memory-ownership

Conversation

@steipete

@steipete steipete commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves unnecessary memory retention after short session listings. Large metadata from a completed listing could remain alive until another request replaced the cached store, or the bounded cache evicted it.

Why This Change Was Made

The child-session candidate cache held every SessionEntry strongly to compare identities. Gateway RPC, embedded TUI, embedded tools, and startup prewarm all construct fresh combined entries, so those requests paid for a cache miss while retaining the preceding snapshot.

Remove that cache and its identity comparison, and use the existing request-local index for the selected parents. Live-controller, navigation-lineage, visibility, ordering, and freshness checks remain in their existing owner. A weak-reference cache would retain the redundant lookup path without useful cross-request hits.

Production: +6/-72 (net -66). Tests/test support: +79/-29 (net +50). The removed test asserted reuse of the retired cache; the replacement checks collection through the real list projection while preserving its returned child links. No schema, persistence, configuration, dependency-version, or public protocol change.

User Impact

Retired listing snapshots are no longer pinned by this derived cache. This is bounded over-retention, not a demonstrated unbounded leak. It does not establish that the separate event-loop saturation issue is solved.

Evidence

  • Baseline: aef65cc57490a5c67ca8dc934ac24225c6d1069c.
  • Heap snapshot: the strong retainer was the child candidate cache's entry map. A synthetic 384-entry fixture with 32 KiB summaries retained every entry and about 12.8 MB; the uncached control retained none.
  • Real SQLite -> combined-store -> Gateway list projection -> database close: 48/48 entries retained before, 0/48 after. Each fixture row carried a 32 KiB compaction summary; the returned parent still had all 47 child links. Uncached controls retained none.
  • The new GC regression fails on the baseline with both input entries retained and passes after the refactor. 293 focused/sibling cases pass, including child ownership, visibility, freshness and performance cases. Repeated after the frozen dependency refresh.
  • Fresh sourcePerformance build succeeds. Independent managed Codex review is clean through P2.
  • Real loopback Gateway on macOS/Node 26.8.1, isolated HOME/state: 32 turns, 48 seeds, 128 updates/4 clients, 3 history clients x 5 burst, 6 subscribers, visible observer, 100 ms cadence, 1000 ms mock stream delay. The unchanged concurrency harness was copied to an ignored artifact and only the list request changed to { limit: 1 } (plus import relocation), to exercise this path.
  • The live run passes unchanged 2000 ms control/handshake budgets, with zero operation failures or plugin metadata scans: readiness max 138.5 ms, sessions.list 310.5 ms, Control UI HTTP 420.6 ms, history p99 380.4 ms/max 381.9 ms, fresh connection 118.2 ms. Source/build inventories were unchanged and temporary state was removed.
  • Limitations: this uses a synthetic provider and HTTP/RPC probes, not a rendered browser or real-provider test. 40/44 readiness samples remained degraded; event-loop utilization was 1. No whole-Gateway memory percentage or universal latency improvement is claimed.
  • Two Blacksmith Testbox attempts stopped at baseline Git authentication before checks/comparison and both leases were stopped. They are not passing Linux proof. The supported local changed-code gate passes all 29 checks after refreshing already-declared missing dependencies with the frozen lockfile; no source workaround or skipped check.

Hosted CI: run 33676308549, attempt 2 passed on 321642251c725df0ce80d179f3ad3be71fae7b1a. The first attempt had 155 successful jobs and one cancellation before any step executed; one normal retry targeted that job, without changing source. The required CI gate is now green.

@steipete steipete self-assigned this Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review September 2, 2026 19:56
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 4:04 PM ET / 20:04 UTC.

ClawSweeper review

What this changes

The PR removes a cross-request cache that strongly retained session entries after short Gateway session listings and adds a garbage-collection regression test.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: the current main branch still retains full session snapshots through the short-list candidate cache, while the proposed request-local index removes that ownership without changing child-link resolution. No blocking correctness or security defect was found in the introduced patch.

Priority: P2
Reviewed head: 321642251c725df0ce80d179f3ad3be71fae7b1a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative owner-boundary repair with credible production-path and regression evidence; no actionable review defect was found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR body supplies after-fix live-output evidence for the production chain—real SQLite storage through the combined-store and Gateway list projection—reporting released entries after database close while the returned parent retains its child links. That directly matches the changed list-projection owner; the separate checked-in GC test is supplemental.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body supplies after-fix live-output evidence for the production chain—real SQLite storage through the combined-store and Gateway list projection—reporting released entries after database close while the returned parent retains its child links. That directly matches the changed list-projection owner; the separate checked-in GC test is supplemental.
Evidence reviewed 6 items Current-main retention source: Current main retains a process-level candidate cache; its entry map strongly references every SessionEntry in the prior short-list snapshot.
Production entry point and fresh owner boundary: The sessions.list handler loads a combined store for each listing, and the combined-store owner creates fresh entries while canonicalizing rows; the existing identity cache therefore retains an obsolete prior snapshot.
Introduced fix preserves the projection boundary: The new index is built from the current store for only selected parent rows; downstream child ownership, liveness, visibility, and ordering checks remain in the existing resolver.
Findings None None.
Security None None.

How this fits together

Gateway session listing loads a combined snapshot of agent session stores, derives child-session links, and returns lightweight rows to RPC clients, the TUI, and startup prewarm. This change removes a process-level derived cache between the fresh snapshot and that row projection.

flowchart LR
  A[Agent session stores] --> B[Combined session snapshot]
  B --> C[Gateway session listing]
  C --> D[Request-local child link index]
  D --> E[Lightweight session rows]
  E --> F[RPC clients and startup prewarm]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -66, Tests +50. Total -16 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 6 72 -66
Tests 3 79 29 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 85 101 -16

Review metrics

Metric Value Why it matters
Production versus test LOC production +6/-72 (net -66); tests/test support +79/-29 (net +50) The fix deletes the retaining production cache while adding a boundary-level GC regression; there is no unjustified production growth.

Technical review

Best possible solution:

Merge the request-local child-link index and retain the isolated GC regression so short listings cannot pin obsolete combined-store metadata.

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

Yes, source-reproducible with high confidence: current main stores every short-list snapshot entry in a process-level Map, while the added isolated GC test directly exercises the list projection and would retain those entries on the baseline.

Is this the best way to solve the issue?

Yes. The cache belongs to a derived, fresh combined-store projection and cannot safely provide useful cross-request identity reuse there; deleting it and retaining only selected request-local links is the narrowest owner-boundary repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0ad459206e68.

Labels

Label changes:

  • add P2: This resolves bounded memory retention in the Gateway session-listing path without evidence of a crash loop, data loss, or security boundary failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body supplies after-fix live-output evidence for the production chain—real SQLite storage through the combined-store and Gateway list projection—reporting released entries after database close while the returned parent retains its child links. That directly matches the changed list-projection owner; the separate checked-in GC test is supplemental.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.

Label justifications:

  • P2: This resolves bounded memory retention in the Gateway session-listing path without evidence of a crash loop, data loss, or security boundary failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body supplies after-fix live-output evidence for the production chain—real SQLite storage through the combined-store and Gateway list projection—reporting released entries after database close while the returned parent retains its child links. That directly matches the changed list-projection owner; the separate checked-in GC test is supplemental.

Evidence

What I checked:

  • Current-main retention source: Current main retains a process-level candidate cache; its entry map strongly references every SessionEntry in the prior short-list snapshot. (src/gateway/session-utils-core.ts:269, 0ad459206e68)
  • Production entry point and fresh owner boundary: The sessions.list handler loads a combined store for each listing, and the combined-store owner creates fresh entries while canonicalizing rows; the existing identity cache therefore retains an obsolete prior snapshot. (src/gateway/server-methods/sessions-read.ts:269, 321642251c72)
  • Introduced fix preserves the projection boundary: The new index is built from the current store for only selected parent rows; downstream child ownership, liveness, visibility, and ordering checks remain in the existing resolver. (src/gateway/session-utils-core.ts:266, 321642251c72)
  • Regression coverage: The isolated Node child keeps the returned list row, forces collection, asserts both original SessionEntry objects are released, and confirms the returned child link remains intact. (src/gateway/session-utils.child-cache-retention.test.ts:5, 321642251c72)
  • Current-main and release history: No introduced-path file changed from the PR base to fetched current main, so current main still has the cache. Recent Gateway session history associates the cache surface with commit 2911761, which is contained in v2026.8.2; partial-clone history lacks an older parent blob, so this is routing evidence rather than exact-line introduction proof. (src/gateway/session-utils-core.ts:269, 2911761ab94f)
  • Submitted real behavior evidence: The complete captured PR body reports an after-fix real SQLite → combined-store → Gateway list projection → database-close trace with 0/48 retained entries and preserved child links, plus focused/sibling validation. It is relevant to the production owner but was not rerun in this read-only review. (321642251c72)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 309c13a into main Sep 2, 2026
466 of 476 checks passed
@steipete
steipete deleted the codex/gateway-memory-ownership branch September 2, 2026 20:29
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant