mirror of
https://github.com/agentclientprotocol/claude-agent-acp.git
synced 2026-12-04 23:22:01 +00:00
perf: rebuild only the status after a child append in a status read (#1763)
## What A cached status cursor checked the file version of each child transcript, and any change rendered the whole root history again. The root render does not depend on the transcript of a child that launched no children: a status read uses only the end of that transcript, for the status update, which is outside the cursor. When only such transcripts changed, the read now reads their ends again and sends the cached root part, the same cursor and the new status. A change to the transcript of a child that launched children still renders the history again, because its launches are on that child's stream. Any other changed input still renders again: the root transcript, a metadata file, the title, the rewind file, or, on AIR, a `SKILL.md` that a Skill call links (see the PR below this one). This is item 5 of the #1754 review. ## Why Synthetic session: a 100 MB root and 60 subagents (3 parents of 30 MB with 4 nested children each), Node, median of 5. A child append is an append to a child without children. | Poll | #1754 v1 / v2 | this stack v1 / v2 | |---|---|---| | Status poll after a child append | 531 ms / 597 ms | 3 ms / 3 ms | A root with TodoWrite, MCP and ToolSearch calls needs the deny-list of the PR below to reach this path. On such a session (100 MB root, 8 subagents, v1 AIR), a status poll after a child append takes 1002 ms on #1754 and 1 ms on this stack. ## Tests - `npm run build` and `npm run check` pass. - `npm run test:run`: 5116 passed. The same 34 tests fail on #1754 in this environment. - `src/tests/session-read-subagents.test.ts` (v1 AIR, v1 RFD, v2): - An append to a child that launched no children gives the same cursor and the new status, with no render and no root read. The status equals that of a read from the start, and the next poll is quiet. - An append to a child that launched children renders again, and finds its new launch. - On AIR, a new `SKILL.md` together with a child append still renders the history again. ## Known issues - The quiet path starts only when the root uses no denied tool (Agent and Task are allowed in a status read). After the PR below this one, that covers sessions with TodoWrite, MCP, Skill, SendMessage, ToolSearch and similar tools. ExitPlanMode still makes every poll render. - A change to the transcript of a child that launched children renders the whole history again.
This commit is contained in:
committed by
GitHub
parent
a522885da9
commit
e41665c206
@@ -93,7 +93,7 @@ V1 has no custom update variants, so on v1 the update is a `session_info_update`
|
||||
- `state` uses the vocabulary of the lifecycle updates. On v1 AIR clients it is a string: `running`, `idle`, `completed`, `failed`, `cancelled` or `disconnected`. Otherwise it is a `subagent_update` state: `{"state":"running"}`, `{"state":"idle"}`, or `{"state":"idle","stopReason":"end_turn" | "cancelled" | "error"}`. The end comes from the last task notification of the child, then from a stop by the user, then from the result of a foreground launch. A background launch's result is no end. A launch whose parent cannot be restored, or a launch with neither a metadata file nor an end, is `disconnected` on v1 AIR clients. Without an end, a child is `idle` when the last user or assistant record of its transcript ends the turn, else `running`. An answer ends the turn with any stop reason except `tool_use` and `pause_turn`, such as `end_turn`, `max_tokens` or `refusal`. So do a record that no model wrote (model `<synthetic>`, such as an API error) and the successful result of a `SubagentHandback` call. `model` is the model of the last record that a model wrote. On the RFD form and v2 a full read reports such a child `idle` too. Past 4 MB without a whole record, a child is `running` with no `model` or `updatedAt`.
|
||||
- `background`, `agentType` and `cwd` come from the metadata file. `model`, `updatedAt` (the `timestamp` of the last record) and `size` (bytes) come from the transcript. A child without a transcript yet has no `size`.
|
||||
|
||||
A child that continues after its end, such as one resumed by `SendMessage`, keeps its end in `state`, and its `size` and `updatedAt` grow. Compare `size` with the previous status to see new work. Because the cursor covers no end state and no title, a child that ends, a stop by the user and a title change keep the cursor valid. The next cursor read returns only new records and the current status. A cached status cursor also covers sessions with Agent and Task calls: it checks the metadata of every child and the file version of each child transcript. A child transcript that is not a regular file, such as a symbolic link, gives no cached cursor.
|
||||
A child that continues after its end, such as one resumed by `SendMessage`, keeps its end in `state`, and its `size` and `updatedAt` grow. Compare `size` with the previous status to see new work. Because the cursor covers no end state and no title, a child that ends, a stop by the user and a title change keep the cursor valid. The next cursor read returns only new records and the current status. A cached status cursor also covers sessions with Agent and Task calls: it checks the metadata of every child and the file version of each child transcript. When only the transcripts of children that launched no children changed, the read does not render the history again: it reads the ends of those transcripts and sends the same cursor with the new status. A change to the transcript of a child that launched children renders the history again, because the launches in it are on that child's stream. A child transcript that is not a regular file, such as a symbolic link, gives no cached cursor.
|
||||
|
||||
Limits:
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ type ReadOptions = {
|
||||
historyEnd?: number;
|
||||
title?: string;
|
||||
storage?: SessionReadStorage;
|
||||
/** For a status read: the status update, which goes out outside the cursor. */
|
||||
status?: SessionReadFrame;
|
||||
/** For a status read: the status, whose update goes out outside the cursor. */
|
||||
status?: SubagentStatus;
|
||||
/** For a child read: the session id of the child's stream in `frames`. */
|
||||
stream?: string;
|
||||
}>;
|
||||
@@ -158,35 +158,45 @@ function subagentRecords(history: SubagentHistory): string {
|
||||
return json([...history.agents].sort(([a], [b]) => a.localeCompare(b)));
|
||||
}
|
||||
|
||||
/** Checks the transcript's metadata and the sidecar inputs read by the replay. */
|
||||
async function storageUnchanged(sessionId: string, storage: SessionReadStorage): Promise<boolean> {
|
||||
/**
|
||||
* Checks the transcript's metadata and the sidecar inputs read by the
|
||||
* replay. Returns the subagent transcripts in `storage.files` that changed,
|
||||
* with their current versions: empty when nothing changed, undefined when
|
||||
* another input changed or a file is not a regular file.
|
||||
*/
|
||||
async function storageChanges(
|
||||
sessionId: string,
|
||||
storage: SessionReadStorage,
|
||||
): Promise<[path: string, version: string | null][] | undefined> {
|
||||
try {
|
||||
// A move or a different matching project must go through the ordinary lookup.
|
||||
const transcript = await findTranscript(sessionId, { strict: true });
|
||||
if (transcript !== storage.transcript) return false;
|
||||
const matchesTranscript = async () => {
|
||||
if (transcript !== storage.transcript) return undefined;
|
||||
const transcriptChanges = async () => {
|
||||
if (storage.version !== undefined) {
|
||||
const root = await lstat(transcript, { bigint: true });
|
||||
if (!root.isFile() || fileVersion(root) !== storage.version) return false;
|
||||
if (!root.isFile() || fileVersion(root) !== storage.version) return undefined;
|
||||
}
|
||||
const changed: [string, string | null][] = [];
|
||||
for (const [file, version] of storage.files ?? []) {
|
||||
const current = await fileVersionAt(file);
|
||||
if (current === undefined || current !== version) return false;
|
||||
if (current === undefined) return undefined;
|
||||
if (current !== version) changed.push([file, current]);
|
||||
}
|
||||
return true;
|
||||
return changed;
|
||||
};
|
||||
if (!(await matchesTranscript())) return false;
|
||||
if (!(await transcriptChanges())) return undefined;
|
||||
if (
|
||||
storage.subagents !== undefined &&
|
||||
subagentRecords(await subagentHistory(sessionId, { strict: true, transcript })) !==
|
||||
storage.subagents
|
||||
)
|
||||
return false;
|
||||
return undefined;
|
||||
if (storage.sidecarTitle !== undefined) {
|
||||
const title = await readSidecarTitle(transcript, { strict: true });
|
||||
if ((title ?? null) !== storage.sidecarTitle) return false;
|
||||
if ((title ?? null) !== storage.sidecarTitle) return undefined;
|
||||
}
|
||||
if (await readRewindPoint(sessionId, undefined, { transcript })) return false;
|
||||
if (await readRewindPoint(sessionId, undefined, { transcript })) return undefined;
|
||||
if (
|
||||
storage.skills &&
|
||||
json(
|
||||
@@ -196,11 +206,12 @@ async function storageUnchanged(sessionId: string, storage: SessionReadStorage):
|
||||
),
|
||||
) !== json(storage.skills.paths)
|
||||
)
|
||||
return false;
|
||||
return await matchesTranscript();
|
||||
return undefined;
|
||||
// The versions of this second check: the caller reads the changed files after them.
|
||||
return await transcriptChanges();
|
||||
} catch {
|
||||
// An uncertain probe leaves validation and errors to the ordinary replay.
|
||||
return false;
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,7 +693,7 @@ type Checkpoint = {
|
||||
storage: SessionReadStorage;
|
||||
boundaries: SessionReadFrame[];
|
||||
title?: string;
|
||||
status?: SessionReadFrame;
|
||||
status?: SubagentStatus;
|
||||
/** The root session, for a child read too. */
|
||||
root: string;
|
||||
/** The child's stream, for a child read. */
|
||||
@@ -849,7 +860,7 @@ export class SessionReads {
|
||||
outgoing: SessionReadFrame[],
|
||||
cursorId: string | undefined,
|
||||
title: string | undefined,
|
||||
current: SessionReadFrame | undefined,
|
||||
current: SubagentStatus | undefined,
|
||||
) => {
|
||||
for (const frame of outgoing) {
|
||||
check();
|
||||
@@ -858,7 +869,7 @@ export class SessionReads {
|
||||
// The subagent status is current, outside the replay cursor.
|
||||
if (current) {
|
||||
check();
|
||||
await options.send(current);
|
||||
await options.send(current.frame(sessionId, options.protocol));
|
||||
}
|
||||
// On v2, and in a v1 status read, the title is current session info, outside the replay cursor.
|
||||
if (
|
||||
@@ -879,16 +890,37 @@ export class SessionReads {
|
||||
// Before the render, which can take seconds on a large session.
|
||||
if (cursor !== undefined && tagOf(cursor) !== tag) throw invalidCursor();
|
||||
const cached = cursor ? this.checkpoints.get(key) : undefined;
|
||||
if (
|
||||
const changes =
|
||||
cached &&
|
||||
cached.cursorId === cursor &&
|
||||
(cached.requestedCwd === cwd || cached.cwd === cwd) &&
|
||||
cached.processCwd === processCwd &&
|
||||
cached.scope === scopeFor(cached.cwd, cached.stream) &&
|
||||
(await storageUnchanged(sessionId, cached.storage)) &&
|
||||
cached.processCwd === currentDirectory()
|
||||
) {
|
||||
return await deliver(cached.boundaries, cached.cursorId, cached.title, cached.status);
|
||||
cached.scope === scopeFor(cached.cwd, cached.stream)
|
||||
? await storageChanges(sessionId, cached.storage)
|
||||
: undefined;
|
||||
if (cached && changes && cached.processCwd === currentDirectory()) {
|
||||
if (changes.length === 0) {
|
||||
return await deliver(cached.boundaries, cached.cursorId, cached.title, cached.status);
|
||||
}
|
||||
// Only child transcripts changed. When the render does not depend on
|
||||
// them, only the status changes, and it is outside the cursor.
|
||||
const status = await cached.status?.afterAppend(changes.map(([file]) => file));
|
||||
if (status) {
|
||||
const result = await deliver(cached.boundaries, cached.cursorId, cached.title, status);
|
||||
const versions = new Map(changes);
|
||||
this.checkpoints.set(key, {
|
||||
...cached,
|
||||
storage: {
|
||||
...cached.storage,
|
||||
files: cached.storage.files!.map(([file, version]) => [
|
||||
file,
|
||||
versions.has(file) ? versions.get(file)! : version,
|
||||
]),
|
||||
},
|
||||
status,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
check();
|
||||
if (useCursor) this.checkpoints.delete(key);
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
* bytes appended since (see `readLaunches`).
|
||||
*
|
||||
* The read reports each announced child once more, in one update outside the
|
||||
* cursor (see {@link SubagentStatus.frame}).
|
||||
* cursor (see {@link SubagentStatus.frame}). An append to a child that
|
||||
* launched no children changes only that update (see
|
||||
* {@link SubagentStatus.afterAppend}).
|
||||
*/
|
||||
import type { SessionMessage } from "@anthropic-ai/claude-agent-sdk";
|
||||
import { open, type FileHandle } from "node:fs/promises";
|
||||
@@ -74,13 +76,29 @@ export type NestedLaunches = {
|
||||
|
||||
const NO_LAUNCHES: NestedLaunches = { messages: [], notifications: [] };
|
||||
|
||||
/** What a {@link SubagentStatusEntry} comes from, to build it again with new transcript ends. */
|
||||
type EntrySource = {
|
||||
sessionId: string;
|
||||
parentSessionId: string | undefined;
|
||||
record: SubagentRecord | undefined;
|
||||
/** The state, from the child's transcript end when it has no end of its own (see `activity`). */
|
||||
state(status: SubagentStatus): SubagentStatusEntry["state"];
|
||||
};
|
||||
|
||||
export class SubagentStatus {
|
||||
private readonly tails = new Map<string, ChildTail>();
|
||||
/** The launches of each child that launched children, by its agent id. */
|
||||
private readonly nested = new Map<string, NestedLaunches>();
|
||||
private reported: SubagentStatusEntry[] = [];
|
||||
private readonly sources = new WeakMap<SubagentStatusEntry, EntrySource>();
|
||||
/** The agent ids that a metadata file names as `parentAgentId`. */
|
||||
private readonly launchers: Set<string>;
|
||||
|
||||
private constructor(readonly history: SubagentHistory) {}
|
||||
private constructor(readonly history: SubagentHistory) {
|
||||
this.launchers = new Set(
|
||||
[...history.agents.values()].flatMap((record) => record.parentAgentId ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
/** Reads the transcript ends of the children of `history`, and the launches of nested children. */
|
||||
static async read(history: SubagentHistory): Promise<SubagentStatus> {
|
||||
@@ -145,7 +163,7 @@ export class SubagentStatus {
|
||||
child.sessionId,
|
||||
parentSessionId,
|
||||
record,
|
||||
end ?? (record ? this.activity(record) : "disconnected"),
|
||||
(status) => end ?? (record ? status.activity(record) : "disconnected"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -160,11 +178,12 @@ export class SubagentStatus {
|
||||
.map((child) => {
|
||||
const ended =
|
||||
child.notified ?? (child.record.stoppedByUser ? "cancelled" : child.launchEnd);
|
||||
const end = ended ? replayEndState(child) : undefined;
|
||||
return this.entry(
|
||||
child.sessionId,
|
||||
child.parentSessionId === rootSessionId ? undefined : child.parentSessionId,
|
||||
child.record,
|
||||
ended ? replayEndState(child) : { state: this.activity(child.record) },
|
||||
(status) => end ?? { state: status.activity(child.record) },
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -174,6 +193,50 @@ export class SubagentStatus {
|
||||
this.reported = entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status after appends to the child transcripts `files`, which it
|
||||
* reads the ends of again, with the entries of the same replay. Undefined
|
||||
* when one of them is not the transcript of a child of `history`, or is
|
||||
* the transcript of a child that launched children: the replay renders
|
||||
* the launches in it, so it must render again.
|
||||
*
|
||||
* The replay depends on the other inputs only: the root transcript, the
|
||||
* metadata files and the transcripts of the children that launched
|
||||
* children. The caller checks that they are unchanged. The entries then
|
||||
* equal those of a new replay.
|
||||
*/
|
||||
async afterAppend(files: string[]): Promise<SubagentStatus | undefined> {
|
||||
const agents = new Map(
|
||||
[...this.history.agents.values()].flatMap(({ agentId }) => {
|
||||
const file = this.file(agentId);
|
||||
return file ? [[file, agentId] as const] : [];
|
||||
}),
|
||||
);
|
||||
const changed = files.map((file) => agents.get(file));
|
||||
const sources = this.reported.map((entry) => this.sources.get(entry));
|
||||
if (
|
||||
changed.some((agentId) => agentId === undefined || this.launchers.has(agentId)) ||
|
||||
sources.some((source) => source === undefined)
|
||||
)
|
||||
return undefined;
|
||||
const status = new SubagentStatus(this.history);
|
||||
for (const [agentId, tail] of this.tails) status.tails.set(agentId, tail);
|
||||
for (const [agentId, launches] of this.nested) status.nested.set(agentId, launches);
|
||||
await Promise.all(
|
||||
(changed as string[]).map(async (agentId) => {
|
||||
const tail = await readTail(this.file(agentId)!);
|
||||
if (tail) status.tails.set(agentId, tail);
|
||||
else status.tails.delete(agentId);
|
||||
}),
|
||||
);
|
||||
status.report(
|
||||
(sources as EntrySource[]).map((source) =>
|
||||
status.entry(source.sessionId, source.parentSessionId, source.record, source.state),
|
||||
),
|
||||
);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status update of the root session `sessionId`, with the {@link report}ed
|
||||
* entries: `_subagent_status` on v2, which accepts custom variants that start
|
||||
@@ -202,13 +265,13 @@ export class SubagentStatus {
|
||||
sessionId: string,
|
||||
parentSessionId: string | undefined,
|
||||
record: SubagentRecord | undefined,
|
||||
state: SubagentStatusEntry["state"],
|
||||
state: EntrySource["state"],
|
||||
): SubagentStatusEntry {
|
||||
const tail = record && this.tails.get(record.agentId);
|
||||
return {
|
||||
const entry: SubagentStatusEntry = {
|
||||
sessionId,
|
||||
...(parentSessionId ? { parentSessionId } : {}),
|
||||
state,
|
||||
state: state(this),
|
||||
...(record?.background ? { background: true } : {}),
|
||||
...(record?.agentType ? { agentType: record.agentType } : {}),
|
||||
...(record?.cwd ? { cwd: record.cwd } : {}),
|
||||
@@ -216,6 +279,8 @@ export class SubagentStatus {
|
||||
...(tail?.updatedAt ? { updatedAt: tail.updatedAt } : {}),
|
||||
...(tail ? { size: tail.size } : {}),
|
||||
};
|
||||
this.sources.set(entry, { sessionId, parentSessionId, record, state });
|
||||
return entry;
|
||||
}
|
||||
|
||||
private file(agentId: string): string | undefined {
|
||||
|
||||
@@ -689,11 +689,12 @@ describe.each(["air", "rfd", "v2"] as const)("status _session/read (%s)", (form)
|
||||
let configDir: string;
|
||||
let session: StatusSession;
|
||||
let sessionId: string;
|
||||
let cwd: string;
|
||||
const status = { filters: { subagents: "status" } };
|
||||
|
||||
beforeEach(async () => {
|
||||
const folder = await configFolder();
|
||||
({ configDir, sessionId } = folder);
|
||||
({ configDir, sessionId, cwd } = folder);
|
||||
session = new StatusSession(sessionId, folder.project, folder.directory, folder.cwd);
|
||||
await session.create();
|
||||
});
|
||||
@@ -951,13 +952,109 @@ describe.each(["air", "rfd", "v2"] as const)("status _session/read (%s)", (form)
|
||||
expect((await poll()).response).toEqual({ cursorId });
|
||||
expect(getSessionMessages).not.toHaveBeenCalled();
|
||||
|
||||
// A child's append changes a file that the checkpoint compares: the poll renders.
|
||||
// A child's append is in the status of the next poll.
|
||||
const sizeOf = (frames: SessionReadFrame[]) =>
|
||||
statusOf(frames).find((entry) => entry.sessionId === idOf("bgrun"))!.size as number;
|
||||
await session.bash(session.agentIdOf("bgrun"));
|
||||
const grown = await poll();
|
||||
expect(sizeOf((await poll()).frames)).toBeGreaterThan(sizeOf(first.frames));
|
||||
|
||||
// On AIR, the link of the Skill call names its SKILL.md: a new one renders
|
||||
// the history again, also together with a child's append.
|
||||
const skill = path.join(cwd, ".claude", "skills", "example", "SKILL.md");
|
||||
await mkdir(path.dirname(skill), { recursive: true });
|
||||
await writeFile(skill, "---\nname: example\n---\nExample skill\n");
|
||||
await session.bash(session.agentIdOf("bgrun"));
|
||||
vi.mocked(getSessionMessages).mockClear();
|
||||
if (form === "air") {
|
||||
await expect(poll()).rejects.toMatchObject(invalidCursor);
|
||||
expect(getSessionMessages).toHaveBeenCalled();
|
||||
} else {
|
||||
expect((await poll()).response).toEqual({ cursorId });
|
||||
expect(getSessionMessages).not.toHaveBeenCalled();
|
||||
}
|
||||
} finally {
|
||||
await r.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("rebuilds only the status after an append to a child that launched no children", async () => {
|
||||
const r = await reader(form);
|
||||
try {
|
||||
const first = await r.read({ sessionId, replayFrom: start, ...status });
|
||||
const cursorId = first.response.cursorId!;
|
||||
const sizeOf = (frames: SessionReadFrame[]) =>
|
||||
statusOf(frames).find((entry) => entry.sessionId === idOf("bgrun"))!.size as number;
|
||||
await session.bash(session.agentIdOf("bgrun"));
|
||||
await session.answer(session.agentIdOf("bgrun")!);
|
||||
vi.mocked(getSessionMessages).mockClear();
|
||||
const reads = vi.spyOn(resumedSession, "readTranscriptEntries");
|
||||
const next = await r.read({
|
||||
sessionId,
|
||||
replayFrom: { type: "cursor", cursorId },
|
||||
...status,
|
||||
});
|
||||
// No render: the root part is the same, the status is new.
|
||||
expect(getSessionMessages).not.toHaveBeenCalled();
|
||||
expect(reads).not.toHaveBeenCalled();
|
||||
expect(next.response).toEqual({ cursorId });
|
||||
expect(statesOf(next.frames)[idOf("bgrun")]).toEqual(stateOf("idle"));
|
||||
expect(sizeOf(next.frames)).toBeGreaterThan(sizeOf(first.frames));
|
||||
// The status of a full render, and the cursor of the read from the start.
|
||||
const fresh = await r.read({ sessionId, replayFrom: start, ...status });
|
||||
expect(statusOf(next.frames)).toEqual(statusOf(fresh.frames));
|
||||
expect(fresh.response).toEqual({ cursorId });
|
||||
// The checkpoint has the new versions: the next poll is quiet.
|
||||
vi.mocked(getSessionMessages).mockClear();
|
||||
const quiet = await r.read({
|
||||
sessionId,
|
||||
replayFrom: { type: "cursor", cursorId },
|
||||
...status,
|
||||
});
|
||||
expect(getSessionMessages).not.toHaveBeenCalled();
|
||||
expect(statusOf(quiet.frames)).toEqual(statusOf(fresh.frames));
|
||||
} finally {
|
||||
await r.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("renders again after an append to a child that launched children, and finds its new launch", async () => {
|
||||
const r = await reader(form);
|
||||
try {
|
||||
let { cursorId } = (await r.read({ sessionId, replayFrom: start, ...status })).response;
|
||||
const poll = async () => {
|
||||
const next = await r.read({
|
||||
sessionId,
|
||||
replayFrom: { type: "cursor", cursorId },
|
||||
...status,
|
||||
});
|
||||
cursorId = next.response.cursorId ?? cursorId;
|
||||
return next;
|
||||
};
|
||||
// The metadata of a child of `bgrun` comes before its launch call in `bgrun`'s transcript.
|
||||
const owner = session.agentIdOf("bgrun")!;
|
||||
const agentId = "adeep000000000000";
|
||||
session.agents.set("deep", { agentId, launch: "toolu_deep" });
|
||||
await writeFile(
|
||||
path.join(session.directory, `agent-${agentId}.meta.json`),
|
||||
JSON.stringify({ agentType: "Explore", toolUseId: "toolu_deep", parentAgentId: owner }),
|
||||
);
|
||||
expect(statesOf((await poll()).frames)).not.toHaveProperty(idOf("deep"));
|
||||
const before = cursorId;
|
||||
await session.assistant(owner, [
|
||||
{
|
||||
type: "tool_use",
|
||||
id: "toolu_deep",
|
||||
name: "Agent",
|
||||
input: { description: "Task deep", prompt: "Do deep", subagent_type: "Explore" },
|
||||
},
|
||||
]);
|
||||
vi.mocked(getSessionMessages).mockClear();
|
||||
const launched = await poll();
|
||||
expect(getSessionMessages).toHaveBeenCalled();
|
||||
expect(sizeOf(grown.frames)).toBeGreaterThan(sizeOf(first.frames));
|
||||
expect(cursorId).not.toBe(before);
|
||||
expect(statusOf(launched.frames).find((entry) => entry.sessionId === idOf("deep"))).toEqual(
|
||||
expect.objectContaining({ parentSessionId: idOf("bgrun"), state: stateOf("running") }),
|
||||
);
|
||||
} finally {
|
||||
await r.dispose();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ export class V1SessionReads {
|
||||
? child.storage(transcript.transcript, transcript.rewound)
|
||||
: transcript.storage,
|
||||
...(child && form ? { stream: child.streamId(form) } : {}),
|
||||
...(subagentStatus ? { status: subagentStatus.frame(sessionId, 1) } : {}),
|
||||
...(subagentStatus ? { status: subagentStatus } : {}),
|
||||
historyEnd,
|
||||
title: transcript.title === undefined ? undefined : options.clientTitle(transcript.title),
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function renderSessionRead(
|
||||
}
|
||||
if (subagentStatus) {
|
||||
subagentStatus.report(subagents?.statusEntries() ?? []);
|
||||
return { frames, cwd, historyEnd, title, storage, status: subagentStatus.frame(sessionId, 2) };
|
||||
return { frames, cwd, historyEnd, title, storage, status: subagentStatus };
|
||||
}
|
||||
return { frames, cwd, historyEnd, title, storage };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user