Repository navigation
fix(gateway): keep event lineage current across session lifetimes - #158581
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. |
Preserve the relocated sharing-entry constructor and main archive metadata while retaining the reviewed lineage owner changes.
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 12:13 AM ET / 04:13 UTC. ClawSweeper reviewWhat this changesThe branch replaces the Gateway’s permanent parent-session cache with current session-projection and private-store metadata when adding lineage to chat and agent events. Merge readiness✅ Ready for maintainer review Keep this PR open. Current main still retains the first lineage lookup for the lifetime of the event handler, so the central defect remains. The inspected patch has no definite introduced correctness defect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives agent events and turns them into chat and agent event payloads for connected clients. Its session projection supplies parent-session facts from committed rows and open incognito stores. flowchart LR
A[Agent events] --> B[Gateway event handler]
C[Session key] --> B
B --> D[Session projection]
D --> E[Committed session metadata]
D --> F[Open incognito store]
E --> G[Current parent session]
F --> G
G --> H[Chat and agent events]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +29, Tests +57. Total +86 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep lineage with the session projection’s committed facts and lifecycle invalidation, then land the focused fix through normal review. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main permanently caches an eligible session’s first lineage result, so a later publication cannot change that handler’s answer. The PR reports a failing baseline regression; this read-only review did not run it. Is this the best way to solve the issue? Yes. Reading committed facts through the existing session projection removes the competing cache and follows row and store lifetimes without adding a persistence format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c88ac865e19c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…enclaw#158581) * perf(gateway): use prepared session lineage for agent events * fix(gateway): preserve canonical lineage through main aliases * refactor(gateway): name the stored lineage lookup key
What Problem This Solves
Fixes stale parent-session attribution and permanently retained lineage lookups when many Control UI sessions are created, replaced, or removed.
User Impact
Agent and chat events follow current prepared controller and parent-session facts. Deleted sessions, closed incognito stores, and disposed projections no longer retain a cached parent. Optional enrichment can be absent while its owner prepares facts. No protocol, configuration, or SQLite schema changes are required.
Why This Change Was Made
The event handler used a permanent map for both successful and missing lineage lookups. Its initial lookup could also read SQLite on the Gateway thread. Events now consume the session projection owner and writer-published incognito metadata without materializing rows or rebuilding registry indexes during ingestion. Stored lineage remains canonical even when display aliases differ.
The lineage reader lives with existing projection relation reads; the sharing-entry constructor moved beside its type to keep both modules within their line caps. Production grows by 29 lines because preserving canonical selection and private-store lifetimes needs more than deleting the obsolete map.
Evidence
node scripts/run-vitest.mjs src/gateway/server-chat.subagent-lineage.test.ts src/gateway/server-chat.agent-events.test.ts src/gateway/session-row-projection.incognito.test.ts --maxWorkers=1: 234 passed, 731.57 s wall before the behavior-preserving helper extraction. Lineage cases subsequently consolidated onto one admitted physical store and projection, retaining all lifecycle assertions.node scripts/run-vitest.mjs src/gateway/server-chat.subagent-lineage.test.ts src/gateway/session-resource-tool-policy.test.ts --maxWorkers=1: 16 passed; 1,201.11 s wall. The lineage test took 44.694 s on this run; the real writer/projection/ephemeral-store composition cannot be protected by a mocked lookup test. One shared fixture covers all transitions; no polling, sleeps, or Gateway boots were added.node scripts/check-changed.mjs: 2,431.90 s wall; all production and 25 test type graphs, structural guards, and dead-export scans passed. Final lint found one shadowed local parameter. Renamed it without changing behavior; the exact changed-file lint command replay passed (exit 0), 141.73 s wall. Formatting and line-cap checks passed again. Earlier valid functional and type proof is reused for this naming-only correction.node scripts/run-vitest.mjs src/gateway/server-chat.subagent-lineage.test.ts --maxWorkers=1: passed, 461.70 s wall / 33.410 s test time, including zero-SQL assertions for all lifecycle and alias transitions.c516733b626827edd2c8bcef9c6087b61f4c5a03.Landing verification
Merged current main
76e32e92441321b2e564263bc385cc7f4cc8ecd7into the reviewed branch without rebasing. The sole textual conflict was the relocated sharing-entry constructor: the resolution preserves main'sarchivedAtand this change'sspawnedBytogether. Main's chat projection and presence work remains intact. Candidate:f4f0728cacf5fb7e71ab269dc764496d0475bc1e.tbx_01m3dv1hc5rz7xczgwkrx99h6n:node scripts/check-changed.mjs --base origin/mainpassed, 1,597.70 s command wall. Production and all 25 test type graphs, structural guards, dead-export scans, and lint passed. Source hashes were verified. Run. The box is confirmed stopped/completed; its backing workflow may show cancellation from normal delegated lease cleanup. Runner portal sync warned after the successful command and confirmed shutdown.origin/<branch>base, and Blacksmith does not support the generic--stop-afterflag. Exactly one Testbox was allocated.f4f0728cacf5fb7e71ab269dc764496d0475bc1e; repository watcher returnedGREEN. No failed jobs or test reruns. The watcher retried one read when the rollup changed during pagination.