GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(fork): preserve steering and delivery invariants after sync · Alb11747/t3code@c1eda99

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • server/src
      • mcp
        • OrchestratorMcpService.ts
        • OrchestratorMcpToolkit.fork.integration.test.ts
      • orchestration-v2
        • Adapters
          • ClaudeAdapterV2.ts
        • DelegatedTaskQuestionDispatch.test.ts
        • Orchestrator.ts
        • ProviderSessionManager.test.ts
        • SteeringCompletion.integration.test.ts
        • runtimeLayer.test.ts
      • peer
        • RemoteDelegation.test.ts
    • web/src/components/chat
      • QueuedRunsControl.browser.test.tsx
  • packages/provider-cursor/src/server
    • adapter.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,13 @@ const make = Effect.gen(function* () {
33613361
);
33623362
// A read past the end of an item's text shows the agent nothing to acknowledge.
33633363
const readPastEnd = (input.textOffset ?? 0) > 0 && items.every((item) => !item.text);
3364-
if (parent !== undefined && scope.thread !== undefined && tasks.length > 0 && !readPastEnd) {
3364+
if (
3365+
parent !== undefined &&
3366+
scope.thread !== undefined &&
3367+
tasks.length > 0 &&
3368+
(input.textOffset ?? 0) === 0 &&
3369+
!readPastEnd
3370+
) {
33653371
for (const task of tasks) {
33663372
const transfer = taskResultTransfer(parent.thread.id, target, task);
33673373
const resultRunId = transfer?.sourcePoint.runId ?? delegatedTaskRun(target, task)?.id;
Collapse file

‎apps/server/src/mcp/OrchestratorMcpToolkit.fork.integration.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpToolkit.fork.integration.test.ts
+70-16Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,33 @@ describe("orchestrator MCP toolkit", () => {
186186
take: Effect.never,
187187
},
188188
);
189-
const waitForContinuationOffers = (count: number) =>
189+
const continuationReservations = (
190+
offers: ReadonlyArray<ProviderContinuationRequests.ProviderContinuationRequest>,
191+
) => {
192+
const reservations = new Map<string, (typeof offers)[number]>();
193+
for (const offer of offers) {
194+
expect(offer.delegatedCompletion).toBeDefined();
195+
const key = JSON.stringify([
196+
offer.threadId,
197+
offer.providerThreadId,
198+
offer.delegatedCompletion,
199+
]);
200+
const previous = reservations.get(key);
201+
if (previous === undefined) reservations.set(key, offer);
202+
else expect(offer).toEqual(previous);
203+
}
204+
return [...reservations.values()];
205+
};
206+
const waitForContinuationOffers = (count: number, distinctReservations = false) =>
190207
Effect.scoped(
191208
Effect.gen(function* () {
192209
const subscription = yield* PubSub.subscribe(offerEvents);
193210
while (true) {
194211
const current = yield* Ref.get(continuationOffers);
195-
if (current.length >= count) return current;
212+
const matched = distinctReservations
213+
? continuationReservations(current)
214+
: current;
215+
if (matched.length >= count) return matched;
196216
yield* PubSub.take(subscription);
197217
}
198218
}),
@@ -201,7 +221,16 @@ describe("orchestrator MCP toolkit", () => {
201221
Effect.gen(function* () {
202222
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
203223
yield* worker.drain();
204-
expect(yield* Ref.get(continuationOffers)).toHaveLength(count);
224+
const offers = yield* Ref.get(continuationOffers);
225+
expect(offers, JSON.stringify(offers)).toHaveLength(count);
226+
});
227+
const expectDeliveryReservationsToStay = (count: number) =>
228+
Effect.gen(function* () {
229+
yield* (yield* EffectWorker.OrchestrationEffectWorkerV2).drain();
230+
const offers = yield* Ref.get(continuationOffers);
231+
const reservations = continuationReservations(offers);
232+
expect(reservations, JSON.stringify(offers)).toHaveLength(count);
233+
return reservations;
205234
});
206235
const layerOrchestrator = ProviderReplayHarness.layerWithRegistry(
207236
{
@@ -325,7 +354,7 @@ describe("orchestrator MCP toolkit", () => {
325354
Layer.mock(ProjectService.ProjectService)({
326355
getById: (id) =>
327356
Effect.succeed(
328-
id === projectId
357+
id === projectId || id === "project:mcp-foreign"
329358
? Option.some({ id, defaultModelSelection: projectDefaultSelection } as never)
330359
: Option.none(),
331360
),
@@ -706,6 +735,7 @@ describe("orchestrator MCP toolkit", () => {
706735

707736
const childPromptReadCall = yield* invoke("t3_thread_read", {
708737
threadId: directChildThreadId,
738+
afterPosition: -1,
709739
limit: 1,
710740
});
711741
const childPromptRead = yield* decodeThreadReadResult(
@@ -1059,7 +1089,7 @@ describe("orchestrator MCP toolkit", () => {
10591089
threadId: parentThreadId,
10601090
cursor: 90,
10611091
}).pipe(Effect.flip);
1062-
expect(unknownPagingParamError.message).toContain("Expected no excess property");
1092+
expect(unknownPagingParamError.message).toContain('Unknown argument "cursor"');
10631093
const threadUpdateTool = server.tools.find(
10641094
({ tool }) => tool.name === "t3_thread_update",
10651095
);
@@ -1582,8 +1612,27 @@ describe("orchestrator MCP toolkit", () => {
15821612

15831613
expect(childFollowup.taskId).toBeDefined();
15841614
expect(activeChildFollowup.taskId).toBeDefined();
1585-
yield* waitForContinuationOffers(2);
1586-
yield* expectOffersToStay(2);
1615+
expect(
1616+
(yield* orchestrator.getThreadProjection(parentThreadId)).subagents.find(
1617+
(task) => task.id === heldFollowup.taskId,
1618+
),
1619+
).toMatchObject({
1620+
cancelledRunId: heldFollowup.runId,
1621+
completionDelivery: { state: "disposed" },
1622+
});
1623+
// Recovery can retry the open cohort while task_status observes it.
1624+
const followupOffers = yield* waitForContinuationOffers(1, true);
1625+
expect(followupOffers[0]).toMatchObject({
1626+
threadId: parentThreadId,
1627+
providerThreadId: parentRun.providerThreadId,
1628+
delivery: "message_text",
1629+
delegatedCompletion: {
1630+
parentRunId: parentRun.id,
1631+
generation: expect.any(Number),
1632+
messageId: expect.any(String),
1633+
},
1634+
});
1635+
yield* expectDeliveryReservationsToStay(1);
15871636
yield* invoke("task_status", { taskId: childFollowup.taskId });
15881637
yield* invoke("task_status", { taskId: activeChildFollowup.taskId });
15891638
yield* Ref.set(continuationOffers, []);
@@ -2188,6 +2237,7 @@ describe("orchestrator MCP toolkit", () => {
21882237

21892238
const promptedReadCall = yield* invoke("t3_thread_read", {
21902239
threadId: promptedThread.threadId,
2240+
afterPosition: -1,
21912241
limit: 1,
21922242
});
21932243
const promptedRead = yield* decodeThreadReadResult(
@@ -3041,7 +3091,7 @@ describe("orchestrator MCP toolkit", () => {
30413091
generation: firstLateDelivery.generation + 1,
30423092
taskIds: [lateTask.id],
30433093
});
3044-
const lateOffers = yield* waitForContinuationOffers(2);
3094+
const lateOffers = yield* waitForContinuationOffers(2, true);
30453095
expect(lateOffers).toHaveLength(2);
30463096
expect(
30473097
successorReserved.runs.filter((run) => {
@@ -3150,7 +3200,7 @@ describe("orchestrator MCP toolkit", () => {
31503200
generation: successorDelivery.generation,
31513201
taskIds: successorDelivery.taskIds,
31523202
});
3153-
yield* expectOffersToStay(2);
3203+
yield* expectDeliveryReservationsToStay(2);
31543204
yield* Deferred.succeed(successorGate, undefined);
31553205
const batchedReserved = yield* waitForProjection(
31563206
orchestrator,
@@ -3182,8 +3232,8 @@ describe("orchestrator MCP toolkit", () => {
31823232
?.state,
31833233
),
31843234
).toEqual(["delivered", "claimed", "claimed"]);
3185-
yield* waitForContinuationOffers(3);
3186-
yield* expectOffersToStay(3);
3235+
yield* waitForContinuationOffers(3, true);
3236+
yield* expectDeliveryReservationsToStay(3);
31873237
expect(
31883238
batchedReserved.runs.filter((run) => {
31893239
const message = batchedReserved.messages.find(
@@ -3230,7 +3280,7 @@ describe("orchestrator MCP toolkit", () => {
32303280
?.state,
32313281
),
32323282
).toEqual(["delivered", "delivered", "delivered", "delivered"]);
3233-
yield* expectOffersToStay(3);
3283+
yield* expectDeliveryReservationsToStay(3);
32343284

32353285
const removeParentGate = yield* Deferred.make<void>();
32363286
parentTerminalGates.set(lateParentThreadId, removeParentGate);
@@ -3924,8 +3974,10 @@ describe("orchestrator MCP toolkit", () => {
39243974
completionWake: "always",
39253975
result: `Codex completed: ${approvalCompletionPrompt}`,
39263976
});
3927-
const offers = (yield* Ref.get(continuationOffers)).filter(
3928-
(offer) => offer.threadId === approvalParentId,
3977+
const offers = continuationReservations(
3978+
(yield* Ref.get(continuationOffers)).filter(
3979+
(offer) => offer.threadId === approvalParentId,
3980+
),
39293981
);
39303982
expect(offers).toHaveLength(1);
39313983
const approvalParent = yield* orchestrator.getThreadProjection(approvalParentId);
@@ -3943,8 +3995,10 @@ describe("orchestrator MCP toolkit", () => {
39433995
expect((yield* readApprovalStatus()).pendingApproval).toBeNull();
39443996
yield* worker.drain();
39453997
expect(
3946-
(yield* Ref.get(continuationOffers)).filter(
3947-
(offer) => offer.threadId === approvalParentId,
3998+
continuationReservations(
3999+
(yield* Ref.get(continuationOffers)).filter(
4000+
(offer) => offer.threadId === approvalParentId,
4001+
),
39484002
),
39494003
).toHaveLength(1);
39504004
yield* Deferred.succeed(approvalParentGate, undefined);
Collapse file

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9662,7 +9662,22 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
96629662
if (current === context) {
96639663
const retry = (yield* Ref.get(providerRetries)).get(context.providerTurnId);
96649664
const queryError = cause === undefined ? undefined : Cause.squash(cause);
9665-
const failure = providerFailureFromQueryError(queryError, closedQuery.receivedInit);
9665+
const queryFailure = providerFailureFromQueryError(
9666+
queryError,
9667+
closedQuery.receivedInit,
9668+
);
9669+
const processExit = cause === undefined ? undefined : claudeProcessExitFailure(cause);
9670+
const failure =
9671+
processExit === undefined
9672+
? queryFailure
9673+
: {
9674+
...queryFailure,
9675+
...processExit,
9676+
retryable:
9677+
processExit.code === "process_killed_by_signal"
9678+
? false
9679+
: queryFailure.retryable,
9680+
};
96669681
const retryFailure =
96679682
cause === undefined ||
96689683
(context.overloadRetry !== null && Cause.hasInterruptsOnly(cause))
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/DelegatedTaskQuestionDispatch.test.ts
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,48 @@ it.effect.each([
263263
],
264264
});
265265

266+
const seedQuestion = Effect.fn("DelegatedTaskQuestionDispatch.seedQuestion")(function* (
267+
childId: ThreadId,
268+
questionId: RuntimeRequestId,
269+
) {
270+
yield* orchestrator.dispatch({
271+
type: "thread.create",
272+
commandId: CommandId.make(`create:${childId}`),
273+
threadId: childId,
274+
projectId: ProjectId.make("project:delegated-question"),
275+
title: "Question child",
276+
modelSelection,
277+
runtimeMode: "full-access",
278+
interactionMode: "default",
279+
branch: null,
280+
worktreePath: cwd,
281+
createdBy: "agent",
282+
creationSource: "mcp",
283+
});
284+
yield* sink.write({
285+
events: [
286+
{
287+
id: EventId.make(`event:pending:${questionId}`),
288+
type: "runtime-request.updated",
289+
threadId: childId,
290+
occurredAt: now,
291+
payload: {
292+
id: questionId,
293+
nodeId: NodeId.make(`node:${questionId}`),
294+
providerTurnId: null,
295+
nativeRequestRef: null,
296+
kind: "user_input",
297+
status: "pending",
298+
responseCapability: { type: "message" },
299+
createdAt: now,
300+
resolvedAt: null,
301+
},
302+
},
303+
],
304+
});
305+
});
306+
yield* seedQuestion(childThreadId, requestId);
307+
266308
const notice = questionNotification(parentThreadId, delegated, childThreadId, {
267309
requestId,
268310
});
@@ -381,6 +423,10 @@ it.effect.each([
381423
{ requestId: RuntimeRequestId.make("request:earlier-question") },
382424
);
383425
earlierMessageId = earlierNotice.messageId;
426+
yield* seedQuestion(
427+
earlierChildThreadId,
428+
RuntimeRequestId.make("request:earlier-question"),
429+
);
384430
yield* orchestrator.dispatch(earlierNotice);
385431
yield* orchestrator.dispatch({
386432
type: "run.interrupt",
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+32-7Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7275,7 +7275,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
72757275
.pipe(mapDispatchError(command));
72767276
if (
72777277
Option.isSome(session) &&
7278-
session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools === true
7278+
session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools ===
7279+
true &&
7280+
// Cursor accepts human input natively and has no Claude boundary hook to drain it.
7281+
!(providerThread.driver === "cursor" && command.createdBy === "user")
72797282
) {
72807283
dispatchMode = { type: "queue_after_active" };
72817284
atToolBoundary = true;
@@ -7555,7 +7558,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
75557558
.pipe(mapDispatchError(command));
75567559
yield* ensureSteeringMessage(command, command);
75577560
steerWhenReadyRunId = target.id;
7558-
if (command.modelSelection === undefined) modelSelection = target.modelSelection;
7561+
if (
7562+
command.modelSelection === undefined &&
7563+
modelSelection.instanceId === target.providerInstanceId
7564+
) {
7565+
modelSelection = target.modelSelection;
7566+
}
75597567
dispatchMode = { type: "queue_after_active" };
75607568
}
75617569
}
@@ -7702,6 +7710,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
77027710
if (
77037711
startupDeliveryIntent !== undefined &&
77047712
activeRun !== undefined &&
7713+
modelSelection.instanceId === activeRun.providerInstanceId &&
77057714
command.modelSelection === undefined &&
77067715
!projection.messages.some((message) => message.id === command.messageId)
77077716
) {
@@ -11819,7 +11828,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1181911828
.pipe(mapDispatchError(command));
1182011829
if (
1182111830
Option.isSome(session) &&
11822-
session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools === true
11831+
session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools === true &&
11832+
!(
11833+
targetProviderThread?.driver === "cursor" &&
11834+
queuedMessage.createdBy === "user" &&
11835+
command.requestedBy !== "agent"
11836+
)
1182311837
) {
1182411838
// The same refusals as the boundary join: Stop wins, and a run that
1182511839
// owns a delegated task keeps its own turn.
@@ -16606,11 +16620,22 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1660616620
Effect.gen(function* () {
1660716621
const attempted = new Set<RunId>();
1660816622
while (true) {
16609-
const projection = yield* projectionStore.getThreadRecords(
16623+
const { runs } = yield* projectionStore.getThreadRecords(threadId, ["runs"], {
16624+
runStatuses: ["queued", "running"],
16625+
});
16626+
if (!runs.some((run) => run.status === "queued")) return;
16627+
const records = yield* projectionStore.getThreadRecords(
1661016628
threadId,
16611-
["runs", "messages", "providerTurns", "providerThreads", "providerSessions"],
16612-
{ turnItemTypes: [], messageRoles: ["user"] },
16629+
["messages", "providerTurns", "providerThreads", "providerSessions"],
16630+
{
16631+
messageRoles: ["user"],
16632+
messageRunIds: runs.map((run) => run.id),
16633+
providerTurnAttemptIds: runs.flatMap((run) =>
16634+
run.activeAttemptId === null ? [] : [run.activeAttemptId],
16635+
),
16636+
},
1661316637
);
16638+
const projection = { ...records, runs };
1661416639
const steeringRunIds = queuedSteeringRunIds(projection.runs);
1661516640
const next = queuedRunsInDeliveryOrder(projection)
1661616641
.filter((queued) => {
@@ -16922,7 +16947,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1692216947
candidate.id === input.taskId &&
1692316948
candidate.origin === "app_owned" &&
1692416949
candidate.childThreadId === command.threadId &&
16925-
isOrchestrationV2WorkActive(candidate.status),
16950+
(isOrchestrationV2WorkActive(candidate.status) || candidate.status === "idle"),
1692616951
);
1692716952
const child = yield* projectionStore
1692816953
.getThreadRecords(
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ function layerTest(input: {
696696
...(input.startTurn === undefined ? {} : { startTurn: input.startTurn }),
697697
...(input.interruptTurn === undefined ? {} : { interruptTurn: input.interruptTurn }),
698698
...(input.beforeUnload === undefined ? {} : { beforeUnload: input.beforeUnload }),
699+
...(input.unloads === undefined ? {} : { unloads: input.unloads }),
700+
...(input.archive === undefined ? {} : { archive: input.archive }),
699701
...(input.spawnBeforeOpen === undefined ? {} : { spawnBeforeOpen: input.spawnBeforeOpen }),
700702
...(input.scopeCloseReached === undefined
701703
? {}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.