Repository navigation
Closed
Description
Bug type
Crash (process/app exits or hangs)
Summary
In Gateway Dashboard / Control UI chat, an embedded run can appear to finish its tool/file work, but the UI remains stuck in a running state:
Stopremains visible- clicking
Stopdoes nothing - gateway health still shows normal
- the affected chat session never returns to idle
This looks like a missing terminal lifecycle event (end / error) reaching the webchat/control-ui path after timeout/abort
Steps to reproduce
A chat run started normally and performed tool/file operations. The UI showed those operations as completed, but the chat remained stuck in a running state.
Observed behavior:
Stopremained visible- clicking
Stophad no effect - gateway health still showed normal
- the chat content already showed completed tool/edit actions
Observed log entry:
embedded run timeout: runId=<...> sessionId=<...> timeoutMs=600000
There were also timeout-related entries such as LLM request timeouts around the same period.
### Investigation notes
From tracing the bundled code in 2026.3.8, this does not look like a simple frontend-only issue.
What I found:
- Control UI chat finalization appears to depend on lifecycle terminal events (phase === "end" or "error")
- the embedded timeout path appears to call abortRun(true) / activeSession.abort()
- that timeout path does not appear to directly emit a terminal lifecycle event itself
- terminal lifecycle emission seems to depend on the embedded subscription path receiving agent_end
- once agentRunStarted === true in webchat/control-ui, the UI path appears to rely on lifecycle terminal events and does not seem to have a fallback finalization path if those events never arrive
### Current hypothesis
There is an edge case where an embedded run times out or aborts after startup, but no terminal lifecycle event reaches Control UI.
That leaves the webchat/control-ui run stuck in a running state even though the run has already ended internally.
### What this does NOT look like
Based on local tracing, this does not currently look like:
- a simple early-return bug in dispatchInboundMessage()
- a frontend-only rendering issue
- an indefinitely blocked cleanup in flushPendingToolResultsAfterIdle() (that cleanup appears bounded)
### Possible areas to inspect
- embedded timeout/abort path in runEmbeddedAttempt(...) / runEmbeddedPiAgent(...)
- whether activeSession.abort() can bypass agent_end
- whether subscribeEmbeddedPiSession(...) can unsubscribe before terminal lifecycle is emitted
- whether webchat/control-ui should defensively finalize a started run when dispatchInboundMessage() settles but no terminal lifecycle event was observed
### Repro hints
In my case this happened in Gateway Dashboard chat after a long-running embedded run that eventually timed out. The UI had already shown completed tool/edit actions, but the run never left the Stop state.
### Expected behavior
After a timeout or abort, the Control UI should always receive a terminal state and the run should finalize as one of:
- completed
- aborted
- error
The UI should leave the `Stop` state.
### Actual behavior
After timeout:
- the run can stay stuck on `Stop`
- clicking `Stop` may do nothing
- the gateway can remain otherwise healthy
- the specific run/session appears zombied in the UI
### OpenClaw version
2026.3.8
### Operating system
Windows 11
### Install method
npm
### Model
openai-codex/gpt-5.3-codex
### Provider / routing chain
chat
### Config file / key location
_No response_
### Additional provider/model setup details
From tracing the bundled code in 2026.3.8, this does not look like a simple frontend-only issue.
What I found:
- Control UI chat finalization appears to depend on lifecycle terminal events (phase === "end" or "error")
- the embedded timeout path appears to call abortRun(true) / activeSession.abort()
- that timeout path does not appear to directly emit a terminal lifecycle event itself
- terminal lifecycle emission seems to depend on the embedded subscription path receiving agent_end
- once agentRunStarted === true in webchat/control-ui, the UI path appears to rely on lifecycle terminal events and does not seem to have a fallback finalization path if those events never arrive
### Logs, screenshots, and evidence
```shell
Impact and severity
No response
Additional information

Activity
lost-abadan commentedon Mar 10, 2026
From
E:\tmp\openclaw\openclaw-2026-03-10.log:2026-03-10 16:45:33 +08:00gateway/wsresponded tonode.listin413ms2026-03-10 16:45:37 +08:00gateway/wsresponded tochat.historyin1165ms2026-03-10 16:45:38 +08:00gateway/wsresponded tochat.historyin429ms2026-03-10 16:46:08 +08:00gateway/wsresponded tonode.listin229ms2026-03-10 16:46:13 +08:00gateway/wsresponded tonode.listin391ms2026-03-10 16:49:58 +08:00gateway/wsresponded tochat.historyin1044ms2026-03-10 16:50:56 +08:00embedded run timeout: runId=c746332e-7e4d-4904-8d48-9df939abf504 sessionId=d7d69323-7b5b-49db-88fc-0508d407e70d timeoutMs=6000002026-03-10 17:00:54 +08:00RPC probe: okopenclaw-barnacle commentedon Apr 27, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
clawsweeper commentedon Apr 27, 2026
Thanks for the context here. I did a careful shell check against current
main, and this is already implemented.Close as implemented: current main ships the embedded lifecycle terminal backstop that emits a terminal lifecycle event when an embedded timeout/error turn returns without
agent_end, and that fix is included inv2026.4.29and later releases.So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review details
Best possible solution:
Keep the shipped runner-level lifecycle backstop; handle distinct remaining stuck-chat cases in their narrower tracking items instead of reopening this timeout lifecycle issue.
Do we have a high-confidence way to reproduce the issue?
Yes. The original bug has a high-confidence source-level reproduction: an embedded timeout/error turn can return without
agent_end; current regression coverage now simulates that missing-terminal path and verifies the synthesized terminal event.Is this the best way to solve the issue?
Yes. The shipped runner-level backstop is the narrow maintainable solution because it emits one terminal lifecycle event from the owner path and reuses the existing gateway chat finalization contract.
Security review:
Security review: No patch is under review for this issue, and the implemented fix is ordinary lifecycle state handling.
What I checked:
createEmbeddedLifecycleTerminalBackstoptracks lifecycle start/end/error and synthesizes a terminallifecycleevent with endedAt, aborted, stopReason, livenessState, and replayInvalid metadata when the embedded runner returns without one. (src/auto-reply/reply/agent-runner-execution.ts:998, e87966434818)onAgentEvent, emitsendafterrunEmbeddedPiAgentreturns, and emitserrorif the runner throws. (src/auto-reply/reply/agent-runner-execution.ts:1695, e87966434818)end/errorevents and emits chatfinal/errorpayloads, so the backstop reaches the same Control UI clearing path as a normalagent_end. (src/gateway/server-chat.ts:284, e87966434818)runEmbeddedPiAgentemit only lifecycle start and return a timeout/error result, then asserting a synthesized terminal lifecycle event is emitted; adjacent coverage asserts no duplicate when the runner already emitted one. (src/auto-reply/reply/agent-runner-execution.test.ts:1644, e87966434818)ebff12e84f32de8fcd454e0833f7016894aaa948, committed 2026-04-29T21:29:07Z with subjectfix(agents): finalize embedded lifecycle backstop. (src/auto-reply/reply/agent-runner-execution.ts:998, ebff12e84f32)v2026.4.29is ahead of the fix with merge base equal toebff12e84f32de8fcd454e0833f7016894aaa948;v2026.5.7also contains the fix. Release metadata showsv2026.4.29was published 2026-04-30T21:01:08Z. (ebff12e84f32)Likely related people:
src/auto-reply/reply/agent-runner-execution.ts,src/auto-reply/reply/agent-runner-execution.test.ts,CHANGELOG.md)fix(agents): always emit terminal lifecycle eventswork in the embedded lifecycle handler that owns normal terminal emission. (role: introduced related lifecycle contract behavior; confidence: medium; commits: 2f84e73c18c9; files:src/agents/pi-embedded-subscribe.handlers.lifecycle.ts)clear embedded runs before lifecycle endchange that added the before-terminal lifecycle hook around this path. (role: recent adjacent lifecycle contributor; confidence: medium; commits: d75725e658f8; files:src/agents/pi-embedded-subscribe.handlers.lifecycle.ts,src/agents/pi-embedded-runner/run/attempt.ts)Codex review notes: model gpt-5.5, reasoning high; reviewed against e87966434818; fix evidence: release v2026.4.29, commit ebff12e84f32.