Repository navigation
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. This PR’s central fix is now superseded by the merged canonical yielded-parent lifecycle work in #95996. That implementation keeps a yielded parent nonterminal through the internal lifecycle contract while deliberately retaining the existing public session status shape; this branch’s remaining Canonical path: Keep the merged internal yielded-parent contract from #95996; open a new, narrowly scoped proposal only if maintainers later decide that a public paused session-status API is required. So I’m closing this here and keeping the remaining discussion on #95996. Review detailsBest possible solution: Keep the merged internal yielded-parent contract from #95996; open a new, narrowly scoped proposal only if maintainers later decide that a public paused session-status API is required. Do we have a high-confidence way to reproduce the issue? No current-main failure remains to reproduce with high confidence: the merged canonical implementation covers the reported yielded-parent nonterminal behavior. The original lifecycle gap was concretely exercised and documented in the PR’s supplied live proof. Is this the best way to solve the issue? No; the branch is no longer the best solution because #95996 merged the same core fix using an internal yielded lifecycle contract that avoids this branch’s new public session-status API. Security review: Security review cleared: The proposed changes alter lifecycle and protocol state only; the supplied diff adds no dependency, workflow, secret, permission, artifact-download, or code-execution surface. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against e2fbd3b1ed75. |
There was a problem hiding this comment.
Pull request overview
Extends the existing sessions_yield “pause” semantics from subagent runs to top-level (main) sessions by persisting yielded lifecycle ends as status: "paused" with a pauseReason: "sessions_yield", and ensuring downstream consumers (UI/broadcasts/restart-recovery) respect that paused state.
Changes:
- Add
"paused"to session run status unions and introducepauseReason: "sessions_yield"on persisted session entries + gateway rows. - Update gateway lifecycle snapshot derivation to map yielded terminal lifecycle events to
status: "paused"and to clearpauseReasonon the next start. - Update broadcasts/session row building and restart-recovery logic + tests to propagate and honor the paused/yielded state.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/gateway/session-utils.types.ts | Adds paused to SessionRunStatus; introduces SessionPauseReason; adds pauseReason to GatewaySessionRow. |
| src/gateway/session-utils.ts | Updates terminal-status predicate for paused; includes pauseReason when building gateway session rows. |
| src/gateway/session-lifecycle-state.ts | Derives status: "paused" + pauseReason for yielded lifecycle ends; clears pauseReason on start; persists pause state. |
| src/gateway/session-lifecycle-state.test.ts | Adds coverage for yielded → paused mapping, yield short-circuiting, and pauseReason clearing on start. |
| src/gateway/server-chat.ts | Includes pauseReason in sessions.changed snapshots. |
| src/config/sessions/types.ts | Persists paused status and adds pauseReason?: "sessions_yield" to SessionEntry. |
| src/agents/tools/sessions-list-tool.ts | Allows "paused" as a readable session status from gateway data. |
| src/agents/tools/sessions-helpers.ts | Extends tool-level SessionRunStatus union to include "paused". |
| src/agents/main-session-restart-recovery.ts | Skips restart recovery for entries paused via sessions_yield. |
| src/agents/main-session-restart-recovery.test.ts | Adds tests ensuring paused/yielded sessions are skipped and not marked restart-aborted by cleaned locks. |
| CHANGELOG.md | Documents the main-session yielded → paused persistence behavior change and recovery skip. |
c1b4ce4 to
fce6130
Compare
fce6130 to
607eefb
Compare
607eefb to
d0f8dfa
Compare
d0f8dfa to
b50d7c0
Compare
|
@clawsweeper re-review Ran the requested exact-head live scenario tonight on an isolated sandbox gateway built from
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Important update on head
This replaces my earlier comment's conclusion that the projection was sound and only the Codex lane was gapped -- the native lane was equally broken live, and the unit tests missed it because they fabricate events that already carry |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Update (head What: the Codex app-server harness emits its own terminal lifecycle event ( Proven live (codex lane): a real Codex gate: checked |
|
CI on head The one red check is not from this PR — it's a pre-existing i18n raw-copy baseline drift already on
The two failures that were mine are fixed: |
|
Rebased onto current Re-verified the PR is not superseded: Adaptations to
Verification on the rebased head (worktree with hydrated modules):
On vocabulary: the paused-vs-deferred naming question raised alongside the still-open (and itself conflicting) #95996 remains a maintainer call. This PR intentionally does not pre-empt that decision; it keeps the |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto current Review finding fixed ([P2] Workboard linked-card paused handling):
No new user-visible strings were added for this; the paused card renders through the existing running lifecycle. A distinct paused visual can be layered on later if wanted. CI failure root-caused and fixed: Verification on head 0cefba4606: On the remaining review risk (persisted |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto current main @ 0d2db46 (#103194). The i18n |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Re-rebased onto current @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto current
|
Treats `sessions_yield` as a non-terminal paused state across the gateway lifecycle, persisted session-state, Control UI projection, and the new `pauseReason` field. Replaces the silent terminal `done` mapping that left orphan recovery unable to distinguish a clean yield from a completed run. The persisted/Gateway/UI session-status enum gains `"paused"` with a `pauseReason: "sessions_yield"` so consumers can distinguish the yield case without ambiguity. Existing consumers of the prior closed-status enum need maintainer acceptance of the compatibility impact. `resolveTerminalMainSessionTranscriptRegistryCheck` short-circuits when the entry status is `"paused"`, even when `endedAt` is positive. Without this, agent dispatch, auto-reply, and session-command callers would run terminal transcript freshness/rotation logic on a yielded paused main session while its queued continuation was still pending, defeating the nonterminal invariant the paused status preserves. `pauseReason` now propagates through every `sessions.changed` broadcast emit site: `server-chat.ts`, `server-session-events.ts`, `server-methods/session-change-event.ts`, and `server-methods/agent.ts` all carry the field. The Control UI side wires the field end-to-end: `GatewaySessionRow` in `ui/src/ui/types.ts` adds an optional `pauseReason` of type `SessionPauseReason`, and `SESSION_EVENT_ROW_FIELDS` in `ui/src/ui/controllers/sessions.ts` includes the field so a paused row delivered by an incremental `sessions.changed` event preserves the reason instead of dropping it on reducer merge. Workboard's `sessionCaptureStatus` projection now uses the shared `isSessionRunActive` helper instead of duplicating the `status === "running" || hasActiveRun === true` check. A paused session has a queued continuation pending; the helper already treats `paused` as active, so Workboard now reports `running` for yielded sessions instead of letting them slip into `done` / `review` while the runner is still about to drain the continuation. Adds the Control UI `sessionsView.statusPaused: "Paused"` label and syncs the 18 locale meta files (`fallbackKeys` + `totalKeys`) so `pnpm ui:i18n:check` passes.
Route the two remaining linked-card decision points (getWorkboardLifecycle and the card Live badge) through the shared isSessionRunActive predicate so a paused (sessions_yield) session with hasActiveRun:false renders as a pending continuation instead of an idle card.
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Extend the subagent yield-pause fix from 6f3b5f86 to top-level (non-subagent) sessions.
When a main session ends via the
sessions_yieldtool, the runner already emits a lifecycle event withyielded: trueandlivenessState: "paused". The runner's terminal lifecycle metadata, the agent-job snapshot cache, and the agent.wait dedupe entry all propagate those flags generically, so subagent and non-subagent runs benefit equally from those parts of 6f3b5f8.The gap is in
gateway/session-lifecycle-state.ts.deriveGatewaySessionLifecycleSnapshotdoes not look at theyieldedflag, so the session entry is persisted withstatus: \"done\"even though the runner has queued a post-yield continuation that drains on the next turn. Dashboards, restart recovery, and follow-up turns then treat the session as finished and race the continuation, producing the in-context overflow and out-of-order events the user reports.Why the same fix needs to apply to the top-level session
The subagent registry tracks active subagent runs in memory and uses
pauseReason: \"sessions_yield\"to keep yielded entries in a paused state instead of marking them complete. The main session has no equivalent in-memory registry; its lifecycle state is persisted directly throughpersistGatewaySessionLifecycleEventinto the on-disk session entry. The gap shows up in three places:status: \"done\", sosessions_list,sessions.changedbroadcasts, and dashboard UI all show the session as finished.main-session-restart-recoveryis keyed offentry.abortedLastRunandentry.status === \"running\". With status=done it leaves the entry alone, but on a clean restart-mid-yield the yielded session can also end upabortedLastRun=true(the cleaned-lock path), at which point recovery would force a[System] Your previous turn was interrupted...resume that races the queued continuation.Shape of the change
yieldedflag inderiveGatewaySessionLifecycleSnapshotand derivestatus: \"paused\"withpauseReason: \"sessions_yield\"instead ofdone. Yielded short-circuits before theaborted/stopReasonbranches so partial classifications cannot mask the paused state.pauseReasonon the next lifecyclestartevent so a fresh run reactivates the session, mirroring howsubagent-registry-lifecycle.tsclearspauseReasonon completion.\"paused\"toSessionRunStatusin bothgateway/session-utils.types.tsandagents/tools/sessions-helpers.ts, and addpauseReason?: \"sessions_yield\"toSessionEntryandGatewaySessionRow.pauseReasonon thesessions.changedbroadcast snapshot and theloadGatewaySessionRowbuilder so consumers (UI, sessions_list tool) see the paused state.isTerminalSessionStatusso the type predicate stays accurate after "paused" joins the union (paused is not terminal).main-session-restart-recoveryfor entries withpauseReason: \"sessions_yield\"so they are not re-prompted with the generic interrupted-turn message.The runner-level changes (yieldDetected -> livenessState=paused/yielded=true) and the gateway agent-job/agent-wait-dedupe propagation that 6f3b5f8 already added are unchanged. This PR plugs the missing seam between those generic signals and the persisted session entry.
Test coverage
src/gateway/session-lifecycle-state.test.ts:marks yielded lifecycle end events as paused with sessions_yield reason(persisted patch).treats yielded as paused even when aborted is set(yield short-circuit).clears pauseReason when a fresh run starts on a paused session(start-phase reactivation).pauseReason: undefinedon non-yield ends.src/agents/main-session-restart-recovery.test.ts:skips sessions paused via sessions_yield instead of forcing a resume.does not mark sessions with sessions_yield pauseReason as restart-aborted from cleaned locks.Local validation
pnpm tsgo:core,pnpm tsgo:core:test,pnpm tsgo:extensions,pnpm tsgo:extensions:test— clean.pnpm test src/gateway/session-lifecycle-state.test.ts src/agents/main-session-restart-recovery.test.ts src/gateway/server-chat.agent-events.test.ts src/config/sessions.test.ts src/agents/tools/sessions-list-tool.test.ts src/gateway/server-methods/agent.test.ts src/gateway/server-methods/agent.create-event.test.ts src/gateway/server-methods/agent-wait-dedupe.test.ts src/agents/subagent-registry.test.ts src/agents/subagent-announce-output.test.ts src/agents/pi-embedded-runner/sessions-yield.orchestration.test.ts— all green (235 tests).pnpm exec oxfmt --check,node scripts/run-oxlint.mjs,pnpm format:docs:check,pnpm check:changelog-attributions— all clean on changed files.Test plan
sessions_yieldfrom a main-session conversation; confirm the session entry persistsstatus: pausedandpauseReason: sessions_yield, and that a follow-up turn flips back torunningwithpauseReason: undefined.Real behavior proof
openclawrun ended via thesessions_yieldtool, the runner emittedyielded=trueandlivenessState=pausedbut the gateway treated it as a clean completion and wrotestatus=done. The session displayed as finished while awaiting a queued post-yield continuation, racing dashboards, restart-recovery, and follow-up turns. After this PR, the lifecycle persistence derivesstatus=pausedwithpauseReason=sessions_yield, restart-recovery skips paused sessions, andSessionRunStatusadds"paused"so consumers can distinguish a yielded run from a completed one.dist/server-chat-*.jsanddist/main-session-restart-recovery-*.jschunks carry the newpauseReason/sessions_yieldlogic; the proof script imports and executes those exact bundle bytes./tmp/proof-75662-amittell.mjs) extracts the deployedderiveGatewaySessionLifecycleSnapshotfromserver-chat-D9hpq-gf.jsviavm.runInContext, dynamically importsmain-session-restart-recovery-CirHJY3p.jsto grab the exported
markRestartAbortedMainSessions, seeds a tempstate-dir with one yielded and one non-yielded
runningentry, and assertsthree behaviors:
phase=endwithyielded=true->status=paused,pauseReason=sessions_yield,abortedLastRun=false.abortedLastRunwrite,
updatedAtunchanged).pauseReasonis markedabortedLastRun=true(existing behavior preserved).Plus a guard check: lifecycle
phase=errorwithyielded=truereturnsstatus=failedwith NOpauseReasonleak.status=paused/pauseReason=sessions_yieldand is skipped by restart recovery (noabortedLastRunmutation, noupdatedAtbump). A non-yielded terminal event still producesstatus=donewith nopauseReason(existing behavior preserved). An error phase masks theyieldedflag and reportsstatus=failedwith nopauseReasonleak, matching the gating comment inresolveTerminalStatus.node scripts/run-vitest.mjs run src/agents/main-session-restart-recovery.test.ts src/gateway/session-lifecycle-state.test.ts-> 22 passed + 15 passed (37/37). Broader:node scripts/run-vitest.mjs run src/gateway/session-utils.test.ts src/gateway/sessions-patch.test.ts src/gateway/session-message-events.test.ts-> 172/172 passed.node scripts/run-oxlint-shards.mjs --only=core --threads=4-> clean.sessions_yieldto completion); this is exercised by the existing vitest coverage inpi-embedded-runner/sessions-yield.orchestration.test.tsrather than reproduced live on rh-bot.Live exact-head capture (2026-06-12): found and fixed an emit-side gap
Running the requested live scenario on an isolated sandbox gateway (loopback :28795, fresh
OPENCLAW_STATE_DIR, Control UI webchat, nativeopenai-completionslane with a tool-calling model) surfaced a real defect in this PR's original head: the paused state never persisted in live runs, on any lane. A store probe polling every 0.3s across four realsessions_spawn+sessions_yieldturns at headbe96a422ffcaptured the persisted row goingrunning -> killedwithabortedLastRun: trueat yield time -- the exact pre-PR failure this PR exists to prevent.Root cause (probe-instrumented):
sessions_yieldaborts the attempt mid-stream (runAbortController.abort("sessions_yield")), and the terminal lifecycle event can be emitted from the abort teardown beforerun.tspost-processing writes theyieldedmeta. The bundle-level instrumentation captured the failing ordering directly:The event reaches
deriveGatewaySessionLifecycleSnapshotcarryingabortedwithoutyielded, andresolveTerminalStatuscorrectly resolves killed. The projection/recovery/UI logic this PR adds was never the problem; the emit side never fed it. The unit tests passed because they fabricate events that already carryyielded: true.Fix (in
a46ba508b8):onYieldnow recordsyieldedthrough the subscription's terminal lifecycle meta channel at tool time, before the abort, using the same late-binding pattern the yield abort itself uses (src/agents/embedded-agent-runner/run/attempt.ts). A regression test pins the handler half: an end event withstate.yieldedset andabortedresolved from theisTerminalAbortedfallback still carriesyielded(src/agents/embedded-agent-subscribe.handlers.lifecycle.test.ts).Post-fix live proof, end to end (same sandbox, instrumented bundle):
Reproduced again on a second pass (store probe
paused/sessions_yieldat 15:54-15:56 with closure-identity probes confirming the onYield-time recording). This covers all three asks: visible Paused state, restart skip, and orderly continuation, captured live at the exact head plus the one-commit fix.Codex lane now covered too (was a sibling-lane gap, now fixed in this PR). The Codex app-server harness lane emits its own terminal lifecycle event (
extensions/codex/src/app-server/run-attempt.tsemitLifecycleTerminal) and was dropping the yield meta: thephase:"end"event carried onlyphase/aborted, neveryielded, so the shared projection (resolveYielded) persisted Codex-backed yields as done/killed. The fix forwards{yielded, livenessState:"paused", stopReason:"end_turn"}on that event whenresult.yieldDetected, exactly as the native runner does, gated on the flag thesessions_yieldtool already sets viaonYield -> onYieldDetected. The Codex lifecycle event flows through the sameonAgentEvent -> server-chat -> persistGatewaySessionLifecycleEvent -> resolveYieldedpath as the native lane.Proven live on the Codex lane: a real
openai/gpt-5.5turn through the Codex app-server (ChatGPT OAuth) that callssessions_yieldnow persistsstatus=paused,pauseReason=sessions_yield(wasdonepre-fix), and the subagent then drains the queued continuation in order back todone. An integration test (extensions/codex/src/app-server/run-attempt.yield-lifecycle.test.ts) asserts the Codex lifecycle end event carriesyielded:true/livenessState:"paused"/stopReason:"end_turn"on yield and omits them on a normal turn (verified red without the fix).Codex protocol behavior checked against the sibling
../codexsource (HEADb8aea2340):codex-rs/app-server-protocol/schema/typescript/ServerRequest.ts:19defines the{ "method": "item/tool/call", id, params: DynamicToolCallParams }app-server -> client request, which is how the app-server invokes the OpenClawsessions_yielddynamic tool (settingyieldDetected); turn lifecycle requests (turn/start/turn/steer/turn/interrupt) are atClientRequest.ts:90. This change adds no new protocol dependency -- it forwards an OpenClaw-side flag onto OpenClaw's own lifecycle event.