Repository navigation
perf(gateway): reuse prepared display projections - #133203
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:55 AM ET / 08:55 UTC. ClawSweeper reviewWhat this changesThis PR refactors Gateway display preparation so session lists, status summaries, anchored history, and progress snapshots reuse per-request work instead of repeating scans, projections, copies, and byte counts. Merge readinessKeep this maintainer-authored Gateway refactor open for normal review. The introduced code preserves the reviewed list, history, progress, and status invariants, but the PR’s Codex Guardian contract assertion could not be independently checked because the required sibling Codex source checkout is absent and DNS prevented obtaining it. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway converts session, run, transcript, and progress state into display-safe RPC responses. These projections feed session lists, status output, history pages, and reconnect snapshots. flowchart LR
A[Session and run state] --> B[Gateway display preparation]
C[Transcript and progress events] --> B
B --> D[Session list]
B --> E[Status summary]
B --> F[History page]
B --> G[Reconnect snapshot]
Decision needed
Why: Repository policy requires direct inspection of that source before a Codex contract or merge verdict, and this read-only environment cannot obtain the checkout. Before merge
Agent review detailsSecurityNone. PR surfaceSource -24, Tests -1. Total -25 across 11 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single selected-parent projection and cached status-row approach, then verify the unchanged Guardian event contract against the actual Codex source before landing. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a behavior-preserving performance refactor, not a report of a current user-visible bug. Read-only source comparison supports its intended equivalence but did not execute target code. Is this the best way to solve the issue? Unclear: the selected-parent and accumulated-cost designs fit the existing owner boundaries and no introduced defect was found, but the stated Codex Guardian contract evidence cannot be confirmed here. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 039187abe405. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Gateway display requests repeatedly compute results they already have: bounded session ordering scans candidates that cannot enter the page, child-link projection evaluates parents outside the selected page, status builds the same completed row twice, anchored history repeatedly copies and recounts its growing window, and progress updates serialize retained events twice.
Why This Change Was Made
Keep preparation at the existing owners and carry its results through the request:
Production +146/−170, net −24; existing test-helper migration +2/−3, net −1, with its assertions retained. No config, schema, protocol, authorization or persistence change; no new dependency or process cache.
Contracts and Tradeoffs
The child-link refactor preserves the two existing registry read policies. A real external SQLite writer demonstrated that the scalar and prepared registry caches can differ within their existing 500 ms lifetime. Short-list reads still use the scalar policy, including its stricter missing-controller behavior; prepared lists keep their snapshot. Hidden children, current controllers, explicit navigation parents, recent terminal links and active descendants remain covered.
Status now deliberately returns the same completed ACP/runtime projection in the per-agent and aggregate views of one summary, even if a backend changes between those phases. Later requests read again. It keeps the first scalar ACP read and its legacy-binding behavior; the batch ACP API is not substituted.
History retains exact sequence groups, first matching anchor, older-before-newer growth, independent blocked directions, oversized-group fallback and archive metadata. For a nonempty JSON array, its cost is one framing byte plus the sum of each message's bytes and separator. Progress keeps sequence rejection, first-seen preamble time, independent Guardian review IDs, strict-review resolution and whole-tool eviction. Native Codex Guardian contracts were checked directly; no approval behavior changes.
Measurements and Verification
Fresh Node 26.8.1 processes, opposite starting orders, uninstrumented complete owners and retained raw samples:
These are local owner/workload measurements, not whole-turn or network latency claims. Small controls are retained: already favorable top-N ordering is 1.7–4.1% slower; short/grouped history selections can cost an extra 0.03–0.08 µs; several tiny list/status/progress cases are noisy or slightly slower. No isolated memory saving is claimed.
Source-bound probes cover 4,960 top-N outputs, 52 complete SQLite-backed status comparisons with 652 identities, 6,768 anchor outputs with 61,391 identities, 189 child comparisons including 174 complete lists, and 8,461 progress comparisons with 25,352 snapshot identities. Mutable nested payloads, real external writer state and final DTO identity are explicitly exercised.
The baseline and initial candidate both passed 471 selected tests across 11 files, including real Gateway history tests for anchors, archives, rejected selectors and byte budgets. The initial changed-file gate passed all type/boundary/dead-export checks but rejected an invariant sequence condition in two loops; the final form restores the original early return without a suppression. Final local checks and live evidence follow; hosted CI must be green before landing.
Final local changed-file checks passed in 190.75 seconds, including core/test types, lint, boundary/dead-export/import and state guards. The 15 affected history checks passed again after the loop cleanup. Independent source review is clean; the fresh automated Codex review reported no actionable findings at its configured P0 threshold. The patch was rebased unchanged onto merged main
5cb702d464a7869e3a1dc4b6f85361d91f3e4291; the published head is28435c17c5a10bddae877fef233fd5e82e4a90a5. All 471 selected tests passed again at that head, followed by a fresh build in 166.34 seconds.At that exact published head, the isolated real-OpenAI Gateway completed a three-turn chat conversation with two actual
web_fetchcalls, then a separate native web-search turn. A newly connected read-only client recovered the active run and retained tool progress with the exact run/tool identity. Real transcript anchors at limits 1/3/100, bounded session ordering, matching aggregate/per-agent status, restricted status, terminal cleanup, and unchanged baseline previews/tool inventories/catalog passed 81 assertions across 32 RPC calls. Node CPU profiles were retained and the owned Gateway stopped cleanly. The live run does not simulate child-controller concurrency or Guardian approvals; those retain the complete-owner and canonical test evidence above.Landing Review
The latest ClawSweeper review found no introduced code defect but could not obtain the sibling Codex checkout in its environment. The maintainer directly inspected the local public Codex checkout at
6478a751fde8884b2fdc76486fe23175a8e795d4: Guardian started/completed notifications and assessment lifecycle identity. At that source version, stable review IDs, optional targets and multiple reviews per command match the retained projection behavior; the refactor still replaces only the matching review and preserves standalone/strict-review handling. A second independent reviewer checked the producer and notification mapping too. This resolves the source-inspection limitation. The rank-up request for exact-head Gateway validation is satisfied by the build/live proof above. Maintainer review accepts the scoped status-snapshot choice and disclosed small timing costs; exact-head CI run 33302579327 is now green.