fix: ignore stale rows in subagent activity checks

This commit is contained in:
Tak Hoffman
2026-03-24 16:57:08 -05:00
parent 40ab7aca3d
commit b8a0258618
2 changed files with 33 additions and 3 deletions

View File

@@ -564,6 +564,35 @@ describe("subagent registry steer restarts", () => {
);
});
it("treats a child session as inactive when only a stale older row is still unended", async () => {
const childSessionKey = "agent:main:subagent:stale-active-older-row";
mod.addSubagentRunForTests({
runId: "run-stale-older",
childSessionKey,
requesterSessionKey: MAIN_REQUESTER_SESSION_KEY,
requesterDisplayKey: MAIN_REQUESTER_DISPLAY_KEY,
task: "older stale row",
startedAt: 100,
createdAt: 100,
cleanup: "keep",
});
mod.addSubagentRunForTests({
runId: "run-current-ended",
childSessionKey,
requesterSessionKey: MAIN_REQUESTER_SESSION_KEY,
requesterDisplayKey: MAIN_REQUESTER_DISPLAY_KEY,
task: "current ended row",
startedAt: 200,
createdAt: 200,
endedAt: 250,
outcome: { status: "ok" },
cleanup: "keep",
});
expect(mod.isSubagentSessionRunActive(childSessionKey)).toBe(false);
});
it("recovers announce cleanup when completion arrives after a kill marker", async () => {
const childSessionKey = "agent:main:subagent:kill-race";
registerRun({

View File

@@ -1596,16 +1596,17 @@ export function resolveRequesterForChildSession(childSessionKey: string): {
export function isSubagentSessionRunActive(childSessionKey: string): boolean {
const runIds = findRunIdsByChildSessionKey(childSessionKey);
let latest: SubagentRunRecord | undefined;
for (const runId of runIds) {
const entry = subagentRuns.get(runId);
if (!entry) {
continue;
}
if (typeof entry.endedAt !== "number") {
return true;
if (!latest || entry.createdAt > latest.createdAt) {
latest = entry;
}
}
return false;
return Boolean(latest && typeof latest.endedAt !== "number");
}
export function shouldIgnorePostCompletionAnnounceForSession(childSessionKey: string): boolean {