fix(orchestrator): session audit remediation — error fidelity, session resume, reconcile visibility #3677
Closedjuliusmarmingewants to merge 16 commits into
t3code/codex-turn-mapping fromt3code/orchestration-v2-audit-fixesopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -162,3 +163,3 @@162163 return belongs ? [true, addProviderTurn(event.providerTurn.id, isRoot)] : [false, state];163164 }164165 case "node.updated": {apps/server/src/orchestration-v2/ProviderAdapter.ts line 495OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -486,4 +510,14 @@486510 readonly startTurn: (487511 input: ProviderAdapterV2TurnInput,488512 ) => Effect.Effect<void, ProviderAdapterV2Error>;513+ /**514+ * Attach an orchestrator-minted run to a provider-initiated turn that is515+ * already in flight (announced via a `turn.wakeup` event). Behaves like516+ * `startTurn` except no prompt is sent to the provider: the adapter adopts517+ * the turn context and replays the wakeup activity it buffered since the518+ * wakeup was announced. Adapters that never self-start turns may omit this.519+ */520+ readonly attachTurn?: (521+ input: ProviderAdapterV2TurnInput,522+ ) => Effect.Effect<void, ProviderAdapterV2Error>;489523 readonly steerTurn: (apps/server/src/orchestration-v2/ProviderSessionManager.ts line 1063OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1009,3 +1060,4 @@10091060 ? persistProviderSessionUpdate(entry, event)10101061 : Effect.void,10111062 ),1063+ Effect.andThen(apps/server/src/orchestration-v2/Orchestrator.ts line 2520OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2478,4 +2517,4 @@24782517 updatedAt: now,24792518 type: "user_message",24802519 messageId: command.messageId,2481- inputIntent: "turn_start",2520+ inputIntent: dispatchMode.type === "attach_wakeup" ? "provider_wakeup" : "turn_start",@@ -0,0 +142,21 @@142+ yield* Effect.logInfo("orchestration-v2.provider-wakeup.dispatched", {143+ threadId: input.threadId,144+ providerThreadId: input.providerThreadId,145+ providerSessionId: input.providerSessionId,146+ origin: input.origin,147+ sequence: dispatched.sequence,148+ });149+ }).pipe(150+ Effect.catchCause((cause) =>151+ Effect.logWarning("orchestration-v2.provider-wakeup.dispatch-failed", {152+ threadId: input.threadId,153+ providerThreadId: input.providerThreadId,154+ providerSessionId: input.providerSessionId,155+ origin: input.origin,156+ cause,157+ }),158+ ),159+ Effect.asVoid,160+ );161+162+export const runWakeupDispatcher: Effect.Effect<
- @@ -518,3 +548,14 @@518548 payload: message,519549 }),520550 ),551+ Stream.tapError((error) =>552+ logProtocolEvent({553+ direction: "incoming",554+ stage: "decoded",555+ payload: {556+ type: "runner.error",557+ method: "messages.stream",558+ message: makeProviderFailure({ cause: error }).message,559+ },560+ }),561+ ),
- @@ -873,0 +898,21 @@898+ Effect.suspend(() => {899+ subagent.streamFlushScheduled = false;900+ if (!subagent.streamPendingText) return Effect.void;901+ subagent.streamPendingText = false;902+ return emitSubagentAssistantSnapshot(subagent);903+ }),904+ ),905+ Effect.forkIn(sessionScope),906+ );907+ });908+909+ // Terminal/one-shot emit: always persists the final text immediately.910+ const flushSubagentAssistant = Effect.fnUntraced(function* (911+ subagent: ActiveAcpSubagent,912+ finalText?: string,913+ ) {914+ if (finalText !== undefined && finalText.length > 0) {915+ subagent.assistantText += finalText;916+ }917+ subagent.streamPendingText = false;918+ yield* emitSubagentAssistantSnapshot(subagent);@@ -1044,9 +1093,12 @@10441093 );10451094 }104610951047- if (1048- taskStatus !== "running" &&1049- subagent.assistantText.length === 0 &&1050- update.result !== null1051- ) {1052- yield* emitSubagentAssistant(subagent, update.result);1096+ if (taskStatus !== "running") {1097+ // Terminal: flush the final text immediately (adopting the1098+ // one-shot result when nothing streamed) instead of leaving the1099+ // last throttled snapshot possibly unemitted.1100+ if (subagent.assistantText.length === 0 && update.result !== null) {1101+ yield* flushSubagentAssistant(subagent, update.result);1102+ } else if (subagent.streamPendingText) {1103+ yield* flushSubagentAssistant(subagent);1104+ }@@ -873,0 +898,21 @@898+ Effect.suspend(() => {899+ subagent.streamFlushScheduled = false;900+ if (!subagent.streamPendingText) return Effect.void;901+ subagent.streamPendingText = false;902+ return emitSubagentAssistantSnapshot(subagent);903+ }),904+ ),905+ Effect.forkIn(sessionScope),906+ );907+ });908+909+ // Terminal/one-shot emit: always persists the final text immediately.910+ const flushSubagentAssistant = Effect.fnUntraced(function* (911+ subagent: ActiveAcpSubagent,912+ finalText?: string,913+ ) {914+ if (finalText !== undefined && finalText.length > 0) {915+ subagent.assistantText += finalText;916+ }917+ subagent.streamPendingText = false;918+ yield* emitSubagentAssistantSnapshot(subagent);
- apps/server/src/orchestration-v2/ProviderWakeupService.ts line 204OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +184,21 @@184+ next.add(input.threadId);185+ return [true, next] as const;186+ }).pipe(187+ Effect.flatMap((claimed) =>188+ claimed189+ ? dispatchWakeup(orchestrator, input).pipe(190+ Effect.ensuring(191+ Ref.update(inFlightThreads, (current) => {192+ const next = new Set(current);193+ next.delete(input.threadId);194+ return next;195+ }),196+ ),197+ Effect.forkScoped,198+ Effect.asVoid,199+ )200+ : Effect.logInfo("orchestration-v2.provider-wakeup.coalesced", {201+ threadId: input.threadId,202+ providerThreadId: input.providerThreadId,203+ origin: input.origin,204+ }),
- apps/server/src/orchestration-v2/ProviderSessionManager.ts line 1048OutdatedResolvedby juliusmarminge@@ -995,3 +1045,4 @@9951045 ),9961046 );99710471048+ const notifyWakeupObserver = (
- @@ -0,0 +197,21 @@197+ return [null, next] as const;198+ }),199+ ),200+ Effect.flatMap((followUp) => (followUp === null ? Effect.void : drainThread(followUp))),201+ );202+203+ return yield* relay.take.pipe(204+ Effect.flatMap((input) =>205+ Ref.modify(threadStates, (current) => {206+ const next = new Map(current);207+ if (current.has(input.threadId)) {208+ next.set(input.threadId, { inFlight: true, followUp: input });209+ return [false, next] as const;210+ }211+ next.set(input.threadId, { inFlight: true, followUp: null });212+ return [true, next] as const;213+ }).pipe(214+ Effect.flatMap((claimed) =>215+ claimed216+ ? drainThread(input).pipe(Effect.forkScoped, Effect.asVoid)217+ : Effect.logInfo("orchestration-v2.provider-wakeup.follow-up-parked", {
- @@ -89,0 +103,21 @@103+} {104+ const messages: Array<string> = [];105+ let code: string | undefined;106+ const seen = new Set<unknown>();107+ let current: unknown = value;108+ for (let depth = 0; depth < MAX_FAILURE_CAUSE_DEPTH; depth += 1) {109+ if (current === null || current === undefined || seen.has(current)) break;110+ seen.add(current);111+ if (typeof current === "string") {112+ if (current.length > 0 && messages.at(-1) !== current) messages.push(current);113+ break;114+ }115+ if (typeof current !== "object" && !(current instanceof Error)) break;116+ const message =117+ current instanceof Error ? current.message : stringField(current, "message");118+ if (typeof message === "string" && message.length > 0 && messages.at(-1) !== message) {119+ messages.push(message);120+ }121+ code ??= stringField(current, "code");122+ current = (current as { readonly cause?: unknown }).cause;123+ }@@ -1045,3 +1052,4 @@10451052 }),10461053 );104710541055+const CODEX_RAW_THREAD_ID_PATTERN = /"threadId"\s*:\s*"([^"]+)"/;
- @@ -90,7 +114,21 @@114+ }115+ if (typeof current !== "object" && !(current instanceof Error)) break;116+ const message =117+ current instanceof Error ? current.message : stringField(current, "message");118+ if (typeof message === "string" && message.length > 0 && messages.at(-1) !== message) {119+ messages.push(message);120+ }121+ code ??= stringField(current, "code");122+ current = (current as { readonly cause?: unknown }).cause;123+ }124+ return { messages, code };125+}126+90127 export function makeProviderFailure(input: {91128 readonly cause?: unknown;92129 readonly message?: string | undefined;93130 readonly code?: string | null | undefined;94131 readonly class?: OrchestrationV2ProviderFailureClass;95132 readonly retryable?: boolean | null;96133 }): OrchestrationV2ProviderFailure {134+ const chain = causeChain(input.cause);
- @@ -1354,3 +1415,6 @@13541415 readonly startedAt: DateTime.Utc;13551416 }) =>13561417 Effect.gen(function* () {1418+ const nativeThreadId = input.turnInput.providerThread.nativeThreadRef?.nativeId;1419+ if (nativeThreadId !== undefined && nativeThreadId !== null) {1420+ logThreadRoutes.set(nativeThreadId, input.turnInput.threadId);
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
29545e92-bfbb-4173-abfd-4a6c6c012d5bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.