Skip to content

Commit 7ca0927

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-25637
2 parents 5c8839e + 7e71392 commit 7ca0927

25 files changed

Lines changed: 983 additions & 111 deletions

‎.coderabbit.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default defineConfig((ctx) => ({
2727
instructions: "Hold changed code to the rules in docs/internals/web-ui.md.",
2828
},
2929
{
30-
path: "**/*.test.{ts,tsx}",
30+
path: "**/*.test.*",
3131
instructions:
3232
"Hold changed tests to the rules in docs/internals/testing.md. Request tests only as those rules allow.",
3333
},
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Test Signal
3+
model: gpt-6-1-terra
4+
reasoning: low
5+
input: incremental
6+
tools:
7+
- browse_code
8+
- modify_pr
9+
# An explicit include overrides ignore.md, which skips test files for every other check.
10+
include:
11+
- "**/*.test.*"
12+
exclude:
13+
- ".repos/**"
14+
requires:
15+
- Check
16+
maxBudgetPerRun: 1
17+
maxBudgetPerPR: 5
18+
conclusion: neutral
19+
---
20+
21+
# Test signal review
22+
23+
Review only the tests this pull request adds or grows. Tests it moves, renames, or deletes are not findings. The rules are in `docs/internals/testing.md` under `## What to test`; read that section first and hold new tests to it.
24+
25+
Post each finding as a brief inline comment on the new test with one fix. Ask only for fewer or smaller tests, never for more coverage.
26+
27+
When there are no findings, make the entire final response exactly `All clear` on one line with nothing else.

‎AGENTS.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
102102
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103103
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105-
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
105+
- Test behavior that can break, such as orchestration and event-sourcing, provider protocol translation, auth and permission guards, persistence and migrations, external-format parsing, race fixes, and the logic a bug fix changed. Leave out tests for what types already guarantee, trivial logic, copy text, smoke runs, mock-call mirrors, callback wiring, and props rendered to static markup.
106+
- Extend before you add. When an existing test or table covers the behavior, add a row or an assertion there. Write a new `it` only when no case fits.
107+
- Test at one layer: the lowest one that fails on `main`. Do not repeat the case in a wrapper test, at each call site, or in web and mobile copies of the same logic.
106108
- [Testing](docs/internals/testing.md) carries these same test rules, plus review guidance, for review bots. Change both together.
107109
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
108110
- Backend behavior changes ship with focused tests for that behavior.
109-
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in the module's existing test file), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.
111+
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in an existing case of the module's test file where one fits), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.
110112
- The server is event-sourced, and side effects run after the command commits. In tests, drain the effect worker (`OrchestrationEffectWorkerV2.drain`) or await the specific persisted event or `Deferred` that marks the milestone. Never wait on sleeps or polling. A test that needs a timeout to pass is wrong. Concretely:
111113
- `it.effect` runs on a `TestClock`; `Effect.sleep` only advances through `TestClock.adjust`. `it.live` is wall-clock and only for subprocess or network fixtures.
112114
- No `yieldNow` or `sleep` polling loops. Await the `Deferred`, take from the `Queue`, or drain the worker.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
48804880
threadId: context.projectionThreadId,
48814881
providerThreadId: context.providerThread.id,
48824882
driver: CODEX_PROVIDER,
4883+
// Codex starts a new turn from this text, so nothing is buffered.
4884+
delivery: "message_text",
48834885
detail: codexBackgroundCommandDetail(payload.item),
48844886
notification: {
48854887
...backgroundWorkNotification([

‎apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ const instanceId = ProviderInstanceId.make("codex");
3535
const modelSelection = { instanceId, model: "test-model" };
3636

3737
const stopEarlierBackgroundWork = ({
38+
wakeAfterStop = false,
3839
failedStart = false,
3940
stopWithQueue,
4041
olderStart = false,
4142
backgroundWorkAfterStop,
4243
stalledRun,
4344
workflowMember = false,
4445
}: {
46+
readonly wakeAfterStop?: boolean;
4547
readonly failedStart?: boolean;
4648
readonly backgroundWorkAfterStop?: "running" | "unknown";
4749
readonly stopWithQueue?: "thread.stop" | "run.interrupt";
@@ -192,6 +194,46 @@ const stopEarlierBackgroundWork = ({
192194
});
193195
yield* worker.drain();
194196
yield* Fiber.join(running);
197+
if (wakeAfterStop) {
198+
const send = (id: string, provider = false) =>
199+
orchestrator.dispatch({
200+
type: "message.dispatch",
201+
commandId: CommandId.make(id),
202+
threadId,
203+
messageId: MessageId.make(`message:${id}`),
204+
text: id,
205+
attachments: [],
206+
dispatchMode: { type: "queue_after_active" },
207+
createdBy: provider ? "agent" : "user",
208+
creationSource: provider ? "provider" : "web",
209+
});
210+
yield* send("follow-up");
211+
yield* orchestrator.dispatch({
212+
type: "thread.stop",
213+
commandId: CommandId.make("stop"),
214+
threadId,
215+
});
216+
// Stop is committed, but its provider interrupt has not run yet.
217+
yield* send("Background task completed.", true);
218+
const [stopped, followUp, wake] = (yield* orchestrator.getThreadProjection(threadId))
219+
.runs;
220+
assert.equal(stopped?.status, "running");
221+
assert.isTrue(followUp?.queueHeld);
222+
assert.isTrue(wake?.queueHeld);
223+
224+
yield* worker.drain();
225+
yield* orchestrator.resumeQueuedRuns;
226+
yield* worker.drain();
227+
const after = yield* orchestrator.getThreadProjection(threadId);
228+
assert.deepEqual(
229+
after.runs.map((run) => run.status),
230+
["interrupted", "queued", "queued"],
231+
);
232+
assert.isTrue(after.runs.find((run) => run.id === followUp?.id)?.queueHeld);
233+
assert.isTrue(after.runs.find((run) => run.id === wake?.id)?.queueHeld);
234+
assert.lengthOf(started, 1);
235+
return;
236+
}
195237
const first = started[0]!;
196238
const codexTurn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
197239
const devServerId = TurnItemId.make("turn-item:dev-server");
@@ -1016,3 +1058,7 @@ it.effect.each(["missing-session-terminal", "returned-interrupt", "superseded-at
10161058
"Stop recovers a stalled run after %s without changing a newer attempt",
10171059
(stalledRun) => stopEarlierBackgroundWork({ stalledRun }),
10181060
);
1061+
1062+
it.effect("Stop holds a provider wake that queues before the stopped turn ends", () =>
1063+
stopEarlierBackgroundWork({ wakeAfterStop: true }),
1064+
);

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ function delegatedTaskTerminalStatus(
729729
function nextQueuedRun(
730730
projection: Pick<OrchestrationV2ThreadProjection, "runs" | "messages">,
731731
): OrchestrationV2Run | undefined {
732-
return queuedRunsInDeliveryOrder(projection)[0];
732+
return queuedRunsInDeliveryOrder(projection).find((run) => run.queueHeld !== true);
733733
}
734734

735735
function followsCurrentConversation(
@@ -1561,8 +1561,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15611561
if (
15621562
projection.thread.archivedAt !== null ||
15631563
projection.thread.deletedAt !== null ||
1564-
projection.runs.some(isBlockingRun) ||
1565-
projection.runs.some((run) => run.status === "queued" && run.queueHeld === true)
1564+
projection.runs.some(isBlockingRun)
15661565
) {
15671566
return;
15681567
}
@@ -5697,6 +5696,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
56975696
}),
56985697
),
56995698
);
5699+
const queueIsHeld = projection.runs.some(
5700+
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5701+
);
5702+
// Buffered wakes need a T3 run for output the CLI already started producing.
5703+
// Stop still holds wakes that arrive before the active run settles.
5704+
const wakeSkipsHold =
5705+
!worktreeSetupUnresolved &&
5706+
activeRun !== undefined &&
5707+
queueIsHeld &&
5708+
command.createdBy === "agent" &&
5709+
command.creationSource === "provider" &&
5710+
!(yield* stopReachedRun(command, command.threadId, activeRun.id));
57005711
const run: OrchestrationV2Run = {
57015712
id: runId,
57025713
threadId: command.threadId,
@@ -5709,10 +5720,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
57095720
activeAttemptId: attemptId,
57105721
status: "queued",
57115722
...(worktreeMissingRun !== undefined ||
5712-
(heldRunsToRelease.length === 0 &&
5713-
projection.runs.some(
5714-
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5715-
))
5723+
(heldRunsToRelease.length === 0 && queueIsHeld && !wakeSkipsHold)
57165724
? { queueHeld: true }
57175725
: {}),
57185726
queuePosition:
@@ -12758,7 +12766,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1275812766
});
1275912767
}
1276012768
}
12761-
const nextRun = selectedRun ?? nextQueuedRun(projection);
12769+
const nextRun = selectedRun ?? queuedRunsInDeliveryOrder(projection)[0];
1276212770
if (
1276312771
usageLimitHoldsQueue(
1276412772
projection,

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ const addRolledBackRecoveryCandidate = Effect.fn("addRolledBackRecoveryCandidate
186186
return threadId;
187187
});
188188

189+
it.effect.each([
190+
["memory", ProjectionStore.layerMemory],
191+
["SQL", layerTest],
192+
] as const)("%s queue readiness skips held runs without bypassing active work", ([, layer]) =>
193+
Effect.gen(function* () {
194+
const store = yield* ProjectionStore.ProjectionStoreV2;
195+
const threadId = yield* addRolledBackRecoveryCandidate("held-queue");
196+
const { runs } = yield* store.getThreadProjection(threadId);
197+
const run = runs[0]!;
198+
const now = yield* DateTime.now;
199+
const held = { ...run, status: "queued" as const, queueHeld: true };
200+
yield* store.apply({
201+
id: EventId.make("held-queue:held"),
202+
type: "run.updated",
203+
threadId,
204+
occurredAt: now,
205+
payload: held,
206+
});
207+
assert.isFalse(yield* store.canStartQueuedRun(threadId));
208+
209+
const wake = { ...run, id: RunId.make("held-queue:wake"), ordinal: 2 };
210+
for (const status of ["running", "queued", "completed"] as const) {
211+
yield* store.apply({
212+
id: EventId.make(`held-queue:wake:${status}`),
213+
type: "run.updated",
214+
threadId,
215+
occurredAt: now,
216+
payload: { ...wake, status },
217+
});
218+
assert.equal(yield* store.canStartQueuedRun(threadId), status === "queued");
219+
}
220+
assert.deepEqual((yield* store.getThreadProjection(threadId)).runs[0], held);
221+
}).pipe(Effect.provide(layer)),
222+
);
223+
189224
it.effect.each([
190225
["memory", ProjectionStore.layerMemory],
191226
["SQL", layerTest],

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5313,11 +5313,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
53135313
SELECT 1 AS ready FROM orchestration_v2_projection_threads AS thread
53145314
WHERE thread.thread_id = ${threadId} AND thread.archived_at IS NULL AND thread.deleted_at IS NULL
53155315
AND EXISTS (SELECT 1 FROM orchestration_v2_projection_runs
5316-
WHERE thread_id = ${threadId} AND status = 'queued')
5316+
WHERE thread_id = ${threadId} AND status = 'queued'
5317+
AND json_extract(payload_json, '$.queueHeld') IS NOT 1)
53175318
AND NOT EXISTS (SELECT 1 FROM orchestration_v2_projection_runs
53185319
WHERE thread_id = ${threadId}
5319-
AND (status IN ('preparing', 'starting', 'running', 'waiting')
5320-
OR (status = 'queued' AND json_extract(payload_json, '$.queueHeld') = 1)))`;
5320+
AND status IN ('preparing', 'starting', 'running', 'waiting'))`;
53215321
return rows.length > 0;
53225322
}),
53235323
)
@@ -7604,14 +7604,13 @@ export const layerMemory: Layer.Layer<ProjectionStoreV2> = Layer.effect(
76047604
return (
76057605
projection.thread.archivedAt === null &&
76067606
projection.thread.deletedAt === null &&
7607-
projection.runs.some((run) => run.status === "queued") &&
7607+
projection.runs.some((run) => run.status === "queued" && run.queueHeld !== true) &&
76087608
!projection.runs.some(
76097609
(run) =>
76107610
run.status === "preparing" ||
76117611
run.status === "starting" ||
76127612
run.status === "running" ||
7613-
run.status === "waiting" ||
7614-
(run.status === "queued" && run.queueHeld === true),
7613+
run.status === "waiting",
76157614
)
76167615
);
76177616
}),

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,21 @@ it.effect.each(["failed", "interrupted"] as const)(
13201320
createdBy: "user",
13211321
creationSource: "web",
13221322
});
1323+
yield* threads.dispatch({
1324+
type: "message.dispatch",
1325+
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:wake`),
1326+
threadId: launched.threadId,
1327+
messageId: MessageId.make(`message:launch:late-queued-follow-up-${ending}:wake`),
1328+
text: "Background task completed.",
1329+
attachments: [],
1330+
dispatchMode: { type: "queue_after_active" },
1331+
createdBy: "agent",
1332+
creationSource: "provider",
1333+
});
1334+
const wake = (yield* threads.getThreadProjection(launched.threadId)).runs.at(-1)!;
1335+
assert.equal(wake.status, "queued");
1336+
assert.isTrue(wake.queueHeld);
1337+
13231338
// Nor does the next one, though the run that message started is now the
13241339
// latest and carries no workspace preparation.
13251340
yield* threads.sendToThread({

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,6 +4904,23 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
49044904
threadId,
49054905
runId: limited.id,
49064906
});
4907+
yield* eventSink.write({
4908+
events: [
4909+
{
4910+
id: EventId.make(`${threadId}:hold-available`),
4911+
type: "run.updated",
4912+
threadId,
4913+
runId: available.id,
4914+
occurredAt: now,
4915+
payload: { ...available, queueHeld: true },
4916+
},
4917+
],
4918+
});
4919+
yield* orchestrator.dispatch({
4920+
type: "queue.resume",
4921+
commandId: CommandId.make(`${threadId}:resume-available`),
4922+
threadId,
4923+
});
49074924
yield* orchestrator.resumeQueuedRuns;
49084925
const after = yield* orchestrator.getThreadProjection(threadId);
49094926
const started = after.runs.find((run) => run.id === available.id);
@@ -5286,6 +5303,80 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
52865303
}),
52875304
);
52885305

5306+
it.effect("starts a provider wake queued beside a held queue", () =>
5307+
Effect.gen(function* () {
5308+
const orchestrator = yield* Orchestrator.OrchestratorV2;
5309+
const recovery = yield* ProviderRuntimeRecoveryService.ProviderRuntimeRecoveryService;
5310+
const events = yield* EventSink.EventSinkV2;
5311+
const threadId = ThreadId.make("queue-hold-provider-wake");
5312+
yield* orchestrator.dispatch({
5313+
type: "thread.create",
5314+
createdBy: "user",
5315+
creationSource: "web",
5316+
commandId: CommandId.make(`${threadId}:create`),
5317+
threadId,
5318+
projectId: ProjectId.make(`${threadId}:project`),
5319+
title: "Wake beside a held queue",
5320+
modelSelection,
5321+
runtimeMode: "full-access",
5322+
interactionMode: "default",
5323+
branch: null,
5324+
worktreePath: process.cwd(),
5325+
});
5326+
const send = (index: number, text: string, source: "web" | "provider" | "server" = "web") =>
5327+
orchestrator.dispatch({
5328+
type: "message.dispatch",
5329+
createdBy: source === "web" ? "user" : "agent",
5330+
creationSource: source,
5331+
commandId: CommandId.make(`${threadId}:message:${index}`),
5332+
threadId,
5333+
messageId: MessageId.make(`${threadId}:message:${index}`),
5334+
text,
5335+
attachments: [],
5336+
modelSelection,
5337+
dispatchMode: { type: index === 0 ? "start_immediately" : "queue_after_active" },
5338+
});
5339+
yield* send(0, "Active");
5340+
yield* send(1, "Queued before the restart");
5341+
yield* recovery.reconcile("startup");
5342+
yield* send(2, "First background task completed.", "provider");
5343+
yield* send(3, "Background task completed.", "provider");
5344+
yield* send(4, "Continue after the command completed.", "server");
5345+
const queued = yield* orchestrator.getThreadProjection(threadId);
5346+
const [held, active, wake] = [queued.runs[1]!, queued.runs[2]!, queued.runs[3]!];
5347+
assert.equal(active.status, "starting");
5348+
assert.isTrue(held.queueHeld);
5349+
assert.equal(wake.status, "queued");
5350+
assert.notEqual(wake.queueHeld, true);
5351+
const textContinuation = queued.runs[4]!;
5352+
assert.isTrue(textContinuation.queueHeld);
5353+
const now = yield* DateTime.now;
5354+
yield* events.write({
5355+
events: [
5356+
{
5357+
id: EventId.make(`${threadId}:active-done`),
5358+
type: "run.updated",
5359+
threadId,
5360+
runId: active.id,
5361+
occurredAt: now,
5362+
payload: { ...active, status: "completed", completedAt: now },
5363+
},
5364+
],
5365+
});
5366+
yield* orchestrator.resumeQueuedRuns;
5367+
const after = yield* orchestrator.getThreadProjection(threadId);
5368+
assert.equal(after.runs.find((run) => run.id === wake.id)?.status, "starting");
5369+
assert.deepEqual(
5370+
after.runs.find((run) => run.id === held.id),
5371+
held,
5372+
);
5373+
assert.deepEqual(
5374+
after.runs.find((run) => run.id === textContinuation.id),
5375+
textContinuation,
5376+
);
5377+
}),
5378+
);
5379+
52895380
it.effect("edits and removes queued runs", () =>
52905381
Effect.gen(function* () {
52915382
const orchestrator = yield* Orchestrator.OrchestratorV2;

0 commit comments

Comments
 (0)