fix: preserve swept subagent context agent dir

This commit is contained in:
Josh Lehman
2026-04-27 19:53:38 -07:00
parent a7550fc8ae
commit 91352a17eb
2 changed files with 69 additions and 0 deletions

View File

@@ -890,4 +890,71 @@ describe("subagent registry seam flow", () => {
},
);
});
it("passes stored agentDir through swept context-engine cleanup paths", async () => {
const now = Date.parse("2026-03-24T12:00:00Z");
mod.addSubagentRunForTests({
runId: "run-session-swept-context-engine",
childSessionKey: "agent:alt:session:child-session",
controllerSessionKey: "agent:main:session:parent",
requesterSessionKey: "agent:main:session:parent",
requesterOrigin: undefined,
requesterDisplayKey: "parent",
task: "session cleanup",
cleanup: "keep",
expectsCompletionMessage: undefined,
spawnMode: "session",
agentDir: "/tmp/agent-session",
workspaceDir: "/tmp/workspace-session",
createdAt: now - 20_000,
startedAt: now - 10_000,
sessionStartedAt: now - 10_000,
accumulatedRuntimeMs: 0,
endedAt: now - 8_000,
outcome: { status: "ok", startedAt: now - 10_000, endedAt: now - 8_000, elapsedMs: 2_000 },
cleanupHandled: true,
cleanupCompletedAt: now - 6 * 60_000,
});
mod.addSubagentRunForTests({
runId: "run-archive-swept-context-engine",
childSessionKey: "agent:alt:session:child-archive",
controllerSessionKey: "agent:main:session:parent",
requesterSessionKey: "agent:main:session:parent",
requesterOrigin: undefined,
requesterDisplayKey: "parent",
task: "archive cleanup",
cleanup: "delete",
expectsCompletionMessage: undefined,
spawnMode: "run",
agentDir: "/tmp/agent-archive",
workspaceDir: "/tmp/workspace-archive",
createdAt: now - 20_000,
startedAt: now - 10_000,
sessionStartedAt: now - 10_000,
accumulatedRuntimeMs: 0,
endedAt: now - 8_000,
outcome: { status: "ok", startedAt: now - 10_000, endedAt: now - 8_000, elapsedMs: 2_000 },
archiveAtMs: now - 1,
cleanupHandled: true,
});
await mod.__testing.sweepOnceForTests();
await waitForFast(() => {
expect(mocks.resolveContextEngine).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
agentDir: "/tmp/agent-session",
workspaceDir: "/tmp/workspace-session",
}),
);
expect(mocks.resolveContextEngine).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
agentDir: "/tmp/agent-archive",
workspaceDir: "/tmp/workspace-archive",
}),
);
});
});
});

View File

@@ -826,6 +826,7 @@ async function sweepSubagentRuns() {
void notifyContextEngineSubagentEnded({
childSessionKey: entry.childSessionKey,
reason: "swept",
agentDir: entry.agentDir,
workspaceDir: entry.workspaceDir,
});
subagentRuns.delete(runId);
@@ -865,6 +866,7 @@ async function sweepSubagentRuns() {
void notifyContextEngineSubagentEnded({
childSessionKey: entry.childSessionKey,
reason: "swept",
agentDir: entry.agentDir,
workspaceDir: entry.workspaceDir,
});
}