Skip to content

fix(voice-call): prevent stale runtimes after gateway restart - #120289

Merged
steipete merged 1 commit into
mainfrom
steipete/goofy-lumiere-0d6ef4
Aug 7, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/goofy-lumiere-0d6ef4

Conversation

@steipete

@steipete steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #120288

What Problem This Solves

Fixes an issue where operators restarting or reloading a gateway with the Voice Call plugin could end up with stale runtime state when an older plugin generation finished startup or cleanup after its successor was already attached. That timing could recreate a runtime from old configuration, let old cleanup disrupt the new runtime, or leave Voice Call unavailable after restart.

Why This Change Was Made

Voice Call now owns its process-global runtime through an explicit plugin-generation coordinator. Startup, running, and stopping slots carry an exact owner; activation advances a monotonic epoch only when a staged generation actually starts or is used, so failed/staged registrations do not disturb the active generation and retired closures cannot revive later.

The fix stays inside the plugin boundary. Gateway shutdown grace and registry-bound tool retention remain unchanged; retained tools now receive a visible lifecycle error instead of adopting or mutating successor state. A focused lifecycle suite uses controlled promises to prove the original execution order and exact-owner cleanup.

AI-assisted: implementation and review used Claude Code and Codex. The final diff was manually inspected and passed the repository autoreview gate.

User Impact

Voice Call restarts and plugin configuration reloads now keep runtime ownership deterministic. A successor generation waits for the predecessor's actual stop barrier where appropriate, while delayed startup, stale service cleanup, and retained tool closures cannot recreate or interfere with another generation's runtime.

Evidence

  • node scripts/run-vitest.mjs extensions/voice-call/index.test.ts extensions/voice-call/index.lifecycle.test.ts — 55 tests passed.
  • node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo — passed.
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test.tsbuildinfo — passed.
  • node scripts/run-oxlint.mjs extensions/voice-call/index.ts extensions/voice-call/index.test.ts extensions/voice-call/index.lifecycle.test.ts — passed.
  • node_modules/.bin/oxfmt --check extensions/voice-call/index.ts extensions/voice-call/index.test.ts extensions/voice-call/index.lifecycle.test.ts — passed.
  • git diff --check — passed.
  • Codex autoreview, --mode uncommitted — clean; no accepted/actionable findings.
  • node scripts/check-changed.mjs -- ... classified the extension production/test lanes but remote Crabbox/Testbox providers were unavailable; the exact extension typecheck, lint, format, focused test, and diff checks above were run locally as the documented trusted-source fallback.

The production delta is the new runtime ownership boundary (+170/-66); tests are separate (+285/-72) and move the prior lifecycle cases into a dedicated deterministic suite.

@steipete
steipete marked this pull request as ready for review August 7, 2026 16:10
@openclaw-barnacle openclaw-barnacle Bot added channel: voice-call Channel integration: voice-call size: L maintainer Maintainer-authored PR labels Aug 7, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 7, 2026, 4:47 PM ET / 20:47 UTC.

ClawSweeper review

What this changes

The PR assigns Voice Call runtime startup, use, and teardown to a specific plugin generation so stale closures cannot create, reuse, clear, or stop a successor runtime after gateway restart.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review. Current main still has the ownerless global runtime slots described by the linked bug, while this PR adds a plugin-local exact-generation coordinator; no concrete patch defect was found, but its protected maintainer label requires human handling.

Priority: P1
Reviewed head: 1424170cf4b7399ba0a949d57b9ce9b922c206e9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and strong deterministic regression coverage, with only operational restart-trace uncertainty remaining.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR has deterministic lifecycle coverage for the reported ordering; an operational restart trace would be stronger but is not a contributor-proof gate here.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR has deterministic lifecycle coverage for the reported ordering; an operational restart trace would be stronger but is not a contributor-proof gate here.
Evidence reviewed 5 items Current-main defect remains: Current main still uses three ownerless process-global slots; runtime creation/adoption and stop cleanup infer ownership from whichever global values are present, matching the linked stale-generation mechanism.
Owner-boundary repair: The PR coordinator gives starting, running, and stopping slots an exact generation owner, promotes a runtime only while that owner remains current, and clears slots by identity during stop.
Lifecycle coverage: The new controlled-promise suite covers pending startup, successor stop barriers, stale cleanup, retained tools, and retry after a same-generation creation failure.
Findings None None.
Security None None.

How this fits together

Voice Call registers gateway services and tools that share one process-wide runtime. Gateway reload can attach a successor registry while old service shutdown remains in flight, so the plugin must fence delayed closures from retired generations.

flowchart LR
  Gateway[Gateway reload] --> Old[Retiring Voice Call generation]
  Gateway --> New[Successor Voice Call generation]
  Old --> Coordinator[Generation-owned runtime coordinator]
  New --> Coordinator
  Tools[Retained tool closure] --> Coordinator
  Coordinator --> Runtime[Voice Call runtime]
  Coordinator --> Result[Call succeeds or lifecycle error]
Loading

Decision needed

Question Recommendation
Is the deterministic exact-head lifecycle coverage sufficient to accept the remaining operational restart uncertainty for this process-wide Voice Call runtime change? Land with focused lifecycle proof: Accept the controlled-promise coverage because it reproduces the gateway replacement order and validates exact-owner teardown.

Why: The patch is correct by source and focused regression evidence, but the protected maintainer label requires an explicit human decision on accepting the absence of an operational restart trace.

Before merge

  • Resolve merge risk (P1) - This changes process-wide runtime availability during restart; the deterministic suite covers the reported ordering, but no operational Voice Call restart trace demonstrates every deployment reload path.
Agent review details

Security

None.

PR surface

Source +104, Tests +213. Total +317 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 170 66 +104
Tests 2 285 72 +213
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 455 138 +317

Review metrics

Metric Value Why it matters
Production vs test LOC production +170/-66; tests +285/-72 The production growth is justified by the new runtime ownership boundary, while the separate lifecycle suite supplies the ordering regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #120288
Summary: This PR is the concrete candidate repair for the linked Voice Call stale-runtime generation bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land with focused lifecycle proof (recommended)
    Accept the deterministic restart-order regressions and exact-head green checks as sufficient for this plugin-local availability repair.
  2. Request a restart trace
    Pause for a redacted operational Voice Call restart or reload trace if maintainers need evidence beyond the controlled lifecycle interleavings.

Technical review

Best possible solution:

Retain the plugin-local exact-owner coordinator and land it once a maintainer accepts the deterministic lifecycle proof for the gateway reload ordering.

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

Yes—current main’s ownerless runtime slots establish the reported stale-closure path, and the PR’s controlled-promise tests encode the gateway replacement interleaving; this read-only review did not run the scenario.

Is this the best way to solve the issue?

Yes—the plugin-local coordinator is the best fix because the gateway deliberately permits old service disposal to outlive registry retirement, while Voice Call owns the shared runtime being protected.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 588d8bb85388.

Labels

Label justifications:

  • P1: A timing-dependent gateway restart can leave the Voice Call plugin unavailable or operating with stale runtime state.
  • merge-risk: 🚨 availability: Merging changes process-wide runtime startup and teardown ordering during gateway replacement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR has deterministic lifecycle coverage for the reported ordering; an operational restart trace would be stronger but is not a contributor-proof gate here.

Evidence

What I checked:

  • Current-main defect remains: Current main still uses three ownerless process-global slots; runtime creation/adoption and stop cleanup infer ownership from whichever global values are present, matching the linked stale-generation mechanism. (extensions/voice-call/index.ts:239, 588d8bb85388)
  • Owner-boundary repair: The PR coordinator gives starting, running, and stopping slots an exact generation owner, promotes a runtime only while that owner remains current, and clears slots by identity during stop. (extensions/voice-call/index.ts:240, 1424170cf4b7)
  • Lifecycle coverage: The new controlled-promise suite covers pending startup, successor stop barriers, stale cleanup, retained tools, and retry after a same-generation creation failure. (extensions/voice-call/index.lifecycle.test.ts:138, 1424170cf4b7)
  • Gateway ordering and SDK contract: Gateway retirement can continue after a five-second service-stop grace, while the public global-singleton helper intentionally retains a process-local symbol singleton; keeping ownership coordination in Voice Call is therefore the appropriate boundary. (src/gateway/server-close.ts:858, 588d8bb85388)
  • Feature provenance: The shared Voice Call runtime model appears to date to the historical shared-runtime repair; this PR is not already contained in current main. (extensions/voice-call/index.ts:239, ba4cd90dbcb1)

Likely related people:

  • steipete: Historical Voice Call work introduced the shared webhook runtime model, and this PR owns its generation-safety repair. (role: shared-runtime feature owner and current repair author; confidence: high; commits: ba4cd90dbcb1, 1424170cf4b7; files: extensions/voice-call/index.ts)
  • Dallin Romney: Recent merged Voice Call tool invocation-context work touches the retained-closure boundary relevant to this repair. (role: recent adjacent runtime contributor; confidence: medium; commits: 8b1a9ccaa4; files: extensions/voice-call/index.ts)
  • Vincent Koc: Recent Voice Call lifecycle and shutdown-barrier history is adjacent to the restart ordering exercised here. (role: recent lifecycle contributor; confidence: medium; commits: 58d08dedd3, 695d184; files: extensions/voice-call/index.ts, src/plugins/services.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Optionally attach a redacted Voice Call restart or reload trace if maintainers want production-boundary evidence before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-07T17:38:59.537Z sha a7b6a25 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T20:41:55.104Z sha 1424170 :: needs maintainer review before merge. :: none

Prevent retained plugin closures from recreating, adopting, or stopping successor runtimes across shutdown and restart.

Add deterministic lifecycle regressions for pending startup, exact-owner stop, retained tools, and generation restart.
@steipete
steipete force-pushed the steipete/goofy-lumiere-0d6ef4 branch from a7b6a25 to 1424170 Compare August 7, 2026 19:49
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased onto current main at c691f2e41cd61b26b5457541f5ff5ecbd7f2a9a3; exact head is 1424170cf4b7399ba0a949d57b9ce9b922c206e9. The focused Voice Call lifecycle suite passes 55/55 on this head.

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Retrying the exact-head review request because the prior worker lease (github-run-31213248473-1) expired without publishing a verdict. Head remains 1424170cf4b7399ba0a949d57b9ce9b922c206e9; exact-head CI and focused tests are green.

@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready verification for exact head 1424170cf4b7399ba0a949d57b9ce9b922c206e9:

Maintainer decision: accept the controlled deferred-promise lifecycle suite as sufficient proof for this plugin-local ownership repair. It reproduces the gateway replacement order, pending-start continuation, exact-owner teardown, retained-tool behavior, and successor restart boundary without requiring a live telephony provider. No remaining proof gap blocks landing.

@steipete
steipete merged commit 32361e7 into main Aug 7, 2026
86 checks passed
@steipete
steipete deleted the steipete/goofy-lumiere-0d6ef4 branch August 7, 2026 20:56
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 8, 2026
Prevent retained plugin closures from recreating, adopting, or stopping successor runtimes across shutdown and restart.

Add deterministic lifecycle regressions for pending startup, exact-owner stop, retained tools, and generation restart.
steipete added a commit that referenced this pull request Aug 18, 2026
…-ends

The gateway's in-process restart (SIGUSR1 config reload) reuses the cached
plugin registry, so service stop/start run on the same retained voice-call
registration. Generation fencing from #120289 treated that restart as a stale
actor: stop retired the generation forever, the next start silently bailed,
and every voicecall.* RPC answered UNAVAILABLE "runtime generation is
retired" while the webhook never rebound.

- Registrations now hold a replaceable generation: service start after stop
  mints a fresh generation, takes over a running slot owned by a retired
  predecessor, and reports start failures to service health instead of
  silently returning.
- The voicecall CLI classifies gateway failures with typed guards instead of
  message substrings: standalone/store fallback only when the gateway is
  genuinely absent; reachable-but-failed (request errors, auth, timeout)
  exits with actionable text; a standalone webhook port collision explains
  that a running Gateway probably owns the port instead of raw EADDRINUSE.
- Plugin SDK gateway-runtime exports structural isGatewayTransportError /
  isGatewayClientRequestError guards (+2 documented surface budget).
- Regression coverage: same-registration stop/start restart, retired-owner
  takeover, typed CLI fallback classification, and a real token-auth gateway
  server routing voicecall.status through callGatewayFromCli.
steipete added a commit that referenced this pull request Aug 18, 2026
…-ends (#125458)

* fix(voice-call): survive gateway in-process restart and stop CLI dead-ends

The gateway's in-process restart (SIGUSR1 config reload) reuses the cached
plugin registry, so service stop/start run on the same retained voice-call
registration. Generation fencing from #120289 treated that restart as a stale
actor: stop retired the generation forever, the next start silently bailed,
and every voicecall.* RPC answered UNAVAILABLE "runtime generation is
retired" while the webhook never rebound.

- Registrations now hold a replaceable generation: service start after stop
  mints a fresh generation, takes over a running slot owned by a retired
  predecessor, and reports start failures to service health instead of
  silently returning.
- The voicecall CLI classifies gateway failures with typed guards instead of
  message substrings: standalone/store fallback only when the gateway is
  genuinely absent; reachable-but-failed (request errors, auth, timeout)
  exits with actionable text; a standalone webhook port collision explains
  that a running Gateway probably owns the port instead of raw EADDRINUSE.
- Plugin SDK gateway-runtime exports structural isGatewayTransportError /
  isGatewayClientRequestError guards (+2 documented surface budget).
- Regression coverage: same-registration stop/start restart, retired-owner
  takeover, typed CLI fallback classification, and a real token-auth gateway
  server routing voicecall.status through callGatewayFromCli.

* refactor(voice-call): split CLI modules and dedupe gateway fallbacks

Collapse the four duplicated gateway-or-runtime command blocks (speak, dtmf,
end, continue fallback) into one generic runGatewayManagerCommand helper —
the continue command owns its legacy-method fallback and operation polling
via a gatewayCall closure, so the helper carries no per-command policy.
Smoke reuses the shared initiateVoiceCall path instead of a bespoke
fallback.

Split the 988-line cli.ts into concept modules (cli-gateway-call,
cli-call-log, cli-command-io) and drop its grandfathered max-lines
suppression plus the now-stale max-lines and assertion-safety baseline
entries (shrink-only ratchet maintenance).

Behavior-frozen: stdout/exit semantics unchanged; net -2 production LOC.

* fix(voice-call): redact gateway URLs in CLI operational errors

ClawSweeper P1: the operational-error formatter interpolated the raw
connectionDetails.url, so a configured gateway URL with userinfo or query
tokens would print credentials into terminal output. Redact the composed
message once with the canonical net-policy redactor (also covers
remote-controlled close-reason text), exported through the plugin SDK
gateway-runtime subpath (+1 documented surface budget). Regression test
covers a credential-bearing URL in both the URL and message fields.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
…-ends (openclaw#125458)

* fix(voice-call): survive gateway in-process restart and stop CLI dead-ends

The gateway's in-process restart (SIGUSR1 config reload) reuses the cached
plugin registry, so service stop/start run on the same retained voice-call
registration. Generation fencing from openclaw#120289 treated that restart as a stale
actor: stop retired the generation forever, the next start silently bailed,
and every voicecall.* RPC answered UNAVAILABLE "runtime generation is
retired" while the webhook never rebound.

- Registrations now hold a replaceable generation: service start after stop
  mints a fresh generation, takes over a running slot owned by a retired
  predecessor, and reports start failures to service health instead of
  silently returning.
- The voicecall CLI classifies gateway failures with typed guards instead of
  message substrings: standalone/store fallback only when the gateway is
  genuinely absent; reachable-but-failed (request errors, auth, timeout)
  exits with actionable text; a standalone webhook port collision explains
  that a running Gateway probably owns the port instead of raw EADDRINUSE.
- Plugin SDK gateway-runtime exports structural isGatewayTransportError /
  isGatewayClientRequestError guards (+2 documented surface budget).
- Regression coverage: same-registration stop/start restart, retired-owner
  takeover, typed CLI fallback classification, and a real token-auth gateway
  server routing voicecall.status through callGatewayFromCli.

* refactor(voice-call): split CLI modules and dedupe gateway fallbacks

Collapse the four duplicated gateway-or-runtime command blocks (speak, dtmf,
end, continue fallback) into one generic runGatewayManagerCommand helper —
the continue command owns its legacy-method fallback and operation polling
via a gatewayCall closure, so the helper carries no per-command policy.
Smoke reuses the shared initiateVoiceCall path instead of a bespoke
fallback.

Split the 988-line cli.ts into concept modules (cli-gateway-call,
cli-call-log, cli-command-io) and drop its grandfathered max-lines
suppression plus the now-stale max-lines and assertion-safety baseline
entries (shrink-only ratchet maintenance).

Behavior-frozen: stdout/exit semantics unchanged; net -2 production LOC.

* fix(voice-call): redact gateway URLs in CLI operational errors

ClawSweeper P1: the operational-error formatter interpolated the raw
connectionDetails.url, so a configured gateway URL with userinfo or query
tokens would print credentials into terminal output. Redact the composed
message once with the canonical net-policy redactor (also covers
remote-controlled close-reason text), exported through the plugin SDK
gateway-runtime subpath (+1 documented surface budget). Regression test
covers a credential-bearing URL in both the URL and message fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug]: Voice Call can revive stale runtime generations during restart

1 participant