Files
deepseek-harness/docs/upgrade-guide/v0.2.2-rc.3/session-fork-source/guide.md
T
Kexin Liu e50e24de40 feat(session): 等父前缀持久化后创建共享 fork (#8392)
* 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.
2026-11-17 17:28:59 +08:00

1.9 KiB

kind, description
kind description
upgrade-guide Agent factory callers create forks by naming the shared parent prefix beside the seed.

Fork creation takes a parent source

English | 中文

Change

A fork passes CreateAgentOptions.parentSource: { sessionId, endSeq } beside its seed: the parent and the exclusive length of the parent prefix the child shares. The first endSeq seed events must be the parent's stored events as a persistence read or observation returned them. The factory forwards the constructed log with that parent as SessionPersistenceCreateOptions.parentSource, and the backend stores it before create() resolves: SQLite drains a live parent writer, references the persisted prefix, and writes only the events after endSeq; JSONL copies the log. A parent whose stored history is shorter than endSeq rejects creation on SQLite with SESSION_FORK_PREFIX_NOT_PERSISTED.

The session/fork Remote request and its inclusive atSeq remain unchanged. Later parent events do not extend the child history. Direct replay or restoration using complete seed events remains available to Agent factory callers, and ContinuableCreateSpec.seed keeps supplying the subagent prefix.

Migration

  1. Add parentSource: { sessionId, endSeq } beside seed when the history comes from a parent Session; keep inheritedEventCount and meta.isSeeded.
  2. Supply the parent prefix exactly as persistence returned it. A cold observation's persistedEventCount bounds endSeq; events after it, such as interrupted-turn repairs, belong to the child.
  3. Fork at a completed turn, reopen the child, and confirm it contains the selected history. Append another parent turn and confirm the child history remains unchanged. See the Agent creation reference for the source fields and the persistence service for backend storage.