Skip to content

fix(test): prevent cold artifact reads racing database preparation - #186160

Merged
steipete merged 2 commits into
mainfrom
steipete/fix-managed-image-actions-e2e-flake-20261027
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/fix-managed-image-actions-e2e-flake-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes cold managed-artifact downloads failing with SessionMutationFactsUnavailableError while 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 calls readCurrent at 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 uses harness.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:

Regression Unfixed main Candidate
Already-opening writer Fails with AgentDatabaseRegistryChangedError Passes
Pending same-path replacement Incorrectly resolves instead of rejecting Rejects during preparation

Final focused file: 22/22 passed under Node, single worker, on the source committed as 5bb7a1a2abd97931d1ebaa955fb8fa1d285fc089. Targeted typecheck pnpm tsgo:core:test --ci-graphs-json '["core-test-gateway-root"]' passed. Changed-file oxlint, oxfmt, and git diff --check passed.

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: -3 and exits successfully under the interim rule. The requested --base origin/main --no-merge-base invocation 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.txt is untouched by this PR. No CI rerun was requested and this PR is left ready for the TS lead; it has not been merged.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:22:21.629103Z 5bb7a1a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: Database registration invalidates the captured witness, producing SessionMutationFactsUnavailableError.
  • After: The request waits before capturing the witness and proceeds unless its captured database was replaced.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The runtime repair and distinct boundary tests are coherent; supplied Gateway results are descriptive, and an independently attributed required budget check still fails.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored classification exempts ordinary contributor proof gating; the body reports controlled Gateway download recovery with correct bytes and stale-ID rejection, while inspected regression code exercises real database preparation behind a scheduling delay.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A first managed-artifact download can fail while background transcript backfill opens its session database.
Reason: The maintainer-authored direction repairs an observed failure without retries, new configuration, or a competing state owner.

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
Reviewed head: b4ad418feaf44eb465600f2a937fc37c97fa813f

Before merge

  • Resolve the test-line budget failure before landing (P2) - The added coverage increases counted test lines by 60 while the head contains 6,286,024 lines against a 6,285,587 ceiling. scripts/check-test-lines-ratchet.mts:118-127 accepts an over-budget tree only when the PR delta is nonpositive, so inherited excess does not exempt this patch. This activates the failing test-lines subcheck and aggregate CI gate. Preserve the distinct opener-race and replacement regressions while obtaining shared headroom or consolidating counted tests.

Findings

  • [P2] Resolve the test-line budget failure before landing — src/gateway/session-sharing-preparation.test.ts:122-125
Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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:

  • [P2] Resolve the test-line budget failure before landing — src/gateway/session-sharing-preparation.test.ts:122-125
    The added coverage increases counted test lines by 60 while the head contains 6,286,024 lines against a 6,285,587 ceiling. scripts/check-test-lines-ratchet.mts:118-127 accepts an over-budget tree only when the PR delta is nonpositive, so inherited excess does not exempt this patch. This activates the failing test-lines subcheck and aggregate CI gate. Preserve the distinct opener-race and replacement regressions while obtaining shared headroom or consolidating counted tests.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against bd5b160075e3.

Provenance checked

  • Acquisition across storage readiness keeps the original intent (526f67d: Retain publication facts and source retirement guards before storage waits so concurrent metadata updates remain usable without adopting a replacement source.)
  • Worker-backed discovery and sharing reads keeps the original intent (949dbc5: Move durable target discovery and sharing reads into existing workers while retaining live authorization and physical-source ownership.)
  • Same-path replacement regression keeps the original intent (cbc53ac: Preserve session identity and authorization boundaries while moving bundled session reads and authority into workers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 526f67d adds src/gateway/session-sharing-preparation.ts:294 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 526f67dc6382; files: src/gateway/session-sharing-preparation.ts)
  • Shakker: Raw commit 65e49fa adds src/gateway/session-sharing-preparation.ts:145 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 65e49fa2008c; files: src/gateway/session-sharing-preparation.ts)

PR surface

Source +15, Tests +60. Total +75 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 17 2 +15
Tests 1 85 25 +60
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 102 27 +75

Labels

Label changes:

  • add P2: An intermittent cold-artifact download failure merits a focused repair, without evidence of widespread outage or urgent user impact.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: An intermittent cold-artifact download failure merits a focused repair, without evidence of widespread outage or urgent user impact.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

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.
@steipete
steipete force-pushed the steipete/fix-managed-image-actions-e2e-flake-20261027 branch from b4ad418 to 5bb7a1a Compare October 27, 2026 19:20
@steipete
steipete merged commit 12bb616 into main Oct 27, 2026
128 of 132 checks passed
@steipete
steipete deleted the steipete/fix-managed-image-actions-e2e-flake-20261027 branch October 27, 2026 20:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant