Skip to content

Commit 4a8dc40

Browse files
Silthusclaude
andcommitted
fix: remote task requests hold settle and snooze, pasted declines read as text
A thread with an unanswered remote task request can no longer be settled or snoozed. A pasted file or image a question cannot take now reads as its label instead of a dangling reference, on paste and stash restore alike. The question banner keeps the environment name visible on narrow screens, and the user guide notes that an older linked machine keeps its requests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 38f9abb commit 4a8dc40

9 files changed

Lines changed: 103 additions & 49 deletions

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
ThreadId,
7272
TurnItemId,
7373
TrimmedNonEmptyString,
74+
unansweredRemoteTaskRequests,
7475
} from "@t3tools/contracts";
7576
import { modelSelectionsEqual } from "@t3tools/shared/model";
7677
import { recordThreadOpen } from "@t3tools/shared/paletteSearch";
@@ -3052,9 +3053,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
30523053
const pendingRequests = projection.runtimeRequests.filter(
30533054
(request) => request.status === "pending",
30543055
);
3055-
const blockingRequestExists = pendingRequests.some(
3056-
(request) => request.kind !== "user_input" || request.responseCapability.type !== "message",
3057-
);
3056+
const blockingRequestExists =
3057+
pendingRequests.some(
3058+
(request) =>
3059+
request.kind !== "user_input" || request.responseCapability.type !== "message",
3060+
) || unansweredRemoteTaskRequests(projection.thread).length > 0;
30583061
const blocker = blockingRequestExists
30593062
? "is waiting on an approval or question. Answer it before settling."
30603063
: runningRunExists
@@ -3187,7 +3190,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
31873190
cause: `Thread ${command.threadId} snooze wake time ${command.snoozedUntil} is not in the future.`,
31883191
});
31893192
}
3190-
if (projection.runtimeRequests.some((request) => request.status === "pending")) {
3193+
if (
3194+
projection.runtimeRequests.some((request) => request.status === "pending") ||
3195+
unansweredRemoteTaskRequests(projection.thread).length > 0
3196+
) {
31913197
return yield* new OrchestratorDispatchError({
31923198
commandId: command.commandId,
31933199
commandType: command.type,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ it.layer(layerTest)("a delegated task in a linked environment", (it) => {
511511
),
512512
[approval.requestId],
513513
);
514+
const settle = yield* orchestrator
515+
.dispatch({
516+
type: "thread.settle",
517+
commandId: CommandId.make("command:settle:mirrors"),
518+
threadId: parent.threadId,
519+
})
520+
.pipe(Effect.flip);
521+
assert.include(String(settle.cause), "is waiting on an approval or question");
522+
const snooze = yield* orchestrator
523+
.dispatch({
524+
type: "thread.snooze",
525+
commandId: CommandId.make("command:snooze:mirrors"),
526+
threadId: parent.threadId,
527+
snoozedUntil: DateTime.formatIso(DateTime.add(now, { hours: 1 })),
528+
})
529+
.pipe(Effect.flip);
530+
assert.include(String(snooze.cause), "cannot be snoozed");
514531

515532
yield* orchestrator.dispatch({
516533
type: "delegated_task.remote.complete",

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
121121
import { ComposerCodeBlockNodeView } from "./chat/ComposerCodeBlockNodeView";
122122
import { resolveAssistantCitationCommentDismissal } from "./chat/assistantCitationCommentDismissal";
123123
import { composerCodeBlockHighlight } from "./composerCodeBlockHighlight";
124-
import { importPastedComposerText } from "./composerInlineTokenPaste";
124+
import { type ImportedContextIds, importPastedComposerText } from "./composerInlineTokenPaste";
125125
import { didComposerSelectionChangeVisibly } from "./composerSelection";
126126
import type { ComposerDraftContextRecords } from "./composerContextPresentation";
127127

@@ -151,7 +151,7 @@ export interface ComposerPromptEditorProps {
151151
| ((contextIds: ReadonlyArray<string>) => string | null)
152152
| undefined;
153153
importContextFragment?:
154-
| ((fragment: ComposerContextClipboardFragment) => ReadonlyMap<string, string>)
154+
| ((fragment: ComposerContextClipboardFragment) => ImportedContextIds)
155155
| undefined;
156156
skills: ReadonlyArray<ServerProviderSkill>;
157157
disabled: boolean;

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
200200
<>
201201
<ComposerBanner.Separator />
202202
<span className="max-w-[40%] min-w-0 truncate text-muted-foreground">
203-
Delegated task on {prompt.remoteEnvironmentLabel}
203+
<span className="@max-[560px]:hidden">Delegated task on </span>
204+
{prompt.remoteEnvironmentLabel}
204205
</span>
205206
</>
206207
) : null}

‎apps/web/src/components/chat/useComposerContextImport.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { countQuestionAttachments, questionAttachmentDraftId } from "../../quest
4343
import { elementContextToPreviewAnnotation } from "../../lib/elementContext";
4444
import { orchestrationEnvironment } from "~/state/orchestration";
4545
import { pendingDraftWork } from "./pendingDraftWork";
46+
import type { ImportedContextIds } from "../composerInlineTokenPaste";
4647
import { randomUUID } from "~/lib/utils";
4748
import { readPreparedConnection } from "~/state/session";
4849
import { resolveAssetUrl } from "~/assets/assetUrls";
@@ -274,8 +275,8 @@ export function useComposerContextImport(input: {
274275
records: ReadonlyArray<ComposerContextRecord>,
275276
sourceEnvironmentId: EnvironmentId | null,
276277
threadDraftTarget = attachmentDraftTarget,
277-
): ReadonlyMap<string, string> => {
278-
const rewritten = new Map<string, string>();
278+
): ImportedContextIds => {
279+
const rewritten = new Map<string, string | null>();
279280
const dependentAttachmentLocalIds = new Map<string, string>();
280281
const skippedDependentAttachmentIds = new Set<string>();
281282
const target = {
@@ -343,7 +344,10 @@ export function useComposerContextImport(input: {
343344
continue;
344345
}
345346
const conflicts = existing !== undefined;
346-
if (!pastedContextRecordFits(record.kind, target)) continue;
347+
if (!pastedContextRecordFits(record.kind, target)) {
348+
rewritten.set(record.contextId, null);
349+
continue;
350+
}
347351
switch (record.kind) {
348352
case "terminal": {
349353
const threadId = activeThread?.id ?? activeThreadId;
@@ -422,9 +426,7 @@ export function useComposerContextImport(input: {
422426
}
423427
return rewritten;
424428
};
425-
const importContextFragment = (
426-
fragment: ComposerContextClipboardFragment,
427-
): ReadonlyMap<string, string> =>
429+
const importContextFragment = (fragment: ComposerContextClipboardFragment): ImportedContextIds =>
428430
importContextRecords(fragment.records, fragment.source.environmentId);
429431
const importContextFragmentStable = useStableCallback(importContextFragment);
430432

‎apps/web/src/components/chat/useComposerStash.ts‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
useComposerDraftStore,
2020
} from "../../composerDraftStore";
2121
import { type ComposerPromptEditorHandle } from "../ComposerPromptEditorTiptap";
22+
import {
23+
type ImportedContextIds,
24+
rewriteImportedContextReferences,
25+
} from "../composerInlineTokenPaste";
2226
import {
2327
MAX_STASH_ENTRIES,
2428
type PromptStashEntry,
@@ -29,7 +33,6 @@ import { type PendingUserInput } from "../../session-logic";
2933
import { type ReviewCommentContext } from "../../reviewCommentContext";
3034
import { collapseExpandedComposerCursor } from "../../composer-logic";
3135
import { compressImageForStash } from "../../lib/imageCompression";
32-
import { formatInlineContextReference } from "~/lib/composerContextReferences";
3336
import { isCommandPaletteOpen } from "../../commandPaletteBus";
3437
import { pendingDraftWork } from "./pendingDraftWork";
3538
import {
@@ -45,7 +48,6 @@ import {
4548
verifyStashedAttachmentUpload,
4649
} from "../../lib/attachmentUploadQueue";
4750
import { remainingComposerAttachmentSlots } from "./composerThreadImport";
48-
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
4951
import { resizeSnapShotSource } from "../../lib/snapShotSource";
5052
import { registerCommands } from "../../shortcuts/dispatcher";
5153
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../../terminalUiStateStore";
@@ -94,7 +96,7 @@ export function useComposerStash(input: {
9496
records: ReadonlyArray<ComposerContextRecord>,
9597
sourceEnvironmentId: EnvironmentId | null,
9698
threadDraftTarget?: ChatComposerProps["composerDraftTarget"],
97-
) => ReadonlyMap<string, string>;
99+
) => ImportedContextIds;
98100
readonly expandMobileComposer: () => void;
99101
}) {
100102
const {
@@ -203,19 +205,12 @@ export function useComposerStash(input: {
203205
});
204206
}
205207

206-
const rewrittenContextIds = entry.records
207-
? importContextRecords(entry.records, null, composerDraftTarget)
208-
: new Map<string, string>();
209-
const restoredPrompt = replaceComposerContextReferences(entry.prompt, (reference) => {
210-
const contextId = rewrittenContextIds.get(reference.contextId);
211-
return contextId
212-
? formatInlineContextReference({
213-
...reference,
214-
contextId,
215-
kind: reference.kind === "element" ? "preview-annotation" : reference.kind,
216-
})
217-
: reference.source;
218-
});
208+
const restoredPrompt = entry.records
209+
? rewriteImportedContextReferences(
210+
entry.prompt,
211+
importContextRecords(entry.records, null, composerDraftTarget),
212+
)
213+
: entry.prompt;
219214
const currentPrompt = promptRef.current;
220215
const nextPrompt =
221216
restoredPrompt.length === 0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { rewriteImportedContextReferences } from "./composerInlineTokenPaste";
4+
5+
describe("rewriteImportedContextReferences", () => {
6+
const pasted =
7+
"See ![shot.png](t3-context://v1/image/img_a) and [notes.md](t3-context://v1/file/file_b) in [build](t3-context://v1/terminal/term_c)";
8+
9+
it.each([
10+
[
11+
"points an imported record at its new id",
12+
new Map([["img_a", "img_z"]]),
13+
"See ![shot.png](t3-context://v1/image/img_z) and [notes.md](t3-context://v1/file/file_b) in [build](t3-context://v1/terminal/term_c)",
14+
],
15+
[
16+
"pastes a declined record as its label",
17+
new Map([
18+
["img_a", null],
19+
["file_b", null],
20+
]),
21+
"See shot.png and notes.md in [build](t3-context://v1/terminal/term_c)",
22+
],
23+
])("%s", (_, importedIds, expected) => {
24+
expect(rewriteImportedContextReferences(pasted, importedIds)).toBe(expected);
25+
});
26+
});

‎apps/web/src/components/composerInlineTokenPaste.ts‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,34 @@ export function readPastedComposerContext(
3737
};
3838
}
3939

40+
// null marks a record the target declined; its reference pastes as plain text.
41+
export type ImportedContextIds = ReadonlyMap<string, string | null>;
42+
43+
export function rewriteImportedContextReferences(
44+
text: string,
45+
importedIds: ImportedContextIds,
46+
): string {
47+
if (importedIds.size === 0) return text;
48+
return replaceComposerContextReferences(text, (occurrence) => {
49+
const nextId = importedIds.get(occurrence.contextId);
50+
if (nextId === null) return occurrence.label;
51+
return nextId
52+
? formatComposerContextReference({
53+
...occurrence,
54+
contextId: ComposerContextId.make(nextId),
55+
kind: occurrence.kind === "element" ? "preview-annotation" : occurrence.kind,
56+
})
57+
: occurrence.source;
58+
});
59+
}
60+
4061
export function importPastedComposerText(
4162
clipboardData: Pick<DataTransfer, "getData">,
42-
importContextFragment?: (
43-
fragment: ComposerContextClipboardFragment,
44-
) => ReadonlyMap<string, string>,
63+
importContextFragment?: (fragment: ComposerContextClipboardFragment) => ImportedContextIds,
4564
): string {
4665
const pastedText = clipboardData.getData("text/plain");
4766
const fragment = importContextFragment ? readPastedComposerContext(clipboardData) : null;
48-
const rewrittenIds =
49-
fragment && fragment.records.length > 0 ? importContextFragment!(fragment) : null;
50-
const text =
51-
rewrittenIds && rewrittenIds.size > 0
52-
? replaceComposerContextReferences(pastedText, (occurrence) => {
53-
const nextId = rewrittenIds.get(occurrence.contextId);
54-
return nextId
55-
? formatComposerContextReference({
56-
...occurrence,
57-
contextId: ComposerContextId.make(nextId),
58-
kind: occurrence.kind === "element" ? "preview-annotation" : occurrence.kind,
59-
})
60-
: occurrence.source;
61-
})
62-
: pastedText;
63-
return text;
67+
return fragment && fragment.records.length > 0
68+
? rewriteImportedContextReferences(pastedText, importContextFragment!(fragment))
69+
: pastedText;
6470
}

‎docs/user/remote-access.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ ends, as for any delegated task. It keeps following the task across restarts.
299299
If the other machine revokes the link, or the link is removed here, the task
300300
fails with that reason. When the task asks a question or needs an approval,
301301
this thread shows it, so you can answer from any device connected to this
302-
machine.
302+
machine. A machine on an older T3 Code version keeps those requests to itself;
303+
answer them there.
303304

304305
## Manage or revoke access
305306

0 commit comments

Comments
 (0)