Skip to content

Commit 202002e

Browse files
committed
fix(server,web,mobile): idle compaction never blocks settle or shows as an agent-visible outcome
1 parent ed6cd61 commit 202002e

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,8 +2657,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
26572657
const automaticQueuedRuns = projection.runs.filter(
26582658
(run) => run.status === "queued" && automaticMessageIds.has(run.userMessageId),
26592659
);
2660-
const runningRunExists = projection.runs.some((run) =>
2661-
["preparing", "starting", "running", "waiting"].includes(run.status),
2660+
// Idle compaction is hidden maintenance and may finish after the thread settles.
2661+
const runningRunExists = projection.runs.some(
2662+
(run) =>
2663+
run.idleCompactionOfRunId === undefined &&
2664+
["preparing", "starting", "running", "waiting"].includes(run.status),
26622665
);
26632666
// Includes a queue held after a Stop, which otherwise shows no activity.
26642667
const queuedMessageExists = projection.runs.some(

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,15 @@ export function isTerminalRunStatus(
480480
);
481481
}
482482

483+
// Idle compaction is server maintenance, never a thread outcome agents read or wait on.
484+
const isUserFacingRun = (run: OrchestrationV2Run) => run.idleCompactionOfRunId === undefined;
485+
483486
export function latestRun(
484487
projection: Pick<OrchestrationV2ThreadProjection, "runs">,
485488
): OrchestrationV2Run | undefined {
486-
return projection.runs.toSorted((left, right) => right.ordinal - left.ordinal)[0];
489+
return projection.runs
490+
.filter(isUserFacingRun)
491+
.toSorted((left, right) => right.ordinal - left.ordinal)[0];
487492
}
488493

489494
/** The newest run in `run`'s restart continuation chain, or `run` itself. */
@@ -504,7 +509,7 @@ export function latestActiveRun(
504509
projection: Pick<OrchestrationV2ThreadProjection, "runs">,
505510
): OrchestrationV2Run | undefined {
506511
return projection.runs
507-
.filter(isActiveRun)
512+
.filter((run) => isUserFacingRun(run) && isActiveRun(run))
508513
.toSorted((left, right) => right.ordinal - left.ordinal)[0];
509514
}
510515

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ export function deriveThreadRuntime(
292292
providerName: providerSession?.driver ?? null,
293293
...threadErrorSummary(
294294
latestRootProviderFailure(latestRunProjection, projection.turnItems),
295-
providerSession?.lastError ?? null,
295+
// Outside the open chat, an idle compaction's session error stays hidden like the shell's.
296+
!options.includeIdleCompaction &&
297+
latestMatchingRun(projection, () => true, { includeIdleCompaction: true })
298+
?.idleCompactionOfRunId !== undefined
299+
? null
300+
: (providerSession?.lastError ?? null),
296301
),
297302
updatedAt: DateTime.formatIso(projection.updatedAt),
298303
};

0 commit comments

Comments
 (0)