diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index cd56460369bd6..67d61332ae7c8 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -322,9 +322,11 @@ const ensureNativeFork: CommandPolicyV2Shape["ensureNativeFork"] = (input) => { }; const ensureRollback: CommandPolicyV2Shape["ensureRollback"] = (input) => { + // Without native truncation, the next turn replays the kept conversation as a handoff. if ( !input.capabilities.threads.canRollbackThread || - !input.capabilities.checkpointing.providerCanRollbackConversation + (!input.capabilities.checkpointing.providerCanRollbackConversation && + !input.capabilities.context.canConsumeHandoffSummaries) ) { return Effect.fail( unsupported(input, "rollback", "providerInstanceId conversation rollback is unavailable"), diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 27b7a2e12878d..f023fe5aa8697 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -82,6 +82,7 @@ import { import * as KeyedLock from "@t3tools/shared/KeyedLock"; import { modelSelectionsEqual } from "@t3tools/shared/model"; import { modelSwitchSince } from "./modelSwitch.ts"; +import { contextBoundaryOrdinal, isScheduledFreshRun } from "./contextBoundary.ts"; import { isPlaceholderThreadTitle } from "./placeholderThreadTitle.ts"; import { combinePullRequestWatchWakes, type PullRequestWatchWake } from "./pullRequestWatch.ts"; import { recordThreadOpen } from "@t3tools/shared/paletteSearch"; @@ -1364,42 +1365,6 @@ function appendContextHandoffId( return handoffId === null ? handoffIds : Array.from(new Set([...handoffIds, handoffId])); } -/** A fresh-session schedule run starts a side conversation; the thread's own one continues past it. */ -function isScheduledFreshRun( - run: Pick, - turnItems: OrchestrationV2ThreadProjection["turnItems"], -): boolean { - // Turn items, unlike messages, are not narrowed to the runs since the latest compaction. - return ( - run.freshContext === true && - turnItems.some( - (item) => - item.type === "user_message" && - item.messageId === run.userMessageId && - item.scheduledTaskId !== undefined, - ) - ); -} - -/** Ordinal of the latest started fresh-context run. Runs before it never reach a provider again. */ -function contextBoundaryOrdinal( - projection: Pick, -): number { - let boundary = 0; - for (const run of projection.runs) { - if ( - run.freshContext === true && - run.status !== "queued" && - !cancelledBeforeStart(run) && - run.ordinal > boundary && - !isScheduledFreshRun(run, projection.turnItems) - ) { - boundary = run.ordinal; - } - } - return boundary; -} - /** The provider thread a message continues: the active one, unless a fresh-session schedule run started it. */ function conversationProviderThread( projection: Pick< diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index 7b0759ae99b0b..95595c3a0a2ae 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -1028,19 +1028,6 @@ function makeLocalCommandHarness(input: { ), ); const fallbackEnsureThread = vi.fn(() => Effect.succeed(providerThread)); - const resumeFallbackSession = { - driver: providerThread.driver, - resumeThread: () => - Effect.fail( - input.resumeFailure ?? - new ProviderAdapter.ProviderAdapterEventStreamError({ - driver: providerThread.driver, - providerSessionId, - cause: "native thread is gone", - }), - ), - ensureThread: fallbackEnsureThread, - }; const providerSession = { id: providerSessionId, driver: providerThread.driver, @@ -1059,6 +1046,20 @@ function makeLocalCommandHarness(input: { updatedAt: now, lastError: null, }; + const resumeFallbackSession = { + driver: providerThread.driver, + providerSession, + resumeThread: () => + Effect.fail( + input.resumeFailure ?? + new ProviderAdapter.ProviderAdapterEventStreamError({ + driver: providerThread.driver, + providerSessionId, + cause: "native thread is gone", + }), + ), + ensureThread: fallbackEnsureThread, + }; const startTurn = vi.fn((_turn: ProviderAdapter.ProviderAdapterV2TurnInput) => Effect.void); const sideChatThread = { ...providerThread, diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 5996a090bf4bd..7764bca5cca0c 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -9,6 +9,7 @@ import { type OrchestrationV2ProviderThread, type OrchestrationV2Run, type OrchestrationV2RunAttempt, + type OrchestrationV2ThreadProjection, type OrchestrationV2TurnItem, isCompactionCommandMessage, parseGoalCommand, @@ -43,6 +44,7 @@ import * as EventSink from "./EventSink.ts"; import * as ProviderUsageAnalytics from "../telemetry/ProviderUsageAnalytics.ts"; import * as ContextHandoffService from "./ContextHandoffService.ts"; import { isActiveRun } from "./CommandPolicy.ts"; +import { contextBoundaryOrdinal } from "./contextBoundary.ts"; import { DEFAULT_HANDOFF_TOKEN_CAP, handoffTokenCapConfig, @@ -118,6 +120,53 @@ const refusedBeforePrompt = (error: unknown): boolean => error.detail === CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL) || (Predicate.hasProperty(error, "cause") && refusedBeforePrompt(error.cause)); +/** + * Whether a non-truncating provider's native session lost the conversation kept before `run`. + * Rollback resets it: the newest accepted turn was rolled back (works without legacy-missing + * native ids) or ran under another native id (rollback of runs the provider never accepted). + */ +const nativeSessionMissesKeptTurns = ( + projection: Pick< + OrchestrationV2ThreadProjection, + "thread" | "runs" | "attempts" | "providerTurns" | "contextHandoffs" + >, + providerThread: OrchestrationV2ProviderThread, + run: OrchestrationV2Run, +): boolean => { + const nativeId = providerThread.nativeThreadRef?.nativeId; + if (nativeId === undefined) return false; + const acceptedAttemptIds = new Set(projection.providerTurns.map((turn) => turn.runAttemptId)); + const accepted = projection.attempts.filter((attempt) => acceptedAttemptIds.has(attempt.id)); + const runsById = new Map(projection.runs.map((source) => [source.id, source])); + const ordinalOf = (attempt: OrchestrationV2RunAttempt) => + runsById.get(attempt.runId)?.ordinal ?? 0; + const newest = accepted + .filter((attempt) => attempt.providerThreadId === providerThread.id) + .toSorted((a, b) => ordinalOf(a) - ordinalOf(b) || a.attemptOrdinal - b.attemptOrdinal) + .at(-1); + if (newest === undefined) return false; + // Inherited fork history is kept even when every local run was rolled back. + const keepsHistory = + (projection.thread.forkedFrom?.type === "run" && projection.thread.lineage.sideChat !== true) || + accepted.some((attempt) => { + const source = runsById.get(attempt.runId); + return ( + source !== undefined && source.ordinal < run.ordinal && source.status !== "rolled_back" + ); + }); + return ( + keepsHistory && + (runsById.get(newest.runId)?.status === "rolled_back" || + (newest.nativeThreadId !== undefined && newest.nativeThreadId !== nativeId)) && + !projection.contextHandoffs.some( + (handoff) => + handoff.toProviderThreadId === providerThread.id && + handoff.delivery?.nativeThreadId === nativeId && + handoff.delivery.status !== "pending", + ) + ); +}; + /** Missing execution records cannot be repaired by retrying a start. */ export class ProviderTurnStartRunStateMissingError extends Schema.TaggedError()( "ProviderTurnStartRunStateMissingError", @@ -1084,6 +1133,8 @@ export const layer: Layer.Layer< type: "provider_resume_fallback", }); const createdAt = yield* DateTime.now; + const history = yield* projectionStore.getTurnStartHistory(input.threadId); + const boundary = contextBoundaryOrdinal({ runs: projection.runs, turnItems: history }); const handoff = yield* contextHandoffService.prepareProviderHandoff({ threadId: projection.thread.id, targetRunId: run.id, @@ -1095,13 +1146,25 @@ export const layer: Layer.Layer< coveredRunOrdinals: { from: 1, to: Math.max(1, run.ordinal - 1) }, strategy: "full_thread_summary", runs: projection.runs, - items: (yield* projectionStore.getTurnStartHistory(input.threadId)).filter( - (item) => - item.runId === null || - projection.runs.some( - (source) => source.id === item.runId && source.ordinal < run.ordinal, - ), - ), + items: [ + ...(boundary === 0 + ? yield* ContextHandoffService.readInheritedHandoffItems( + projectionStore, + projection.thread, + ) + : []), + ...history.filter((item) => + item.runId === null + ? boundary === 0 + : projection.runs.some( + (source) => + source.id === item.runId && + source.ordinal >= boundary && + source.ordinal < run.ordinal && + source.status !== "rolled_back", + ), + ), + ], createdAt, }); return { handoff, transferId, createdAt }; @@ -1328,15 +1391,21 @@ export const layer: Layer.Layer< handoff.delivery?.nativeThreadId === providerThread.nativeThreadRef?.nativeId && handoff.delivery?.status === "pending", ); + // A provider that cannot truncate rolls back into a fresh native session holding none of the kept turns. + const nativeSessionLacksKeptTurns = + !session.providerSession.capabilities.checkpointing.providerCanRollbackConversation && + nativeSessionMissesKeptTurns(projection, providerThread, run); const resumed = yield* Effect.result( - uncertainDelivery + uncertainDelivery || nativeSessionLacksKeptTurns ? Effect.fail( new ProviderAdapter.ProviderAdapterTurnStartError({ driver: session.driver, threadId: projection.thread.id, providerThreadId: providerThread.id, runId, - cause: "Uncertain native history injection", + cause: uncertainDelivery + ? "Uncertain native history injection" + : "Native session holds none of the kept conversation", }), ) : session.resumeThread({ @@ -1416,9 +1485,11 @@ export const layer: Layer.Layer< runId, reason: uncertainDelivery ? "uncertain_history_delivery" - : resumed._tag === "Success" - ? "handoff_budget_exhausted" - : "resume_failed", + : nativeSessionLacksKeptTurns + ? "native_session_lacks_kept_turns" + : resumed._tag === "Success" + ? "handoff_budget_exhausted" + : "resume_failed", errorTag: resumed._tag === "Failure" ? resumed.failure._tag : "ContextHandoffBudgetError", }); const replacement = yield* loadFromProvider( diff --git a/apps/server/src/orchestration-v2/contextBoundary.ts b/apps/server/src/orchestration-v2/contextBoundary.ts new file mode 100644 index 0000000000000..1d9ca8d552fa2 --- /dev/null +++ b/apps/server/src/orchestration-v2/contextBoundary.ts @@ -0,0 +1,39 @@ +import type { OrchestrationV2Run, OrchestrationV2ThreadProjection } from "@t3tools/contracts"; + +import { cancelledBeforeStart } from "./RestartBackgroundNote.ts"; + +/** A fresh-session schedule run starts a side conversation; the thread's own one continues past it. */ +export function isScheduledFreshRun( + run: Pick, + turnItems: OrchestrationV2ThreadProjection["turnItems"], +): boolean { + // Turn items, unlike messages, are not narrowed to the runs since the latest compaction. + return ( + run.freshContext === true && + turnItems.some( + (item) => + item.type === "user_message" && + item.messageId === run.userMessageId && + item.scheduledTaskId !== undefined, + ) + ); +} + +/** Ordinal of the latest started fresh-context run. Runs before it never reach a provider again. */ +export function contextBoundaryOrdinal( + projection: Pick, +): number { + let boundary = 0; + for (const run of projection.runs) { + if ( + run.freshContext === true && + run.status !== "queued" && + !cancelledBeforeStart(run) && + run.ordinal > boundary && + !isScheduledFreshRun(run, projection.turnItems) + ) { + boundary = run.ordinal; + } + } + return boundary; +} diff --git a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts index edc12dcd98840..289e99b414990 100644 --- a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts +++ b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts @@ -131,6 +131,8 @@ function makeTestAdapter(input: { readonly backgroundTasksEndWithProcess?: true; readonly backgroundWork?: Ref.Ref; readonly closedSessions?: Ref.Ref>; + // ACP cannot truncate, so its rollback answers with a fresh, empty native session. + readonly rollback?: "truncates" | "replaces_native_thread"; }): ProviderAdapter.ProviderAdapterV2["Service"] { return { instanceId: input.instanceId, @@ -448,8 +450,25 @@ function makeTestAdapter(input: { respondToRuntimeRequest: () => Effect.void, readThreadSnapshot: () => unimplemented(input.driver, "readThreadSnapshot unused in provider switch test"), - rollbackThread: () => - unimplemented(input.driver, "rollbackThread unused in provider switch test"), + rollbackThread: ({ providerThread }) => + input.rollback === undefined + ? unimplemented(input.driver, "rollbackThread unused in provider switch test") + : Effect.succeed({ + providerThread: + input.rollback === "truncates" || providerThread.nativeThreadRef === null + ? providerThread + : { + ...providerThread, + nativeThreadRef: { + ...providerThread.nativeThreadRef, + nativeId: `${providerThread.nativeThreadRef.nativeId}:after-rollback`, + }, + nativeConversationHeadRef: null, + }, + providerTurns: [], + messages: [], + runtimeRequests: [], + }), forkThread: () => unimplemented(input.driver, "forkThread unused in provider switch test"), }; @@ -1630,6 +1649,304 @@ describe("orchestration v2 provider switching", () => { }), ); + it.live.each([ + { + name: "an ACP rollback that starts a fresh agent session", + instanceId: GROK_MODEL_SELECTION.instanceId, + driver: GROK_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + modelSelection: GROK_MODEL_SELECTION, + rollback: "replaces_native_thread", + failResumeAfterRollback: false, + history: "plain", + delivers: ["favourite colour is teal"], + withholds: ["favourite animal is an otter"], + }, + { + name: "a native rollback whose next resume fails", + instanceId: CLAUDE_MODEL_SELECTION.instanceId, + driver: CLAUDE_DRIVER, + capabilities: ClaudeProviderCapabilitiesV2, + modelSelection: CLAUDE_MODEL_SELECTION, + rollback: "truncates", + failResumeAfterRollback: true, + history: "plain", + delivers: ["favourite colour is teal"], + withholds: ["favourite animal is an otter"], + }, + { + // Pi forks into a new native thread that still holds the kept turns. + name: "a native rollback that forks a new native thread", + instanceId: CLAUDE_MODEL_SELECTION.instanceId, + driver: CLAUDE_DRIVER, + capabilities: ClaudeProviderCapabilitiesV2, + modelSelection: CLAUDE_MODEL_SELECTION, + rollback: "replaces_native_thread", + failResumeAfterRollback: false, + history: "plain", + delivers: [], + withholds: ["favourite colour is teal", "favourite animal is an otter"], + }, + { + name: "an ACP rollback where no attempt recorded its native session", + instanceId: GROK_MODEL_SELECTION.instanceId, + driver: GROK_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + modelSelection: GROK_MODEL_SELECTION, + rollback: "replaces_native_thread", + failResumeAfterRollback: false, + history: "legacy_all_turns", + delivers: ["favourite colour is teal"], + withholds: ["favourite animal is an otter"], + }, + { + name: "an ACP rollback of a forked thread to its baseline", + instanceId: GROK_MODEL_SELECTION.instanceId, + driver: GROK_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + modelSelection: GROK_MODEL_SELECTION, + rollback: "replaces_native_thread", + failResumeAfterRollback: false, + history: "forked_to_baseline", + delivers: ["home town is Oslo"], + withholds: ["favourite colour is teal", "favourite animal is an otter"], + }, + { + name: "an ACP rollback in a thread restarted with fresh context", + instanceId: GROK_MODEL_SELECTION.instanceId, + driver: GROK_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + modelSelection: GROK_MODEL_SELECTION, + rollback: "replaces_native_thread", + failResumeAfterRollback: false, + history: "after_fresh_context", + delivers: ["favourite colour is teal"], + withholds: ["home town is Oslo", "favourite animal is an otter"], + }, + ] as const)( + "gives the agent the kept conversation and not the rewound turn after $name", + (scenario) => + Effect.scoped( + Effect.gen(function* () { + const name = `rollback-kept-context-${scenario.driver}-${scenario.history}`; + const cwd = yield* checkpointWorkspace(name); + const capturedTurns = yield* Ref.make>([]); + const injectedHistory = yield* Ref.make>([]); + const failResumeOnce = yield* Ref.make(false); + const nativeThreadGeneration = yield* Ref.make(0); + const layerRegistry = ProviderAdapterRegistry.layerFromAdapters([ + makeTestAdapter({ + instanceId: scenario.instanceId, + driver: scenario.driver, + capabilities: scenario.capabilities, + modelSelection: scenario.modelSelection, + responseByRunOrdinal: { 1: "noted", 2: "noted", 3: "noted" }, + capturedTurns, + injectedHistory, + failResumeOnce, + nativeThreadGeneration, + rollback: scenario.rollback, + }), + ]); + yield* Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const runToCompletion = Effect.fn("runToCompletion")(function* ( + ordinal: number, + text: string, + thread: ThreadId = threadId, + freshContext = false, + ) { + yield* orchestrator.dispatch({ + type: "message.dispatch", + commandId: CommandId.make(`${thread}:${ordinal}`), + threadId: thread, + messageId: MessageId.make(`${thread}:${ordinal}`), + createdBy: "user", + creationSource: "web", + text, + attachments: [], + modelSelection: scenario.modelSelection, + ...(freshContext ? { freshContext: true } : {}), + dispatchMode: { type: "start_immediately" }, + }); + yield* orchestrator.streamStoredEvents.pipe( + Stream.filter( + ({ event }) => + event.type === "run.updated" && + event.threadId === thread && + event.payload.ordinal === ordinal && + (event.payload.status === "completed" || event.payload.status === "failed"), + ), + Stream.runHead, + ); + yield* worker.drain(); + }); + const createThread = (thread: ThreadId) => + orchestrator.dispatch({ + type: "thread.create", + commandId: CommandId.make(`${thread}:create`), + threadId: thread, + projectId, + createdBy: "user", + creationSource: "web", + title: "Edit from here", + modelSelection: scenario.modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + if (scenario.history === "forked_to_baseline") { + const sourceThreadId = ThreadId.make(`${name}:source`); + yield* createThread(sourceThreadId); + yield* runToCompletion( + 1, + "My home town is Oslo. Reply with only the word: noted", + sourceThreadId, + ); + yield* orchestrator.dispatch({ + type: "thread.fork", + commandId: CommandId.make(`${name}:fork`), + sourceThreadId, + targetThreadId: threadId, + sourcePoint: { + type: "run", + runId: (yield* orchestrator.getThreadProjection(sourceThreadId)).runs[0]!.id, + }, + createdBy: "user", + creationSource: "web", + }); + } else { + yield* createThread(threadId); + } + // Runs before a fresh-context run never reach a provider again. + const first = scenario.history === "after_fresh_context" ? 2 : 1; + if (first === 2) { + yield* runToCompletion(1, "My home town is Oslo. Reply with only the word: noted"); + } + yield* runToCompletion( + first, + "My favourite colour is teal. Reply with only the word: noted", + threadId, + first === 2, + ); + yield* runToCompletion( + first + 1, + "My favourite animal is an otter. Reply with only the word: noted", + ); + const beforeRollback = yield* orchestrator.getThreadProjection(threadId); + if (scenario.history === "legacy_all_turns") { + yield* (yield* EventSink.EventSinkV2).write({ + events: beforeRollback.attempts.map( + ({ nativeThreadId: _nativeThreadId, ...legacy }, index) => ({ + id: EventId.make(`${name}:legacy-attempt:${index}`), + type: "run-attempt.updated" as const, + threadId, + occurredAt: beforeRollback.thread.createdAt, + payload: legacy, + }), + ), + }); + } + const keptOrdinal = scenario.history === "forked_to_baseline" ? 0 : first; + const keptCheckpoint = beforeRollback.checkpoints.find( + (checkpoint) => + (checkpoint.appRunOrdinal ?? 0) === keptOrdinal && checkpoint.status === "ready", + ); + if (keptCheckpoint === undefined) { + return yield* Effect.die("Expected a checkpoint after the first turn."); + } + yield* orchestrator.dispatch({ + type: "checkpoint.rollback", + commandId: CommandId.make(`${name}:rollback`), + threadId, + scopeId: keptCheckpoint.scopeId, + checkpointId: keptCheckpoint.id, + restoreFiles: false, + }); + yield* orchestrator.streamStoredEvents.pipe( + Stream.filter( + ({ event }) => + (event.type === "run.updated" && + event.payload.ordinal === first + 1 && + event.payload.status === "rolled_back") || + (event.type === "thread.metadata-updated" && + event.payload.rollbackFailure != null), + ), + Stream.runHead, + ); + yield* worker.drain(); + assert.deepEqual( + (yield* orchestrator.getThreadProjection(threadId)).runs.map((run) => run.status), + scenario.history === "forked_to_baseline" + ? ["rolled_back", "rolled_back"] + : [...(first === 2 ? ["completed"] : []), "completed", "rolled_back"], + ); + if (scenario.failResumeAfterRollback) { + const providerSessionId = (yield* orchestrator.getThreadProjection(threadId)) + .providerThreads[0]?.providerSessionId; + if (providerSessionId == null) { + return yield* Effect.die("Expected a provider session after the rollback."); + } + yield* orchestrator.dispatch({ + type: "provider-session.detach", + commandId: CommandId.make(`${name}:detach`), + threadId, + providerSessionId, + }); + yield* worker.drain(); + yield* Ref.set(failResumeOnce, true); + } + const historyBeforeRun3 = (yield* Ref.get(injectedHistory)).length; + yield* runToCompletion(first + 2, "What did I say first?"); + + const run3 = (yield* Ref.get(capturedTurns)).at(-1); + const delivered = + (run3?.text ?? "") + + (yield* encodeJson((yield* Ref.get(injectedHistory)).slice(historyBeforeRun3))); + for (const kept of scenario.delivers) { + assert.include(delivered, kept, "the agent's session lacks this kept turn"); + } + for (const withheld of scenario.withholds) { + assert.notInclude(delivered, withheld, "the session holds it or it was rewound"); + } + if (scenario.name === "an ACP rollback that starts a fresh agent session") { + const recoveries = (projection: OrchestrationV2ThreadProjection) => + projection.contextHandoffs.filter( + (handoff) => handoff.strategy === "full_thread_summary", + ).length; + const recoveriesBeforeRun4 = recoveries( + yield* orchestrator.getThreadProjection(threadId), + ); + const sessionsBeforeRun4 = yield* Ref.get(nativeThreadGeneration); + yield* runToCompletion(4, "And what did I say second?"); + assert.strictEqual( + recoveries(yield* orchestrator.getThreadProjection(threadId)), + recoveriesBeforeRun4, + "the recovered session holds the kept turns, so the next turn replays nothing", + ); + assert.strictEqual(yield* Ref.get(nativeThreadGeneration), sessionsBeforeRun4); + } + }).pipe( + Effect.provide( + ProviderReplayHarness.layerWithRegistry( + { + name, + runtimePolicyOverride: { + cwd, + approvalPolicy: "never", + sandboxPolicy: { type: "readOnly" }, + }, + }, + layerRegistry, + ), + ), + ); + }), + ), + ); + it.live.each([ ["background work", new ClaudeBackgroundWorkBlocksQueryReplacementError()], ["an unreadable append file", new ClaudeAppendSystemPromptFileError({ path: "missing.md" })], diff --git a/docs/user/providers-acp.md b/docs/user/providers-acp.md index 701d5638b3fd8..453c777e3c8c0 100644 --- a/docs/user/providers-acp.md +++ b/docs/user/providers-acp.md @@ -128,8 +128,8 @@ remain agent-specific. ## Checkpoints Checkpoint rollback restores your files as usual. ACP agents cannot rewind their own conversation, -so the next turn after a rollback starts a fresh agent session that no longer remembers the -conversation from before the checkpoint. +so the next turn after a rollback starts a fresh agent session and T3 Code sends it the kept +conversation, without the turns you rolled back. Registry instances are not used for T3's app-owned text generation, such as thread titles, commit messages, branch names, or pull request descriptions. Configure a text-generation-capable provider diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 5934240905edf..696ee6b30d8d7 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -802,8 +802,8 @@ export const AcpProviderCapabilitiesV2 = { checkpointing: { appCanCheckpointFilesystem: true, supportsNestedCheckpointScopes: true, - // ACP lacks truncation; rollback restores T3 checkpoints and starts a fresh agent session. - providerCanRollbackConversation: true, + // ACP lacks truncation; rollback starts a fresh agent session and turn start replays the kept history. + providerCanRollbackConversation: false, providerRollbackReturnsSnapshot: true, providerCanReadConversationSnapshot: false, },