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(server): agent auto sends steer past an explicit queue (#43357) · patroza/t3code@5fda4f7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • Orchestrator.ts
    • ProjectionStore.test.ts
    • ProjectionStore.ts
    • SteeringCompletion.integration.test.ts
    • ThreadManagementService.ts
  • packages/contracts/src
    • orchestrationV2.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7678,14 +7678,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
76787678
dispatchMode = { type: "queue_after_active" };
76797679
}
76807680
// An agent's automatic send must not overtake its own earlier message still queued
7681-
// (e.g. behind /compact), or the agent receives them out of send order.
7681+
// (e.g. behind /compact), or the agent receives them out of send order. A message it
7682+
// explicitly queued as a later turn is no such barrier.
76827683
if (
76837684
command.deliveryIntent === "auto" &&
76847685
command.createdBy === "agent" &&
76857686
(dispatchMode.type === "steer_active" || dispatchMode.type === "restart_active")
76867687
) {
76877688
const queuedRuns = projection.runs.filter(
7688-
(run) => run.status === "queued" && run.queueHeld !== true,
7689+
(run) => run.status === "queued" && run.queueHeld !== true && run.explicitQueue !== true,
76897690
);
76907691
if (queuedRuns.length > 0) {
76917692
const queuedMessages = yield* projectionStore
@@ -8292,6 +8293,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
82928293
rootNodeId,
82938294
activeAttemptId: attemptId,
82948295
status: "queued",
8296+
...(command.explicitQueue === true ? { explicitQueue: true as const } : {}),
82958297
...(steerWhenReadyRunId === undefined ? {} : { steerWhenReadyRunId }),
82968298
// A restart cancels its run; nobody knows whether the provider read the steer, so a person decides.
82978299
...(worktreeMissingRun !== undefined ||
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.test.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,6 +3982,29 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
39823982
"keeps restart-cancelled work through a stale run.updated",
39833983
() => restartCancelledWorkSurvivesStaleRunUpdate,
39843984
);
3985+
it.effect("keeps a run's explicit queue marker through a run.updated that omits it", () =>
3986+
Effect.gen(function* () {
3987+
const store = yield* ProjectionStore.ProjectionStoreV2;
3988+
const threadId = yield* addRolledBackRecoveryCandidate("explicit-queue-stale-update");
3989+
const run = (yield* store.getThreadProjection(threadId)).runs[0]!;
3990+
const now = yield* DateTime.now;
3991+
const update = (id: string, payload: typeof run) =>
3992+
store.apply({
3993+
id: EventId.make(`event:explicit-queue-stale-update:${id}`),
3994+
type: "run.updated",
3995+
threadId,
3996+
runId: run.id,
3997+
providerInstanceId,
3998+
occurredAt: now,
3999+
payload,
4000+
});
4001+
yield* update("marked", { ...run, explicitQueue: true });
4002+
yield* update("completed", { ...run, status: "completed", completedAt: now });
4003+
const updated = (yield* store.getThreadProjection(threadId)).runs[0];
4004+
assert.equal(updated?.status, "completed");
4005+
assert.equal(updated?.explicitQueue, true);
4006+
}),
4007+
);
39854008
it.effect("records restart-cancelled work without regressing a run that completed since", () =>
39864009
Effect.gen(function* () {
39874010
const store = yield* ProjectionStore.ProjectionStoreV2;
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.ts
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,9 @@ function preserveRunRecordedFields(
998998
current.restartCancelledBackgroundWork !== undefined
999999
? { restartCancelledBackgroundWork: current.restartCancelledBackgroundWork }
10001000
: {}),
1001+
...(next.explicitQueue === undefined && current.explicitQueue !== undefined
1002+
? { explicitQueue: current.explicitQueue }
1003+
: {}),
10011004
// Only a submission sets the output; a lifecycle write carries it as it was when read.
10021005
...(current.output !== undefined ? { output: current.output } : {}),
10031006
};
@@ -2437,7 +2440,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
24372440
THEN json_set(
24382441
${payload},
24392442
${path},
2440-
json_extract(orchestration_v2_projection_runs.payload_json, ${path})
2443+
orchestration_v2_projection_runs.payload_json -> ${path}
24412444
)
24422445
ELSE ${payload}
24432446
END
@@ -2668,8 +2671,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
26682671
completed_at = excluded.completed_at,
26692672
payload_json = ${keepRecordedRunOutput(
26702673
keepRecordedRunField(
2671-
keepRecordedRunField(sql`excluded.payload_json`, "$.delegatedCompletion"),
2672-
"$.restartCancelledBackgroundWork",
2674+
keepRecordedRunField(
2675+
keepRecordedRunField(sql`excluded.payload_json`, "$.delegatedCompletion"),
2676+
"$.restartCancelledBackgroundWork",
2677+
),
2678+
"$.explicitQueue",
26732679
),
26742680
)}
26752681
`;
Collapse file

‎apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,3 +4494,62 @@ it.effect("a side chat that opens with /goal gets its context on the next questi
44944494
}).pipe(Effect.provide(layer));
44954495
}),
44964496
);
4497+
4498+
it.effect("an agent's auto send steers past its own explicitly queued message", () =>
4499+
Effect.gen(function* () {
4500+
const name = "agent-auto-after-explicit-queue";
4501+
const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(name);
4502+
yield* Effect.gen(function* () {
4503+
const orchestrator = yield* Orchestrator.OrchestratorV2;
4504+
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
4505+
const manager = yield* ThreadManagementService.ThreadManagementService;
4506+
const threadId = yield* startFirstTurn;
4507+
const send = (text: string, mode: "auto" | "queue") =>
4508+
manager.sendToThread({
4509+
projectId: ProjectId.make(`project:${name}`),
4510+
threadId,
4511+
commandId: CommandId.make(text),
4512+
messageId: MessageId.make(text),
4513+
text,
4514+
attachments: [],
4515+
mode,
4516+
createdBy: "agent",
4517+
creationSource: "mcp",
4518+
senderThreadId: ThreadId.make("thread:sender"),
4519+
});
4520+
const later = yield* send("later", "queue");
4521+
const now = yield* send("now", "auto");
4522+
yield* worker.drain();
4523+
4524+
const projection = yield* orchestrator.getThreadProjection(threadId);
4525+
assert.deepEqual(
4526+
{
4527+
later: later.delivery,
4528+
now: now.delivery,
4529+
targetsRunningTurn: now.run.id === started[0]?.runId,
4530+
adapterReceived: steered.map((text) => text.split("\n").at(-1)),
4531+
queuedRunIds: projection.runs
4532+
.filter((run) => run.status === "queued")
4533+
.map((run) => run.id),
4534+
},
4535+
{
4536+
later: "queued",
4537+
now: "steered",
4538+
targetsRunningTurn: true,
4539+
adapterReceived: ["now"],
4540+
queuedRunIds: [later.run.id],
4541+
},
4542+
);
4543+
}).pipe(
4544+
Effect.provide(
4545+
ThreadManagementService.layer.pipe(
4546+
Layer.provideMerge(layer),
4547+
Layer.provide(ServerSettings.layerTest()),
4548+
Layer.provide(
4549+
CommandReceiptStore.layer.pipe(Layer.provide(SqlitePersistence.layerMemory)),
4550+
),
4551+
),
4552+
),
4553+
);
4554+
}),
4555+
);
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadManagementService.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ const make = Effect.gen(function* () {
986986
...(input.outputSchema === undefined ? {} : { outputSchema: input.outputSchema }),
987987
dispatchMode,
988988
...(mode === "auto" ? { deliveryIntent: "auto" } : {}),
989+
...(mode === "queue" ? { explicitQueue: true as const } : {}),
989990
createdBy: input.createdBy,
990991
creationSource: input.creationSource,
991992
});
Collapse file

‎packages/contracts/src/orchestrationV2.ts‎

Copy file name to clipboardExpand all lines: packages/contracts/src/orchestrationV2.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,8 @@ export const OrchestrationV2Run = Schema.Struct({
830830
status: OrchestrationV2RunStatus,
831831
queuePosition: Schema.optional(Schema.NullOr(PositiveInt)),
832832
queueHeld: Schema.optional(Schema.Boolean),
833+
/** The sender asked for a separate turn; it is not an ordering barrier for a later auto send. */
834+
explicitQueue: Schema.optional(Schema.Literal(true)),
833835
steerWhenReadyRunId: Schema.optional(RunId),
834836
requestedAt: Schema.DateTimeUtc,
835837
startedAt: Schema.NullOr(Schema.DateTimeUtc),
@@ -3637,6 +3639,7 @@ export const OrchestrationV2Command = Schema.Union([
36373639
steerFollowUpAfterRunOrdinal: Schema.optional(NonNegativeInt),
36383640
usageLimitRecoveryRequestId: Schema.optional(CommandId),
36393641
deliveryIntent: Schema.optional(Schema.Literals(["auto", "steer", "restart"])),
3642+
explicitQueue: Schema.optional(Schema.Literal(true)),
36403643
delegatedCompletion: Schema.optional(
36413644
Schema.Struct({
36423645
parentRunId: RunId,

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.