- Add scoped thread list, read, send, wait, and interrupt tools - Track creation provenance and map provider turns across adapters - Centralize thread lifecycle operations in a management service
755 lines
23 KiB
TypeScript
755 lines
23 KiB
TypeScript
import { assert, it } from "@effect/vitest";
|
|
import {
|
|
EventId,
|
|
MessageId,
|
|
type ModelSelection,
|
|
NodeId,
|
|
ProjectId,
|
|
ProviderInstanceId,
|
|
ProviderThreadId,
|
|
ProviderTurnId,
|
|
RunAttemptId,
|
|
RunId,
|
|
ThreadId,
|
|
TurnItemId,
|
|
} from "@t3tools/contracts";
|
|
import * as DateTime from "effect/DateTime";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Layer from "effect/Layer";
|
|
import * as Schema from "effect/Schema";
|
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
|
|
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
|
|
import { ProjectionStoreV2, layer as projectionStoreLayer } from "./ProjectionStore.ts";
|
|
|
|
const TestLayer = Layer.mergeAll(
|
|
projectionStoreLayer.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
|
|
SqlitePersistenceMemory,
|
|
);
|
|
const modelSelection = {
|
|
instanceId: ProviderInstanceId.make("codex"),
|
|
model: "gpt-5.4",
|
|
} satisfies ModelSelection;
|
|
const encodeUnknownJsonString = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
|
|
|
|
it.layer(TestLayer)("ProjectionStoreV2", (it) => {
|
|
it.effect("builds shell snapshots without decoding full turn item payloads", () =>
|
|
Effect.gen(function* () {
|
|
const projectionStore = yield* ProjectionStoreV2;
|
|
const sql = yield* SqlClient.SqlClient;
|
|
const now = yield* DateTime.now;
|
|
const nowIso = DateTime.formatIso(now);
|
|
const threadId = ThreadId.make("thread:projection-shell-stale-item");
|
|
const projectId = ProjectId.make("project:projection-shell");
|
|
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-shell-thread-created"),
|
|
type: "thread.created",
|
|
threadId,
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: threadId,
|
|
projectId,
|
|
title: "Projection shell",
|
|
defaultProvider: "codex",
|
|
modelSelection: {
|
|
provider: "codex",
|
|
model: "gpt-5.4",
|
|
},
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: null,
|
|
lineage: {
|
|
parentThreadId: null,
|
|
relationshipToParent: null,
|
|
rootThreadId: threadId,
|
|
},
|
|
forkedFrom: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
},
|
|
});
|
|
|
|
yield* sql`
|
|
INSERT INTO orchestration_v2_projection_turn_items (
|
|
turn_item_id,
|
|
thread_id,
|
|
run_id,
|
|
node_id,
|
|
provider_thread_id,
|
|
provider_turn_id,
|
|
parent_item_id,
|
|
ordinal,
|
|
type,
|
|
status,
|
|
updated_at,
|
|
payload_json
|
|
)
|
|
VALUES (
|
|
${"turn-item:stale-user-message"},
|
|
${threadId},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${0},
|
|
${"user_message"},
|
|
${"completed"},
|
|
${nowIso},
|
|
${encodeUnknownJsonString({
|
|
id: "turn-item:stale-user-message",
|
|
threadId,
|
|
runId: null,
|
|
nodeId: null,
|
|
providerThreadId: null,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: 0,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: nowIso,
|
|
completedAt: nowIso,
|
|
updatedAt: nowIso,
|
|
type: "user_message",
|
|
messageId: "message:stale-user-message",
|
|
text: "stale user message",
|
|
attachments: [],
|
|
})}
|
|
)
|
|
`;
|
|
|
|
const shell = yield* projectionStore.getShellSnapshot();
|
|
const fullProjectionExit = yield* Effect.exit(projectionStore.getThreadProjection(threadId));
|
|
|
|
assert.deepEqual(
|
|
shell.threads.map((thread) => ({
|
|
id: thread.id,
|
|
itemCount: thread.itemCount,
|
|
visibleItemCount: thread.visibleItemCount,
|
|
status: thread.status,
|
|
})),
|
|
[
|
|
{
|
|
id: threadId,
|
|
itemCount: 1,
|
|
visibleItemCount: 1,
|
|
status: "idle",
|
|
},
|
|
],
|
|
);
|
|
assert.equal(fullProjectionExit._tag, "Failure");
|
|
}),
|
|
);
|
|
|
|
it.effect("removes rolled back runs from the active visible projection", () =>
|
|
Effect.gen(function* () {
|
|
const projectionStore = yield* ProjectionStoreV2;
|
|
const now = yield* DateTime.now;
|
|
const threadId = ThreadId.make("thread:projection-rollback-prune");
|
|
const projectId = ProjectId.make("project:projection-rollback-prune");
|
|
const runId = RunId.make("run:projection-rollback-prune");
|
|
const attemptId = RunAttemptId.make("attempt:projection-rollback-prune");
|
|
const rootNodeId = NodeId.make("node:projection-rollback-prune:root");
|
|
const assistantNodeId = NodeId.make("node:projection-rollback-prune:assistant");
|
|
const providerThreadId = ProviderThreadId.make("provider-thread:projection-rollback-prune");
|
|
const providerTurnId = ProviderTurnId.make("provider-turn:projection-rollback-prune");
|
|
const userMessageId = MessageId.make("message:projection-rollback-prune:user");
|
|
const assistantMessageId = MessageId.make("message:projection-rollback-prune:assistant");
|
|
const userTurnItemId = TurnItemId.make("turn-item:projection-rollback-prune:user");
|
|
const assistantTurnItemId = TurnItemId.make("turn-item:projection-rollback-prune:assistant");
|
|
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:thread-created"),
|
|
type: "thread.created",
|
|
threadId,
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: threadId,
|
|
projectId,
|
|
title: "Projection rollback prune",
|
|
defaultProvider: "codex",
|
|
modelSelection,
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: providerThreadId,
|
|
lineage: {
|
|
parentThreadId: null,
|
|
relationshipToParent: null,
|
|
rootThreadId: threadId,
|
|
},
|
|
forkedFrom: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:provider-thread"),
|
|
type: "provider-thread.updated",
|
|
threadId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: providerThreadId,
|
|
provider: "codex",
|
|
providerSessionId: null,
|
|
appThreadId: threadId,
|
|
ownerNodeId: null,
|
|
nativeThreadRef: null,
|
|
nativeConversationHeadRef: null,
|
|
status: "active",
|
|
firstRunOrdinal: 1,
|
|
lastRunOrdinal: 1,
|
|
handoffIds: [],
|
|
forkedFrom: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:run-created"),
|
|
type: "run.created",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: runId,
|
|
threadId,
|
|
ordinal: 1,
|
|
provider: "codex",
|
|
modelSelection,
|
|
providerThreadId,
|
|
userMessageId,
|
|
rootNodeId,
|
|
activeAttemptId: attemptId,
|
|
status: "completed",
|
|
requestedAt: now,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
checkpointId: null,
|
|
contextHandoffId: null,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:attempt-created"),
|
|
type: "run-attempt.created",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: attemptId,
|
|
runId,
|
|
attemptOrdinal: 1,
|
|
rootNodeId,
|
|
provider: "codex",
|
|
providerThreadId,
|
|
providerTurnId,
|
|
reason: "initial",
|
|
status: "completed",
|
|
startedAt: now,
|
|
completedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:root-node"),
|
|
type: "node.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: rootNodeId,
|
|
threadId,
|
|
runId,
|
|
parentNodeId: null,
|
|
rootNodeId,
|
|
kind: "root_turn",
|
|
status: "completed",
|
|
countsForRun: true,
|
|
providerThreadId,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
runtimeRequestId: null,
|
|
checkpointScopeId: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:assistant-node"),
|
|
type: "node.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: assistantNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: assistantNodeId,
|
|
threadId,
|
|
runId,
|
|
parentNodeId: rootNodeId,
|
|
rootNodeId,
|
|
kind: "assistant_message",
|
|
status: "completed",
|
|
countsForRun: false,
|
|
providerThreadId,
|
|
providerTurnId,
|
|
nativeItemRef: null,
|
|
runtimeRequestId: null,
|
|
checkpointScopeId: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:provider-turn"),
|
|
type: "provider-turn.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: providerTurnId,
|
|
providerThreadId,
|
|
nodeId: rootNodeId,
|
|
runAttemptId: attemptId,
|
|
nativeTurnRef: null,
|
|
ordinal: 1,
|
|
status: "completed",
|
|
startedAt: now,
|
|
completedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:user-message"),
|
|
type: "message.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: userMessageId,
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
role: "user",
|
|
text: "rolled back user",
|
|
attachments: [],
|
|
streaming: false,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:assistant-message"),
|
|
type: "message.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: assistantNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "agent",
|
|
creationSource: "provider",
|
|
id: assistantMessageId,
|
|
threadId,
|
|
runId,
|
|
nodeId: assistantNodeId,
|
|
role: "assistant",
|
|
text: "rolled back assistant",
|
|
attachments: [],
|
|
streaming: false,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:user-item"),
|
|
type: "turn-item.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: userTurnItemId,
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
providerThreadId,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: 100,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
updatedAt: now,
|
|
type: "user_message",
|
|
messageId: userMessageId,
|
|
inputIntent: "turn_start",
|
|
text: "rolled back user",
|
|
attachments: [],
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:assistant-item"),
|
|
type: "turn-item.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: assistantNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: assistantTurnItemId,
|
|
threadId,
|
|
runId,
|
|
nodeId: assistantNodeId,
|
|
providerThreadId,
|
|
providerTurnId,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: 101,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
updatedAt: now,
|
|
type: "assistant_message",
|
|
messageId: assistantMessageId,
|
|
text: "rolled back assistant",
|
|
streaming: false,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:run-rolled-back"),
|
|
type: "run.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: runId,
|
|
threadId,
|
|
ordinal: 1,
|
|
provider: "codex",
|
|
modelSelection,
|
|
providerThreadId,
|
|
userMessageId,
|
|
rootNodeId,
|
|
activeAttemptId: attemptId,
|
|
status: "rolled_back",
|
|
requestedAt: now,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
checkpointId: null,
|
|
contextHandoffId: null,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-rollback-prune:root-rolled-back"),
|
|
type: "node.updated",
|
|
threadId,
|
|
runId,
|
|
nodeId: rootNodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: rootNodeId,
|
|
threadId,
|
|
runId,
|
|
parentNodeId: null,
|
|
rootNodeId,
|
|
kind: "root_turn",
|
|
status: "rolled_back",
|
|
countsForRun: true,
|
|
providerThreadId,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
runtimeRequestId: null,
|
|
checkpointScopeId: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
},
|
|
});
|
|
|
|
const projection = yield* projectionStore.getThreadProjection(threadId);
|
|
|
|
assert.deepEqual(
|
|
projection.runs.map((run) => run.status),
|
|
["rolled_back"],
|
|
);
|
|
assert.deepEqual(
|
|
projection.nodes.map((node) => [node.id, node.status]),
|
|
[
|
|
[assistantNodeId, "completed"],
|
|
[rootNodeId, "rolled_back"],
|
|
],
|
|
);
|
|
assert.lengthOf(projection.providerTurns, 1);
|
|
assert.lengthOf(projection.messages, 2);
|
|
assert.lengthOf(projection.turnItems, 2);
|
|
assert.lengthOf(projection.visibleTurnItems, 0);
|
|
}),
|
|
);
|
|
|
|
it.effect("keeps fork visible items stable after a source run is rolled back", () =>
|
|
Effect.gen(function* () {
|
|
const projectionStore = yield* ProjectionStoreV2;
|
|
const now = yield* DateTime.now;
|
|
const projectId = ProjectId.make("project:projection-fork-source-rollback");
|
|
const sourceThreadId = ThreadId.make("thread:projection-fork-source-rollback:source");
|
|
const targetThreadId = ThreadId.make("thread:projection-fork-source-rollback:target");
|
|
const sourceProviderThreadId = ProviderThreadId.make(
|
|
"provider-thread:projection-fork-source-rollback:source",
|
|
);
|
|
const targetProviderThreadId = ProviderThreadId.make(
|
|
"provider-thread:projection-fork-source-rollback:target",
|
|
);
|
|
const sourceRun1Id = RunId.make("run:projection-fork-source-rollback:source:1");
|
|
const sourceRun2Id = RunId.make("run:projection-fork-source-rollback:source:2");
|
|
const sourceRun1NodeId = NodeId.make("node:projection-fork-source-rollback:source:1");
|
|
const sourceRun2NodeId = NodeId.make("node:projection-fork-source-rollback:source:2");
|
|
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-fork-source-rollback:source-thread"),
|
|
type: "thread.created",
|
|
threadId: sourceThreadId,
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: sourceThreadId,
|
|
projectId,
|
|
title: "Projection fork source rollback source",
|
|
defaultProvider: "codex",
|
|
modelSelection,
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: sourceProviderThreadId,
|
|
lineage: {
|
|
parentThreadId: null,
|
|
relationshipToParent: null,
|
|
rootThreadId: sourceThreadId,
|
|
},
|
|
forkedFrom: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-fork-source-rollback:target-thread"),
|
|
type: "thread.created",
|
|
threadId: targetThreadId,
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: targetThreadId,
|
|
projectId,
|
|
title: "Projection fork source rollback target",
|
|
defaultProvider: "codex",
|
|
modelSelection,
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: targetProviderThreadId,
|
|
lineage: {
|
|
parentThreadId: sourceThreadId,
|
|
relationshipToParent: "fork",
|
|
rootThreadId: sourceThreadId,
|
|
},
|
|
forkedFrom: {
|
|
type: "run",
|
|
threadId: sourceThreadId,
|
|
runId: sourceRun2Id,
|
|
},
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
},
|
|
});
|
|
|
|
for (const [ordinal, runId, nodeId, promptText, responseText] of [
|
|
[1, sourceRun1Id, sourceRun1NodeId, "source one", "one"],
|
|
[2, sourceRun2Id, sourceRun2NodeId, "source two", "two"],
|
|
] as const) {
|
|
yield* projectionStore.apply({
|
|
id: EventId.make(`event:projection-fork-source-rollback:run-${ordinal}`),
|
|
type: "run.created",
|
|
threadId: sourceThreadId,
|
|
runId,
|
|
nodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: runId,
|
|
threadId: sourceThreadId,
|
|
ordinal,
|
|
provider: "codex",
|
|
modelSelection,
|
|
providerThreadId: sourceProviderThreadId,
|
|
userMessageId: MessageId.make(
|
|
`message:projection-fork-source-rollback:user:${ordinal}`,
|
|
),
|
|
rootNodeId: nodeId,
|
|
activeAttemptId: null,
|
|
status: "completed",
|
|
requestedAt: now,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
checkpointId: null,
|
|
contextHandoffId: null,
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make(`event:projection-fork-source-rollback:user-item-${ordinal}`),
|
|
type: "turn-item.updated",
|
|
threadId: sourceThreadId,
|
|
runId,
|
|
nodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
createdBy: "user",
|
|
creationSource: "web",
|
|
id: TurnItemId.make(`turn-item:projection-fork-source-rollback:user:${ordinal}`),
|
|
threadId: sourceThreadId,
|
|
runId,
|
|
nodeId,
|
|
providerThreadId: sourceProviderThreadId,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: ordinal * 100,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
updatedAt: now,
|
|
type: "user_message",
|
|
messageId: MessageId.make(`message:projection-fork-source-rollback:user:${ordinal}`),
|
|
inputIntent: "turn_start",
|
|
text: promptText,
|
|
attachments: [],
|
|
},
|
|
});
|
|
yield* projectionStore.apply({
|
|
id: EventId.make(`event:projection-fork-source-rollback:assistant-item-${ordinal}`),
|
|
type: "turn-item.updated",
|
|
threadId: sourceThreadId,
|
|
runId,
|
|
nodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: TurnItemId.make(`turn-item:projection-fork-source-rollback:assistant:${ordinal}`),
|
|
threadId: sourceThreadId,
|
|
runId,
|
|
nodeId,
|
|
providerThreadId: sourceProviderThreadId,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: ordinal * 100 + 1,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
updatedAt: now,
|
|
type: "assistant_message",
|
|
messageId: MessageId.make(
|
|
`message:projection-fork-source-rollback:assistant:${ordinal}`,
|
|
),
|
|
text: responseText,
|
|
streaming: false,
|
|
},
|
|
});
|
|
}
|
|
|
|
const targetBeforeRollback = yield* projectionStore.getThreadProjection(targetThreadId);
|
|
assert.deepEqual(
|
|
targetBeforeRollback.visibleTurnItems.map((row) => row.item.type),
|
|
["user_message", "assistant_message", "user_message", "assistant_message", "fork"],
|
|
);
|
|
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-fork-source-rollback:run-2-rolled-back"),
|
|
type: "run.updated",
|
|
threadId: sourceThreadId,
|
|
runId: sourceRun2Id,
|
|
nodeId: sourceRun2NodeId,
|
|
provider: "codex",
|
|
occurredAt: now,
|
|
payload: {
|
|
id: sourceRun2Id,
|
|
threadId: sourceThreadId,
|
|
ordinal: 2,
|
|
provider: "codex",
|
|
modelSelection,
|
|
providerThreadId: sourceProviderThreadId,
|
|
userMessageId: MessageId.make("message:projection-fork-source-rollback:user:2"),
|
|
rootNodeId: sourceRun2NodeId,
|
|
activeAttemptId: null,
|
|
status: "rolled_back",
|
|
requestedAt: now,
|
|
startedAt: now,
|
|
completedAt: now,
|
|
checkpointId: null,
|
|
contextHandoffId: null,
|
|
},
|
|
});
|
|
|
|
const targetAfterRollback = yield* projectionStore.getThreadProjection(targetThreadId);
|
|
assert.deepEqual(
|
|
targetAfterRollback.visibleTurnItems.map((row) => [
|
|
row.visibility,
|
|
row.item.type,
|
|
row.item.type === "user_message" || row.item.type === "assistant_message"
|
|
? row.item.text
|
|
: row.item.title,
|
|
]),
|
|
[
|
|
["inherited", "user_message", "source one"],
|
|
["inherited", "assistant_message", "one"],
|
|
["inherited", "user_message", "source two"],
|
|
["inherited", "assistant_message", "two"],
|
|
["synthetic", "fork", "Forked from conversation"],
|
|
],
|
|
);
|
|
}),
|
|
);
|
|
});
|