Remove unused items tracking from Claude adapter state (#13718)
Co-authored-by: Claude <[email protected]>
This commit is contained in:
1 parent
c216ba4dad
commit
5660ab5cb5
2 files changed
+57
-20
No files matched your search
@@ -6691,6 +6691,56 @@ describe("ClaudeAdapterLive", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("completed turns keep their ids but not the SDK messages", () => {
|
||||
const harness = makeHarness();
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
const session = yield* adapter.startSession({
|
||||
threadId: THREAD_ID,
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
const turn = yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
input: "hello",
|
||||
attachments: [],
|
||||
});
|
||||
const completedFiber = yield* Stream.filter(
|
||||
adapter.streamEvents,
|
||||
(event) => event.type === "turn.completed",
|
||||
).pipe(Stream.runHead, Effect.forkChild);
|
||||
|
||||
harness.query.emit({
|
||||
type: "assistant",
|
||||
session_id: "sdk-session-1",
|
||||
uuid: "assistant-1",
|
||||
parent_tool_use_id: null,
|
||||
message: {
|
||||
id: "assistant-message-1",
|
||||
content: [{ type: "text", text: "Hi" }],
|
||||
},
|
||||
} as unknown as SDKMessage);
|
||||
harness.query.emit({
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
is_error: false,
|
||||
errors: [],
|
||||
session_id: "sdk-session-1",
|
||||
uuid: "result-1",
|
||||
} as unknown as SDKMessage);
|
||||
yield* Fiber.join(completedFiber);
|
||||
|
||||
const snapshot = yield* adapter.readThread(session.threadId);
|
||||
assert.deepEqual(
|
||||
snapshot.turns.map((entry) => ({ id: String(entry.id), items: entry.items })),
|
||||
[{ id: String(turn.turnId), items: [] }],
|
||||
);
|
||||
}).pipe(
|
||||
Effect.provideService(Random.Random, makeDeterministicRandomService()),
|
||||
Effect.provide(harness.layer),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("rewinds Claude history when the fork omits retained system messages", () => {
|
||||
const forkCalls: Array<Parameters<NonNullable<ClaudeAdapterLiveOptions["forkSession"]>>> = [];
|
||||
let firstTurnId = "";
|
||||
|
||||
@@ -267,7 +267,6 @@ interface ClaudeTurnState {
|
||||
* steered instead (the queued message continues the same turn).
|
||||
*/
|
||||
readonly synthetic?: boolean;
|
||||
readonly items: Array<unknown>;
|
||||
readonly assistantTextBlocks: Map<number, AssistantTextBlockState>;
|
||||
readonly assistantTextBlockOrder: Array<AssistantTextBlockState>;
|
||||
readonly capturedProposedPlanKeys: Set<string>;
|
||||
@@ -422,10 +421,11 @@ interface ClaudeSessionContext {
|
||||
resumeSessionId: string | undefined;
|
||||
readonly pendingApprovals: Map<ApprovalRequestId, PendingApproval>;
|
||||
readonly pendingUserInputs: Map<ApprovalRequestId, PendingUserInput>;
|
||||
readonly turns: Array<{
|
||||
id: TurnId;
|
||||
items: Array<unknown>;
|
||||
}>;
|
||||
/** Completed turn ids, reported by readThread and trimmed on rollback.
|
||||
* SDK messages are not kept: rollback reads Claude's own history through
|
||||
* turnStartMessageIds, and a long-lived session would otherwise hold every
|
||||
* message it ever produced. */
|
||||
readonly turns: Array<{ readonly id: TurnId }>;
|
||||
readonly inFlightTools: Map<number, ToolInFlight>;
|
||||
readonly claudeTasks: Map<string, ClaudeTaskState>;
|
||||
readonly taskAgents: Map<string, ClaudeTaskAgentState>;
|
||||
@@ -2176,10 +2176,7 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
}
|
||||
return {
|
||||
threadId,
|
||||
turns: context.turns.map((turn) => ({
|
||||
id: turn.id,
|
||||
items: [...turn.items],
|
||||
})),
|
||||
turns: context.turns.map((turn) => ({ id: turn.id, items: [] })),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -2808,10 +2805,7 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
});
|
||||
}
|
||||
|
||||
context.turns.push({
|
||||
id: turnState.turnId,
|
||||
items: [...turnState.items],
|
||||
});
|
||||
context.turns.push({ id: turnState.turnId });
|
||||
|
||||
yield* emitThreadTokenUsage(context, usageSnapshot, {
|
||||
rawMethod: "claude/result",
|
||||
@@ -3175,10 +3169,6 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.turnState) {
|
||||
context.turnState.items.push(message.message);
|
||||
}
|
||||
|
||||
for (const toolResult of toolResultBlocksFromUserMessage(message)) {
|
||||
const toolEntry = Array.from(context.inFlightTools.entries()).find(
|
||||
([, tool]) => tool.itemId === toolResult.toolUseId,
|
||||
@@ -3378,7 +3368,6 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
turnId,
|
||||
startedAt,
|
||||
synthetic: true,
|
||||
items: [],
|
||||
assistantTextBlocks: new Map(),
|
||||
assistantTextBlockOrder: [],
|
||||
capturedProposedPlanKeys: new Set(),
|
||||
@@ -3461,7 +3450,6 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
cwd: path.resolve(context.session.cwd ?? "."),
|
||||
});
|
||||
}
|
||||
context.turnState.items.push(message.message);
|
||||
if (
|
||||
normalizeClaudeActiveTokenUsage(
|
||||
message.message.usage,
|
||||
@@ -5205,7 +5193,6 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
const turnState: ClaudeTurnState = {
|
||||
turnId,
|
||||
startedAt: yield* nowIso,
|
||||
items: [],
|
||||
assistantTextBlocks: new Map(),
|
||||
assistantTextBlockOrder: [],
|
||||
capturedProposedPlanKeys: new Set(),
|
||||
|
||||
Reference in new issue
Block a user