Skip to content

fix(gateway): refresh placement reads after concurrent publication - #165166

Merged
steipete merged 1 commit into
mainfrom
dbasync/placerace
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/placerace

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Users occasionally saw a placement-authority-changed error asking them to resend their message just after the previous turn finished. A placement publication can supersede an in-flight admission read and reject the next turn with placement authority changed, even though no execution has started. Holding the real projection read while the preceding turn releases its claim reproduces this remaining reader race on the base.

The originally reported initial-setup E2E flake was already repaired on main by 7ecc80a45736, which stopped treating runtime preference selection as execution authority. This is a follow-up repair to the stricter placement reader, not a replacement for that fix.

Why This Change Was Made

The existing placement authority owner waits for pending publication settlement and refreshes superseded, unconsumed reads against their original physical store. Notifications replace polling. Confirmed rollback remains usable; unknown outcomes, cancellation, owner closure, and replacement remain fenced. Observations handed to consumers retain their existing strict checks. No writer or consumer effect is replayed.

The regression forces the interleaving with a held promise, checks fresh claim-free facts and zero caller-thread SQL, and covers settlement, cancellation, and close behavior using the existing fixture. A real-Gateway diagnostic trace locates the second preference observation before the first turn releases its claim: placement stays active at generation 5, while the claim/result owner publishes new state. The controlled failure is exposed as a terminal UNAVAILABLE response and a visible chat error. The UI says the input will not run automatically and instructs the user to copy it and send again; rendererStall is null.

User Impact

Ordinary placement publications no longer fail pure read preparation. Execution claims, synchronous worker transactions, FIFO settlement, current grants, schemas, retention, durability, public SDK signatures, and update behavior are unchanged. No new OPENCLAW_* names or dependencies.

Production LOC: +106 / −36 / net +70 across two files (142 changed production lines). T1: 894 → 894 globally; the placement store remains 4 → 4. No SQL operation moves in this follow-up.

Adjacent ownership work: #162433. The change stays in the existing placement reader/authority owner; broader turn and queue ownership is untouched.

Required update acceptance: passed. Published 2026.9.8 successfully updated to the exact candidate package; managed Gateway replacement, readiness, build identity, durable history preservation, and incognito restart behavior all passed. Earlier provider setup failures were infrastructure-only; no product assertion or ownership guard was bypassed.

Evidence

Base: a0c1b065b5b25b54cd1f855881a2c13d2237f467.

  • Deterministic regression on the base: 1 failed, 7 passed, with the exact placement-authority error; pnpm test src/gateway/worker-environments/placement-read-projection.worker.test.ts --maxWorkers=1, 138.31s wall.
  • Candidate regression file: 9/9 passed, same command, 87.83s wall. These include compiler/cache costs and are not a performance comparison. The native-worker fixture proves real read/publication ordering and absence of caller-thread SQL; no real timers were added.
  • Focused owner, launcher, chat admission, shared-state/worker import-closure, and runtime-process build-graph tests: 100/100 across 9 files, --maxWorkers=1, 734.53s wall on the loaded local host.
  • node scripts/check-changed.mjs: passed (including production/test typechecking, lint, guards, and zero runtime import cycles).
  • Madge: 0 cycles. Pinned-base database-worker ratchet: passed. Independent Codex review through P2: scoped-clean.
  • Same AWS host, controlled prior-claim-release interleaving: historical 77bb00588056 1/1 failed (113s) → actual candidate 1/1 passed (86s), with both accepted turns launched exactly once. The trace changes observation sequence 9 → 14, with ownerActive=true, sameOwner=true, no pending mutation, and placement still active at generation 5; the first claim changes to null. This is a real claim publication, not a projection refresh generation bump.
  • Candidate ordinary E2E: 10/10 passed, 489s total wall. Natural historical attempts did not reproduce the flake: 0/10 focused failures and 0/3 original 13-file shard failures (each 26 tests; 240/232/230s). Three diagnostic shard replays also passed. Current main independently passed 20/20 (10 generic, 10 CI-prebuilt). Controlled and natural rates are kept separate; the original repair belongs to 7ecc80a45736, while the new held-read unit regression proves this PR's additional reader fix.
  • One optional candidate shard was interrupted after the ten focused runs to preserve the lease for the controlled pair. Its log showed 13 files/26 tests passing, but there was no completed command receipt, so it is excluded from success counts. The normal workspace owner confirmed process settlement before the controlled run.
  • Released SDK check: full v2026.9.8 → f0274b804377 declaration report completed locally (digest a24517d4). Placement types are SDK-reachable through Gateway request-context contracts. The generated prepareRuntimeRefresh(sessionId: string) Promise return and all result/authority fields are byte-identical before/after; this PR changes no existing sync/async, parameter, callback, or export contract. The new helper is an internal module export, so no new compatibility shim or deprecation record is required. The full release comparison also contains inherited SDK changes outside this four-file PR.
  • Worker routing audit: no new broker/admission dependency is introduced; existing host-owned fork projects cover the affected worker callers. The three unlisted Gateway-core siblings (node-workspace-retain-coordinator, placement-move-schema, placement-projector) passed 43/43 with --maxWorkers=1, 115.99s wrapper wall time (101.71s Vitest). No routing expansion was needed. All new imports already belong to the compiled-wrapper dependency inventory.
  • Exact-head CI: run 37240275492 passed, including security-fast and openclaw/ci-gate. The initial PR context check rejected the old heading; the body now uses the required template and run 37240916562 passed.
  • Published driver 2026.9.8 × exact candidate f0274b80437744d62dc917229e5f7d2b9e3fa394: passed, cell exit 0 in 638.934s on isolated Linux. The installed driver completed the update; managed service replacement, /readyz 200, running version/build identity, retained durable history, and cleared incognito state were verified. Candidate tarball SHA-256: 753b4628bf45ff6ed9cabc6bacf392d5471cfedb9daafcee85ffcc47e733828d. The synthetic service shim used the supported stop/update/start path after an unsupported property query; all acceptance assertions passed. Environment prerequisite repairs were Docker, Buildx, and SSH-session group activation; no source changes were needed.

Exact-head CI completed successfully in 8m36s (22:30:33–22:39:09 UTC); local focused timings above include compilation on a loaded host. The required published-driver update precondition is complete. Independent P2 autoreview and exact-head ClawSweeper found no actionable code or security findings; the latter’s outstanding proof item is resolved by this update cell.

Wait for pending placement publications and refresh superseded read-only
preparation against the captured physical database. Keep returned observations,
cancellation, owner replacement, and uncertain outcomes fenced; never replay
writes or consumer effects.

A held projection read followed by the preceding claim release fails on the
base and passes with fresh facts and zero caller-thread SQL. The original
initial-setup runtime preference race was already fixed by 7ecc80a;
this completes the remaining pure placement-reader preparation path.

Focused tests, changed checks, import boundaries, cycle checks, the database
worker ratchet, and independent P2 review pass. The published-driver update
cell remains a merge precondition after infrastructure failures.
@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: f0274b80437744d62dc917229e5f7d2b9e3fa394
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/worker-environments/placement-turn-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:23 PM ET / 23:23 UTC (Revision 4).

ClawSweeper review

What this changes

The Gateway waits for concurrent placement publications and refreshes unfinished reads so the next message avoids a spurious placement-authority error.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still rejects reads superseded during preparation. No actionable defects were found, and the recorded published-driver update acceptance resolves the previous review’s blocker.

Priority: P2
Reviewed head: f0274b80437744d62dc917229e5f7d2b9e3fa394

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with a failing-base regression, real-Gateway recovery evidence, and completed update acceptance.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied controlled real-Gateway trace exercises concurrent claim publication through placement preparation and records both accepted turns launching exactly once after the fix. Exact-candidate published-driver update acceptance resolves the prior blocker. No stored-data format or schema contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The supplied controlled real-Gateway trace exercises concurrent claim publication through placement preparation and records both accepted turns launching exactly once after the fix. Exact-candidate published-driver update acceptance resolves the prior blocker. No stored-data format or schema contract changes.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta and original authority implementation. The introduced changes are limited to placement read preparation, settlement notifications, regression coverage, and explanatory documentation.
Refresh and fencing boundary: Read preparation retains its captured database admission and owner, waits through settlement, and repeats only the read. Cancellation, indeterminate outcomes, owner closure, and replacement reject preparation; returned observations retain strict publication checks.
Consumer authority remains current: Chat admission checks the placement service, selected session, and retained observation after preparation. File reads additionally recheck session authority and workspace roots; worker routing rechecks run cancellation and placement facts. The patch does not transfer authority to a different principal or replay final effects.
Findings None None.
Security None None.

How this fits together

The placement reader supplies session execution-location and recovery facts to Gateway admission and worker routing. Its authority owner tracks publications so callers can reject stale facts before using them.

flowchart TD
  A[Incoming session turn] --> B[Placement read preparation]
  C[Concurrent placement publication] --> D[Publication settlement]
  D --> B
  B --> E[Read original physical store]
  E --> F{Facts still current?}
  F -->|Refresh needed| B
  F -->|Yes| G[Caller rechecks admission]
  G --> H[Turn routing]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +70, Tests +104, Docs +6. Total +180 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 106 36 +70
Tests 1 104 0 +104
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 216 36 +180

Review metrics

None.

Technical review

Best possible solution:

Keep refresh behavior inside the existing placement authority owner while preserving strict consumer checks and exactly-once execution.

Do we have a high-confidence way to reproduce the issue?

Yes: holding a placement projection read while the preceding claim is released exposes the rejection in the unchanged current-main path. Source inspection and the supplied failing-base regression establish the mechanism; this reviewer did not execute it.

Is this the best way to solve the issue?

Yes: refreshing only unfinished reads at the existing authority owner repairs the race without replaying writes or weakening checks on facts already returned to callers.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded admission race that can require users to resend a message after a preceding turn finishes.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied controlled real-Gateway trace exercises concurrent claim publication through placement preparation and records both accepted turns launching exactly once after the fix. Exact-candidate published-driver update acceptance resolves the prior blocker. No stored-data format or schema contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied controlled real-Gateway trace exercises concurrent claim publication through placement preparation and records both accepted turns launching exactly once after the fix. Exact-candidate published-driver update acceptance resolves the prior blocker. No stored-data format or schema contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta and original authority implementation. The introduced changes are limited to placement read preparation, settlement notifications, regression coverage, and explanatory documentation. (src/gateway/worker-environments/placement-turn-authority.ts:348, f0274b804377)
  • Refresh and fencing boundary: Read preparation retains its captured database admission and owner, waits through settlement, and repeats only the read. Cancellation, indeterminate outcomes, owner closure, and replacement reject preparation; returned observations retain strict publication checks. (src/gateway/worker-environments/placement-turn-authority.ts:310, f0274b804377)
  • Consumer authority remains current: Chat admission checks the placement service, selected session, and retained observation after preparation. File reads additionally recheck session authority and workspace roots; worker routing rechecks run cancellation and placement facts. The patch does not transfer authority to a different principal or replay final effects. (src/gateway/server-methods/chat-send-admission.ts:341, f0274b804377)
  • Meaningful regression coverage: The added regression holds a real projection result while the preceding claim is released, then checks fresh claim-free facts and no caller-thread SQL. Settlement coverage exercises commit, rollback, uncertainty, cancellation, and close without adding real timers. The body records the intended failure on the base and 9/9 passing candidate cases; tests were not executed during this read-only review. (src/gateway/worker-environments/placement-read-projection.worker.test.ts:61, f0274b804377)
  • Current main still needs the repair: The inspected main revision still observes authority, awaits the projection once, and rejects any intervening publication. The earlier setup repair changes runtime preference selection rather than this stricter preparation path, so it does not supersede the PR. (src/gateway/worker-environments/placement-store.ts:139, 5837209ed1ba)
  • After-fix behavior and prior blocker resolved: The captured PR body records a controlled real-Gateway claim-release interleaving: historical failure becomes a candidate pass with both accepted turns launched exactly once. It also records published 2026.9.8 updating to the exact reviewed candidate, exit 0 in 638.934 seconds, readiness 200, matching build identity, retained durable history, and cleared incognito state. This directly addresses the previous review’s required update cell; these are supplied execution receipts, not reviewer-run commands. (f0274b804377)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-04T22:34:35.745Z sha f0274b8 :: blocked before merge. :: none
  • reviewed 2026-10-04T22:45:59.379Z sha f0274b8 :: blocked before merge. :: none
  • reviewed 2026-10-04T23:02:54.052Z sha f0274b8 :: needs changes before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 4, 2026
@steipete
steipete merged commit 5f72ae5 into main Oct 4, 2026
161 of 163 checks passed
@steipete
steipete deleted the dbasync/placerace branch October 4, 2026 23:24
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…penclaw#165166)

Wait for pending placement publications and refresh superseded read-only
preparation against the captured physical database. Keep returned observations,
cancellation, owner replacement, and uncertain outcomes fenced; never replay
writes or consumer effects.

A held projection read followed by the preceding claim release fails on the
base and passes with fresh facts and zero caller-thread SQL. The original
initial-setup runtime preference race was already fixed by a8487f3;
this completes the remaining pure placement-reader preparation path.

Focused tests, changed checks, import boundaries, cycle checks, the database
worker ratchet, and independent P2 review pass. The published-driver update
cell remains a merge precondition after infrastructure failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant