Repository navigation
fix(gateway): stop session refresh loops and reuse run indexes - #156268
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: needs maintainer review before merge. Reviewed September 23, 2026, 2:49 AM ET / 06:49 UTC. ClawSweeper reviewWhat this changesReuse unchanged active-run indexes and subagent ancestor membership during Gateway session refreshes, with regression coverage for invalidation and time-sensitive reads. Merge readiness✅ Ready for maintainer review Keep open: the optimization remains useful on current main, and the introduced changes have no actionable correctness findings. The supplied production-handler replay supports the performance improvement while preserving response content. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway combines stored session rows with live run and subagent facts to produce session lists and updates. This change avoids rebuilding unchanged display indexes while retaining registry-owned invalidation. flowchart TD
A[Session refresh] --> B[Session row projection]
C[Run registry version] --> D{Facts changed?}
E[Subagent topology] --> D
B --> D
D -->|No| F[Reuse display indexes]
D -->|Yes| G[Rebuild display indexes]
F --> H[Current session rows]
G --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +23, Tests +192. Total +215 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep display-index reuse local to each projection, driven by registry-owned versions while refreshing clock-sensitive subagent views. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this is a performance optimization. Current source confirms the repeated work, and the supplied registered-handler replay measures its cost. Is this the best way to solve the issue? Yes. Reusing facts under the existing registry version is a narrow solution that preserves independent indexes and avoids a competing cache owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2e9a2eceb11b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Reuse the registry-owned version within each session-row projection, keeping independent index builders and current subagent clock views. Avoid rebuilding run and ancestor facts for unrelated row updates.
fbbb4e9 to
4a92ee5
Compare
|
Merged via squash.
|
…law#156268) * perf(gateway): reuse active-run facts during session refreshes Reuse the registry-owned version within each session-row projection, keeping independent index builders and current subagent clock views. Avoid rebuilding run and ancestor facts for unrelated row updates. * test(gateway): cover subagent registry refresh settling
What Problem This Solves
Persisting an already-absent subagent run can leave session refreshes spinning over an empty batch. Unrelated row updates also rebuild the complete active-run index and active-ancestor membership when the registries have not changed.
User Impact
Session refreshes finish after an already-absent subagent publication and avoid repeated projection work while keeping run status, model, ownership, and time-sensitive facts current.
Why This Change Was Made
The prepared-context fast path now checks the published subagent revision as well as the row epoch and snapshot, allowing a no-op persistence publication to settle. The existing run-registry version controls index reuse inside each session-row projection. Ancestor membership is reused only while both the run index and subagent topology are unchanged. Each projection and the public index builder still own independent maps, and subagent clock views continue to refresh.
Evidence
The owner and session-projection suites passed 108 tests on Linux with Node 24.19.0. A new regression starts with real persisted-registry publication and waits for
ensureMaterialized; it fails against the original guard. The final 16-case persistence/projection file passed, including the new regression in 2.14 s; its isolated command took 55.69 s. This real persistence and drain boundary is needed to reproduce the starvation loop. The additional test-only changed gate and independent P2 review also passed. The four new cases cover unrelated row epochs, model and identity changes, queue/owner/lifecycle/clear transitions, stale queue callbacks, map isolation, and subagent expiry. Fresh independent review through P2 found no actionable issues.check:changedpassed, including production types, all 25 core test-type partitions, lint, and guards. The new test file passed in 22 ms of test time; the isolatedpnpm test src/gateway/session-row-projection-context.test.ts --maxWorkers=1command took 26.75 s including 12.95 s of shared worker preparation.A matched Linux ABBA replay exercised the registered
sessions.listhandler over 513 stored rows, 512 active runs, and 511 subagent links. Each CPU batch included 16 unrelated stored-row updates and list requests; each variant has six measured batches. V8 allocation sampling includes collected objects.Stable-run index builds fell from 48 to zero per 48 measured calls; the genuine-change control retained all 48 builds. Normalized response digests match within both workloads; only the independently identified temporary store path in the response envelope was normalized. Superseded captured indexes were collected after run changes, while steady reuse retained the current index. RSS was higher in candidate samples, so no retained-heap or RSS saving is claimed.
These are synthetic session-list workload results, not aggregate production CPU measurements. Proof used Node 24.19.0 on one Linux x64 Testbox, with independent frozen dependency installs and verified source/log hashes. Testbox run.
The initial hosted merge ref hit the unrelated UI route-ownership type error fixed upstream in 813a10e7. This branch includes that repair.