@@ -6103,14 +6103,19 @@ describe("ClaudeAdapterV2 background wake turns", () => {
61036103
61046104 const providerTurn = lastProviderTurn(harness.events);
61056105 assert.notEqual(providerTurn.nativeTurnRef?.nativeId, subagentUuid);
6106- const rollbackTo = (providerThreadTurns: ReadonlyArray<typeof providerTurn>) =>
6106+ const rollbackTo = (
6107+ providerThreadTurns: ReadonlyArray<typeof providerTurn>,
6108+ text = "Background task completed.",
6109+ targetTurn = providerTurn,
6110+ ) =>
61076111 harness.runtime.rollbackThread({
61086112 providerThread: harness.providerThread,
61096113 target: {
61106114 type: "provider_turn",
61116115 checkpointId: CheckpointId.make("checkpoint-claude-cursor-subagent-only"),
61126116 appRunOrdinal: 1,
6113- providerTurn,
6117+ providerTurn: targetTurn,
6118+ message: { role: "user", text, attachments: [] },
61146119 },
61156120 providerThreadTurns,
61166121 });
@@ -6127,6 +6132,64 @@ describe("ClaudeAdapterV2 background wake turns", () => {
61276132 ]).pipe(Effect.flip);
61286133 assert.instanceOf(error, ProviderAdapter.ProviderAdapterRollbackThreadError);
61296134 assert.include(String(error.cause), "no SDK assistant message cursor");
6135+ const earlierCursor = "00000000-0000-4000-8000-000000000648";
6136+ const turnsAcrossSilent = [
6137+ {
6138+ ...providerTurn,
6139+ id: ProviderTurnId.make("provider-turn-claude-cursor-earlier"),
6140+ ordinal: providerTurn.ordinal - 1,
6141+ nativeTurnRef: {
6142+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
6143+ nativeId: earlierCursor,
6144+ strength: "weak",
6145+ },
6146+ },
6147+ providerTurn,
6148+ {
6149+ ...providerTurn,
6150+ id: ProviderTurnId.make("provider-turn-claude-cursor-next"),
6151+ ordinal: providerTurn.ordinal + 1,
6152+ },
6153+ ] satisfies ReadonlyArray<typeof providerTurn>;
6154+ const semanticError = yield* rollbackTo(turnsAcrossSilent).pipe(Effect.flip);
6155+ assert.instanceOf(semanticError, ProviderAdapter.ProviderAdapterRollbackThreadError);
6156+ const pastSilentTurn = yield* rollbackTo(turnsAcrossSilent, "/compact");
6157+ assert.equal(
6158+ pastSilentTurn.providerThread.nativeConversationHeadRef?.nativeId,
6159+ earlierCursor,
6160+ );
6161+ const interruptedBeforeCompact = yield* rollbackTo(
6162+ [
6163+ {
6164+ ...providerTurn,
6165+ id: ProviderTurnId.make("provider-turn-claude-cursor-earlier"),
6166+ ordinal: 1,
6167+ nativeTurnRef: {
6168+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
6169+ nativeId: earlierCursor,
6170+ strength: "weak",
6171+ },
6172+ },
6173+ {
6174+ ...providerTurn,
6175+ id: ProviderTurnId.make("provider-turn-claude-interrupted-before-compact"),
6176+ ordinal: 2,
6177+ status: "interrupted",
6178+ },
6179+ { ...providerTurn, ordinal: 3 },
6180+ {
6181+ ...providerTurn,
6182+ id: ProviderTurnId.make("provider-turn-claude-cursor-next"),
6183+ ordinal: 4,
6184+ },
6185+ ],
6186+ "/compact",
6187+ { ...providerTurn, ordinal: 3 },
6188+ ).pipe(Effect.flip);
6189+ assert.instanceOf(
6190+ interruptedBeforeCompact,
6191+ ProviderAdapter.ProviderAdapterRollbackThreadError,
6192+ );
61306193
61316194 yield* harness.runtime.startTurn(
61326195 makeClaudeTestTurnInput({
0 commit comments