Skip to content

fix(workers): retry admission after unrelated placement changes - #170085

Merged
steipete merged 2 commits into
mainfrom
codex/nodew-r7-inventory-base
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/nodew-r7-inventory-base

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes session lifecycle admission failing with Worker placement inventory changed when another session claims, releases, or reconciles a worker. Concurrent testing reproduced the rejection, including three rejected turns in a 180-turn soak.

User Impact

An unrelated placement change during admission is retried once automatically. Changes to the admitting session's placement, repeated inventory invalidation, and lost database authority still reject admission. No configuration, schema, or worker protocol changes are required; update the Gateway.

Why This Change Was Made

Maintenance must retain a global inventory because it protects other sessions from pruning. Keep that guard and record the session IDs that invalidated its observation. At the lifecycle write boundary, rebuild preparation once when those IDs exclude both the prior and resulting session IDs. Never retry removals or an acknowledged commit.

Production LOC: +30 net across five production files; eight changed files total. The small increase records invalidation ownership and bounds recovery, with no sleeps, timeouts, new generations, or persistent state. Removed an unused preparation argument and a one-use authority wrapper. No latency improvement is claimed.

Evidence

  • Original production code at 084f82d27f6c: all three unrelated-change regression cases failed with the reported inventory error; two local-only controls passed. The deterministic fixture commits real placement changes after a real database-worker inventory read and after capture, before admission.
  • Candidate: pnpm test src/gateway/server-worker-placement-startup-maintenance.test.ts --maxWorkers=1 — 15 passed, 596.85 s command wall time (531.30 s Vitest duration). The existing integration suite includes worker compilation and Gateway maintenance fixtures; no new boot fixture or real timer was added. Controls verify that a same-session change and a second invalidation still fail without writing the target session.
  • Targeted type-aware Oxlint, formatting, and git diff --check passed. Independent Codex P0/P1 review was scoped-clean.
  • Final CI run 38292616527 passed on aaa4b6438e4d43683dad835b208fb77fdd94b76c (953 s elapsed), including static checks, changed-code tests, and the wrapper closure. No provider/model call or remote lease was needed for the deterministic concurrency reproduction.

CI follow-up: the first run found that the new error module also needs an entry in the maintainer wrapper runtime inventory. Added that explicit entry; both failing wrapper-closure cases pass locally (106.07 s command wall time, 79.61 s Vitest duration). Production code and the 15-test owner proof are unchanged. The correction also passed independent Codex P0/P1 review.

Rebuild lifecycle admission and maintenance preservation once when another session invalidates the inventory. Keep same-session and live-authority fencing, exclude removals, and never replay an acknowledged write.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 12, 2026 18:24
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 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: aaa4b6438e4d43683dad835b208fb77fdd94b76c
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

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

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retries lifecycle preparation once when an unrelated session invalidates the worker placement inventory.

Example: Creating session concurrent-maintenance-trigger overlaps a worker claim for concurrent-worker-session.

  • Before: Admission fails with Worker placement inventory changed.
  • After: Admission rebuilds its preservation inventory once and succeeds while retaining the worker-owned session.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has no remaining actionable finding and meaningful production-owner regression coverage; supplied behavior evidence remains at the integration-harness level.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied integration evidence exercises real placement writes and lifecycle persistence, and the patch changes bookkeeping recovery rather than principal authorization.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent worker activity can reject another session's lifecycle admission before its turn starts.
Reason: The maintainer-authored direction repairs a demonstrated concurrent-use failure with a bounded retry and no new configuration or public contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses an admission failure still present on main, and the previous wrapper-inventory finding is resolved.

Priority: P2
Reviewed head: aaa4b6438e4d43683dad835b208fb77fdd94b76c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises the production lifecycle owner in an integration fixture, without a shipped-Gateway demonstration of this new retry.
Agent review details

How this fits together

Gateway session lifecycle writes prepare worker-placement preservation facts before committing session updates and maintenance through the existing SQLite owners.

flowchart TD
A[Session lifecycle request] --> B[Prepare lifecycle projection]
B --> C[Capture placement preservation]
C --> D[Guarded SQLite commit]
D --> E[Publish committed session facts]
C --> F[Unrelated inventory invalidation]
F --> B
Loading

Technical review

Best possible solution:

Retain the single preparation retry while preserving same-session rejection, fresh maintenance preservation, and acknowledged-write settlement.

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

The original inventory observation rejects unrelated worker publications before lifecycle commit, and the supplied regression cases exercise that path with real SQLite workers; no target code was executed during this review.

Is this the best way to solve the issue?

A single retry at the lifecycle owner rebuilds the stale preservation facts without weakening the inventory fence or restoring the removed publication-wait machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Lifecycle preparation and acknowledged commit keeps the original intent (80725e3: Move lifecycle inventory and snapshot work into the existing executor while preserving physical-store custody, commit guards, and acknowledgment-driven publication.)
  • Inventory-wide placement fencing keeps the original intent (f04552e: Exempt local claim churn while retaining worker-placement invalidation so maintenance cannot prune newly protected sessions.)
  • Placement read cache keeps the original intent (6b8e69e: Reuse healthy local projections and preservation facts while avoiding stale cache publication during pending or concurrent writes.)
  • Simplified placement preparation keeps the original intent (b690de6: Remove publication settlement listeners and speculative coordination while preserving effect checks, durability, and ordinary settlement.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Bounded retry with commit protection: The retry accepts only the dedicated inventory-change error, excludes explicit removals and both previous and resulting session IDs, and refuses replay after acknowledged commit. (src/config/sessions/session-accessor.sqlite-projection.ts:313, aaa4b6438e4d)
  • Authority failures remain outside retry: Physical database admission, released observations, indeterminate outcomes, and replaced owners are checked before constructing the retryable error; exact-session observations still throw their existing rejection. (src/gateway/worker-environments/placement-turn-authority.ts:205, aaa4b6438e4d)
  • Production-owner regression coverage: The changed integration cases interleave real placement writes with the real preservation read, verify durable session results, and retain same-session and second-invalidation rejection controls; the body reports the intended unrelated-change cases failing on the base and passing on the candidate. (src/gateway/server-worker-placement-startup-maintenance.test.ts:203, aaa4b6438e4d)
  • Previous finding repaired: The sole follow-up commit adds the new runtime error module to the trusted PR wrapper inventory, resolving the previous review's missing-import finding. (scripts/pr-lib/wrapper-components.txt:782, aaa4b6438e4d)
  • Current-main comparison: The fetched main retains the original lifecycle and placement-read behavior in the central changed modules; this PR's bounded retry is not already implemented there. (src/config/sessions/session-accessor.sqlite-projection.ts:107, 8656a687160d)
  • Maintainer direction and current checks: The security guard confirms the author's repository-admin authority. The live PR head matches the reviewed checkout, GitHub reports mergeable, and exact-head CI remains pending without a reported failed check. (aaa4b6438e4d)

PR surface

Source +30, Tests +11, Docs +2, Other +1. Total +44 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 237 207 +30
Tests 1 40 29 +11
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 8 280 236 +44

Review metrics

Metric Value Why it matters
Production versus test changes Production +237/-207, net +30; tests +40/-29, net +11. Most production churn wraps existing preparation; the added logic records invalidating sessions and bounds retry without adding persistent state or another owner.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The fix addresses intermittent lifecycle admission failures during concurrent worker placement activity.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-12T18:32:45.923Z sha f02d1db :: needs changes before merge. :: [P2] Include the new error module in the PR wrapper inventory

Reviewed October 12, 2026, 2:48 PM ET / 18:48 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete
steipete merged commit 8cee6f6 into main Oct 12, 2026
146 of 149 checks passed
@steipete
steipete deleted the codex/nodew-r7-inventory-base branch October 12, 2026 18:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…claw#170085)

## What Problem This Solves

Fixes session lifecycle admission failing with `Worker placement inventory changed` when another session claims, releases, or reconciles a worker. Concurrent testing reproduced the rejection, including three rejected turns in a 180-turn soak.

## User Impact

An unrelated placement change during admission is retried once automatically. Changes to the admitting session's placement, repeated inventory invalidation, and lost database authority still reject admission. No configuration, schema, or worker protocol changes are required; update the Gateway.

## Why This Change Was Made

Maintenance must retain a global inventory because it protects other sessions from pruning. Keep that guard and record the session IDs that invalidated its observation. At the lifecycle write boundary, rebuild preparation once when those IDs exclude both the prior and resulting session IDs. Never retry removals or an acknowledged commit.

Production LOC: **+30 net** across five production files; eight changed files total. The small increase records invalidation ownership and bounds recovery, with no sleeps, timeouts, new generations, or persistent state. Removed an unused preparation argument and a one-use authority wrapper. No latency improvement is claimed.

## Evidence

- Original production code at `2e1d4395f91d`: all three unrelated-change regression cases failed with the reported inventory error; two local-only controls passed. The deterministic fixture commits real placement changes after a real database-worker inventory read and after capture, before admission.
- Candidate: `pnpm test src/gateway/server-worker-placement-startup-maintenance.test.ts --maxWorkers=1` — **15 passed**, **596.85 s command wall time** (531.30 s Vitest duration). The existing integration suite includes worker compilation and Gateway maintenance fixtures; no new boot fixture or real timer was added. Controls verify that a same-session change and a second invalidation still fail without writing the target session.
- Targeted type-aware Oxlint, formatting, and `git diff --check` passed. Independent Codex P0/P1 review was scoped-clean.
- Final [CI run 38292616527](https://github.com/openclaw/openclaw/actions/runs/38292616527) passed on `aaa4b6438e4d43683dad835b208fb77fdd94b76c` (953 s elapsed), including static checks, changed-code tests, and the wrapper closure. No provider/model call or remote lease was needed for the deterministic concurrency reproduction.

CI follow-up: the first run found that the new error module also needs an entry in the maintainer wrapper runtime inventory. Added that explicit entry; both failing wrapper-closure cases pass locally (106.07 s command wall time, 79.61 s Vitest duration). Production code and the 15-test owner proof are unchanged. The correction also passed independent Codex P0/P1 review.
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: L 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