Skip to content

Commit 0feed6a

Browse files
committed
fix(channel): filter commentary phase from channel delivery on phase-tagged providers
When providers like openai-codex/gpt-5.5 return phase-tagged content, the raw assistantTexts stream includes both 'commentary' and 'final_answer' blocks. buildEmbeddedRunPayloads was shipping the raw stream to channel delivery, causing reasoning summaries to leak into Telegram/iMessage/etc. Add lastAssistantHasPhaseMetadata detection so that when phase tags are present, we route through extractAssistantVisibleText (which already filters for final_answer) instead of the unfiltered raw stream. Non-phase-tagged providers are unaffected. Fixes #80458
1 parent 0bb9b42 commit 0feed6a

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

‎src/agents/pi-embedded-runner/run/payloads.ts‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,37 @@ export function buildEmbeddedRunPayloads(params: {
443443
fallbackAnswerSourceText.length > 0 &&
444444
normalizedFallbackAnswerSourceText.length > 0;
445445
const hasAssistantTextPayload = nonEmptyAssistantTexts.length > 0;
446+
// When the model returns phase-tagged content (e.g. openai-codex/gpt-5.5), the raw
447+
// assistantTexts stream may include both "commentary" and "final_answer" blocks.
448+
// Use the already-phase-filtered fallbackAnswerText so that channel delivery only
449+
// ships the final_answer portion. Non-phase-tagged providers are unaffected.
450+
const lastAssistantHasPhaseMetadata = (() => {
451+
const c = params.lastAssistant && params.lastAssistant.content;
452+
if (!Array.isArray(c)) return false;
453+
for (const b of c) {
454+
if (!b || b.type !== "text" || !b.textSignature) continue;
455+
try {
456+
const sig =
457+
typeof b.textSignature === "string" ? JSON.parse(b.textSignature) : b.textSignature;
458+
if (sig && sig.phase) return true;
459+
} catch {}
460+
}
461+
return false;
462+
})();
446463
const answerTexts =
447464
suppressAssistantArtifacts || runAborted
448465
? []
449-
: (shouldUseCanonicalFinalAnswer
450-
? [fallbackAnswerSourceText]
451-
: shouldPreferRawAnswerText && fallbackRawAnswerText
452-
? [fallbackRawAnswerText]
453-
: hasAssistantTextPayload
454-
? nonEmptyAssistantTexts
455-
: fallbackAnswerText
456-
? [fallbackAnswerText]
457-
: []
466+
: (lastAssistantHasPhaseMetadata && fallbackAnswerText
467+
? [fallbackAnswerText]
468+
: shouldUseCanonicalFinalAnswer
469+
? [fallbackAnswerSourceText]
470+
: shouldPreferRawAnswerText && fallbackRawAnswerText
471+
? [fallbackRawAnswerText]
472+
: hasAssistantTextPayload
473+
? nonEmptyAssistantTexts
474+
: fallbackAnswerText
475+
? [fallbackAnswerText]
476+
: []
458477
).filter((text) => !shouldSuppressRawErrorText(text));
459478

460479
let hasUserFacingAssistantReply = hasSourceReplyPayload;

0 commit comments

Comments
 (0)