Skip to content

Commit 1d54ce3

Browse files
authored
fix(agents): reject notices as terminal fallback and completion replies (#128269)
1 parent dd9a1bd commit 1d54ce3

5 files changed

Lines changed: 96 additions & 19 deletions

File tree

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ src/agents/embedded-agent-runner/openrouter-model-capabilities.ts 2
18271827
src/agents/embedded-agent-runner/prepared-compaction-runtime.ts 1
18281828
src/agents/embedded-agent-runner/prompt-cache-observability.ts 2
18291829
src/agents/embedded-agent-runner/replay-history.ts 60
1830-
src/agents/embedded-agent-runner/result-fallback-classifier.ts 3
1830+
src/agents/embedded-agent-runner/result-fallback-classifier.ts 2
18311831
src/agents/embedded-agent-runner/run-entry.ts 3
18321832
src/agents/embedded-agent-runner/run-orchestrator.ts 1
18331833
src/agents/embedded-agent-runner/run.overflow-compaction.harness.ts 5

‎src/agents/embedded-agent-runner/result-fallback-classifier.test.ts‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { GENERIC_EXTERNAL_RUN_FAILURE_TEXT } from "../failover/user-copy.js";
44
import { runWithModelFallback } from "../model-fallback-runner.js";
55
import { classifyEmbeddedAgentRunResultForModelFallback } from "./result-fallback-classifier.js";
66

7+
const supplementalSpeechPayload = {
8+
mediaUrl: "file:///tmp/answer.mp3",
9+
ttsSupplement: { spokenText: "answer", visibleTextAlreadyDelivered: true },
10+
};
11+
712
describe("classifyEmbeddedAgentRunResultForModelFallback", () => {
813
it("does not fallback when sessions_spawn accepted a child session", () => {
914
// Accepted child sessions mean the turn made progress even if the parent did
@@ -128,7 +133,23 @@ describe("classifyEmbeddedAgentRunResultForModelFallback", () => {
128133
});
129134
});
130135

131-
it("advances to the configured fallback after a generic external runner failure", async () => {
136+
it.each([
137+
{
138+
name: "a generic external runner failure",
139+
payload: { text: GENERIC_EXTERNAL_RUN_FAILURE_TEXT },
140+
code: "generic_external_run_failure",
141+
},
142+
{
143+
name: "a transient status notice without a final reply",
144+
payload: { text: "Still working", isStatusNotice: true },
145+
code: "empty_result",
146+
},
147+
{
148+
name: "supplemental speech without a final reply",
149+
payload: supplementalSpeechPayload,
150+
code: "empty_result",
151+
},
152+
])("advances to the configured fallback after $name", async ({ payload, code }) => {
132153
const runs: Array<{ provider: string; model: string }> = [];
133154
const result = await runWithModelFallback({
134155
cfg: undefined,
@@ -140,7 +161,7 @@ describe("classifyEmbeddedAgentRunResultForModelFallback", () => {
140161
runs.push({ provider, model });
141162
return runs.length === 1
142163
? {
143-
payloads: [{ text: GENERIC_EXTERNAL_RUN_FAILURE_TEXT }],
164+
payloads: [payload],
144165
meta: { durationMs: 1 },
145166
}
146167
: { payloads: [{ text: "fallback ok" }], meta: { durationMs: 1 } };
@@ -162,9 +183,11 @@ describe("classifyEmbeddedAgentRunResultForModelFallback", () => {
162183
provider: "external",
163184
model: "primary",
164185
reason: "format",
165-
code: "generic_external_run_failure",
166-
error: GENERIC_EXTERNAL_RUN_FAILURE_TEXT,
186+
code,
167187
});
188+
if (code === "generic_external_run_failure") {
189+
expect(result.attempts[0]?.error).toBe(GENERIC_EXTERNAL_RUN_FAILURE_TEXT);
190+
}
168191
});
169192

170193
it("classifies Codex subscription usage-limit payloads as rate-limit fallback", () => {
@@ -446,6 +469,30 @@ describe("classifyEmbeddedAgentRunResultForModelFallback", () => {
446469
code: "empty_result",
447470
suffix: "without a visible assistant reply",
448471
},
472+
{
473+
name: "compaction-notice-only",
474+
payloads: [{ isCompactionNotice: true, text: "Compacting context" }],
475+
code: "empty_result",
476+
suffix: "without a visible assistant reply",
477+
},
478+
{
479+
name: "fallback-notice-only",
480+
payloads: [{ isFallbackNotice: true, text: "Switching providers" }],
481+
code: "empty_result",
482+
suffix: "without a visible assistant reply",
483+
},
484+
{
485+
name: "status-notice-only",
486+
payloads: [{ isStatusNotice: true, text: "Still working" }],
487+
code: "empty_result",
488+
suffix: "without a visible assistant reply",
489+
},
490+
{
491+
name: "supplemental-speech-only",
492+
payloads: [supplementalSpeechPayload],
493+
code: "empty_result",
494+
suffix: "without a visible assistant reply",
495+
},
449496
{
450497
name: "explicitly hidden",
451498
payloads: [{ visible: false, text: "internal" }],

‎src/agents/embedded-agent-runner/result-fallback-classifier.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,15 @@ function hasDeliverableAssistantPayload(result: {
8787
meta?: { finalAssistantVisibleText?: unknown };
8888
}): boolean {
8989
const finalVisibleText = result.meta?.finalAssistantVisibleText;
90-
const payloads = Array.isArray(result.payloads)
91-
? result.payloads.filter((payload) => {
92-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
93-
return true;
94-
}
95-
const record = payload as { isCommentary?: unknown; visible?: unknown };
96-
return record.isCommentary !== true && record.visible !== false;
97-
})
98-
: [];
9990
return (
10091
(typeof finalVisibleText === "string" &&
10192
finalVisibleText.trim().length > 0 &&
10293
!isSilentReplyPayloadText(finalVisibleText)) ||
103-
hasVisibleAgentPayload(
104-
{ payloads },
105-
{ includeErrorPayloads: false, includeReasoningPayloads: false },
106-
)
94+
hasVisibleAgentPayload(result, {
95+
includeErrorPayloads: false,
96+
includeReasoningPayloads: false,
97+
requireTerminalContent: true,
98+
})
10799
);
108100
}
109101

‎src/agents/subagents/announce/subagent-announce-delivery.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,36 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
20622062
payloads: [{ text: "Waiting for the delegated task.", isReasoning: true }],
20632063
delivered: false,
20642064
},
2065+
{
2066+
name: "only pre-tool commentary",
2067+
payloads: [{ text: "Waiting for the delegated task.", isCommentary: true }],
2068+
delivered: false,
2069+
},
2070+
{
2071+
name: "only a compaction notice",
2072+
payloads: [{ text: "Compacting the session.", isCompactionNotice: true }],
2073+
delivered: false,
2074+
},
2075+
{
2076+
name: "only a provider-fallback notice",
2077+
payloads: [{ text: "Switching providers.", isFallbackNotice: true }],
2078+
delivered: false,
2079+
},
2080+
{
2081+
name: "only a transient status notice",
2082+
payloads: [{ text: "Still working.", isStatusNotice: true }],
2083+
delivered: false,
2084+
},
2085+
{
2086+
name: "only supplemental TTS audio",
2087+
payloads: [
2088+
{
2089+
mediaUrl: "file:///tmp/answer.mp3",
2090+
ttsSupplement: { spokenText: "answer", visibleTextAlreadyDelivered: true },
2091+
},
2092+
],
2093+
delivered: false,
2094+
},
20652095
{
20662096
name: "a failed-tool warning and a successful visible reply",
20672097
payloads: [
@@ -2078,6 +2108,14 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
20782108
],
20792109
delivered: true,
20802110
},
2111+
{
2112+
name: "a status notice and a successful visible reply",
2113+
payloads: [
2114+
{ text: "Still working.", isStatusNotice: true },
2115+
{ text: "The delegated task completed." },
2116+
],
2117+
delivered: true,
2118+
},
20812119
])(
20822120
"requires a successful visible grouped completion reply when the agent returns $name",
20832121
async ({ payloads, delivered }) => {

‎src/agents/subagents/announce/subagent-announce-direct-delivery.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ export async function sendSubagentAnnounceDirectly(params: {
435435
const completionPayloadVisibility = {
436436
includeErrorPayloads: false,
437437
includeReasoningPayloads: false,
438+
requireTerminalContent: true,
438439
};
439440
const hasVisibleGatewayPayload = Boolean(
440441
directAnnounceResult &&
@@ -446,7 +447,6 @@ export async function sendSubagentAnnounceDirectly(params: {
446447
hasVisibleAgentPayload(directAnnounceResult, {
447448
...completionPayloadVisibility,
448449
includeSilentReplyPayloads: false,
449-
requireTerminalContent: true,
450450
}),
451451
);
452452
const hasIntentionalSilentCompletionReply = Boolean(

0 commit comments

Comments
 (0)