fix(hub): skip mid-spawn stubs in persisted scan

SessionManager.open writes title+session before createAgentSession
claims the id. Agent Hub parked that stub, so the spawn CAS failed
with "already owned by another session generation" and the row
could not be revived (no session_init).
This commit is contained in:
Md Tahsin Rahman
2026-08-14 01:34:34 +08:00
parent 326d24bd40
commit 41dfc2cd9e
5 changed files with 155 additions and 8 deletions
@@ -352,7 +352,21 @@ describe("runSubprocess soft request budget", () => {
const rootSessionFile = `${tempDir.path()}/main.jsonl`;
const workerSessionFile = `${tempDir.path()}/main/${id}.jsonl`;
await Bun.write(rootSessionFile, "");
await Bun.write(workerSessionFile, "");
await Bun.write(
workerSessionFile,
[
JSON.stringify({ type: "session", version: 3, id, timestamp: "2026-08-13T17:14:48.000Z", cwd: "/tmp" }),
JSON.stringify({
type: "session_init",
id: "si",
parentId: null,
timestamp: "2026-08-13T17:14:48.000Z",
systemPrompt: "system",
task: "work",
tools: ["read"],
}),
].join("\n"),
);
const controller = new AbortController();
// abort #1 = budget soft-stop (abortSent still false); abort #2 =
// budget hard-abort's abortActiveSession (abortReason already "budget").
@@ -394,7 +408,21 @@ describe("runSubprocess soft request budget", () => {
const rootSessionFile = `${tempDir.path()}/main.jsonl`;
const workerSessionFile = `${tempDir.path()}/main/${id}.jsonl`;
await Bun.write(rootSessionFile, "");
await Bun.write(workerSessionFile, "");
await Bun.write(
workerSessionFile,
[
JSON.stringify({ type: "session", version: 3, id, timestamp: "2026-08-13T17:14:48.000Z", cwd: "/tmp" }),
JSON.stringify({
type: "session_init",
id: "si",
parentId: null,
timestamp: "2026-08-13T17:14:48.000Z",
systemPrompt: "system",
task: "work",
tools: ["read"],
}),
].join("\n"),
);
const promptStarted = Promise.withResolvers<void>();
const promptStopped = Promise.withResolvers<void>();
const handle = createMockSession(