












@@ -2875,6 +2875,7 @@ export const chatHandlers: GatewayRequestHandlers = {
28752875.map((payload) => payload.text?.trim())
28762876.filter((text): text is string => Boolean(text))
28772877.join(" | ") || undefined;
2878+let broadcastedSourceReplyFinal = false;
28782879// WebChat persistence has two owners. Agent runs persist model-visible turns
28792880// through Pi's SessionManager; this dispatcher only owns live delivery payloads.
28802881// Do not blindly mirror agent-run final payloads into JSONL or chat.history can
@@ -3151,10 +3152,13 @@ export const chatHandlers: GatewayRequestHandlers = {
31513152 sessionKey,
31523153 message,
31533154});
3155+broadcastedSourceReplyFinal = true;
31543156}
31553157}
31563158}
3157-if (returnedAgentErrorPayloads.length > 0) {
3159+const shouldBroadcastAgentError =
3160+returnedAgentErrorPayloads.length > 0 && !broadcastedSourceReplyFinal;
3161+if (shouldBroadcastAgentError) {
31583162if (!hasBeforeAgentRunGate) {
31593163await emitUserTranscriptUpdateAfterAgentRun();
31603164}
@@ -3168,27 +3172,25 @@ export const chatHandlers: GatewayRequestHandlers = {
31683172await emitUserTranscriptUpdateAfterAgentRun();
31693173}
31703174if (!context.chatAbortedRuns.has(clientRunId)) {
3171-const returnedAgentError =
3172-returnedAgentErrorPayloads.length > 0
3173- ? errorShape(
3174-ErrorCodes.UNAVAILABLE,
3175-returnedAgentErrorMessage ?? "agent returned an error payload",
3176-)
3177- : undefined;
3175+const returnedAgentError = shouldBroadcastAgentError
3176+ ? errorShape(
3177+ErrorCodes.UNAVAILABLE,
3178+returnedAgentErrorMessage ?? "agent returned an error payload",
3179+)
3180+ : undefined;
31783181setGatewayDedupeEntry({
31793182dedupe: context.dedupe,
31803183key: `chat:${clientRunId}`,
31813184entry: {
31823185ts: Date.now(),
3183-ok: returnedAgentErrorPayloads.length === 0,
3184-payload:
3185-returnedAgentErrorPayloads.length > 0
3186- ? {
3187-runId: clientRunId,
3188-status: "error" as const,
3189-summary: returnedAgentErrorMessage ?? "agent returned an error payload",
3190-}
3191- : { runId: clientRunId, status: "ok" as const },
3186+ok: !shouldBroadcastAgentError,
3187+payload: shouldBroadcastAgentError
3188+ ? {
3189+runId: clientRunId,
3190+status: "error" as const,
3191+summary: returnedAgentErrorMessage ?? "agent returned an error payload",
3192+}
3193+ : { runId: clientRunId, status: "ok" as const },
31923194 ...(returnedAgentError ? { error: returnedAgentError } : {}),
31933195},
31943196});
此內容由慣性聚合(RSS閱讀器)自動聚合整理,僅供閱讀參考。 原文來自 — 版權歸原作者所有。