Repository navigation
fix(gateway): allow first database creation during session discovery - #199862
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR lets ordinary Gateway session discovery accept an agent database first created after candidate preparation. Example: The database for agent cold is created while looking up agent:cold:first-session.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review This PR addresses a concrete current-main regression with a focused fix; no introduced correctness or security defect was found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway session lookup sends configured database candidates through the existing discovery worker, then obtains session rows and membership facts from retained database readers. flowchart TD
A[Gateway session request] --> B[Capture configured paths]
B --> C[Prepare discovery candidates]
C --> D[Wait for pending database creation]
D --> E[Discover session stores]
E --> F[Read retained session facts]
F --> G[Check authority and consume]
Technical reviewBest possible solution: Keep asynchronous discovery and use its existing locator-only preparation mode, leaving opened-file generation and mutation authority with their current owners. Do we have a high-confidence way to reproduce the issue? Source establishes the absent-identity capture, intervening creation wait, and exact rejection; the committed regression forces that sequence, but no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete repair: extend an existing preparation mode to the inventory request and select it at the affected caller, without changing writer or inspection behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b858e90c8fed. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +1, Tests +38. Total +39 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 15, 2026, 7:59 PM ET / November 16, 2026, 00:59 UTC. |
|
Merged via squash.
|
What Problem This Solves
Fixes chat requests failing with
SQLite database path identity changedwhen an agent's first database is created during session discovery.User Impact
First-use session discovery can read the newly created database without rejecting its earlier absence. No configuration, schema, migration, or user action is required.
A separate Bun
SESSION_MUTATION_AUTHORIZATION_CHANGEDfailure remains unresolved; this PR does not claim to repair it.Why This Change Was Made
#197510 moved ordinary Gateway lookup to worker preparation that captures an absent-file identity before the existing worker waits for pending database creation. Legitimate first creation then invalidates that premature identity. Ordinary lookup now selects the existing
captureIdentity: falsemode, restoring its prior path-custody contract. The actual row reader still owns the opened file's generation; mutation, placement, cold-storage, and retained-plan checks remain intact.Production code grows by one line to select that existing mode at the lookup boundary. One regression adds 38 test lines and forces real first creation between preparation and discovery.
Evidence
ce25df37, reported this identity failure on Bun. The unchanged xAI Gateway case also reproduced it under Node in 45.543 s.pnpm check:changed --base 39b066a976970b080df4b107b8ba918e250d4f4e --timed: all stages pass except 12 production / 8 full-tree unused exports. Both exact-parent A/A controls report identical lists. State exports were introduced by feat(state): upgrade state by copy and swap at Gateway startup #198389 and fixed by fix(state): restore dependency checks for upgrade internals #199847; member-welcome exports were introduced by feat(openclaw-id): name invited members from their email and ask who they are on first visit #198491 and fixed by fix(ci): keep member welcome internals private #199789. These are real main regressions already repaired separately.39b066a976970b080df4b107b8ba918e250d4f4e, through P2: scoped-clean, no accepted/actionable findings. The committed change preserves that reviewed snapshot.Synthetic owner measurements use a real allocated 35 GiB SQLite database, 5,000 sessions, and 62,000 workspace files totaling 1.116 GB. The existing qualification owner runs five counterbalanced samples per variant, 3,000 operations each, with separate A/A controls and sampled JS allocation. Candidate census stays equal; premature identity captures fall from one to zero per operation.
APFS A/A controls: wall 43.71/41.80 µs, CPU 49.19/46.21 µs, allocation 18,129/18,334 B. Linux A/A spreads: 1.94% wall, 11.94% CPU, 0.15% allocation. Linux uses a task-owned btrfs loop image on ext4, 8 CPUs/16 GiB RAM, Node 24.22.1. These are qualification-owner mode comparisons, not Gateway throughput or native-allocation claims. No production data was copied.
The original Bun xAI case fails before and after this fix with the separate authorization error. An error-path diagnostic traced it to a pending agent-database registry publication during retained authorization; the guard originates in #163030, but the regression's introducing commit and failing publication owner are still unknown. Later diagnostic passes do not establish a fix. All temporary instrumentation was removed. This unresolved local failure is retained as investigated evidence and is not an inherited-CI exception; exact-head CI remains required.
Existing before/after terminal evidence
These are excerpts from the already-completed canonical
node scripts/run-vitest.mjs runinvocations with explicitOPENCLAW_VITEST_RUNTIME=nodeorbunand--maxWorkers=1. Temporary synthetic paths are redacted. The committed head is byte-identical to the tested candidate.Unchanged real-Gateway xAI case, Node, parent:
Same unchanged real-Gateway case, Node, candidate:
Deterministic first-creation regression, parent Node then candidate Node/Bun:
The unchanged Node Gateway case validates the user flow; the deterministic owner regression establishes the specific first-creation interleaving. The original Bun authorization gap described above remains unresolved.