Skip to content

Commit e886d76

Browse files
committed
fix(server): avoid skipping cursorless turns before compaction
1 parent fe5c22f commit e886d76

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5429,14 +5429,15 @@ describe("ClaudeAdapterV2 background wake turns", () => {
54295429
const rollbackTo = (
54305430
providerThreadTurns: ReadonlyArray<typeof providerTurn>,
54315431
text = "Background task completed.",
5432+
targetTurn = providerTurn,
54325433
) =>
54335434
harness.runtime.rollbackThread({
54345435
providerThread: harness.providerThread,
54355436
target: {
54365437
type: "provider_turn",
54375438
checkpointId: CheckpointId.make("checkpoint-claude-cursor-subagent-only"),
54385439
appRunOrdinal: 1,
5439-
providerTurn,
5440+
providerTurn: targetTurn,
54405441
message: { role: "user", text, attachments: [] },
54415442
},
54425443
providerThreadTurns,
@@ -5480,6 +5481,38 @@ describe("ClaudeAdapterV2 background wake turns", () => {
54805481
pastSilentTurn.providerThread.nativeConversationHeadRef?.nativeId,
54815482
earlierCursor,
54825483
);
5484+
const interruptedBeforeCompact = yield* rollbackTo(
5485+
[
5486+
{
5487+
...providerTurn,
5488+
id: ProviderTurnId.make("provider-turn-claude-cursor-earlier"),
5489+
ordinal: 1,
5490+
nativeTurnRef: {
5491+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
5492+
nativeId: earlierCursor,
5493+
strength: "weak",
5494+
},
5495+
},
5496+
{
5497+
...providerTurn,
5498+
id: ProviderTurnId.make("provider-turn-claude-interrupted-before-compact"),
5499+
ordinal: 2,
5500+
status: "interrupted",
5501+
},
5502+
{ ...providerTurn, ordinal: 3 },
5503+
{
5504+
...providerTurn,
5505+
id: ProviderTurnId.make("provider-turn-claude-cursor-next"),
5506+
ordinal: 4,
5507+
},
5508+
],
5509+
"/compact",
5510+
{ ...providerTurn, ordinal: 3 },
5511+
).pipe(Effect.flip);
5512+
assert.instanceOf(
5513+
interruptedBeforeCompact,
5514+
ProviderAdapter.ProviderAdapterRollbackThreadError,
5515+
);
54835516

54845517
yield* harness.runtime.startTurn(
54855518
makeClaudeTestTurnInput({

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,11 +2032,11 @@ const resolveClaudeRollbackResumeSessionAt = Effect.fn(
20322032

20332033
// Only compaction can be omitted without dropping a retained user prompt.
20342034
if (target.message !== undefined && isCompactionCommandMessage(target.message)) {
2035-
const earlierCursor = input.providerThreadTurns
2035+
const earlierTurn = input.providerThreadTurns
20362036
.filter((turn) => turn.ordinal < target.providerTurn.ordinal)
20372037
.toSorted((left, right) => left.ordinal - right.ordinal)
2038-
.map(claudeTurnCursor)
2039-
.findLast((candidate) => candidate !== null);
2038+
.at(-1);
2039+
const earlierCursor = earlierTurn === undefined ? null : claudeTurnCursor(earlierTurn);
20402040
if (earlierCursor != null) {
20412041
return earlierCursor;
20422042
}

0 commit comments

Comments
 (0)