@@ -28,9 +28,11 @@ import { defaultRuntime } from "../../runtime.js";
2828import { shouldPreserveUserFacingSessionStateForInputProvenance } from "../../sessions/input-provenance.js" ;
2929import { readStringValue } from "../../shared/string-coerce.js" ;
3030import { isInternalMessageChannel } from "../../utils/message-channel.js" ;
31+ import { markReplyPayloadForSourceSuppressionDelivery } from "../reply-payload.js" ;
3132import type { GetReplyOptions , ReplyPayload } from "../types.js" ;
3233import { runCliAgentWithLifecycle } from "./agent-runner-cli-dispatch.js" ;
3334import {
35+ buildPreflightCompactionFailureText ,
3436 resolveRunAfterAutoFallbackPrimaryProbeRecheck ,
3537 resolveSessionRuntimeOverrideForProvider ,
3638} from "./agent-runner-execution.js" ;
@@ -535,19 +537,40 @@ export function createFollowupRunner(params: {
535537 let runResult : Awaited < ReturnType < typeof runEmbeddedAgent > > ;
536538 let fallbackProvider = run . provider ;
537539 let fallbackModel = run . model ;
538- activeSessionEntry = await runPreflightCompactionIfNeeded ( {
539- cfg : runtimeConfig ,
540- followupRun : effectiveQueued ,
541- promptForEstimate : queued . prompt ,
542- defaultModel,
543- agentCfgContextTokens,
544- sessionEntry : activeSessionEntry ,
545- sessionStore,
546- sessionKey : replySessionKey ,
547- storePath,
548- isHeartbeat : opts ?. isHeartbeat === true ,
549- replyOperation,
550- } ) ;
540+ try {
541+ activeSessionEntry = await runPreflightCompactionIfNeeded ( {
542+ cfg : runtimeConfig ,
543+ followupRun : effectiveQueued ,
544+ promptForEstimate : queued . prompt ,
545+ defaultModel,
546+ agentCfgContextTokens,
547+ sessionEntry : activeSessionEntry ,
548+ sessionStore,
549+ sessionKey : replySessionKey ,
550+ storePath,
551+ isHeartbeat : opts ?. isHeartbeat === true ,
552+ replyOperation,
553+ } ) ;
554+ } catch ( err ) {
555+ const message = formatErrorMessage ( err ) ;
556+ replyOperation . fail ( "run_failed" , err ) ;
557+ const preflightCompactionFailureText = buildPreflightCompactionFailureText ( message , {
558+ includeDetails : run . verboseLevel === "on" || run . verboseLevel === "full" ,
559+ } ) ;
560+ if ( preflightCompactionFailureText ) {
561+ await sendFollowupPayloads (
562+ [
563+ markReplyPayloadForSourceSuppressionDelivery ( {
564+ text : preflightCompactionFailureText ,
565+ } ) ,
566+ ] ,
567+ effectiveQueued ,
568+ { provider : fallbackProvider , modelId : fallbackModel } ,
569+ ) ;
570+ return ;
571+ }
572+ throw err ;
573+ }
551574 let bootstrapPromptWarningSignaturesSeen = resolveBootstrapWarningSignaturesSeen (
552575 activeSessionEntry ?. systemPromptReport ,
553576 ) ;
0 commit comments