You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 891ae87
Browse filesBrowse the repository at this point in the historyBrowse files
fix(sessions): preserve fork lifecycle ownership and context
Preserve incognito storage, revalidate message-cut authority at commit, and keep late UI fork results scoped to their presentation. Carry prepared child identity and actual context through subagent cleanup and receipts. Verify native source cuts with canonical projection and preserve supervision connection and cleanup ownership. Document the separate canonical-descendant initialization limitation.
Copy file name to clipboardExpand all lines: docs/concepts/session-tool.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,7 +136,7 @@ See [Session state awareness](/concepts/session-state) for the full model: event
136
136
137
137
## Spawning sub-agents
138
138
139
-
`sessions_spawn` creates an isolated session for a background taskby default. It is always non-blocking; it returns immediately with a `runId` and `childSessionKey`. Native sub-agent runs receive the delegated task in the child session's first visible `[Subagent Task]` message, while the system prompt carries only sub-agent runtime rules and routing context.
139
+
`sessions_spawn` creates a separate session for a background task. Non-thread spawns start with isolated context by default; thread-bound spawns follow the configured context policy described below. It is always non-blocking; it returns immediately with a `runId` and `childSessionKey`. Native sub-agent runs receive their delegated task in a `[Subagent Task]` message appended after any forked history; inherited task envelopes are context, not the current child's assignment. The system prompt carries only sub-agent runtime rules and routing context.
140
140
141
141
Key options:
142
142
@@ -145,7 +145,7 @@ Key options:
145
145
-`runTimeoutSeconds` to override the configured child-run timeout; `0` disables it.
146
146
-`thread: true` to bind the spawn to a chat thread (Discord, Slack, etc.).
147
147
-`sandbox: "require"` to enforce sandboxing on the child.
148
-
-`context: "fork"`for native sub-agents when the child needs the current requester transcript; omit it or use `context: "isolated"` for a clean child. `context: "fork"` is only valid with `runtime: "subagent"`. Thread-bound native sub-agents default to `context: "fork"` unless `threadBindings.defaultSpawnContext` says otherwise.
148
+
-`context: "fork"` when the child needs the current requester transcript; this requires `runtime: "subagent"` and the same agent as the requester, whether the child is hidden or visible. Use `context: "isolated"`explicitly for a clean child. Omission means isolated context for non-thread spawns; thread-bound native sub-agents follow `threadBindings.defaultSpawnContext`, which defaults to `fork`.
149
149
-`visible: true` to create a persistent dashboard session instead of a hidden sub-agent session. Visible spawns support an explicit sidebar `category`, model, working directory, same-agent transcript fork, and an optional [managed worktree](/concepts/managed-worktrees); see [Sub-agents](/tools/subagents#tool-parameters) for the exact compatibility limits. The accepted result is a receipt: it includes the child session key, run id, a Control UI `sessionUrl` (omitted when the Control UI is disabled), and an `owner` record naming the requesting agent. When acknowledging the spawn in a channel, put the session URL on the first line and `Owner: <label>` on the second. The spawned session is attributed to the requesting agent in the sidebar; see [Multi-user mode](/concepts/multi-user#agent-spawned-sessions).
150
150
151
151
Default leaf sub-agents do not get session tools. When `maxSpawnDepth >= 2`, depth-1 orchestrator sub-agents additionally receive `sessions_spawn`, `subagents`, `sessions_list`, and `sessions_history` so they can manage their own children. Leaf runs still do not get recursive orchestration tools.
Older installs may still have `sessions.json` files under the agent `sessions/`
20
20
directory. Treat those files as legacy session-row migration inputs or explicit
21
-
offline-maintenance targets. Gateway startup and `openclaw doctor --fix` import
22
-
hot legacy rows and transcript history into the per-agent SQLite store
23
-
automatically. Run `openclaw doctor --session-sqlite inspect
24
-
--session-sqlite-all-agents`, then follow the [Doctor migration
25
-
sequence](/cli/doctor#session-sqlite-migration), when you need explicit
26
-
inspection or validation evidence. If a migration fails after legacy transcript
21
+
offline-maintenance targets. Gateway startup does not import them. Stop the
22
+
Gateway, back up its state, and use `openclaw doctor --fix` to import legacy rows
23
+
and transcript history into the per-agent SQLite store. Run
24
+
`openclaw doctor --session-sqlite inspect --session-sqlite-all-agents`, then
25
+
follow the [Doctor migration sequence](/cli/doctor#session-sqlite-migration)
26
+
for inspection and validation. If a migration fails after legacy transcript
27
27
artifacts were archived, use the Doctor recovery mode from that sequence.
28
28
Recovery uses migration manifests, restores only the affected archived support
29
29
artifacts, prepares a sanitized GitHub issue report when requested, and does not
@@ -137,7 +137,8 @@ Each `sessionKey` points at a current `sessionId` (the SQLite transcript identit
137
137
-**Control UI reconnect resume** preserves the currently visible session for one reconnect send when the Gateway receives the matching `sessionId` from an operator UI client. This is a one-shot signal; ordinary stale sends still create a new `sessionId`.
138
138
-**System events** (heartbeat, cron wakeups, exec notifications, gateway bookkeeping) may mutate the session row but never extend daily/idle reset freshness. Reset rollover discards queued system-event notices for the previous session before the fresh prompt is built.
139
139
-**Automatic parent fork policy** uses OpenClaw's active branch when creating a thread or subagent fork. If that branch is too large (over a fixed internal cap, currently 100K tokens), OpenClaw starts the child with isolated context instead of failing or inheriting unusable history. Sizing is automatic and not configurable; legacy `session.parentForkMaxTokens` config is removed by `openclaw doctor --fix`.
140
-
-**Operator forks**: `sessions.create { parentSessionKey, fork: true }` creates a new session whose transcript branches from the parent's current state. Admission uses the selected child model's effective usable input capacity, falling back to the 100K safety cap when model capacity is unavailable. The fork is refused while the parent has an active run, inherits the parent's model selection unless one is passed explicitly, and marks the child `forkedFromParent` with fresh token counters.
140
+
-**Operator forks**: `sessions.create { parentSessionKey, fork: true }` branches from the parent's current state. Admission uses the selected child model's effective usable input capacity, falling back to the 100K safety cap when model capacity is unavailable. A normal fork is refused while the parent has an active run; adding `forkFrom: "last-completed"` copies only through the last completed assistant message, excluding the in-progress tail. Unlike automatic parent forks, an operator fork over its capacity limit is rejected rather than accepted with isolated context. The child inherits the parent's model selection unless one is passed explicitly. The response marks it `forkedFromParent`, and token counters start fresh.
141
+
-**Message forks**: `sessions.fork { sessionKey, entryId }` creates a child from the active-path prefix before the selected user message and returns that message to the composer for editing. The parent remains unchanged. Incognito forks retain the parent's in-memory storage class; restarting the Gateway removes both sessions. See [Control UI](/web/control-ui) for fork and rewind actions.
|`isolated`| Fresh research, independent implementation, slow tool work, or anything that can be briefed in the task text | Creates a clean child transcript. This is the default and keeps token use lower.|
136
-
|`fork`| Work that depends on the current conversation, prior tool results, or nuanced instructions already present in the requester transcript | Branches the requester transcript into the child session before the child starts. |
|`isolated`| Fresh research, independent implementation, slow tool work, or anything that can be briefed in the task text | Creates a clean child transcript. Default for non-thread spawns; keeps token use lower. |
138
+
|`fork`| Work that depends on the current conversation, prior tool results, or nuanced instructions already present in the requester transcript | Branches the requester transcript into the child session before the child starts. |
137
139
138
140
Use `fork` sparingly. It is for context-sensitive delegation, not a
139
141
replacement for writing a clear task prompt.
@@ -160,11 +162,13 @@ session to confirm the effective tool list.
160
162
-**Thinking:** native sub-agents inherit the caller unless you set `agents.defaults.subagents.thinking` (or per-agent `agents.entries.*.subagents.thinking`). ACP runtime spawns also apply `agents.defaults.models["provider/model"].params.thinking` for the selected model. An explicit `sessions_spawn.thinking` still wins.
161
163
-**Run timeout:** pass `runTimeoutSeconds` to set a timeout for a specific native, ACP, or visible sub-agent run. When omitted, OpenClaw uses `agents.defaults.subagents.runTimeoutSeconds` if configured; otherwise it falls back to `0` (no timeout). An explicit `0` disables the timeout for that run.
162
164
-**Process lifetime:** a detached OpenClaw sub-agent has its own run lifecycle. A background task created inside an external CLI backend is different: it shares the parent CLI subprocess and stops if that parent reaches `agents.defaults.timeoutSeconds`.
163
-
-**Task delivery:** native sub-agents receive the delegated task in their first visible `[Subagent Task]` message. The sub-agent system prompt carries runtime rules and routing context, not a hidden duplicate of the task.
165
+
-**Task delivery:** native sub-agents receive their delegated task in a `[Subagent Task]` message appended after any forked history. Inherited task envelopes are context, not the current child's assignment. The sub-agent system prompt carries runtime rules and routing context, not a hidden duplicate of the task.
164
166
165
-
Accepted native sub-agent spawns include the resolved child model metadata
166
-
in the tool result: `resolvedModel` contains the applied model ref and
167
-
`resolvedProvider` contains the provider prefix when the ref has one.
167
+
Accepted native sub-agent spawns report their actual initialized `context`
168
+
(`fork` or `isolated`), including `isolated` when a requested fork exceeds the
169
+
parent-context size cap. They also include resolved child model metadata:
170
+
`resolvedModel` contains the applied model ref and `resolvedProvider` contains
171
+
the provider prefix when the ref has one.
168
172
169
173
### Delegation prompt mode
170
174
@@ -245,8 +249,8 @@ In `prefer` mode, hidden sub-agents are for internal legwork that the user does
`fork` branches the requester's current transcript into the child session. Native sub-agents only. Thread-bound spawns default to `fork`; non-thread spawns default to `isolated`. A visible fork must target the same agent as the requester.
`fork` branches the requester's current transcript into the child session. Native sub-agents only. Non-thread spawns default to `isolated`; thread-bound spawns follow `threadBindings.defaultSpawnContext`, which defaults to `fork`. Pass `isolated` explicitly to guarantee clean context. All native forks, hidden or visible, must target the same agent as the requester.
Create a persistent dashboard session for work the user will watch or return to, or when they ask for a thread. Visible spawns support only `runtime: "subagent"` and always keep the created session.
0 commit comments