Skip to content

Commit 601f9d1

Browse files
committed
fix(auto-reply): preserve accepted spawn completions
1 parent ed19873 commit 601f9d1

4 files changed

Lines changed: 75 additions & 1 deletion

File tree

‎src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,57 @@ describe("runReplyAgent auto-compaction token update", () => {
545545
);
546546
});
547547

548+
it("keeps accepted child-session spawn completions silent", async () => {
549+
const sessionKey = "main";
550+
const sessionEntry = {
551+
sessionId: "session",
552+
updatedAt: Date.now(),
553+
totalTokens: 50_000,
554+
};
555+
runEmbeddedAgentMock.mockResolvedValueOnce({
556+
payloads: [],
557+
acceptedSessionSpawns: [{ runId: "run-child", childSessionKey: "agent:main:child" }],
558+
meta: {
559+
agentMeta: {
560+
provider: "anthropic",
561+
model: "claude",
562+
},
563+
finalAssistantVisibleText: "",
564+
},
565+
});
566+
567+
const { typing, sessionCtx, resolvedQueue, followupRun } = createBaseRun({
568+
storePath: "",
569+
sessionEntry,
570+
});
571+
572+
const result = await runReplyAgent({
573+
commandBody: "spawn child",
574+
followupRun,
575+
queueKey: sessionKey,
576+
resolvedQueue,
577+
shouldSteer: false,
578+
shouldFollowup: false,
579+
isActive: false,
580+
isStreaming: false,
581+
typing,
582+
sessionCtx,
583+
sessionEntry,
584+
sessionStore: { [sessionKey]: sessionEntry },
585+
sessionKey,
586+
defaultModel: "anthropic/claude-opus-4-6",
587+
agentCfgContextTokens: 200_000,
588+
resolvedVerboseLevel: "off",
589+
isNewSession: false,
590+
blockStreamingEnabled: false,
591+
resolvedBlockStreamingBreak: "message_end",
592+
shouldInjectGroupIntro: false,
593+
typingMode: "instant",
594+
});
595+
596+
expect(result).toBeUndefined();
597+
});
598+
548599
it("starts queued followup drain only after clearing the active reply operation", async () => {
549600
const sessionKey = "main";
550601
const sessionEntry = {

‎src/auto-reply/reply/agent-runner.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveAgentConfig,
99
resolveSessionAgentId,
1010
} from "../../agents/agent-scope.js";
11+
import { hasAcceptedSessionSpawn } from "../../agents/accepted-session-spawn.js";
1112
import { resolveContextTokensForModel } from "../../agents/context.js";
1213
import { DEFAULT_CONTEXT_TOKENS } from "../../agents/defaults.js";
1314
import { hasVisibleAgentPayload } from "../../agents/embedded-agent-runner/delivery-evidence.js";
@@ -254,12 +255,14 @@ function hasSuccessfulSideEffectDelivery(params: {
254255
didSendViaMessagingTool?: boolean;
255256
successfulCronAdds?: number;
256257
didSendDeterministicApprovalPrompt?: boolean;
258+
acceptedSessionSpawns?: readonly unknown[];
257259
}): boolean {
258260
return (
259261
params.didSendViaMessagingTool === true ||
260262
hasSuccessfulSourceReplyDelivery(params) ||
261263
(params.successfulCronAdds ?? 0) > 0 ||
262-
params.didSendDeterministicApprovalPrompt === true
264+
params.didSendDeterministicApprovalPrompt === true ||
265+
hasAcceptedSessionSpawn(params.acceptedSessionSpawns)
263266
);
264267
}
265268

@@ -1965,6 +1968,7 @@ export async function runReplyAgent(params: {
19651968
didSendViaMessagingTool: runResult.didSendViaMessagingTool,
19661969
successfulCronAdds: runResult.successfulCronAdds,
19671970
didSendDeterministicApprovalPrompt: runResult.didSendDeterministicApprovalPrompt,
1971+
acceptedSessionSpawns: runResult.acceptedSessionSpawns,
19681972
});
19691973
const successfulSourceReplyDelivery = hasSuccessfulSourceReplyDelivery({
19701974
blockReplyPipeline,

‎src/auto-reply/reply/followup-runner.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,6 +4627,23 @@ describe("createFollowupRunner messaging delivery and dedupe", () => {
46274627
expect(onBlockReply).not.toHaveBeenCalled();
46284628
});
46294629

4630+
it("does not emit the empty fallback after an accepted child-session spawn", async () => {
4631+
const { onBlockReply } = await runMessagingCase({
4632+
agentResult: {
4633+
payloads: [],
4634+
acceptedSessionSpawns: [{ runId: "run-child", childSessionKey: "agent:main:child" }],
4635+
},
4636+
queued: {
4637+
...baseQueuedRun("discord"),
4638+
originatingChannel: "discord",
4639+
originatingTo: "channel:C1",
4640+
} as FollowupRun,
4641+
});
4642+
4643+
expect(routeReplyMock).not.toHaveBeenCalled();
4644+
expect(onBlockReply).not.toHaveBeenCalled();
4645+
});
4646+
46304647
it("keeps message-tool-only empty followup completions silent", async () => {
46314648
const queued = baseQueuedRun("discord");
46324649
const { onBlockReply } = await runMessagingCase({

‎src/auto-reply/reply/followup-runner.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
entryMatchesAutoFallbackPrimaryProbe,
88
markAutoFallbackPrimaryProbe,
99
} from "../../agents/agent-scope.js";
10+
import { hasAcceptedSessionSpawn } from "../../agents/accepted-session-spawn.js";
1011
import { resolveBootstrapWarningSignaturesSeen } from "../../agents/bootstrap-budget.js";
1112
import { getCliSessionBinding } from "../../agents/cli-session.js";
1213
import { resolveContextTokensForModel } from "../../agents/context.js";
@@ -1460,6 +1461,7 @@ export function createFollowupRunner(params: {
14601461
messagingToolSentTargets: runResult.messagingToolSentTargets,
14611462
messagingToolSourceReplyPayloads: runResult.messagingToolSourceReplyPayloads,
14621463
}) ||
1464+
hasAcceptedSessionSpawn(runResult.acceptedSessionSpawns) ||
14631465
runResult.didSendDeterministicApprovalPrompt === true ||
14641466
(runResult.successfulCronAdds ?? 0) > 0 ||
14651467
didSendCompactionNoticePayload ||

0 commit comments

Comments
 (0)