Repository navigation
fix(test): prevent cold artifact reads racing database preparation - #186160
Conversation
Codex Review SummaryThis 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. |
|
🦞👀 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 changes before merge. What this changesThis PR waits for pending database preparation before capturing session-sharing registry facts and rejects database replacement during that wait. Example: An artifact download starts while transcript backfill is opening sessions.sqlite.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR narrowly fixes the cold-artifact readiness race, but its added tests trigger the enforced test-line budget failure. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherGateway session authorization prepares database-backed sharing facts that artifact handlers consume before returning authorized file bytes. flowchart LR
A[Artifact request] --> B[Session sharing preparation]
C[Pending database open] --> B
B --> D[Registry and file identity checks]
D --> E[Current sharing authorization]
E --> F[Artifact bytes]
Technical reviewBest possible solution: Keep the existing preparation owner and identity checks, preserve both regressions, and resolve the test-line gate before landing. Do we have a high-confidence way to reproduce the issue? Current-main source captures the registry witness before discovery awaits native preparation, allowing registration to invalidate it; the PR reports a controlled before/after Gateway reproduction, but this review executed no target code. Is this the best way to solve the issue? The runtime change is the smallest complete repair using existing owners: join readiness before witness capture while retaining acquisitions and rejecting file replacement. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bd5b160075e3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +15, Tests +60. Total +75 across 2 files. Added test files: 0. View PR surface stats
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 October 27, 2026, 1:55 PM ET / 17:55 UTC. |
Join already-pending native database preparation before capturing session-sharing registry facts. Preserve captured file identities across the wait and reject replacements. This prevents background transcript backfill registration from invalidating the first managed artifact request, without retries or weaker authorization checks.
b4ad418 to
5bb7a1a
Compare
…penclaw#186160) * fix(test): prevent cold artifact reads racing database preparation Join already-pending native database preparation before capturing session-sharing registry facts. Preserve captured file identities across the wait and reject replacements. This prevents background transcript backfill registration from invalidating the first managed artifact request, without retries or weaker authorization checks. * fix(test): consolidate session sharing race coverage
What Problem This Solves
Fixes cold managed-artifact downloads failing with
SessionMutationFactsUnavailableErrorwhile a background transcript backfill opens the session database. Related: #186071, whose E2E failure exposed this race outside that PR's changed path.Target discovery already awaited pending native database preparation, but sharing acquisition captured its registry witness first. The opener's registration could invalidate that witness during the required wait. Join existing preparations before capturing the witness, retain source acquisitions across the wait, and verify captured file identities afterward. File replacement and subsequent authority changes still invalidate the read. No retries or timeout increases.
Production delta: +15 lines, unchanged by the test-only follow-up. The growth orders the existing dependency and preserves the file-generation boundary; it adds no new cache or owner. No performance claim is attached to this correctness repair.
Evidence
The original controlled fresh-download Gateway reproduction failed with the same 179-character error as CI, then passed with the fix, including image/document bytes and stale-ID rejection. It held the real backfill writer's native open, staged registration immediately before the first artifact authorization, then released the writer. Diagnostic hooks were removed from the final change.
Unforced baseline loops passed Node 5/5 and Bun 7/7, confirming why repetition alone missed the interleaving. Two concurrent single-worker loops passed Node 5/5 and Bun 5/5 on the previous PR head
b4ad418feaf44eb465600f2a937fc37c97fa813f(all three original cases per run: 30/30 cases). These are prior-head evidence, not fresh E2E claims for this test-only consolidation.Test consolidation
The follow-up removes duplicated setup using the existing sharing harness and a shared Vitest fixture. No whole test or distinct contract was deleted. Both the opening-writer race and pending-phase same-path replacement remain regression tests; the latter still requires preparation itself to reject. The prepared replacement case remains too, with identical row contents so it tests physical identity.
In
publishes durable sharing facts before observers, the repeated direct rejection assertion after replacement is covered by the same test's commit observer: it callsreadCurrentat the replacement publication and the test verifies the recorded rejection. Three separate error-array shape assertions are consolidated into one expected-error assertion. Repeated transaction setup usesharness.transaction; other changes reuse config, path, session, and entry fixtures. Main's #186123 relocation of the unrelated ALS retention test is preserved.The consolidated regressions were rerun against unfixed main
c4c345af4e8842219a880c13a1788a560878dc84:AgentDatabaseRegistryChangedErrorFinal focused file: 22/22 passed under Node, single worker, on the source committed as
5bb7a1a2abd97931d1ebaa955fb8fa1d285fc089. Targeted typecheckpnpm tsgo:core:test --ci-graphs-json '["core-test-gateway-root"]'passed. Changed-file oxlint, oxfmt, andgit diff --checkpassed.PR net test-line delta: −3, down from +60 (this follow-up removes 63 lines). The ratchet against the exact PR base reports
Test lines: 6286332; ceiling: 6286325; over by: 7; net delta: -3and exits successfully under the interim rule. The requested--base origin/main --no-merge-baseinvocation also passed with delta −125; that moving-ref comparison includes unrelated newer main changes, so −3 is this PR's own delta. No ceiling edit was made.Independent subagent review (autoreview route unavailable), P2 and higher: no remaining actionable findings. The helper again refused the requested provider because it did not match operator configuration; configuration was not changed. The original review's file-replacement finding remains fixed, and the follow-up review confirmed the stricter preparation-time assertion.
The earlier head's only underlying CI failure was the test-line ratchet; other selected functional, build, lint, architecture, and security checks passed. The follow-up addresses this PR's own test-line growth.
config/test-lines-baseline.txtis untouched by this PR. No CI rerun was requested and this PR is left ready for the TS lead; it has not been merged.