Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
commandId: CommandId.makeUnsafe("cmd-thread-create"),
threadId: THREAD_ID,
projectId: PROJECT_ID,
parentThreadId: null,
title: "Integration Thread",
modelSelection: {
provider,
Expand Down Expand Up @@ -277,6 +278,7 @@ it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
commandId: CommandId.makeUnsafe("cmd-thread-create-real-codex"),
threadId: THREAD_ID,
projectId: PROJECT_ID,
parentThreadId: null,
title: "Integration Thread",
modelSelection: {
provider: "codex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ describe("CheckpointReactor", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create"),
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Thread",
modelSelection: {
provider: "codex",
Expand Down
14 changes: 14 additions & 0 deletions apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe("OrchestrationEngine", () => {
{
id: ThreadId.makeUnsafe("thread-bootstrap"),
projectId: asProjectId("project-bootstrap"),
parentThreadId: null,
title: "Bootstrap Thread",
modelSelection: {
provider: "codex" as const,
Expand Down Expand Up @@ -198,6 +199,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-1-create"),
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Thread",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -258,6 +260,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-archive-create"),
threadId: ThreadId.makeUnsafe("thread-archive"),
projectId: asProjectId("project-archive"),
parentThreadId: null,
title: "Archive me",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -325,6 +328,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-replay-create"),
threadId: ThreadId.makeUnsafe("thread-replay"),
projectId: asProjectId("project-replay"),
parentThreadId: null,
title: "replay",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -393,6 +397,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-stream-thread-create"),
threadId: ThreadId.makeUnsafe("thread-stream"),
projectId: asProjectId("project-stream"),
parentThreadId: null,
title: "domain-stream",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -445,6 +450,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-ack-create"),
threadId: ThreadId.makeUnsafe("thread-ack"),
projectId: asProjectId("project-ack"),
parentThreadId: null,
title: "Ack Thread",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -482,6 +488,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-missing-project"),
threadId: ThreadId.makeUnsafe("thread-missing-project"),
projectId: asProjectId("project-missing"),
parentThreadId: null,
title: "Missing Project Thread",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -533,6 +540,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-turn-diff-create"),
threadId: ThreadId.makeUnsafe("thread-turn-diff"),
projectId: asProjectId("project-turn-diff"),
parentThreadId: null,
title: "Turn diff thread",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -653,6 +661,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-flaky-1"),
threadId: ThreadId.makeUnsafe("thread-flaky-fail"),
projectId: asProjectId("project-flaky"),
parentThreadId: null,
title: "flaky-fail",
modelSelection: {
provider: "codex",
Expand All @@ -673,6 +682,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-flaky-2"),
threadId: ThreadId.makeUnsafe("thread-flaky-ok"),
projectId: asProjectId("project-flaky"),
parentThreadId: null,
title: "flaky-ok",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -745,6 +755,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-atomic-create"),
threadId: ThreadId.makeUnsafe("thread-atomic"),
projectId: asProjectId("project-atomic"),
parentThreadId: null,
title: "atomic",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -887,6 +898,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-sync-create"),
threadId: ThreadId.makeUnsafe("thread-sync"),
projectId: asProjectId("project-sync"),
parentThreadId: null,
title: "sync-before",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -973,6 +985,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-duplicate-1"),
threadId: ThreadId.makeUnsafe("thread-duplicate"),
projectId: asProjectId("project-duplicate"),
parentThreadId: null,
title: "duplicate",
modelSelection: {
provider: "codex",
Expand All @@ -993,6 +1006,7 @@ describe("OrchestrationEngine", () => {
commandId: CommandId.makeUnsafe("cmd-thread-duplicate-2"),
threadId: ThreadId.makeUnsafe("thread-duplicate"),
projectId: asProjectId("project-duplicate"),
parentThreadId: null,
title: "duplicate",
modelSelection: {
provider: "codex",
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
payload: {
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: ProjectId.makeUnsafe("project-1"),
parentThreadId: ThreadId.makeUnsafe("thread-parent"),
title: "Thread 1",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -152,6 +153,17 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
`;
assert.deepEqual(messageRows, [{ messageId: "message-1", text: "hello" }]);

const threadRows = yield* sql<{
readonly threadId: string;
readonly parentThreadId: string | null;
}>`
SELECT
thread_id AS "threadId",
parent_thread_id AS "parentThreadId"
FROM projection_threads
`;
assert.deepEqual(threadRows, [{ threadId: "thread-1", parentThreadId: "thread-parent" }]);

const stateRows = yield* sql<{
readonly projector: string;
readonly lastAppliedSequence: number;
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/orchestration/Layers/ProjectionPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
yield* projectionThreadRepository.upsert({
threadId: event.payload.threadId,
projectId: event.payload.projectId,
parentThreadId: event.payload.parentThreadId,
title: event.payload.title,
modelSelection: event.payload.modelSelection,
runtimeMode: event.payload.runtimeMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
INSERT INTO projection_threads (
thread_id,
project_id,
parent_thread_id,
title,
model_selection_json,
branch,
Expand All @@ -68,6 +69,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
VALUES (
'thread-1',
'project-1',
'thread-parent',
'Thread 1',
'{"provider":"codex","model":"gpt-5-codex"}',
NULL,
Expand Down Expand Up @@ -256,6 +258,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
{
id: ThreadId.makeUnsafe("thread-1"),
projectId: asProjectId("project-1"),
parentThreadId: ThreadId.makeUnsafe("thread-parent"),
title: "Thread 1",
modelSelection: {
provider: "codex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
SELECT
thread_id AS "threadId",
project_id AS "projectId",
parent_thread_id AS "parentThreadId",
title,
model_selection_json AS "modelSelection",
runtime_mode AS "runtimeMode",
Expand Down Expand Up @@ -666,6 +667,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
const threads: ReadonlyArray<OrchestrationThread> = threadRows.map((row) => ({
id: row.threadId,
projectId: row.projectId,
parentThreadId: row.parentThreadId,
title: row.title,
modelSelection: row.modelSelection,
runtimeMode: row.runtimeMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe("ProviderCommandReactor", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create"),
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Thread",
modelSelection: modelSelection,
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create"),
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Thread",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -771,6 +772,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create-plan-source"),
threadId: sourceThreadId,
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Plan Source",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -806,6 +808,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create-plan-target"),
threadId: targetThreadId,
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Plan Target",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -958,6 +961,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create-plan-source-guarded"),
threadId: sourceThreadId,
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Plan Source",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -1111,6 +1115,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create-plan-source-unrelated"),
threadId: sourceThreadId,
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Plan Source",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -1146,6 +1151,7 @@ describe("ProviderRuntimeIngestion", () => {
commandId: CommandId.makeUnsafe("cmd-thread-create-plan-target-unrelated"),
threadId: targetThreadId,
projectId: asProjectId("project-1"),
parentThreadId: null,
title: "Plan Target",
modelSelection: {
provider: "codex",
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/orchestration/commandInvariants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const readModel: OrchestrationReadModel = {
{
id: ThreadId.makeUnsafe("thread-1"),
projectId: ProjectId.makeUnsafe("project-a"),
parentThreadId: null,
title: "Thread A",
modelSelection: {
provider: "codex",
Expand All @@ -78,6 +79,7 @@ const readModel: OrchestrationReadModel = {
{
id: ThreadId.makeUnsafe("thread-2"),
projectId: ProjectId.makeUnsafe("project-b"),
parentThreadId: null,
title: "Thread B",
modelSelection: {
provider: "codex",
Expand Down Expand Up @@ -157,6 +159,7 @@ describe("commandInvariants", () => {
commandId: CommandId.makeUnsafe("cmd-2"),
threadId: ThreadId.makeUnsafe("thread-3"),
projectId: ProjectId.makeUnsafe("project-a"),
parentThreadId: null,
title: "new",
modelSelection: {
provider: "codex",
Expand All @@ -181,6 +184,7 @@ describe("commandInvariants", () => {
commandId: CommandId.makeUnsafe("cmd-3"),
threadId: ThreadId.makeUnsafe("thread-1"),
projectId: ProjectId.makeUnsafe("project-a"),
parentThreadId: null,
title: "dup",
modelSelection: {
provider: "codex",
Expand Down
19 changes: 19 additions & 0 deletions apps/server/src/orchestration/commandInvariants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ export function requireThreadArchived(input: {
);
}

export function requireThreadNotDeleted(input: {
readonly readModel: OrchestrationReadModel;
readonly command: OrchestrationCommand;
readonly threadId: ThreadId;
}): Effect.Effect<OrchestrationThread, OrchestrationCommandInvariantError> {
return requireThread(input).pipe(
Effect.flatMap((thread) =>
thread.deletedAt === null
? Effect.succeed(thread)
: Effect.fail(
invariantError(
input.command.type,
`Thread '${input.threadId}' is deleted and cannot handle command '${input.command.type}'.`,
),
),
),
);
}

export function requireThreadNotArchived(input: {
readonly readModel: OrchestrationReadModel;
readonly command: OrchestrationCommand;
Expand Down
Loading
Loading