fix(mobile): gate thread controls on live runs
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7b3105ef38
commit
7a4a0fa759
5 files changed
+113
-3
No files matched your search
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
|
||||
import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell";
|
||||
import {
|
||||
deriveThreadActivityRun,
|
||||
deriveThreadInterruptibleRunId,
|
||||
deriveThreadRuntime,
|
||||
} from "@t3tools/client-runtime/state/thread-execution";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
@@ -149,7 +150,7 @@ export function useThreadComposerState() {
|
||||
}, [selectedThreadActivityRun, selectedThreadSessionActivity, selectedThreadShell]);
|
||||
|
||||
const activeThreadBusy = threadRuntimeIsActive(selectedThreadRuntime);
|
||||
const interruptibleRunId = selectedThreadRuntime?.activeRunId ?? null;
|
||||
const interruptibleRunId = deriveThreadInterruptibleRunId(selectedThreadProjection?.projection);
|
||||
|
||||
const onSendMessage = useCallback(async () => {
|
||||
if (!selectedThreadShell) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { v2Projection } from "./orchestrationV2TestFixtures.ts";
|
||||
import {
|
||||
deriveLatestThreadRun,
|
||||
deriveThreadActivityRun,
|
||||
deriveThreadInterruptibleRunId,
|
||||
deriveThreadRuntime,
|
||||
threadRuntimeHasInterruptibleRun,
|
||||
} from "./threadExecution.ts";
|
||||
@@ -50,6 +51,7 @@ describe("thread execution presentation", () => {
|
||||
activeRunId: runningRun.id,
|
||||
});
|
||||
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
|
||||
expect(deriveThreadInterruptibleRunId(projection)).toBe(runningRun.id);
|
||||
});
|
||||
|
||||
it("does not expose a queued-only run as interruptible", () => {
|
||||
@@ -67,6 +69,7 @@ describe("thread execution presentation", () => {
|
||||
activeRunId: null,
|
||||
});
|
||||
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
|
||||
expect(deriveThreadInterruptibleRunId(projection)).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps checkpoint-wait activity visible without exposing a non-functional interrupt", () => {
|
||||
@@ -84,5 +87,7 @@ describe("thread execution presentation", () => {
|
||||
activeRunId: null,
|
||||
});
|
||||
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
|
||||
expect(deriveThreadInterruptibleRunId(projection)).toBeNull();
|
||||
expect(deriveThreadInterruptibleRunId(null)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -78,6 +78,14 @@ export function deriveThreadRuntime(
|
||||
};
|
||||
}
|
||||
|
||||
export function deriveThreadInterruptibleRunId(
|
||||
projection: OrchestrationV2ThreadProjection | null | undefined,
|
||||
): ThreadRuntimeSummary["activeRunId"] {
|
||||
return projection === null || projection === undefined
|
||||
? null
|
||||
: (deriveThreadRuntime(projection)?.activeRunId ?? null);
|
||||
}
|
||||
|
||||
export function threadRuntimeHasInterruptibleRun(
|
||||
runtime: ThreadRuntimeSummary | null | undefined,
|
||||
): boolean {
|
||||
|
||||
@@ -33,7 +33,13 @@ describe("thread workflows", () => {
|
||||
const state = deriveThreadQueueWorkflowState({
|
||||
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
|
||||
runs: [
|
||||
{ id: "active", status: "running", providerThreadId: "provider-thread", ordinal: 1 },
|
||||
{
|
||||
id: "active",
|
||||
status: "running",
|
||||
providerThreadId: "provider-thread",
|
||||
activeAttemptId: "attempt-active",
|
||||
ordinal: 1,
|
||||
},
|
||||
{ id: "later", status: "queued", userMessageId: "message-later", ordinal: 3 },
|
||||
{
|
||||
id: "first",
|
||||
@@ -47,6 +53,13 @@ describe("thread workflows", () => {
|
||||
{ id: "message-first", text: "First" },
|
||||
{ id: "message-later", text: "Later" },
|
||||
],
|
||||
providerTurns: [
|
||||
{
|
||||
id: "provider-turn-active",
|
||||
runAttemptId: "attempt-active",
|
||||
status: "running",
|
||||
},
|
||||
],
|
||||
providerThreads: [
|
||||
{
|
||||
id: "provider-thread",
|
||||
@@ -72,6 +85,83 @@ describe("thread workflows", () => {
|
||||
expect(state.canPromoteToSteer).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["preparing", "starting", "waiting"] as const)(
|
||||
"does not promote queued work into a %s run",
|
||||
(status) => {
|
||||
const state = deriveThreadQueueWorkflowState({
|
||||
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
|
||||
runs: [
|
||||
{
|
||||
id: "active",
|
||||
status,
|
||||
providerThreadId: "provider-thread",
|
||||
activeAttemptId: "attempt-active",
|
||||
ordinal: 1,
|
||||
},
|
||||
{ id: "queued", status: "queued", userMessageId: "message", ordinal: 2 },
|
||||
],
|
||||
messages: [{ id: "message", text: "Queued" }],
|
||||
providerTurns: [
|
||||
{
|
||||
id: "provider-turn-active",
|
||||
runAttemptId: "attempt-active",
|
||||
status: status === "waiting" ? "completed" : "starting",
|
||||
},
|
||||
],
|
||||
providerThreads: [
|
||||
{
|
||||
id: "provider-thread",
|
||||
appThreadId: "thread",
|
||||
providerSessionId: "provider-session",
|
||||
},
|
||||
],
|
||||
providerSessions: [
|
||||
{
|
||||
id: "provider-session",
|
||||
status: "running",
|
||||
capabilities: capabilities({ queued: true, steer: true }),
|
||||
},
|
||||
],
|
||||
} as never);
|
||||
|
||||
expect(state.canPromoteToSteer).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not promote queued work until the running provider turn is projected", () => {
|
||||
const state = deriveThreadQueueWorkflowState({
|
||||
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
|
||||
runs: [
|
||||
{
|
||||
id: "active",
|
||||
status: "running",
|
||||
providerThreadId: "provider-thread",
|
||||
activeAttemptId: "attempt-active",
|
||||
ordinal: 1,
|
||||
},
|
||||
{ id: "queued", status: "queued", userMessageId: "message", ordinal: 2 },
|
||||
],
|
||||
messages: [{ id: "message", text: "Queued" }],
|
||||
providerTurns: [],
|
||||
providerThreads: [
|
||||
{
|
||||
id: "provider-thread",
|
||||
appThreadId: "thread",
|
||||
providerSessionId: "provider-session",
|
||||
},
|
||||
],
|
||||
providerSessions: [
|
||||
{
|
||||
id: "provider-session",
|
||||
status: "running",
|
||||
capabilities: capabilities({ queued: true, steer: true }),
|
||||
},
|
||||
],
|
||||
} as never);
|
||||
|
||||
expect(state.canPromoteToSteer).toBe(false);
|
||||
});
|
||||
|
||||
it("does not expose known unsupported queue or fork actions", () => {
|
||||
const projection = {
|
||||
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
|
||||
|
||||
@@ -84,6 +84,12 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
|
||||
const activeRun = resolveActiveThreadRun(projection);
|
||||
const session = resolveThreadProviderSession(projection);
|
||||
const capabilities = session?.capabilities.turns;
|
||||
const hasSteerableProviderTurn =
|
||||
activeRun?.status === "running" &&
|
||||
activeRun.activeAttemptId !== null &&
|
||||
projection.providerTurns.some(
|
||||
(turn) => turn.runAttemptId === activeRun.activeAttemptId && turn.status === "running",
|
||||
);
|
||||
const queuedRuns = copySorted(
|
||||
projection.runs.filter((run) => run.status === "queued"),
|
||||
(left, right) =>
|
||||
@@ -101,7 +107,7 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
|
||||
queuedRuns,
|
||||
canReorder: capabilities?.supportsQueuedMessages === true,
|
||||
canPromoteToSteer:
|
||||
activeRun !== null &&
|
||||
hasSteerableProviderTurn &&
|
||||
(capabilities?.supportsActiveSteering === true ||
|
||||
capabilities?.supportsSteeringByInterruptRestart === true),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user