Repository navigation
fix(gateway): session lists stall after identity-scope changes - #156339
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs real behavior proof before merge. Reviewed September 23, 2026, 6:03 AM ET / 10:03 UTC. ClawSweeper reviewWhat this changesThe Gateway reuses prepared session rows across identity-scope-only reloads and retains catalog facts while their replacement is pending. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this remains a distinct, useful fix absent from current main. The reviewed patch preserves the existing authorization and invalidation boundaries, and no actionable correctness defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway’s session projection combines stored session records, configuration, and model catalog facts into rows for session-list requests. Request authorization remains separate from these cached display facts. flowchart TD
A[Configuration publication] --> B{Only identity scopes changed?}
B -->|Yes| C[Retain prepared session rows]
B -->|No| D[Refresh affected facts]
E[Model replacement settles] --> D
D --> C
C --> F[Current request authorization]
F --> G[Session list response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +275, Docs +2. Total +343 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep cache reuse confined to unchanged session facts, with current access policy and model-replacement settlement controlled by their existing owners. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main broadly invalidates resident rows on identity-scope publication and can adopt an unavailable catalog during replacement. The registered-handler regression targets that path; this review did not execute it. Is this the best way to solve the issue? Yes. The patch extends the existing projection and lifecycle owners with narrowly guarded reuse, without adding settings, persisted state, or a competing authorization path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6b4ebc043bc8. 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.
|
…law#156339) * fix(gateway): retain session facts across identity-scope reloads * test(gateway): preserve operator scope types in reload fixtures
|
Complementary follow-up: #159939 has merged. This PR retains prepared session rows and catalog facts during identity-scope reloads; the follow-up preserves verified WebSocket connections and accepted runs when another login's grants change. The fixes address different effects of the same reload, and neither replaces the other. |
What Problem This Solves
Fixes: session lists repeat expensive database reads and row rebuilding when an operator changes identity scopes and clients reconnect.
User Impact
Identity-scope-only hot reloads retain already prepared session data while applying the current access policy. Changes that affect session data, model facts, or resolution provenance still refresh it. There are no schema changes, migrations, new settings, or required operator actions.
Why This Change Was Made
Config publication previously invalidated every resident row even when only identity scopes changed. During the ensuing model-runtime replacement, a temporarily unavailable catalog could cause another rebuild before the identical completed catalog returned.
The projection now advances its config without invalidating unchanged rows for that narrowly checked change. It also retains loaded catalog facts until the model owner's existing replacement promise settles, including failure and supersession. Permission revocation, current authorization, forced invalidation, same-object publications, and queued session writes keep their existing owners and behavior.
Evidence
The registered
sessions.listregression failed before the fix by rereading unchanged live and archived rows. It now covers scope addition/change/removal, a concurrent committed session change, changed model facts and resolution provenance, forced invalidation, and same-object publication.A synthetic managed reload exercised secrets publication, hot reload, prepared-model replacement, the resident projection, and 19 concurrent registered list calls. Before catalog retention it performed four row reads and three materializations for two sessions; afterward both counts are zero, with the same returned rows and model facts. Providers and service handles were synthetic; this did not boot real Gateway sockets or the installed plugin inventory.
A separate 4,000-session snapshot-publication reproduction went from 63 worker batches rereading and rebuilding all 4,000 rows to zero rereads and rebuilds. This establishes eliminated work, not a calibrated production latency claim.
127 focused tests pass across session projection, connection-policy revocation, model lifecycle, auth reload, and catalog publication. Fresh independent review found no actionable P0–P2 defects. Production typechecking passed. Initial CI caught four scope-array inference errors in the new test fixture; the fixture now uses the canonical operator-scope type and explicit config types. Its exact
gateway-methodstypecheck and registered regression pass locally, and the test-only correction has a fresh clean review. The full changed-file gate now passes, including production and all 25 test type graphs, lint/format, dead exports, import cycles, and repository guards. Hosted CI run 35836666118 passes on head4e7d100069437675ee0d1af0ba64e5e1d6b12147(128 successful jobs, 16 intentional skips). The completed exact-head ClawSweeper review reports no correctness or security findings; its proof request is addressed below.Integration with main
e331b970664a4f8b923e136e348b0e47f98cbe81, which includes the registry-refresh fix in fix(gateway): stop session refresh loops and reuse run indexes #156268, passes all three selected regressions together: identity-scope reload, pending catalog replacement, and persisting an already-absent registry run. The integration used the exact reviewed PR diff and an independent frozen dependency installation; source fingerprints remained unchanged. Wall time was 43.19 seconds, including 12.317 seconds of compiler preparation.Test cost, measured with
pnpm test <file> --maxWorkers=1: the new registered-handler test takes 1.291 seconds in its body and 20.696 seconds wall including a 12.119-second compiler-cache miss; the new catalog test takes 26 ms in its body and 6.064 seconds wall. The modified existing lifecycle file passes 43 cases in 11.332 seconds wall; its changed failure-publication case takes 68 ms. Hosted CI test-body times are 983 ms for the registered-handler test, 16 ms for the catalog test, and 76 ms for the modified lifecycle case; all 43 lifecycle case bodies total 3.722 seconds (not suite wall time). The managed stress fixtures remain outside per-PR CI.A later integration against main
a1107a5217b67fbb2e4ecb27d7bc458cc3713a9calso passes: the same three Gateway regressions plus all seven auth-publication recovery cases from #156561, 10 cases across four files in 66.78 seconds. This used an independent frozen install and the exact reviewed diff, with unchanged source fingerprints.Behavior proof and review disposition
The applicable proof is the executed Gateway boundary behavior, including the registered
sessions.listhandler, real SQLite workers, runtime config publication, and model-replacement lifecycle. The proof applies to the changed contract. The permanent regression fails on the original behavior and passes at this reviewed head; hosted CI independently runs these cases.The managed-reload replay uses synthetic provider and service handles with the production publication/replacement owners and 19 concurrent registered requests. Selected fields from its recorded after-change output:
{"materializedAfterReload":0,"materialized":0,"readBatches":0,"rowKeysRead":0,"catalogEntriesEqual":true,"catalogRoutesEqual":true,"pluginRegistrySame":true,"pluginMetadataSame":true}The corresponding before-change replay recorded four row reads and three materializations for two unchanged sessions. Current config adoption, scope revocation, changed session writes, model/provenance changes, replacement failure, and supersession have separate passing regression coverage. This demonstrates preserved output and eliminated redundant work at the affected boundary. It does not claim socket-level, installed-provider, or production latency proof.
Maintainer disposition of the generic proof request in the completed review: the recorded boundary proof applies to this internal caching change and is sufficient for its changed contract. No transport, provider protocol, or stored-data contract changes. The review identifies no missing specific behavior or code defect. Production performance verification remains a separate follow-up after an authorized deployment.