fix(orchestrator): preserve migrated and nested history
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
48346a72ab
commit
4414baf371
4 files changed
+98
-9
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
cursorRuntimeAgentPolicy,
|
||||
cursorSdkModelSelection,
|
||||
makeCursorAgentOptions,
|
||||
nestedToolCallFromEnvelope,
|
||||
} from "./CursorAdapterV2.ts";
|
||||
import { isCursorCancellationError, loggedCursorAgentOptions } from "./CursorAgentSdk.ts";
|
||||
|
||||
@@ -168,4 +169,27 @@ describe("CursorAdapterV2", () => {
|
||||
assert.isFalse(isCursorCancellationError(new Error("request failed")));
|
||||
assert.isFalse(isCursorCancellationError(null));
|
||||
});
|
||||
|
||||
it("preserves failed nested read calls when Cursor omits their path", () => {
|
||||
assert.deepEqual(
|
||||
nestedToolCallFromEnvelope({
|
||||
toolCallId: "tool:failed-read",
|
||||
readToolCall: {
|
||||
args: {},
|
||||
result: { error: "File path was not provided." },
|
||||
},
|
||||
}),
|
||||
{
|
||||
callId: "tool:failed-read",
|
||||
toolCall: {
|
||||
type: "read",
|
||||
args: { path: "<unknown path>" },
|
||||
result: {
|
||||
status: "error",
|
||||
error: "File path was not provided.",
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -573,7 +573,7 @@ function nestedGrepWorkspaceResults(success: Record<string, unknown>): Record<st
|
||||
);
|
||||
}
|
||||
|
||||
function nestedToolCallFromEnvelope(
|
||||
export function nestedToolCallFromEnvelope(
|
||||
envelope: Record<string, unknown>,
|
||||
): { readonly callId: string; readonly toolCall: ToolCall } | undefined {
|
||||
const callId = typeof envelope.toolCallId === "string" ? envelope.toolCallId : undefined;
|
||||
@@ -598,10 +598,7 @@ function nestedToolCallFromEnvelope(
|
||||
? args.path
|
||||
: typeof success?.path === "string"
|
||||
? success.path
|
||||
: undefined;
|
||||
if (path === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
: "<unknown path>";
|
||||
return {
|
||||
callId: nestedCallId,
|
||||
toolCall: {
|
||||
|
||||
@@ -105,6 +105,66 @@ layer("035_036_OrchestrationV2", (it) => {
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves turn items with colliding ordinals in migration 037", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
yield* runMigrations({ toMigrationInclusive: 36 });
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_runs (
|
||||
run_id,
|
||||
thread_id,
|
||||
ordinal,
|
||||
provider,
|
||||
status,
|
||||
requested_at,
|
||||
payload_json
|
||||
) VALUES (
|
||||
'run:one',
|
||||
'thread:one',
|
||||
1,
|
||||
'codex',
|
||||
'completed',
|
||||
'2026-01-01T00:00:00.000Z',
|
||||
'{}'
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_turn_items (
|
||||
turn_item_id,
|
||||
thread_id,
|
||||
run_id,
|
||||
ordinal,
|
||||
type,
|
||||
status,
|
||||
updated_at,
|
||||
payload_json
|
||||
) VALUES
|
||||
('turn-item:b', 'thread:one', 'run:one', 7, 'assistant_message', 'completed', '2026-01-01T00:00:00.000Z', '{}'),
|
||||
('turn-item:a', 'thread:one', 'run:one', 7, 'assistant_message', 'completed', '2026-01-01T00:00:00.000Z', '{}'),
|
||||
('turn-item:c', 'thread:one', 'run:one', 9, 'assistant_message', 'completed', '2026-01-01T00:00:00.000Z', '{}'),
|
||||
('turn-item:d', 'thread:two', NULL, 42, 'assistant_message', 'completed', '2026-01-01T00:00:00.000Z', '{}')
|
||||
`;
|
||||
|
||||
yield* runMigrations({ toMigrationInclusive: 37 });
|
||||
|
||||
const positions = yield* sql<{
|
||||
readonly thread_id: string;
|
||||
readonly turn_item_id: string;
|
||||
readonly ordinal: number;
|
||||
}>`
|
||||
SELECT thread_id, turn_item_id, ordinal
|
||||
FROM orchestration_v2_turn_item_positions
|
||||
ORDER BY thread_id, ordinal
|
||||
`;
|
||||
assert.deepStrictEqual(positions, [
|
||||
{ thread_id: "thread:one", turn_item_id: "turn-item:a", ordinal: 1_000_001 },
|
||||
{ thread_id: "thread:one", turn_item_id: "turn-item:b", ordinal: 1_000_002 },
|
||||
{ thread_id: "thread:one", turn_item_id: "turn-item:c", ordinal: 1_000_003 },
|
||||
{ thread_id: "thread:two", turn_item_id: "turn-item:d", ordinal: 1 },
|
||||
]);
|
||||
}).pipe(Effect.provide(NodeSqliteClient.layerMemory())),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("upgrades a database already at released main migration 034", () =>
|
||||
|
||||
@@ -137,14 +137,22 @@ export default Effect.gen(function* () {
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
INSERT OR IGNORE INTO orchestration_v2_turn_item_positions (
|
||||
INSERT INTO orchestration_v2_turn_item_positions (
|
||||
thread_id,
|
||||
turn_item_id,
|
||||
ordinal
|
||||
)
|
||||
SELECT thread_id, turn_item_id, ordinal
|
||||
FROM orchestration_v2_projection_turn_items
|
||||
ORDER BY thread_id, ordinal, turn_item_id
|
||||
SELECT
|
||||
item.thread_id,
|
||||
item.turn_item_id,
|
||||
COALESCE(run.ordinal, 0) * 1000000 + ROW_NUMBER() OVER (
|
||||
PARTITION BY item.thread_id, COALESCE(run.ordinal, 0)
|
||||
ORDER BY item.ordinal, item.turn_item_id
|
||||
)
|
||||
FROM orchestration_v2_projection_turn_items AS item
|
||||
LEFT JOIN orchestration_v2_projection_runs AS run
|
||||
ON run.thread_id = item.thread_id
|
||||
AND run.run_id = item.run_id
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
|
||||
Reference in new issue
Block a user