@@ -763,6 +763,18 @@ function cancelledAppOwnedTask( |
763 | 763 | }; |
764 | 764 | } |
765 | 765 |
|
| 766 | +function askedForLinkedMachine( |
| 767 | + card: Extract<OrchestrationV2TurnItem, { readonly type: "link_request" }>, |
| 768 | + linked: Extract<OrchestrationV2InternalCommand, { readonly type: "link_request.record" }>, |
| 769 | +): boolean { |
| 770 | + if (card.requestedAccess !== linked.requestedAccess) return false; |
| 771 | + if (card.environmentId !== undefined) return card.environmentId === linked.linkedEnvironmentId; |
| 772 | + if (card.url !== undefined) return linked.url !== undefined && card.url === linked.url; |
| 773 | + const normalize = (text: string | undefined) => text?.trim().toLowerCase() ?? ""; |
| 774 | + const hint = normalize(card.hint); |
| 775 | + return hint !== "" && hint === normalize(linked.hint) && hint === normalize(linked.linkedLabel); |
| 776 | +} |
| 777 | + |
766 | 778 | // A workspace change detaches the session, which can settle the calling run at once. Queuing its |
767 | 779 | // follow-up in a later command would let a delegated task report its result before that exists. |
768 | 780 | function metadataUpdateContinuation( |
@@ -10448,6 +10460,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio |
10448 | 10460 | type: _type, |
10449 | 10461 | commandId: _commandId, |
10450 | 10462 | turnItemId: _turnItemId, |
| 10463 | + answeringTurnItemIds, |
10451 | 10464 | wake, |
10452 | 10465 | ...fields |
10453 | 10466 | } = command; |
@@ -10507,6 +10520,39 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio |
10507 | 10520 | occurredAt: now, |
10508 | 10521 | payload: turnItem, |
10509 | 10522 | }); |
| 10523 | + // The link answers the older cards that asked for the same machine and |
| 10524 | + // access. They end without waking anyone: the agent hears this link. |
| 10525 | + // A card still being answered stays open for its own answer to end. |
| 10526 | + if (!unchanged && command.linkStatus === "linked") { |
| 10527 | + for (const item of projection.turnItems) { |
| 10528 | + if ( |
| 10529 | + item.type !== "link_request" || |
| 10530 | + item.linkStatus !== "pending" || |
| 10531 | + item.ordinal >= turnItem.ordinal || |
| 10532 | + answeringTurnItemIds?.includes(item.id) === true || |
| 10533 | + !askedForLinkedMachine(item, command) |
| 10534 | + ) { |
| 10535 | + continue; |
| 10536 | + } |
| 10537 | + yield* emit( |
| 10538 | + events, |
| 10539 | + command, |
| 10540 | + )({ |
| 10541 | + type: "turn-item.updated", |
| 10542 | + threadId: command.threadId, |
| 10543 | + ...(item.runId === null ? {} : { runId: item.runId }), |
| 10544 | + ...(item.nodeId === null ? {} : { nodeId: item.nodeId }), |
| 10545 | + occurredAt: now, |
| 10546 | + payload: { |
| 10547 | + ...item, |
| 10548 | + status: "cancelled", |
| 10549 | + linkStatus: "cancelled", |
| 10550 | + completedAt: now, |
| 10551 | + updatedAt: now, |
| 10552 | + }, |
| 10553 | + }); |
| 10554 | + } |
| 10555 | + } |
10510 | 10556 | // The agent asked without waiting, so the answer reaches it as a |
10511 | 10557 | // notification: it starts a turn, or follows the one running. Only the |
10512 | 10558 | // answer that closes the card wakes it, and never a closed thread. |
|