Skip to content

fix: shutdown waits on optional worker reconciliation - #180841

Merged
steipete merged 3 commits into
mainfrom
steipete/team-reconcilehang
Oct 22, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/team-reconcilehang

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Related: #178538, #176777, #172971

What Problem This Solves

Fixes shutdown waiting indefinitely for optional worker reconciliation when an allocation lookup never returns or reconciliation is queued behind an admitted provider mutation.

User Impact

A stopped Gateway can leave optional reconciliation without discarding the durable allocation or cleanup intent. Existing explicit destroys and admitted provider mutations still settle before their owner closes. Pending shutdown diagnostics now identify the environment, provider, and operation.

Why This Change Was Made

The affected Team deployment included #178538. That change bounded inspection, but the allocation lookup in provider-owner-lifecycle.ts:313 still entered the provider queue without the reconciliation cancellation signal. The environment lock also admitted an uncancellable observer wait, and placement joined the whole shared sweep.

The environment owner now passes reconciliation cancellation into read-only allocation lookup and checks it before recording errors or publishing a late allocation identity. Queued reconciliation can stop waiting before it acquires the lock; its retained callback checks shutdown before doing work. The shared sweep exposes a shutdown-cancellable observation while retaining actual work in the existing owner joins. Provider queue ownership for mutations is unchanged. No schema or public provider contract changes.

The complete incident journal does not identify an environment, provider, or leaf call. This fixes reproducible remaining cancellation gaps and adds bounded diagnostics, without claiming to have identified the production leaf. Pending traces name lock/inventory, installation/credential, and provider-call stages (inspect, resolve-allocation, provision, destroy, SSH identity). Provider identity is captured at call admission, so formatting still identifies the call after inventory reads are closed. Direct reconciliation preserves inventory recovery by awaiting readiness before reading diagnostic provider identity.

Accepted limitation: a provider mutation or admitted durable effect still has to settle; shutdown cannot safely abandon it or fabricate its receipt. Providers without a cancellation API may finish a read-only request later; its result cannot resume the cancelled reconciliation or cause destruction.

Evidence

Sanitized Team journal, team-20261022-full-1638-1647.log.gz, decompressed line 1435:

2026-10-22 16:47:25.613 UTC shutdown deadline reached
worker-environments.reconcile.environment=268475ms
worker-placement.reconcile.environments=248785ms
shutdown.connection-dependent-sidecars=83170ms
shutdown.worker-placement.reconcile.active=83169ms

Those repeated counters put the two reconciles at approximately 16:42:57 and 16:43:16, before the 16:46 shutdown. The supplied journal records main-process 9/KILL at 16:47:30; it does not identify the sender or attribute later SSH children to this reconcile.

The regression uses the real placement/environment owners with a provider allocation lookup that never returns. Close must finish within the test's 10-second limit before releasing that lookup, preserve the exact saved intent, avoid provision/bootstrap/destroy, and expose attributable diagnostics. A second owner regression releases queued reconciliation while retaining an admitted destroy until its actual completion.

Validation: 88 focused tests passed across the placement-startup cleanup, service inventory/lifetime, provider reconciliation, allocation cleanup, and destroy-timeout suites. The latest rerun passed both inventory tests in 1.5 seconds of test time (36.7 seconds including compilation) and all nine sidecar tests in 3.6 seconds (11.1 seconds total); the stalled-lookup regression completed in 232 ms. Core and affected test typechecks, targeted oxlint, formatting, and docs link audit passed. Both cancellation regressions fail on unchanged main. The diagnostic regression also fails when formatting tries to read an unavailable inventory, and passes with the captured call identity. GitHub review identified an eager diagnostic read that blocked direct inventory recovery; the extended seal/reopen test failed before that correction and now passes. Independent local and final committed-branch Codex reviews returned scoped-clean with no actionable P0–P2 findings. Exact-head CI run 39828882493 completed with 57 successful jobs, 27 conditional skips, and zero failures on ec774ce617dde37bca4cd267801d5c36a2ab1d31, with no rerun or inherited-failure exception.

Production: +161/-70 (net +91). Tests: +68/-14 (net +54). Docs: +10/-0. The production growth is cancellation boundaries and bounded diagnostic context, with the existing provider queue moved intact into its owning helper; no new scheduler or state owner.

Focused proof commands
pnpm test src/gateway/worker-environments/service-inventory-recovery.test.ts src/gateway/worker-environments/service-lifetime.test.ts src/gateway/worker-environments/provider-allocation-cleanup.test.ts src/gateway/worker-environments/provider-reconciliation.test.ts src/gateway/worker-environments/provider-destroy-timeout.test.ts --maxWorkers=1
pnpm test src/gateway/server-worker-placement-startup-cleanup.test.ts --maxWorkers=1
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-other.json --incremental
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-root.json --incremental
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <changed-ts-files>
node scripts/run-format.mts --write <changed-files>
pnpm docs:check-links
git diff --check

The final allocation-lookup regression times out at 10 seconds on unchanged main, and passes in 793 ms with the fix. The queued-reconcile regression also fails on unchanged main and passes with the fix. Tests use synthetic external I/O and real owners; no live Gateway was touched.

Initial CI on a848219915e31f14ca334f423f625277caf07bc0 reported a skill-library worker E2E timing failure: the assertion received the legitimate pending/queue observation before provider start. The test and agent.wait owner are unchanged from main; the isolated test passed on both that PR head and the exact main base. A cancelled Security Review attempt was also reported by the rollup watcher; the independent security-sensitive status was successful. The final-head run passed, including the skill-library test; no rerun was required.

@clawsweeper

clawsweeper Bot commented Oct 22, 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 22, 2026 17:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T18:12:50.599233Z ec774ce 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a848219915

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR cancels optional worker-reconciliation waits during shutdown while retaining admitted mutations and adding attributable pending-operation diagnostics.

Example: Allocation lookup for worker-startup-indeterminate never returns during cleanup.

  • Before: Placement shutdown waits for the lookup and cannot advance to environment teardown.
  • After: Shutdown releases the observation and preserves the saved provisioning and cleanup intent for recovery.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has meaningful owner-level regression coverage and resolves the prior finding; behavioral confidence remains limited to in-process evidence.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored PR is outside the ordinary proof gate; supplied red/green evidence exercises the production placement and environment owners with synthetic provider I/O, rather than a shipped Gateway and real transport.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway shutdown can remain blocked on optional worker reconciliation and reach its shutdown deadline.
Reason: The maintainer-authored direction repairs evidenced cancellation gaps while preserving accepted-work settlement; the smallest-fix review found no unnecessary parallel owner or test scaffolding.

Merge readiness

✅ Ready for maintainer review

This PR addresses concrete shutdown cancellation gaps, and the previous inventory-recovery finding is fixed; no actionable introduced defect remains in the reviewed diff.

Priority: P1
Reviewed head: ec774ce617dde37bca4cd267801d5c36a2ab1d31

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The new allocation-lookup and queued-lock cancellation paths have owner-level regressions, but no shipped Gateway run with a real transport is supplied.
Agent review details

How this fits together

Gateway placement reconciliation calls the environment service, which serializes provider operations and persists lifecycle outcomes; shutdown must release optional observations while joining accepted mutations.

flowchart TD
  A[Gateway shutdown] --> B[Placement reconciliation]
  B --> C[Environment service]
  C --> D[Environment lock]
  D --> E[Provider operation queue]
  E --> F[Read-only observations]
  E --> G[Admitted mutations]
  G --> H[Durable lifecycle state]
Loading

Technical review

Best possible solution:

Keep cancellation at the existing environment and provider owners, preserving durable intent and joining every admitted mutation.

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

Current-main source shows allocation lookup without reconciliation cancellation and queued lock waits that retain observers; committed owner regressions and reported base failures support reproduction, but no code was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs cancellation at the existing owners, retains mutation serialization and settlement, and avoids new configuration, persistence, or public provider contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Provider operation serialization keeps the original intent (82f6280: Retain raw provider-operation ownership after caller timeouts so replay and teardown cannot overlap.)
  • Reconciliation observation cancellation keeps the original intent (5cedb0d: Release cancelled observations while retaining provider mutations and preserving maintenance-interrupted allocation intent.)
  • Failed-placement allocation lookup during shutdown changes intended behavior with a stated reason (0661763: Defer terminal-placement cleanup until after readiness while retaining allocation adoption safety and shutdown drainage.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +91, Tests +54, Docs +10. Total +155 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 161 70 +91
Tests 2 68 14 +54
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 239 84 +155

Review metrics

Metric Value Why it matters
Production versus test changes Production +161/-70; tests +68/-14 Growth carries cancellation boundaries and diagnostic context while moving the existing provider queue intact; tests protect distinct shutdown and inventory-recovery failures.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • 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 status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported shutdown stall can prevent Gateway restart, and current source exposes the remaining uncancellable waits.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • 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-22T17:57:56.574Z sha a848219 :: needs changes before merge. :: [P1] Recover the inventory before reading diagnostic provider identity

Reviewed October 22, 2026, 2:15 PM ET / 18:15 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Fixed the inventory-recovery finding in ec774ce. Direct reconciliation now captures the provider only after store.ready() recovers the inventory. The existing seal/reopen regression now calls reconcileEnvironment() directly: it failed at the eager diagnostic read before the correction and passes afterward.

Pending provider diagnostics also retain their captured identity after inventory closure. Both inventory tests and all nine placement shutdown tests pass; core and affected test typechecks, targeted lint, formatting, and fresh independent review are clean. CI is running on the new head.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Oct 22, 2026
@steipete
steipete enabled auto-merge (squash) October 22, 2026 18:30
@steipete
steipete merged commit 51ee257 into main Oct 22, 2026
151 of 154 checks passed
@steipete
steipete deleted the steipete/team-reconcilehang branch October 22, 2026 18:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
* fix(gateway): release optional reconciliation during shutdown

* fix(gateway): retain provider diagnostics after inventory closure

* fix(gateway): recover inventory before reconcile diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. 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