Skip to content

Commit 2c5988e

Browse files
committed
server/orchestration-v2: keep the held-work hold while the report run is queued
A report requested behind another run stays queued until that run ends, so its request time alone does not mean the report has started. A full or merge sweep in that window could still settle the thread.
1 parent 1baceba commit 2c5988e

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,22 +1286,31 @@ describe("ThreadSettlementServiceV2 worker", () => {
12861286
yield* startHarness(reactor, fixture.activation, fixture.snapshotReads);
12871287
assert.deepStrictEqual(yield* Ref.get(fixture.commands), []);
12881288

1289+
// The report turn was requested but waits behind another run.
1290+
const reportAt = DateTime.makeUnsafe(Date.parse(NOW) + 1_000);
1291+
const report = {
1292+
...held,
1293+
latestRunId: RunId.make("run:report"),
1294+
latestUserMessageAt: reportAt,
1295+
latestRunRequestedAt: reportAt,
1296+
};
1297+
yield* Ref.set(
1298+
fixture.snapshots,
1299+
makeSnapshot([{ ...report, status: "queued" }, mergedInApp]),
1300+
);
12891301
yield* fixture.publishMerge;
12901302
assert.strictEqual(yield* Queue.take(dispatched), mergedInApp.id);
12911303
assert.deepStrictEqual(
12921304
(yield* Ref.get(fixture.commands)).map((command) => command.threadId),
12931305
[mergedInApp.id],
12941306
);
12951307

1296-
const reportAt = DateTime.makeUnsafe(Date.parse(NOW) + 1_000);
12971308
yield* Ref.set(
12981309
fixture.snapshots,
12991310
makeSnapshot([
13001311
{
1301-
...held,
1302-
latestRunId: RunId.make("run:report"),
1303-
latestUserMessageAt: reportAt,
1304-
latestRunRequestedAt: reportAt,
1312+
...report,
1313+
status: "completed",
13051314
latestRunStartedAt: reportAt,
13061315
latestRunCompletedAt: DateTime.makeUnsafe(Date.parse(NOW) + 20_000),
13071316
},

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function threadHasQueuedTurnStart(
127127
function awaitsHeldWorkReport(
128128
thread: Pick<
129129
ProjectionStore.ProjectionSettlementCandidate,
130-
"heldWorkEndedAt" | "latestUserMessageAt" | "latestRunRequestedAt"
130+
"heldWorkEndedAt" | "latestUserMessageAt" | "latestRunRequestedAt" | "status"
131131
>,
132132
nowMs: number,
133133
): boolean {
@@ -139,6 +139,8 @@ function awaitsHeldWorkReport(
139139
) {
140140
return false;
141141
}
142+
// A report requested behind another run stays queued until that run ends.
143+
if (thread.status === "queued") return true;
142144
const turnRequestedAtMs = latestMillis([
143145
toMillis(thread.latestUserMessageAt),
144146
toMillis(thread.latestRunRequestedAt),

0 commit comments

Comments
 (0)