fix(antigravity): order mid-reply steers after the first answer #49064 (GitHub #49057)
Mergedelectrum(GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/49057/headmerged by juliusmarminge View on GitHubelectrum(GitHub profile, opens in a new tab) linked this to fix #48620
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelstakeover:in-progress
- @@ -11740,0 +12038,21 @@12038+ // steer while its busy RPC was still in flight, revert it to12039+ // pending before retrying.12040+ if (12041+ isAgentBusyPromptError(error) &&12042+ !superseded() &&12043+ trackedSteer.released12044+ ) {12045+ yield* runRuntimeCallbackAtGeneration(12046+ generation,12047+ Effect.gen(function* () {12048+ if (context.finalized) return;12049+ trackedSteer.released = false;12050+ trackedSteer.pendingEmitted = false;12051+ if (!context.pendingPromptSteers.includes(trackedSteer)) {12052+ context.pendingPromptSteers.push(trackedSteer);12053+ }12054+ yield* emitPendingSteer(context, trackedSteer);12055+ }),12056+ );12057+ }12058+ })@@ -11682,5 +11928,21 @@11928+ const wasPromptSettled = context.promptSettled;1168211929 context.promptSettled = false;1168311930 context.promptSettledStatus = null;1168411931 context.backgroundFinalizeGeneration += 1;1168511932 context.promptSentAt = yield* Clock.currentTimeMillis;1168611933 const previousPromptSettled = yield* Deferred.isDone(context.promptWireSettled);11934+ if (trackSteer && context.steerBoundary !== undefined) {11935+ const existingReply = lastAssistantReply(context);11936+ const decision = context.steerBoundary.onSteerQueued({11937+ previousPromptSettled: previousPromptSettled || wasPromptSettled,11938+ hasPendingSteers: context.pendingPromptSteers.length > 0,11939+ hasAssistantReply:11940+ existingReply !== null &&11941+ existingReply.finalAnswer !== true &&11942+ existingReply.text.trim().length > 0,11943+ });11944+ if (decision === "finalize_prior_reply" && existingReply !== null) {11945+ // Close and mark the finished prior reply before the steer prompt launches11946+ // so an immediate steer chunk cannot merge into the previous segment.11947+ yield* finalizePreSteerReply(context, existingReply);11948+ } else if (decision === "defer") {@@ -11740,0 +12023,21 @@12023+ Effect.catchIf(12024+ (error) =>12025+ steerMeta !== undefined &&12026+ error._tag === "AcpRequestError" &&12027+ error.code === -32600 &&12028+ !context.interrupted &&12029+ !context.finalized &&12030+ !superseded(),12031+ () => runPromptAttempt({ prompt: steerPrompt }),12032+ ),12033+ Effect.tapError((error) =>12034+ trackedSteer !== undefined12035+ ? Effect.gen(function* () {12036+ trackedSteer.attemptDispatched = null;12037+ // If output from an earlier reply prematurely released this12038+ // steer while its busy RPC was still in flight, revert it to12039+ // pending before retrying.12040+ if (12041+ isAgentBusyPromptError(error) &&12042+ !superseded() &&12043+ trackedSteer.released
Pushedf4d54d4
- @@ -3095,0 +3190,21 @@3190+ instances,3191+ stores,3192+ eventSink,3193+ IdAllocator.layer,3194+ ThreadCommandExecutor.layer,3195+ git,3196+ ),3197+ ),3198+ ),3199+ );3200+ })();3201+3202+ it.effect(3203+ "orders a mid-reasoning steer after the first final reply in persisted projections",3204+ () =>3205+ Effect.gen(function* () {3206+ const opened = yield* openSessionWithRunningCommand(3207+ {},3208+ undefined,3209+ { agentVersion: "1.5.11", holdsFirstPrompt: true },3210+ { initialToolCalls: [], skipInitialReply: true, skipInitialUsage: true },
Pushedd7a06ae
- @@ -3095,0 +3192,21 @@3192+3193+ it.effect(3194+ "orders a mid-reasoning steer after the first final reply in persisted projections",3195+ () =>3196+ Effect.gen(function* () {3197+ const opened = yield* openSessionWithRunningCommand(3198+ {},3199+ undefined,3200+ { agentVersion: "1.5.11", holdsFirstPrompt: true },3201+ { initialToolCalls: [], skipInitialReply: true, skipInitialUsage: true },3202+ );3203+ const { session, providerThread, usage, send, startTurn, until } = opened;3204+ const threadId = ThreadId.make("thread-antigravity-wake");3205+ const runId = RunId.make("run-antigravity-wake-1");3206+ const steerId = MessageId.make("message-antigravity-mid-reasoning-steer");3207+3208+ yield* startTurn(1, false);3209+ yield* send({3210+ sessionUpdate: "agent_thought_chunk",3211+ content: { type: "text", text: "Reasoning about prompt 1." },3212+ });@@ -3095,0 +3540,21 @@3540+ const opened = yield* openSessionWithRunningCommand(3541+ {},3542+ undefined,3543+ { agentVersion: "1.5.11", holdsFirstPrompt: true },3544+ {3545+ onSteerPrompt: ({ send: emit }) =>3546+ emit({3547+ sessionUpdate: "agent_message_chunk",3548+ content: { type: "text", text: "Immediate steer reply." },3549+ }).pipe(Effect.as(undefined)),3550+ },3551+ );3552+ const { session, providerThread, usage, send, startTurn, until } = opened;3553+3554+ yield* startTurn(1, false);3555+ const started = yield* until(3556+ (event) =>3557+ event.type === "turn_item.updated" &&3558+ event.turnItem.type === "assistant_message" &&3559+ event.turnItem.text === "I'll render once the fetch finishes.",3560+ );@@ -3095,0 +3768,21 @@3768+ threadId: ThreadId.make("thread-antigravity-wake"),3769+ runId: RunId.make("run-antigravity-wake-1"),3770+ providerThread,3771+ providerTurnId,3772+ message: makeSteerMessage(steer2, "Second steer"),3773+ });3774+ yield* TestClock.adjust("1500 millis");3775+ yield* send(usage);3776+ yield* send({3777+ sessionUpdate: "agent_message_chunk",3778+ content: { type: "text", text: "Reply to steer 2." },3779+ });3780+ yield* send(usage);3781+ yield* opened.releaseSteer;3782+ const run = yield* until((event) => event.type === "turn.terminal");3783+3784+ const steer1Events = steerEvents(run).filter(([id]) => id === steer1);3785+ assert.equal(3786+ steer1Events.at(-1)?.[1],3787+ "pending",3788+ "a superseded steer whose in-flight RPC rejected busy must end pending for redelivery",@@ -1139,0 +1156,21 @@1156+ if (replyOpen || hasPendingSteers || !previousPromptSettled) {1157+ return "defer";1158+ }1159+ return "none";1160+ },1161+ onSessionUpdate: ({1162+ notification,1163+ ingestsOutput,1164+ hasPendingSteers,1165+ hasCompletedPreSteerReply,1166+ isKnownToolCall,1167+ }) => {1168+ const update = notification.update;1169+ if (update.sessionUpdate === "usage_update") {1170+ replyOpen = false;1171+ return hasPendingSteers ? "mark_reply_complete" : "none";1172+ }1173+ if (1174+ !ingestsOutput ||1175+ ((update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") &&1176+ isKnownToolCall)@@ -4148,0 +4268,21 @@4268+ context.completedPreSteerReply = null;4269+ for (const steer of context.pendingPromptSteers.splice(0)) {4270+ const everDispatched = yield* Deferred.isDone(steer.dispatched);4271+ const inFlight =4272+ steer.attemptDispatched !== null && (yield* Deferred.isDone(steer.attemptDispatched));4273+ if (settledStatus === "completed" && inFlight) {4274+ if (steer.pendingEmitted) {4275+ yield* emitSteerStatus(context, steer.messageId, "completed");4276+ }4277+ continue;4278+ }4279+ // Interrupted, failed, cancelled, or unaccepted: leave pending so orchestration4280+ // either reports delivery unconfirmed on Stop or requeues the unread steer.4281+ if (everDispatched) yield* emitPendingSteer(context, steer);4282+ }4283+ });4284+4285+ const releaseDeferredPromptSteers = Effect.fnUntraced(function* (context: ActiveAcpTurn) {4286+ const preSteerReply = context.completedPreSteerReply;4287+ if (preSteerReply === null) return;4288+ context.completedPreSteerReply = null;@@ -8972,3 +9190,6 @@89729190 : ({ outcome: { outcome: "selected", optionId } } as const),89739191 };89749192 }9193+ const approvalContext = yield* activeContext;9194+ if (approvalContext !== null) {9195+ yield* applySteerBoundaryPermissionRequest(approvalContext, params);@@ -11064,3 +11292,11 @@1106411292 flavor.hasPendingReply !== undefined1106511293 ? yield* flavor.hasPendingReply(context.nativeThreadId)1106611294 : false;11295+ const pendingSteerReply =11296+ !pendingReply &&11297+ deferredBackgroundWork &&11298+ status === "completed" &&11299+ !context.interrupted &&11300+ context.pendingPromptSteers.length > 0 &&11301+ flavor.hasPendingReply !== undefined11302+ ? yield* flavor.hasPendingReply(context.nativeThreadId)@@ -11737,4 +12017,17 @@11737- { prompt: steerPrompt },11738- { dispatched, released: releasedForSteer },11739- ),11740- ),12017+ runPromptAttempt({12018+ prompt: steerPrompt,12019+ ...(steerMeta === undefined ? {} : { _meta: steerMeta }),12020+ }).pipe(12021+ // The turn ended before it took the steer, so it starts the next12022+ // prompt, unless Stop or a later steer came first.12023+ Effect.catchIf(12024+ (error) =>12025+ steerMeta !== undefined &&12026+ error._tag === "AcpRequestError" &&12027+ error.code === -32600 &&12028+ !context.interrupted &&12029+ !context.finalized &&12030+ !superseded(),12031+ () => runPromptAttempt({ prompt: steerPrompt }),12032+ ),12033+ Effect.tapError(() =>
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged thise389f8c
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.




Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
275a000ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.