* test(session): cover SQLite persistence and document the provider * test(session): align coverage with the latest SQLite implementation * test(session): adapt storage coverage to the current SQLite backend * feat(session)!: pass fork source through agent creation * refactor: prepare forks privately and append child segment events * refactor: choose fork sharing in SQLite creation transaction * fix(session): preserve caller-prepared fork seeds * feat(session): flush fixed fork prefix before child creation * fix(session): persist fork sources and await parent drain * chore: remove test and documentation changes from fork PR * refactor(agent-loop): reuse agent fork source type * fix(session): retain SQLite handle and JSONL errors after rebase * perf(session): create forks from the caller's history without reloading the parent The fork source carries the complete child history from seq 0. A live parent's log supplies the shared prefix; a cold parent's prefix is used as persistence returned it to the caller. The factory no longer reopens the parent, and the JSONL backend copies the supplied history instead of decoding the parent log again. The SQLite backend drains a live parent writer before sharing its persisted prefix, so the factory no longer flushes the parent or tracks owner disposal during that wait; its fork creation serializes child events without the read-side validation and reports publication failures through the shared wrapper. * refactor(session-query): report the persisted prefix length on live observations A live observation reports its event count as the persisted prefix, so the fork command's boundary fallback only covers observations from other producers. * test(session): exclude the SQLite POSIX lease from Windows coverage The SQLite copy of the session write lease executes its POSIX face only off Windows, matching the JSONL exclusion. * test(session): report legacy opener failures on stderr The two-process suite asserts only the error name; the message and cause now reach the inherited stderr so a CI failure identifies the SQLite error. * refactor(agent): keep seed as the constructor input and narrow the fork source CreateAgentOptions.seed stays the only constructor history; source names the parent and cut a seeded fork shares. The factory stores the constructed log with that source at creation, so no fork-only seed selection remains in the loop. * test(session): complete fork regressions and documentation * test(session): propagate current SQLite fixtures through fork regressions * test(session): describe fork creation from the caller's history The fork source now carries the complete child history and the factory no longer reopens or flushes the parent, so the fake factories, source expectations, and cancellation cases follow that flow: a sharing backend drains the parent writer itself, JSONL copies the supplied history, and observations always report the persisted prefix. Documentation, the upgrade guide, and the generated catalogs describe the same behavior. * test(session): cover fork creation without a factory flush The in-process fork provider's cases no longer wait for a parent flush: the live log supplies the completed prefix and cancellation is exercised while child storage is pending. The Remote fork command's boundary fallback is covered by an observation that omits its persisted count. * test(session): drop redundant observation assertions in the fork fallback case * test(session): describe fork creation with seed beside a parent source The agent factory keeps seed as the constructor history and source names only the parent and cut, so the fakes, source expectations, and documentation follow that split; the case where a live parent replaced the supplied prefix no longer applies. * refactor(session): name the fork parent option parentSource `CreateAgentOptions.source` and `SessionPersistenceCreateOptions.source` become `parentSource`: the field names the parent Session a seeded fork shares its prefix with, and the shorter name read as a generic origin. * refactor(session-query): report persistedEventCount on cold observations only A live observation holds the Session's own events, none of them read-time repairs, so its stored prefix is its whole log and the field said nothing; only a cold read appends interrupted-turn closers in memory and needs to tell the fork cut where the stored prefix ends.
description, kind
| description | kind |
|---|---|
| In-process fork subagent backend for users and maintainers choosing, configuring, or debugging children seeded with the parent's completed turns. | package-reference |
@deepseek-ai/dsh-subagent-fork-in-process
English | 中文
Summary
dsh-subagent-fork-in-process is an in-process subagent backend that seeds each child with the parent's completed conversation turns: the child sees every finished turn and none of the in-flight one, so follow-up work builds on the conversation without duplicating it. A delegation tool reaches it under the fork provider name, and its behavior matches the spawn backend except for the session seed. Choose it when a subtask continues this conversation; choose spawn when the child must stand alone. The seed is a one-time snapshot taken at fork time: later parent turns never reach the child.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
Mount this backend when delegated work must build on the parent's conversation. The common path mirrors spawn: load the subagent service and this backend, then point a delegation tool such as dsh-tool-subagent at the fork provider.
When to choose it
Choose fork when the child needs the conversation's completed turns — a follow-up analysis, a review, a continuation. Choose spawn when the child should start clean, or an out-of-process backend when the child must not share this process. The seed carries conversation history only: the child still gets a fresh tool scope and none of the parent's authority.
Seed boundary
The seed ends at the parent's last completed turn. A parent's current tool-calling turn is still open when a subagent starts, so that in-flight turn is never included; before the first completed turn the seed is empty and the child behaves like a fresh spawn.
Minimal configuration
Load the subagent service and this backend, then configure a delegation tool. This composition exposes a subagent tool backed by fork:
- name: '@deepseek-ai/dsh-subagent'
- name: '@deepseek-ai/dsh-subagent-fork-in-process'
- name: '@deepseek-ai/dsh-tool-subagent'
config:
provider: fork
| Field | Default | Meaning |
|---|---|---|
providerName |
fork |
Provider name registered on ctx.subagents |
The generated configuration catalog is the exhaustive source for every accepted field and its JSDoc.
What a fork delegation does
One tool call creates a background child and returns its name immediately. The child works in its own session; the parent receives its final answer in a completion notice. The child can also send messages through send_message. A rejected start leaves no published child. Programmatic callers such as workflows can await the activation result directly.
Understand the implementation
Implementation internals — click to expand
This section explains the design decisions behind the backend and where the behavior in Use this package comes from.
Design concept
This backend supplies the balanced completed-turn prefix of the parent log as the child session seed. The subagent service records the inherited range so results contain only the child’s own output.
Source map
| File | Role |
|---|---|
src/index.ts |
Provider registration: prefix computation, Config schema, capability declaration |
Run flow
prepareContinuable() captures the parent’s completed-turn prefix once at creation. startActivation() creates the child with that seed, and the subagent service composes the inherited preset and optional structured output. The provider advertises agent options, output, and depth capabilities; independent preset selection is unsupported.
Lifecycle binding
The delegation tool creates a background activation and returns the child's name. Parent and child share the same messaging tool definitions and ordering; the parent's name in identity runtime context and the return guidance in the initial task both follow inherited history. Workflows await results with caller delivery and send no completion notice to the parent.
Further Exploration
Read these pages when the package-level contract is not enough; they move from the shared subagent model to the sibling backends and the design evidence for preserving the inherited request prefix.
- Subagent subsystem — start requests, results, provider contract, and in-process depth and seed.
- dsh-subagent-spawn-in-process — the fresh-child sibling backend.
- dsh-tool-subagent — the model-facing delegation tool that reaches this provider.
- Generated configuration catalog — every accepted config field and its source declaration.
- Forked children preserve the parent request prefix — why continuable fork preserves the inherited request prefix.
Model Experience
Child-agent history and envelope
What the model sees
The child receives the parent's balanced completed-turn prefix, then the new task as a message from the parent agent: Agent <parent name> sent a message: followed by the task content verbatim. It joins the parent's preset revision, which supplies persona and tools. Parent agent-local restrictions are not copied. An optional structured-output request adds a child-only tool; the parent's current in-flight turn is excluded.
Token effect
Forking duplicates retained completed history into the child's request, which then accumulates its own tokens independently. A first-turn fork has no inherited history.
KV Cache effect
The child may reuse the inherited byte-identical prefix under the same provider and model. Structured output, generated-SDK, route changes, or historical descriptor overrides on cold resume can invalidate reuse before inherited history; later child history is append-only. Continuable messaging adds no child-only system-prompt section or tool schema; the parent id and return guidance follow inherited history in the initial delegated task (cache-preserving fork Agent Note).
Parent tool result, indirectly
What the model sees
Through dsh-tool-subagent, the parent first receives the child's name, then a completion notice with its final answer. Child-authored messages arrive through send_message; the inherited prefix and internal work remain in the child session.
Token effect
Parent input grows by one data-dependent final result retained until compaction.
KV Cache effect
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
Known Limitations and Deferred Work
These limits define when the backend is the wrong choice; they are current package constraints.
- The seed is a one-time snapshot — the child sees the parent's completed turns as of the fork and nothing the parent logs afterwards; there is no live context sharing.
- Prefix reuse depends on matching request inputs — parent and child messaging definitions match byte for byte; structured output, generated-SDK, route changes, or restored historical overrides can still break equality. Rationale: the cache-preserving fork Agent Note.
- Shipped fork tools do not expose child LLM route selection — they inherit the parent's provider and model so the copied history remains eligible for KV Cache reuse. Route selection stays disabled until a change can preserve reuse or expose a bounded recomputation cost.
Dev Note
Working context for maintainers — click to expand
None.