Repository navigation
fix(workers): retry admission after unrelated placement changes - #170085
Conversation
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.
|
🦞👀 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 maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway 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
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +30, Tests +11, Docs +2, Other +1. Total +44 across 8 files. Added test files: 0. View PR surface stats
Review metrics
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 HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 2:48 PM ET / 18:48 UTC (Revision 2). |
…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.
What Problem This Solves
Fixes session lifecycle admission failing with
Worker placement inventory changedwhen 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
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.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.git diff --checkpassed. Independent Codex P0/P1 review was scoped-clean.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.