Skip to content
8 changes: 8 additions & 0 deletions apps/mobile/src/features/threads/ThreadQueueControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
);
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message");
const holdQueuedRun = useAtomCommand(threadEnvironment.holdQueuedRun, {
label: "hold queued message",
reportFailure: false,
reportDefect: false,
});
const resume = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
const resumeHeldQueue = useAtomCommand(threadEnvironment.resumeThreadQueue, {
label: "resume queue",
Expand Down Expand Up @@ -192,6 +197,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
(get) => get(environmentThreadDetails.quietThreadAtom(target))?.projection.runs ?? null,
),
}),
(held) => {
void holdQueuedRun({ ...target, input: { threadId: target.threadId, runId, held } });
},
Comment on lines +200 to +202

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Real-client edit lifecycle remains unverified

The ThreadQueueSheet closes immediately after opening an edit. The PR lists no real-client pass or base/head scenario proof, both required by verification guidance.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Agreed that a real-client pass is still owed; the PR description says so. The maintainer is checking it by hand in a dev build. The sheet closing after Edit is existing behavior: navigation.goBack() after beginQueuedRunEdit was already there, and the edit continues in the thread composer.

);
navigation.goBack();
return;
Expand Down
14 changes: 7 additions & 7 deletions apps/mobile/src/state/queued-run-edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe("beginQueuedRunEdit", () => {
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>(
[{ id: original.runId, status: "queued" }],
);
beginQueuedRunEdit(threadKey, original, runs);
beginQueuedRunEdit(threadKey, original, runs, () => {});
const draft = getComposerDraftSnapshot(queuedEditDraftKey(threadKey, original.runId));
expect(draft.text).toBe(prefix.trimEnd());
expect(
Expand All @@ -146,7 +146,7 @@ describe("beginQueuedRunEdit", () => {
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
{ id: runId, status: "queued" },
]);
beginQueuedRunEdit(threadKey, edit([]), runs);
beginQueuedRunEdit(threadKey, edit([]), runs, () => {});

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);

Expand All @@ -163,7 +163,7 @@ describe("beginQueuedRunEdit", () => {
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
{ id: runId, status: "queued" },
]);
beginQueuedRunEdit(threadKey, edit([image("removed")]), runs);
beginQueuedRunEdit(threadKey, edit([image("removed")]), runs, () => {});
removeQueuedRunEditAttachment(threadKey, "removed");

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
Expand All @@ -184,7 +184,7 @@ describe("beginQueuedRunEdit", () => {
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
{ id: runId, status: "queued" },
]);
beginQueuedRunEdit(threadKey, edit([]), runs);
beginQueuedRunEdit(threadKey, edit([]), runs, () => {});
setComposerDraftText(queuedEditDraftKey(threadKey, runId), "revised");

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
Expand All @@ -205,7 +205,7 @@ describe("beginQueuedRunEdit", () => {
{ id: runId, status: "queued" },
]);
setComposerDraftText(threadKey, "other work");
beginQueuedRunEdit(threadKey, edit([]), runs);
beginQueuedRunEdit(threadKey, edit([]), runs, () => {});
setComposerDraftText(queuedEditDraftKey(threadKey, runId), "changed");

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
Expand All @@ -223,7 +223,7 @@ describe("beginQueuedRunEdit", () => {
const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
{ id: runId, status: "queued" },
]);
beginQueuedRunEdit(threadKey, edit([]), runs);
beginQueuedRunEdit(threadKey, edit([]), runs, () => {});
setComposerDraftText(queuedEditDraftKey(threadKey, runId), "");

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
Expand All @@ -242,7 +242,7 @@ describe("beginQueuedRunEdit", () => {
{ id: runId, status: "queued" },
]);
setComposerDraftText(threadKey, "other work");
beginQueuedRunEdit(threadKey, edit([image("kept")]), runs);
beginQueuedRunEdit(threadKey, edit([image("kept")]), runs, () => {});
removeQueuedRunEditAttachment(threadKey, "kept");

appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
Expand Down
4 changes: 3 additions & 1 deletion apps/mobile/src/state/queued-run-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { stripAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerCont
import {
makeQueuedRunEditStore,
resolveQueuedEditExit,
type HoldQueuedRun,
type QueuedRunsAtom,
} from "@t3tools/client-runtime/queued-run-edit";

Expand Down Expand Up @@ -113,6 +114,7 @@ export function beginQueuedRunEdit(
threadKey: string,
edit: QueuedRunEdit,
runs: QueuedRunsAtom,
hold: HoldQueuedRun,
): void {
const previous = getQueuedRunEdit(threadKey);
if (previous !== null && previous.runId !== edit.runId) {
Expand All @@ -128,7 +130,7 @@ export function beginQueuedRunEdit(
queuedRunEdits.begin(
threadKey,
{ ...edit, originalText },
{ runs, onRunLeftQueue: exitQueuedRunEdit },
{ runs, onRunLeftQueue: exitQueuedRunEdit, hold },
);
}

Expand Down
28 changes: 17 additions & 11 deletions apps/server/src/orchestration-v2/EffectOutbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,20 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
type: Schema.Literal("delegated-tasks.stop"),
reason: Schema.optional(Schema.String),
}),
Schema.Struct({
type: Schema.Literal("queued-run.hold.expire"),
runId: RunId,
heldUntil: Schema.DateTimeUtcFromString,
}),
]);
export type OrchestrationEffectRequestV2 = typeof OrchestrationEffectRequestV2.Type;

// These wait only on their own kind, so one due in minutes cannot hold back a thread's turns.
const OWN_LANE_EFFECT_TYPES = [
"thread-title.generate",
"queued-run.hold.expire",
] as const satisfies ReadonlyArray<OrchestrationEffectRequestV2["type"]>;

export const REPLAY_SAFE_EFFECT_TYPES_AFTER_PROCESS_LOSS = [
"provider-runtime.continue",
"provider-session.detach",
Expand All @@ -152,6 +163,7 @@ export const REPLAY_SAFE_EFFECT_TYPES_AFTER_PROCESS_LOSS = [
"attachment.cleanup",
"thread-title.generate",
"delegated-tasks.stop",
"queued-run.hold.expire",
] as const satisfies ReadonlyArray<OrchestrationEffectRequestV2["type"]>;

export const PROCESS_BOUND_EFFECT_TYPES = [
Expand Down Expand Up @@ -339,6 +351,10 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
available,
Array.from({ length: Math.min(64, Math.max(0, Math.floor(count))) }, () => undefined),
).pipe(Effect.asVoid);
const effectLane = (alias: "candidate" | "active") =>
sql.literal(
`CASE WHEN ${alias}.effect_type IN (${OWN_LANE_EFFECT_TYPES.map((type) => `'${type}'`).join(", ")}) THEN ${alias}.effect_type ELSE '' END`,
);
// Retry backoff must block later effects so turns cannot race a pending rollback.
const claimableCandidatePredicate = (
availableBefore?: string,
Expand Down Expand Up @@ -368,17 +384,7 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
}
)
)
AND (
(
candidate.effect_type = 'thread-title.generate'
AND active.effect_type = 'thread-title.generate'
)
OR
(
candidate.effect_type != 'thread-title.generate'
AND active.effect_type != 'thread-title.generate'
)
)
AND ${effectLane("candidate")} = ${effectLane("active")}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Earlier edit expiry can wait

editHoldExpiryEffect can append a renewed timer due before an existing timer for another message on the same thread. The lane orders pending timers by insertion, so the earlier deadline waits for the later one.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Claude Opus 5.5 responding on behalf of jagrat7

Not changing this. It needs two different messages on one thread to be held at the same time (two devices, two messages), and the cost is only a late expiry, bounded by the other hold's deadline. Giving each run its own lane would put a JSON read into every outbox claim, which is a hot path.

)
AND ${
maxRunningTitleGenerations === undefined
Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/orchestration-v2/EffectWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,26 @@ export const layerExecutor: Layer.Layer<
}),
),
);
case "queued-run.hold.expire":
return threads
.dispatch({
type: "queued-run.hold.expire",
commandId: CommandId.make(`${effect.id}:expire`),
threadId: effect.threadId,
runId: effect.request.runId,
heldUntil: effect.request.heldUntil,
})
.pipe(
Effect.asVoid,
Effect.mapError(
(cause) =>
new OrchestrationEffectExecutionError({
effectId: effect.id,
effectType: effect.request.type,
cause,
}),
),
);
}
}),
});
Expand Down
18 changes: 18 additions & 0 deletions apps/server/src/orchestration-v2/FoundationPersistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,20 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {
const providerEffectId = "effect:foundation-title-effect-lane:b-provider";
const nextTitleEffectId = "effect:foundation-title-effect-lane:c-title";
const nextCriticalEffectId = "effect:foundation-title-effect-lane:d-critical";
// An edit-hold timer due in minutes must not hold back either lane.
const heldUntil = DateTime.add(yield* DateTime.now, { minutes: 5 });
yield* outbox.enqueue([
{
id: "effect:foundation-title-effect-lane:0-edit-hold",
commandId,
threadId,
request: {
type: "queued-run.hold.expire",
runId: RunId.make("run:foundation-title-effect-lane"),
heldUntil,
},
availableAt: heldUntil,
},
{
id: titleEffectId,
commandId,
Expand Down Expand Up @@ -2864,6 +2877,11 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {
workerId: "title-lane-worker",
});
}
yield* outbox.cancelUnsettled({
threadId,
effectTypes: ["queued-run.hold.expire"],
reason: "Test cleanup.",
});
}),
);

Expand Down
Loading
Loading