Skip to content

fix: allow retrying refused native worker cleanup - #198240

Merged
RomneyDa merged 6 commits into
mainfrom
openclaw/native-close-reviewed-20261113
Nov 15, 2026
Merged

RomneyDa merged 6 commits into
mainfrom
openclaw/native-close-reviewed-20261113

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes native-worker cleanup becoming permanently unusable after an early close is refused because work is still active or an execution owner rejects cleanup (RRI-509).

User Impact

A caller can finish its existing work and explicitly retry cleanup without restarting the process. Actual native teardown failures remain terminal, preventing a replacement source from overlapping retained native resources. No automatic work replay, schema, configuration, or public API change.

Why This Change Was Made

Check for unjoined workers after execution owners settle but before entering the closing state. Clear only a rejected pre-teardown close attempt; retain the existing successful-close coalescing and terminal native-failure state. The existing source remains the sole lifecycle owner; no new state or retry mechanism is introduced.

The follow-up CI repair registers the existing read-only Home real-Gateway test in the canonical real-Gateway inventory. This keeps it out of bundled/ordinary test lanes when real-Gateway tests are skipped and assigns it to its dedicated shard. It backports the relevant main-branch inventory repair without changing test timeouts or native behavior.

Evidence

  • On base dff958dae159ef494a81bbac95b2fee8075612c8, the two new retry scenarios fail at the intended boundary: new work is rejected after a refused live-worker close, and an owner-close retry returns the cached first failure. The terminal teardown control passes on the base.
  • Real process-isolated lifecycle fixture: 13/13 pass on the pinned Bun fork, including active-worker refusal, one-time owner failure, concurrent successful close, fresh-source reuse, terminal native teardown, existing resource custody, and generation cleanup. Test-file duration 16.85s; wrapper wall time 17.62s. The existing cold-start-deadline case accounts for 15.24s; the new cases total 0.40s.
  • The three new scenarios also pass on Node v26.12.1 (2.90s file duration; 3.69s wrapper wall time).
  • Focused TypeScript check passes for the lifecycle owner, fixture, tests, and their imported closure.
  • Affected consumers: 16/16 pass across native-handle, runtime-generation, and CLI cleanup suites (4 files, 35.27s wrapper wall time, including cold compiled-fixture preparation). An earlier auxiliary run was invalidated by edits to its captured fixture; this result is the stable final-tree rerun.
  • Focused lint, formatting, and staged git diff --check pass. Staged test-line ratchet passes against the reproduction base: 6,672,265 lines, 6,672,316 ceiling, 51 lines slack. Fresh independent review completed with no P0–P2 findings; publication was approved after direct review. No live Gateway was modified.
  • Follow-up CI repair: run 43416918348, job 131857822841 identified a PR-caused suppression-inventory failure. The fixture now saves/restores the Worker method descriptor and joins through the restored receiver, removing the new typescript/unbound-method suppression without changing production behavior or growing the test allocation.
  • Repair-owner validation: suppression suite 14/14 passed, affected teardown scenario passed, and targeted TypeScript/lint/format and diff checks passed. Fresh independent read-only review of 249be48e5861b4f30a8c2862fb3b810a3b6030b0..56e122382d58711d7dd28b08356563b4f12f46ca found no P0–P2 issues. Published head 6ced26f3e013312115846123227093bd46fc2bfc has an identical tree to that reviewed repair.
  • Prior-head CI was not green: PR run 43418249404, job 131862377395 failed with a 120000 ms timeout at ui/src/e2e/home-readonly.real-gateway.e2e.test.ts:45:3, with stack location ui/src/e2e/control-ui-e2e-suite.test-support.ts:694:9. Earlier scheduled main run 43409014923, job 131830982650, at head f4e9c2731b1b8361eca92edfaf9e030012444d32, had the identical test path, timeout, and stack annotation. The inherited failure was subsequently traced to the Home test missing from the canonical real-Gateway inventory, allowing execution in the bundled lane despite the real-Gateway skip setting.
  • November 15 CI repair: the 14-line inventory/ownership regression patch backports the relevant main fixes (58c15494 / 2110db5a) while preserving timeouts. Repair-owner validation demonstrated red/green discovery and ownership behavior; 8 sharding tests and targeted types/lint/format passed, and fresh independent review found no actionable issues. Published head 9011102268e6820f8f912b5fcc257d4a73232412 is tree-identical to reviewed commit a302cc1850efb68a4401317db93f197ee6d66c6c.
  • Exact-head CI run 43762456115 completed successfully: 40 jobs passed, 29 skipped, no failures. All three checks-ui-e2e shards and openclaw/ci-gate passed. The dedicated real-Gateway lane was skipped in this run; the local inventory/ownership proof above verifies correct placement. The prior erroneous bundled-lane Home failure did not recur. This result applies to head 9011102268e6820f8f912b5fcc257d4a73232412, not the older failed runs.
  • Hosted review of native head 6ced26f3e013 reported no findings. November 14 observation-only replay on that unchanged head, Node v26.12.1, captured the requested real-process native-boundary trace. All three subprocesses exited 0 with empty stderr: close-live-worker (1.769s), close-owner-retry (1.044s), and close-teardown-failure (0.948s). Observed sequences:
    • Live worker: reply 42 → close refused (Native worker execution owners have not joined) → continued request 8 returned 9 → explicit retry and concurrent close resolved with no active workers → old source rejected new work → distinct fresh source usable.
    • Owner retry: cleanup attempt 1 refused (Native worker execution owner cleanup failed) → continued request 8 returned 9 → explicit retry made cleanup attempt 2 → concurrent closes resolved with no active workers → distinct fresh source usable.
    • Terminal control: synthetic Worker.terminate failure → two closes retained the identical failure, with owner cleanup attempted only once → new work rejected and failed source retained. Final supervisor cleanup reported exit 1; this is the terminated supervisor's exit, not the containing fixture's successful exit 0. Only this terminal control injects native termination failure; lifecycle admission and settlement use production code. No live Gateway was modified.
  • Inspectable base-versus-head native-boundary trace: both refusal scenarios fail on the reproduction base and pass on native head 6ced26f3e013; the terminal failure control passes on both. Native production and fixture code are unchanged by the inventory-only CI repair, so this proof remains applicable. It is native-boundary proof, not live Gateway/model execution.

Test-audit: each new scenario protects a distinct lifecycle contract at the real source boundary. Native failure is injected only at Worker termination inside its isolated child process; no production test hook is added. The existing fixture and case table are reused. CI ownership regressions separately enforce complete real-Gateway inventory, correct skip behavior, and dedicated-shard placement.

Simplification: moved rather than duplicated the joined-worker guard, reused the existing closing flag, and added no new production state. Native production delta +4 lines; native regression delta +126 lines, covered by the dedicated RRI-509 test-line allocation. The CI follow-up adds 14 lines across the existing inventory and ownership test helper.

Worked on by

RomneyDa and others added 2 commits November 13, 2026 11:24
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: 016c5c6c-b745-4cda-808a-f47a77f8fd72
@clawsweeper

clawsweeper Bot commented Nov 13, 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.

RomneyDa and others added 2 commits November 13, 2026 11:34
Store and restore the Worker prototype descriptor, then join through the restored receiver. Fixes the PR-caused lint suppression inventory failure without changing production behavior or growing the test allocation.

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: afb073dc-1eba-487b-9810-c4ed84ba3365
@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR allows explicit cleanup retries after pre-teardown refusal while preserving terminal native teardown failures.

Example: Cleanup is requested while an echo worker is active, then the caller finishes and retries.

  • Before: The refused close permanently seals the source and subsequent cleanup returns the cached rejection.
  • After: The worker can still reply with 9 to input 8, and cleanup succeeds after the worker joins.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified defect, but the required recorded behavior evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An early cleanup refusal can force a process restart even after the caller finishes its work.
Reason: The maintainer-authored direction restores explicit recovery with a small owner-level change while retaining terminal teardown failures.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a concrete cleanup retry defect still present on current main, with no introduced correctness findings.

Priority: P2
Reviewed head: 6ced26f3e013312115846123227093bd46fc2bfc

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Share a redacted terminal or log trace through the production native-source boundary showing refused cleanup, continued worker replies, successful explicit retry, and terminal teardown failure; redact IPs, keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The native-worker lifecycle owner connects execution owners to retained worker supervisors and spawn brokers, admitting work and joining native resources during cleanup.

flowchart TD
  A[Execution owners] --> B[Native source]
  B --> C[Worker supervisor]
  C --> D[Native workers]
  B --> E[Spawn broker]
  A --> F[Explicit cleanup]
  F --> B
Loading

Technical review

Best possible solution:

Keep the existing source as the sole cleanup owner, allowing explicit retries only before native teardown begins.

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

Current-main control flow deterministically retains the refused close and can seal a still-active source; the PR reports matching base failures, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs the owning lifecycle boundary with existing state, preserves native failure custody and successful-close coalescing, and avoids restoring the retired shutdown graph.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests +126, Other +2. Total +132 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 3 +4
Tests 2 128 2 +126
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 137 5 +132

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression growth Production +4 net lines; tests and fixture +126 net lines The growth reuses the existing fixture to protect two retry failures and the distinct terminal-teardown boundary.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A concrete native cleanup recovery defect has a narrow fix, without evidence of an urgent widespread outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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.

Reviewed November 13, 2026, 6:52 AM ET / 11:52 UTC.

@RomneyDa

Copy link
Copy Markdown
Member Author

Native cleanup proof: base fails, this head passes

Replayed both complete source snapshots with Node v26.12.1 on Linux, in separate processes with isolated temporary homes:

  • Base: dff958dae159ef494a81bbac95b2fee8075612c8
  • PR: 6ced26f3e013312115846123227093bd46fc2bfc
Scenario Base exit PR exit What it establishes
Active-worker close refused 1 0 Base rejects new work: Native worker source is closing. PR keeps the source usable, replies 9 to input 8, then joins on explicit retry.
Execution-owner close refused once 1 0 Base returns its cached cleanup failure. PR invokes owner cleanup a second time and coalesces concurrent close callers.
Native teardown fails 0 0 Both retain the same terminal failure, reject new work, and prevent overlapping replacement resources.

These exercise the production native-source owner, supervisor, and actual Worker transport, not mocked admission/settlement. The existing committed process-isolated fixture was copied with observation-only event recording; production files were unchanged. The terminal control injects an error at the real supervisor’s Worker.terminate, and the owner-refusal control intentionally fails its first cleanup. This is native-boundary proof, not live Gateway/model execution.

Reproduce the committed assertions at this PR head:

node scripts/run-vitest.mjs run src/infra/worker-native-lifecycle.test.ts --maxWorkers=1 -t 'close-live-worker|close-owner-retry|close-teardown-failure'
Actual observed PR subprocess output (all exit 0, empty stderr)

close-live-worker (1.081s)

[
  {
    "ending": "close-live-worker",
    "trace": [
      {
        "event": "worker-reply",
        "value": 42
      },
      {
        "event": "close-refused",
        "message": "Native worker execution owners have not joined",
        "activeWorkers": true
      },
      {
        "event": "continued-request",
        "value": 8
      },
      {
        "event": "worker-reply",
        "value": 9
      },
      {
        "event": "explicit-retry",
        "activeWorkers": false
      },
      {
        "event": "retry-and-concurrent-close-resolved",
        "activeWorkers": false,
        "ownerAttempts": 0
      },
      {
        "event": "work-rejected-after-teardown",
        "message": "Native worker source is closing"
      },
      {
        "event": "fresh-source",
        "sameSource": false
      }
    ],
    "refusedSourceUsable": true,
    "retryJoined": true,
    "freshSourceUsable": true
  }
]

close-owner-retry (1.112s)

[
  {
    "ending": "close-owner-retry",
    "trace": [
      {
        "event": "worker-reply",
        "value": 42
      },
      {
        "event": "owner-close",
        "attempt": 1
      },
      {
        "event": "close-refused",
        "message": "Native worker execution owner cleanup failed",
        "activeWorkers": true
      },
      {
        "event": "continued-request",
        "value": 8
      },
      {
        "event": "worker-reply",
        "value": 9
      },
      {
        "event": "explicit-retry",
        "activeWorkers": true
      },
      {
        "event": "owner-close",
        "attempt": 2
      },
      {
        "event": "retry-and-concurrent-close-resolved",
        "activeWorkers": false,
        "ownerAttempts": 2
      },
      {
        "event": "work-rejected-after-teardown",
        "message": "Native worker source is closing"
      },
      {
        "event": "fresh-source",
        "sameSource": false
      }
    ],
    "refusedSourceUsable": true,
    "retryJoined": true,
    "freshSourceUsable": true
  }
]

close-teardown-failure (1.149s)

[
  {
    "ending": "close-teardown-failure",
    "trace": [
      {
        "event": "terminal-close-rejected",
        "message": "synthetic native teardown failure",
        "sameFailure": true,
        "ownerAttempts": 1
      },
      {
        "event": "work-rejected-after-teardown",
        "message": "Native worker source is closing"
      },
      {
        "event": "terminal-close-rejected",
        "message": "synthetic native teardown failure",
        "sameFailure": true,
        "ownerAttempts": 1
      },
      {
        "event": "work-rejected-after-teardown",
        "message": "Native worker source is closing"
      }
    ],
    "failedSourceRetained": true,
    "overlapRefused": true
  },
  {
    "event": "supervisor-cleanup",
    "exitCode": 1
  }
]

The final supervisor-cleanup exitCode 1 is the terminated supervisor’s exit, not the containing fixture’s successful exit 0.

CI is tracked separately: the existing Home UI timeout is still red; this proof does not make that run green or waive its gate. Its failure path is being investigated rather than rerun blindly.

RomneyDa and others added 2 commits November 15, 2026 21:12
Backport canonical real-Gateway inventory and ownership assertions so bundled CI does not cold-start the Home Gateway test. Preserve timeouts and real-Gateway coverage.

Co-authored-by: RomneyDa <[email protected]>

Co-authored-by: vincentkoc <[email protected]>
Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: baa6eae6-0dad-479c-ac65-941704454554
@RomneyDa
RomneyDa merged commit adb660f into main Nov 15, 2026
141 checks passed
@RomneyDa
RomneyDa deleted the openclaw/native-close-reviewed-20261113 branch November 15, 2026 22:05
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
* fix: allow retrying refused native worker cleanup

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>

* fix: allow retrying refused native worker cleanup

Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: 016c5c6c-b745-4cda-808a-f47a77f8fd72

* test: restore native teardown fixture without suppression

Store and restore the Worker prototype descriptor, then join through the restored receiver. Fixes the PR-caused lint suppression inventory failure without changing production behavior or growing the test allocation.

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>

* Publish openclaw/native-close-reviewed-20261113

Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: afb073dc-1eba-487b-9810-c4ed84ba3365

* fix(ci): place readonly Home proof in real Gateway lane

Backport canonical real-Gateway inventory and ownership assertions so bundled CI does not cold-start the Home Gateway test. Preserve timeouts and real-Gateway coverage.

Co-authored-by: RomneyDa <[email protected]>

Co-authored-by: vincentkoc <[email protected]>

* Publish openclaw/native-close-reviewed-20261113

Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: baa6eae6-0dad-479c-ac65-941704454554

---------

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
* fix(workers): preserve missing-module startup errors

Render non-Error diagnostic causes before forwarding native worker failures so loader host objects cannot replace the original error with DataCloneError. Keep primitive causes and structured Error metadata, and verify the real supervisor error and join path on stock Bun, the pinned fork, and Node.

Removes the native error-forwarding dependency on oven-sh/bun#46711.

* fix(workers): narrow serialized diagnostic scalars explicitly

* test(workers): consolidate native failure regressions

Reuse one shared and cyclic error graph, extend the downlevel value table, and cover missing worker entries inside the existing supervisor recovery flow before its healthy sibling control. Preserve the original cases while reducing test lines by two against the PR base; remove the now-unneeded allocation.

(cherry picked from commit 058133d)

Release adaptation: Only cloneable diagnostic normalization and encoder/lifecycle regressions. Later inherited-code fix 416b357 is independent, not prerequisite; supervisor timing and plugin startup rewrites excluded.

Follow-up dispositions: d82e097 test(process): wait for broker failure before retained replacement (openclaw#202539); 416b357 fix: preserve the real reason a worker failed; 907e17b fix(plugins): avoid Gateway stalls during source preparation (openclaw#200320); adb660f fix: allow retrying refused native worker cleanup (openclaw#198240)

Validation: Direct exported encoder/decoder: baseline fails 3 non-Error diagnostic cases; fixed passes 3; primitive and Error graph regression retained. Normal wrapper lifecycle proof pending compiled-worker setup. diff --check passes.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit cb68af332a1182ed21b39c10b53b1f6e3036461c)
(cherry picked from commit 7a4af04d616ab677c58fa1f369b947bef45c382a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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