Skip to content

fix(gateway): new sessions fail with "Worker placement inventory changed" while other local turns start or finish - #165984

Merged
steipete merged 2 commits into
mainfrom
codex/stab-placement-inventory
Oct 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/stab-placement-inventory

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer decision (2026-10-05): approved. Local placement publications no longer revoke session maintenance's inventory-wide placement fence. The fence stays fully intact for worker (non-local) placements, including a worker placement created after an empty read.

What Problem This Solves

Fixes: a new session's first turn fails with Worker placement inventory changed when other local turns start or finish at the same moment. It needs no workers to be configured; ordinary local use under concurrency is enough.

User Impact

User impact: under concurrent use (several sessions or channel messages at once), new turns no longer fail with Worker placement inventory changed. Nothing changes for deployments that use workers: a worker placement published during session maintenance still fences that maintenance and forces fresh preparation.

Why This Change Was Made

Session maintenance prepares preservation with an inventory-wide placement observation, then commits. Ordinary local turns acquire and release durable placement claims even with no workers configured, and every such publication revoked all inventory-wide observations. That rejected the maintenance commit of an unrelated new session, even though maintenance's preservation scan excludes local placements.

placement-turn-authority.ts now decides once, at publication, whether a change affects an observation. Inventory-wide observations ignore local claim publications. Per-session observations, non-local placements, unknown publications, and remote-exec placements whose turn claim has a local owner stay fenced. Only local claim churn is exempt: a publication whose prior placement is local or provably absent and whose new placement is local or absent (acquire, release, clear). Native and worker publishers supply the transaction-held prior state when they stage the change. A transition into or out of a non-local placement, or one whose prior state is unknown, still revokes inventory-wide observations, including when the outcome is uncertain or invalidated. (A review of the first commit found that classifying by the new state alone also exempted worker-to-local transitions; the second commit narrows it.) The change also removes a duplicate publication-sequence write and merges two equivalent authority checks. Production lines net to zero.

Ordinary local turns still publish durable claims. Removing those writes would change lifecycle, exclusion, and persisted-state behavior, so that stays a separate follow-up.

Evidence

Live (dev Gateway, OpenAI-backed agents on the built-in and Codex runtimes; agents warmed first, then 2 x (4 rounds x 15 concurrent sessions.create with a short first turn)):

Build Turns Worker placement inventory changed other failures
main f986a7aaf15b 120 8 (both runtimes) 1 Failed to observe plugin state entry ... Session entry facts changed during their mutation check
this branch (both commits) 120 0 1 of the same plugin-state error
main 2983dfcfb319, one burst 60 5 -

The plugin-state mutation-check failure reproduces at the same rate on main and does not involve this code; it is tracked separately.

Deterministic proof: the startup-maintenance characterization tests now require immediate success for local claim acquisition and release. Restoring only the production owner to main makes exactly those three local cases fail with Worker placement inventory changed, while the worker-dispatch and remote-exec controls still pass.

TMPDIR=/private/tmp/oc-placement-fence pnpm test src/gateway/server-worker-placement-startup-maintenance.test.ts --maxWorkers=1          # 11 passed, 45.95 s wall
TMPDIR=/private/tmp/oc-placement-fence pnpm test src/gateway/worker-environments/placement-read-projection.worker.test.ts --maxWorkers=1 # 12 passed, 53.85 s wall
TMPDIR=/private/tmp/oc-placement-fence pnpm test src/gateway/worker-environments/placement-turn-authority.test.ts --maxWorkers=1          # 20 passed
production owner restored to main, same tests:                                                                                        # 3 failed | 20 passed (intended local cases)

pnpm tsgo:core, targeted oxlint and oxfmt, the docs MDX check, and git diff --check pass. Autoreview of the final branch was scoped-clean with no P0-P2 findings.

Both commits: production +61/-55, tests +220/-31, docs +8/-1. The second commit adds 6 owner regressions (worker/unknown -> local transitions, invalidated transitions) that fail on the first commit; 62 tests pass across the four placement suites.

Classify local placement publications before settlement so local claim acquisition and release do not invalidate maintenance's non-local inventory. Preserve per-session authority and worker inventory fencing, including remote-exec local claims and dispatch after an empty scan.

Convert the maintenance characterization to success regressions, cover publication settlement, and document the boundary. Retain durable local claims and their dispatch, workspace, and recovery contracts.
@clawsweeper

clawsweeper Bot commented Oct 6, 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 6, 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: f568fe799e7f1059d3e0acf92df663427d35053e
  • 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 6, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 3:59 AM ET / 07:59 UTC (Revision 2).

ClawSweeper review

What this changes

The PR prevents unrelated local turn claims from interrupting session maintenance while preserving fences for worker placements and non-local transitions.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still has the reported invalidation mechanism, and the updated patch preserves non-local and per-session fences. No actionable introduced defect was found.

Priority: P1
Reviewed head: f568fe799e7f1059d3e0acf92df663427d35053e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant live comparison and meaningful regression controls supports normal good PR quality.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured live Gateway comparison exercises the changed placement-observation owner through concurrent sessions.create first turns and reports 8/120 placement failures before versus 0/120 after both commits. Boundary regressions supplement that evidence with worker and uncertain-transition controls. Persisted data formats and write semantics are unchanged, so no migration is required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured live Gateway comparison exercises the changed placement-observation owner through concurrent sessions.create first turns and reports 8/120 placement failures before versus 0/120 after both commits. Boundary regressions supplement that evidence with worker and uncertain-transition controls. Persisted data formats and write semantics are unchanged, so no migration is required.
Evidence reviewed 10 items Pinned introduction: Reviewed the merge-base-to-head delta, including production publications, maintenance regressions, and documentation. The stale test merge was not used to infer removal of current-main behavior.
Current main still needs the repair: Current main's pending-publication predicate still treats every non-tool publication as affecting inventory observations; it has no local-only classification.
Conservative publication classification: Inventory exemption requires a local postimage and a known local or absent predecessor. Unknown and non-local predecessors stay fenced; per-session observations still reject matching publications.
Findings None None.
Security None None.

How this fits together

The Gateway records where sessions execute and retains observations of those placements during session maintenance. Placement publications determine whether maintenance can safely use its prepared preservation inventory.

flowchart TD
  A[Concurrent session turns] --> B[Placement writer]
  B --> C[Prior and new placement state]
  C --> D[Placement observation owner]
  D --> E[Local-only inventory remains valid]
  D --> F[Worker or session observation fenced]
  E --> G[Session maintenance commit]
  F --> H[Fresh preparation required]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +189, Docs +7. Total +202 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 61 55 +6
Tests 3 220 31 +189
Docs 1 8 1 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 289 87 +202

Review metrics

Metric Value Why it matters
Reported concurrent first-turn failures 8/120 before; 0/120 after The live comparison exercises the session-creation workflow affected by the placement fence.

Technical review

Best possible solution:

Keep placement publication classification in the existing authority owner, preserving durable local claims and all non-local, per-session, and stale-claim safeguards.

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

Yes: current-main source exposes the invalidation mechanism, and the captured live comparison reproduces it through concurrent sessions.create first turns. This reviewer did not execute a reproduction.

Is this the best way to solve the issue?

Yes: classifying publications against transaction-held prior state repairs the preservation fence at its owner without removing durable claims or weakening per-session authority.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Ordinary concurrent local use can fail new session turns without any configured workers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured live Gateway comparison exercises the changed placement-observation owner through concurrent sessions.create first turns and reports 8/120 placement failures before versus 0/120 after both commits. Boundary regressions supplement that evidence with worker and uncertain-transition controls. Persisted data formats and write semantics are unchanged, so no migration is required.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured live Gateway comparison exercises the changed placement-observation owner through concurrent sessions.create first turns and reports 8/120 placement failures before versus 0/120 after both commits. Boundary regressions supplement that evidence with worker and uncertain-transition controls. Persisted data formats and write semantics are unchanged, so no migration is required.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head delta, including production publications, maintenance regressions, and documentation. The stale test merge was not used to infer removal of current-main behavior. (f568fe799e7f)
  • Current main still needs the repair: Current main's pending-publication predicate still treats every non-tool publication as affecting inventory observations; it has no local-only classification. (src/gateway/worker-environments/placement-turn-authority.ts:87, d6bd730e10bc)
  • Conservative publication classification: Inventory exemption requires a local postimage and a known local or absent predecessor. Unknown and non-local predecessors stay fenced; per-session observations still reject matching publications. (src/gateway/worker-environments/placement-turn-authority.ts:423, f568fe799e7f)
  • Transaction-held predecessor: The worker reads the predecessor inside its write transaction before execution, and the host captures that transaction admission fact for publication classification. Native publishers similarly use the transaction's current state. (src/gateway/worker-environments/placement-turn-claims.worker.ts:82, f568fe799e7f)
  • Preservation and live authority remain separate: The preservation reader excludes local and reclaimed placements. Maintenance rechecks its prepared observation when capturing preservation keys, while claim liveness and tool authorization retain their existing independent checks. No schema, serialized format, config, or public SDK contract changes were introduced. (src/gateway/worker-environments/placement-row-codec.ts:153, f568fe799e7f)
  • Boundary regressions: The maintenance test interleaves real placement acquisition or release with a fresh lifecycle upsert and verifies the persisted session. Its worker-dispatch control rejects before the session row appears. Additional tests cover native and worker transitions back to local, unknown predecessors, uncertain settlement, restart clearing, and per-session fencing. (src/gateway/server-worker-placement-startup-maintenance.test.ts:199, f568fe799e7f)

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 (1 earlier review cycle)
  • reviewed 2026-10-06T07:14:27.582Z sha c2ebc61 :: needs maintainer review before merge. :: none

Capture prior placement state in the existing writer transaction before classifying claim publications. Preserve maintenance inventory observations only for known local or absent prior and staged placements; unknown and non-local transitions remain fenced through invalidation.

Cover native and worker transitions, committed and uncertain publications, local claim clearing, and local retirement. Keep per-session authority and remote-exec fencing unchanged. No schema, public config, SDK, or update migration is required.
@steipete
steipete merged commit f04552e into main Oct 6, 2026
123 of 125 checks passed
@steipete
steipete deleted the codex/stab-placement-inventory branch October 6, 2026 08:05
@steipete

steipete commented Oct 6, 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 7, 2026
…ged" while other local turns start or finish (openclaw#165984)

* fix(gateway): preserve maintenance fences across local turns

Classify local placement publications before settlement so local claim acquisition and release do not invalidate maintenance's non-local inventory. Preserve per-session authority and worker inventory fencing, including remote-exec local claims and dispatch after an empty scan.

Convert the maintenance characterization to success regressions, cover publication settlement, and document the boundary. Retain durable local claims and their dispatch, workspace, and recovery contracts.

* fix(gateway): fence non-local placement transitions to local

Capture prior placement state in the existing writer transaction before classifying claim publications. Preserve maintenance inventory observations only for known local or absent prior and staged placements; unknown and non-local transitions remain fenced through invalidation.

Cover native and worker transitions, committed and uncertain publications, local claim clearing, and local retirement. Keep per-session authority and remote-exec fencing unchanged. No schema, public config, SDK, or update migration is required.
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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