The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 08:15 UTC
fix(server): an old link card no longer keeps a thread asking for input (#28491)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
George Nijo committed
Nov 1, 2026 at 16:53 UTC
625b9ac5c58600a3400d08fe8202420248f33e2a
2 files changed
+77
-17
apps/server/src/orchestration-v2/ProjectionStore.ts
+42
-17
@@ -1419,12 +1419,24 @@ function secretRequestAsPendingInput(
1419
1420
/**
1421
* A secret card is answered while its agent waits in the run. A link card's
1422
- * agent asked without waiting, so the card waits on the user after its run.
1422
+ * agent asked without waiting, so the card waits on the user after its run,
1423
+ * until the user writes in the thread again and so has moved past it.
1424
*/
1424
-const waitsOnUser = (item: OrchestrationV2TurnItem, liveRunIds: ReadonlySet<RunId>) =>
1425
- item.type === "link_request" ||
1425
+const waitsOnUser = (
1426
+ item: OrchestrationV2TurnItem,
1427
+ liveRunIds: ReadonlySet<RunId>,
1428
+ latestUserAuthoredMessageAt: DateTime.Utc | null,
1429
+) =>
1430
+ (item.type === "link_request" && linkCardStillAsks(item, latestUserAuthoredMessageAt)) ||
1431
(item.type === "secret_request" && item.runId !== null && liveRunIds.has(item.runId));
1432
1433
+const linkCardStillAsks = (
1434
+ item: OrchestrationV2TurnItem,
1435
+ latestUserAuthoredMessageAt: DateTime.Utc | null,
1436
+) =>
1437
+ latestUserAuthoredMessageAt === null ||
1438
+ !DateTime.isGreaterThan(latestUserAuthoredMessageAt, item.startedAt ?? item.updatedAt);
1439
+
1440
export function threadShellFromProjection(
1441
projection: OrchestrationV2ThreadProjection,
1442
): OrchestrationV2ThreadShell {
@@ -1460,23 +1472,29 @@ export function threadShellFromProjection(
1472
DateTime.toEpochMillis(right.createdAt) - DateTime.toEpochMillis(left.createdAt),
1473
)[0] ?? null,
1474
);
1475
+ const userMessages = projection.messages
1476
+ .filter((message) => message.role === "user" && idleCompactionOf(message) === undefined)
1477
+ .toSorted(
1478
+ (left, right) =>
1479
+ DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt),
1480
+ );
1481
+ const latestUserAuthoredMessageAt =
1482
+ userMessages.find((message) => message.createdBy === "user")?.updatedAt ?? null;
1483
if (pendingRuntimeRequest === null || pendingRuntimeRequest.blocking === false) {
1484
pendingRuntimeRequest =
1485
secretRequestAsPendingInput(
1486
projection.turnItems
1467
- .filter((item) => item.status === "waiting" && waitsOnUser(item, liveRunIds))
1487
+ .filter(
1488
+ (item) =>
1489
+ item.status === "waiting" &&
1490
+ waitsOnUser(item, liveRunIds, latestUserAuthoredMessageAt),
1491
+ )
1492
.toSorted(
1493
(left, right) =>
1494
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt),
1495
)[0] ?? null,
1496
) ?? pendingRuntimeRequest;
1497
}
1474
- const userMessages = projection.messages
1475
- .filter((message) => message.role === "user" && idleCompactionOf(message) === undefined)
1476
- .toSorted(
1477
- (left, right) =>
1478
- DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt),
1479
- );
1498
const latestUserMessage = userMessages[0] ?? null;
1499
const pendingBackgroundTasks = derivePendingBackgroundWork({
1500
latestRun,
@@ -1545,8 +1563,7 @@ export function threadShellFromProjection(
1563
// initial hydration and streaming updates independent of transcript size.
1564
latestVisibleMessage: null,
1565
latestUserMessageAt: latestUserMessage?.updatedAt ?? null,
1548
- latestUserAuthoredMessageAt:
1549
- userMessages.find((message) => message.createdBy === "user")?.updatedAt ?? null,
1566
+ latestUserAuthoredMessageAt,
1567
hasActionableProposedPlan: projection.plans.some(
1568
(plan) => plan.kind === "proposed_plan" && plan.status === "active",
1569
),
@@ -6026,6 +6043,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6043
WHERE message.thread_id = t.thread_id
6044
AND message.role = 'user'
6045
AND json_extract(message.payload_json, '$.createdBy') = 'user'
6046
+ AND NOT ${isIdleCompactionMessage("message")}
6047
ORDER BY message.updated_at DESC, message.message_id DESC
6048
LIMIT 1
6049
) AS latest_user_authored_message_at,
@@ -6280,6 +6298,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6298
FROM orchestration_v2_projection_messages message
6299
WHERE message.thread_id = t.thread_id AND message.role = 'user'
6300
AND json_extract(message.payload_json, '$.createdBy') = 'user'
6301
+ AND NOT ${isIdleCompactionMessage("message")}
6302
ORDER BY message.updated_at DESC, message.message_id DESC
6303
LIMIT 1
6304
) AS latest_user_authored_message_at
@@ -6475,6 +6494,10 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6494
pendingTurnItemsByThreadId,
6495
} = input;
6496
const thread = yield* decodeThreadPayload(row.payload_json);
6497
+ const latestUserAuthoredMessageAt =
6498
+ row.latest_user_authored_message_at === null
6499
+ ? null
6500
+ : DateTime.makeUnsafe(row.latest_user_authored_message_at);
6501
const waitingCards = [
6502
row.pending_secret_request_payload_json === null
6503
? null
@@ -6482,7 +6505,12 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6505
row.pending_link_request_payload_json === null
6506
? null
6507
: yield* decodeTurnItemPayload(row.pending_link_request_payload_json),
6485
- ].filter((item) => item !== null);
6508
+ ]
6509
+ .filter((item) => item !== null)
6510
+ .filter(
6511
+ (item) =>
6512
+ item.type !== "link_request" || linkCardStillAsks(item, latestUserAuthoredMessageAt),
6513
+ );
6514
let pendingRuntimeRequest =
6515
row.pending_request_payload_json !== null
6516
? pendingRuntimeRequestSummary(
@@ -6601,10 +6629,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6629
row.latest_user_message_at === null
6630
? null
6631
: DateTime.makeUnsafe(row.latest_user_message_at),
6604
- latestUserAuthoredMessageAt:
6605
- row.latest_user_authored_message_at === null
6606
- ? null
6607
- : DateTime.makeUnsafe(row.latest_user_authored_message_at),
6632
+ latestUserAuthoredMessageAt,
6633
hasActionableProposedPlan: row.has_actionable_proposed_plan === 1,
6634
pendingBackgroundTasks,
6635
providerInstanceHistory: providerInstanceHistoryForShell({
apps/server/src/peer/PeerLinkRequests.test.ts
+35
@@ -495,6 +495,41 @@ it.live("the agent asks without waiting, and the user links the box after its tu
495
).toMatchObject({ kind: "user_input" });
496
expect(yield* a.projections.getSettlementCandidates(threadId)).toEqual([]);
497
498
+ // Once the user writes in the thread again, the card stops asking but stays answerable.
499
+ const wroteAt = DateTime.add(card.startedAt!, { seconds: 1 });
500
+ yield* a.sink.write({
501
+ commandId: CommandId.make("command:user-writes:laptop"),
502
+ events: [
503
+ {
504
+ id: EventId.make("event:user-writes"),
505
+ type: "message.updated",
506
+ threadId,
507
+ occurredAt: wroteAt,
508
+ payload: {
509
+ createdBy: "user",
510
+ creationSource: "web",
511
+ id: MessageId.make("message:user-writes"),
512
+ threadId,
513
+ runId: null,
514
+ nodeId: null,
515
+ role: "user",
516
+ text: "Something else",
517
+ attachments: [],
518
+ streaming: false,
519
+ createdAt: wroteAt,
520
+ updatedAt: wroteAt,
521
+ },
522
+ },
523
+ ],
524
+ });
525
+ expect((yield* a.orchestrator.getThreadShell(threadId))?.pendingRuntimeRequest).toBeNull();
526
+ expect(
527
+ ProjectionStore.threadShellFromProjection(
528
+ yield* a.orchestrator.getThreadProjection(threadId),
529
+ ).pendingRuntimeRequest,
530
+ ).toBeNull();
531
+ expect(yield* cardOf(a)).toMatchObject({ status: "waiting", linkStatus: "pending" });
532
+
533
// The user's client mints a code on the box and picks more than the agent suggested.
534
const pairing = yield* b.auth.issuePairingCredential();
535
yield* a.requests.answer({