openclaw/docs/tools/code-mode
Peter Steinberger b2d26e4a61
fix(code-mode): retire warm workers with their host
## What Problem This Solves

Completed Code Mode workers could remain alive after their creating Gateway or CLI command closed. The warm pool and idle-expiry timers had no host lifetime.

## User Impact

Closing a host now waits for its Code Mode workers to retire. Other live hosts keep their workers, and failed native cleanup remains owned for a later retry. Standalone executor calls close completed workers immediately instead of retaining an unowned warm pool. Suspended continuations retain their existing contract.

## Why This Change Was Made

Warm pools capture the existing resource host when created. Each host owns a scheduler scope and its admitted workers; idle expiry uses that scope. Reuse stays within the creating host. The four-worker bound, five-minute idle period, fresh VM contexts, and memory-pressure eviction remain unchanged.

Production: **+65 / -7 / net +58** (`src/**` and `extensions/**`, excluding tests and support). This growth supplies host isolation and joined retirement; this cut is not a LOC reduction. There are no persisted format or configuration changes. Update behavior: existing state remains compatible; the retirement ordering takes effect after restart.

## Evidence

Independent reviews of the production change and the test-fixture correction are clean through P2. Candidate: `6c475248c2ab5b21a3eb0b9e121b38e76d5bffe3`.

- The final source tree passed all 30 tests across the five Code Mode lifecycle/native sibling files in **22.31s pnpm wall**. The native warm-pool fixture now supplies a real host and joins its teardown; the real workers, test bodies, and worker-count assertions are preserved.
- The original production implementation failed the new standalone-worker retirement assertion as intended. The initial 14 lifecycle cases passed in **15.33s pnpm wall**. Full production changed checks passed in **1414.68s**; the final test-only delta passed its changed checks in **205.14s**.
- The final candidate build passed in **434.34s**. Its canonical package passed tarball integrity checks.
- The two native warm-pool failures during development were deterministic fixture mismatches: standalone calls no longer retain a pool, while those tests assert host-owned reuse. This was not a flake fix; no assertions, timeouts, retries, or worker implementations were weakened.

Blacksmith Testbox leases: `tbx_01m3t3g3afjjrmnqjhr0mqasv0` ([native and production proof](https://github.com/openclaw/openclaw/actions/runs/36779653190)) and `tbx_01m3taxfbahdc6c63a38n0fq50` ([final build, fixture checks, and update cell](https://github.com/openclaw/openclaw/actions/runs/36792095804)). The first lease completed at two hours during the fixture changed gate, after all 30 tests passed. The unfinished gate was completed on the fresh lease; the disconnected run is not counted as a passing gate.

The real published `2026.9.7` updater installed the exact candidate in **151s**. Both installed Gateways passed health and joined SIGTERM; the original disabled cron job, workspace bytes, authored configuration, and SQLite integrity were preserved. Doctor applied its existing implicit-main-roster normalization (`agents.entries.main = {}`). The first verification incorrectly expected the whole agents object to remain byte-shaped; source inspection confirmed the existing migration, and a separate read-only verification of the same original artifacts asserted that exact normalization and all remaining preservation checks. The update was not rerun. This cell covers installed update and shutdown; the worker tests above cover warm-worker custody.
2026-10-01 00:41:27 +00:00
..
configuration.md fix(anthropic): finish Opus 5.5 defaults and thinking display (#156093) 2026-09-22 23:59:18 -07:00
executors.md perf(agents): stop spawning Code Mode watchdog threads per evaluation (#156066) 2026-09-23 01:47:18 +00:00
guest-api.md fix(code-mode): nested tool errors lose their message when details only flag the error (#159359) 2026-09-26 22:11:08 -07:00
internals.md fix(code-mode): retire warm workers with their host 2026-10-01 00:41:27 +00:00
maintainers.md fix(agents): preserve tool authority through hook rebuilds (#159532) 2026-09-27 02:18:55 -07:00
output.md feat: run Code Mode on Node or isolated QuickJS (#154522) 2026-09-21 17:33:04 -07:00
quickstart.md feat: enable automatic Code Mode for preferred models (#155614) 2026-09-22 04:19:15 -07:00
tool-surface.md fix(code-mode): exec backgrounds after 1 s and forces extra poll turns (#160841) 2026-09-28 18:55:27 -07:00
troubleshooting.md fix: distinguish Code Mode guest errors after tool calls (#160217) 2026-09-28 12:07:09 -04:00