Skip to content

fix: workspace tools fail after session continuation - #170791

Merged
roboclaw-bot merged 2 commits into
mainfrom
openclaw/crisp-langoustine
Oct 13, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
openclaw/crisp-langoustine

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes workspace tools failing with “Session changed while preparing its project” when a session resumes after a child result or another internal continuation.

User Impact

Users can continue working in the same prepared workspace after a resumed turn. Existing cancellation, workspace preparation, and stale-tool safety checks remain enforced. No configuration or data migration is required.

Why This Change Was Made

A successor could inherit the previous chat run’s expired workspace-readiness context. Autonomous runs now start without that inherited context, and chat dispatch always installs its own context—even when no preparation is pending.

Evidence

  • Reproduced the reported error in this work session immediately after a child-result continuation.
  • Both new successor-boundary regressions failed with that exact error before the fix and pass afterward. They use real host-bound filesystem reads and verify old retained tools stay denied.
  • 32 Gateway tests passed (53.96 seconds wall); 16 existing workspace-readiness safety tests passed.
  • Targeted typecheck, lint, formatting, and diff checks passed.
  • Independent review found no actionable P0–P2 findings.
  • Separate existing product fixture could not reach its early-prompt precondition: Checkout did not publish early prompt (callback=true, sourceOnly=false). This is not claimed as passing. Live latest-main continuation verification will be recorded after landing.

Worked on by

Work sessions


View the OpenClaw team session

roboclaw-bot and others added 2 commits October 13, 2026 07:34
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 72e1b295-0219-4f85-9855-0a0323b2e061
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 13, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 13, 2026 07:38
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) October 13, 2026 07:43
@roboclaw-bot
roboclaw-bot merged commit 27aef9a into main Oct 13, 2026
199 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/crisp-langoustine branch October 13, 2026 07:52
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
* fix: workspace tools fail after session continuation

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

* fix: workspace tools fail after session continuation

Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 72e1b295-0219-4f85-9855-0a0323b2e061

---------

Co-authored-by: steipete <[email protected]>
obviyus added a commit that referenced this pull request Nov 21, 2026
…rn ends (#203113)

## Problem

In a worktree session, the first turn starts a background exec with an exit wake and calls `sessions_yield`. When the command exits, the wake is refused before it starts with `Session changed while preparing its project; retry the task.` The exec result never reaches the agent. The chat then shows "This turn yielded, but no registered continuation can resume it. The run has ended." The user has to send another message to get the agent going again.

Cause: the first turn of a session with a deferred checkout runs inside `runWithAgentWorkspaceReadiness` (#169136). The exec child's exit callback runs in that turn's async context, so it inherits the turn's workspace gate. After the turn yields and ends, the session-event wake reaches `admitReplyTurn`, which captures the inherited gate and calls its `assertCurrent()` in the store-writer phase. The retired run is no longer registered, so the check throws the ownership error, about 10 ms after admission starts. Nothing in the session changed. The production log matches: `lifecycle-admission failed reason=writer`, then the refused wake.

Agent runs and follow-ups already clear this gate (#170791). Session-event wakes, queue and mailbox drains, and subagent announce/cleanup did not.

## Fix

`runOutsideAdmittedTurnScopes` (renamed from `runOutsideAdmittedGenerationScopes`) is the single entry point for detached work that is re-admitted when it executes. It now also drops the inherited workspace gate, the same way it drops the inherited plugin generations. Every detached re-admission now runs under the gate of the turn it actually starts. The name change touches only its existing callers.

A pre-start failure is not retried. A retry would have run in the same leaked context and failed the same way, and with the cause removed this failure no longer happens. A real session change before the wake (deleted chat, reset) keeps its existing behavior.

## Evidence

- Regression test (`bash-tools.exec-background-followup.test.ts`): a real background exec started inside a turn's workspace gate. The gate retires before the command exits, and the test asserts that the wake turn runs and its prompt carries the exec output. Red on base with the production error, green with the fix. The rest of that file and the consumer tests (session-event, queue, mailbox, subagent announce, chat-send/agent-run readiness) pass.
- Real Gateway, base vs head, from source. Isolated state, real model (OpenAI, embedded OpenClaw runtime). `sessions.create` with `worktree: true` and an initial message, so the checkout is deferred as in the incident. The agent runs `sleep 20; echo <marker>` in the background with an exit wake, then calls `sessions_yield`:
  - base: the wake fails with `session event execution failed source=exec ... Session changed while preparing its project`, then `completion delivery failed`. The transcript ends with "This turn yielded, but no registered continuation can resume it."
  - head: the wake turn runs, and the agent replies with the exact marker. No ownership errors.
- `tsgo:core`, `check:test-types`, oxlint/oxfmt on the changed files. The `max-lines` finding on `session-event-handoff.ts` is inherited: the file has the same line count as on `main`.

## Merge danger

Two-way door: no state, schema, config, or published contract changes, and a revert fully undoes it. Blast radius if wrong: detached wakes (exec, cron, restart, subagent completions) and queued follow-ups no longer see an inherited first-turn workspace gate. They admit against current session state, as agent runs and follow-ups already do.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…rn ends (openclaw#203113)

## Problem

In a worktree session, the first turn starts a background exec with an exit wake and calls `sessions_yield`. When the command exits, the wake is refused before it starts with `Session changed while preparing its project; retry the task.` The exec result never reaches the agent. The chat then shows "This turn yielded, but no registered continuation can resume it. The run has ended." The user has to send another message to get the agent going again.

Cause: the first turn of a session with a deferred checkout runs inside `runWithAgentWorkspaceReadiness` (openclaw#169136). The exec child's exit callback runs in that turn's async context, so it inherits the turn's workspace gate. After the turn yields and ends, the session-event wake reaches `admitReplyTurn`, which captures the inherited gate and calls its `assertCurrent()` in the store-writer phase. The retired run is no longer registered, so the check throws the ownership error, about 10 ms after admission starts. Nothing in the session changed. The production log matches: `lifecycle-admission failed reason=writer`, then the refused wake.

Agent runs and follow-ups already clear this gate (openclaw#170791). Session-event wakes, queue and mailbox drains, and subagent announce/cleanup did not.

## Fix

`runOutsideAdmittedTurnScopes` (renamed from `runOutsideAdmittedGenerationScopes`) is the single entry point for detached work that is re-admitted when it executes. It now also drops the inherited workspace gate, the same way it drops the inherited plugin generations. Every detached re-admission now runs under the gate of the turn it actually starts. The name change touches only its existing callers.

A pre-start failure is not retried. A retry would have run in the same leaked context and failed the same way, and with the cause removed this failure no longer happens. A real session change before the wake (deleted chat, reset) keeps its existing behavior.

## Evidence

- Regression test (`bash-tools.exec-background-followup.test.ts`): a real background exec started inside a turn's workspace gate. The gate retires before the command exits, and the test asserts that the wake turn runs and its prompt carries the exec output. Red on base with the production error, green with the fix. The rest of that file and the consumer tests (session-event, queue, mailbox, subagent announce, chat-send/agent-run readiness) pass.
- Real Gateway, base vs head, from source. Isolated state, real model (OpenAI, embedded OpenClaw runtime). `sessions.create` with `worktree: true` and an initial message, so the checkout is deferred as in the incident. The agent runs `sleep 20; echo <marker>` in the background with an exit wake, then calls `sessions_yield`:
  - base: the wake fails with `session event execution failed source=exec ... Session changed while preparing its project`, then `completion delivery failed`. The transcript ends with "This turn yielded, but no registered continuation can resume it."
  - head: the wake turn runs, and the agent replies with the exact marker. No ownership errors.
- `tsgo:core`, `check:test-types`, oxlint/oxfmt on the changed files. The `max-lines` finding on `session-event-handoff.ts` is inherited: the file has the same line count as on `main`.

## Merge danger

Two-way door: no state, schema, config, or published contract changes, and a revert fully undoes it. Blast radius if wrong: detached wakes (exec, cron, restart, subagent completions) and queued follow-ups no longer see an inherited first-turn workspace gate. They admit against current session state, as agent runs and follow-ups already do.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…rn ends (#203113)

## Problem

In a worktree session, the first turn starts a background exec with an exit wake and calls `sessions_yield`. When the command exits, the wake is refused before it starts with `Session changed while preparing its project; retry the task.` The exec result never reaches the agent. The chat then shows "This turn yielded, but no registered continuation can resume it. The run has ended." The user has to send another message to get the agent going again.

Cause: the first turn of a session with a deferred checkout runs inside `runWithAgentWorkspaceReadiness` (#169136). The exec child's exit callback runs in that turn's async context, so it inherits the turn's workspace gate. After the turn yields and ends, the session-event wake reaches `admitReplyTurn`, which captures the inherited gate and calls its `assertCurrent()` in the store-writer phase. The retired run is no longer registered, so the check throws the ownership error, about 10 ms after admission starts. Nothing in the session changed. The production log matches: `lifecycle-admission failed reason=writer`, then the refused wake.

Agent runs and follow-ups already clear this gate (#170791). Session-event wakes, queue and mailbox drains, and subagent announce/cleanup did not.

## Fix

`runOutsideAdmittedTurnScopes` (renamed from `runOutsideAdmittedGenerationScopes`) is the single entry point for detached work that is re-admitted when it executes. It now also drops the inherited workspace gate, the same way it drops the inherited plugin generations. Every detached re-admission now runs under the gate of the turn it actually starts. The name change touches only its existing callers.

A pre-start failure is not retried. A retry would have run in the same leaked context and failed the same way, and with the cause removed this failure no longer happens. A real session change before the wake (deleted chat, reset) keeps its existing behavior.

## Evidence

- Regression test (`bash-tools.exec-background-followup.test.ts`): a real background exec started inside a turn's workspace gate. The gate retires before the command exits, and the test asserts that the wake turn runs and its prompt carries the exec output. Red on base with the production error, green with the fix. The rest of that file and the consumer tests (session-event, queue, mailbox, subagent announce, chat-send/agent-run readiness) pass.
- Real Gateway, base vs head, from source. Isolated state, real model (OpenAI, embedded OpenClaw runtime). `sessions.create` with `worktree: true` and an initial message, so the checkout is deferred as in the incident. The agent runs `sleep 20; echo <marker>` in the background with an exit wake, then calls `sessions_yield`:
  - base: the wake fails with `session event execution failed source=exec ... Session changed while preparing its project`, then `completion delivery failed`. The transcript ends with "This turn yielded, but no registered continuation can resume it."
  - head: the wake turn runs, and the agent replies with the exact marker. No ownership errors.
- `tsgo:core`, `check:test-types`, oxlint/oxfmt on the changed files. The `max-lines` finding on `session-event-handoff.ts` is inherited: the file has the same line count as on `main`.

## Merge danger

Two-way door: no state, schema, config, or published contract changes, and a revert fully undoes it. Blast radius if wrong: detached wakes (exec, cron, restart, subagent completions) and queued follow-ups no longer see an inherited first-turn workspace gate. They admit against current session state, as agent runs and follow-ups already do.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 582f5d4)

Release adaptation: Preserve stable plugin invocation cleanup while also clearing the retired workspace readiness gate.

Companion audit: #204249, #204105, #203999, #202513 not applicable (later authority changes); #204260, #204178, #197395, #203156 missing in this lane, not dependencies.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant