GeezerVison is showing github.com — fix(server): a model set on a thread also holds for its queue and its… · AdEx-Partners-DE/t3code@c7bc22b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/OpenThreadModelOverride.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,8 +92,18 @@ export const make = Effect.gen(function* () { | 92 | 92 | }); | 93 | 93 | if (next === null) { | 94 | 94 | // Already there: still reported, so a client whose composer shows an | 95 | | - // older pick for this thread can line it up. | | 95 | + // older pick for this thread can line it up. Messages waiting in its | | 96 | + // queue may still carry an older model and would move the thread back. | 96 | 97 | selections.push({ threadId: thread.id, modelSelection: thread.modelSelection }); | | 98 | + yield* threads | | 99 | + .dispatch({ | | 100 | + type: "thread.model-selection.set", | | 101 | + commandId: CommandId.make(`${input.commandId}:queued:${thread.id}`), | | 102 | + threadId: thread.id, | | 103 | + modelSelection: thread.modelSelection, | | 104 | + includeQueuedRuns: true, | | 105 | + }) | | 106 | + .pipe(Effect.ignore); | 97 | 107 | continue; | 98 | 108 | } | 99 | 109 | const set = yield* threads | @@ -102,6 +112,7 @@ export const make = Effect.gen(function* () { | 102 | 112 | commandId: CommandId.make(`${input.commandId}:model:${thread.id}`), | 103 | 113 | threadId: thread.id, | 104 | 114 | modelSelection: next, | | 115 | + includeQueuedRuns: true, | 105 | 116 | }) | 106 | 117 | .pipe( | 107 | 118 | Effect.as(true), | @@ -150,6 +161,7 @@ export const make = Effect.gen(function* () { | 150 | 161 | commandId: CommandId.make(`${input.commandId}:model:${threadId}`), | 151 | 162 | threadId: thread.id, | 152 | 163 | modelSelection: entry.previous, | | 164 | + includeQueuedRuns: true, | 153 | 165 | }) | 154 | 166 | .pipe( | 155 | 167 | Effect.as(true), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3337,6 +3337,39 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | 3337 | 3337 | payload: updatedThread, | 3338 | 3338 | }); | 3339 | 3339 |
| | 3340 | + if (command.type === "thread.model-selection.set" && command.includeQueuedRuns === true) { | | 3341 | + const records = yield* projectionStore | | 3342 | + .getThreadRecords(command.threadId, ["runs"]) | | 3343 | + .pipe( | | 3344 | + Effect.mapError( | | 3345 | + (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }), | | 3346 | + ), | | 3347 | + ); | | 3348 | + for (const run of records.runs) { | | 3349 | + if ( | | 3350 | + run.status !== "queued" || | | 3351 | + modelSelectionsEqual(run.modelSelection, command.modelSelection) | | 3352 | + ) { | | 3353 | + continue; | | 3354 | + } | | 3355 | + yield* emit( | | 3356 | + events, | | 3357 | + command, | | 3358 | + )({ | | 3359 | + type: "run.updated", | | 3360 | + threadId: command.threadId, | | 3361 | + runId: run.id, | | 3362 | + providerInstanceId: command.modelSelection.instanceId, | | 3363 | + occurredAt: now, | | 3364 | + payload: { | | 3365 | + ...run, | | 3366 | + providerInstanceId: command.modelSelection.instanceId, | | 3367 | + modelSelection: command.modelSelection, | | 3368 | + }, | | 3369 | + }); | | 3370 | + } | | 3371 | + } | | 3372 | + | 3340 | 3373 | if (command.type === "thread.metadata.update" && command.regenerateTitle === true) { | 3341 | 3374 | yield* Ref.update(effects, (existing) => [ | 3342 | 3375 | ...existing, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/scheduledTasks/ScheduledTaskService.ts +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -943,12 +943,11 @@ export const layer = Layer.effect( | 943 | 943 | scheduledTaskId: active.id, | 944 | 944 | text: prompt, | 945 | 945 | attachments: [], | 946 | | - // An idle task carries on the thread's own work, so it runs on | 947 | | - // whatever the thread runs on. Sending the task's model would | 948 | | - // move the thread to it, account and all. | 949 | | - ...(active.schedule.type === "idle" | 950 | | - ? {} | 951 | | - : { modelSelection: active.modelSelection }), | | 946 | + // A task bound to a thread carries on that thread's work, so it | | 947 | + // runs on whatever the thread runs on. Sending the task's own | | 948 | + // model would move the thread to it, account and all, and undo | | 949 | + // a model the user set on the thread since. The task's model is | | 950 | + // for the threads it launches. | 952 | 951 | // Scheduled prompts must not interrupt tools in the bound thread. | 953 | 952 | mode: "queue", | 954 | 953 | createdBy: active.createdBy, | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/orchestrationV2.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2924,6 +2924,12 @@ export const OrchestrationV2Command = Schema.Union([ | 2924 | 2924 | commandId: CommandId, | 2925 | 2925 | threadId: ThreadId, | 2926 | 2926 | modelSelection: ModelSelection, | | 2927 | + /** | | 2928 | + * Also move the messages waiting in the thread's queue to this selection. | | 2929 | + * Each queued message otherwise keeps the model it was sent with and | | 2930 | + * moves the thread back to it when it starts. | | 2931 | + */ | | 2932 | + includeQueuedRuns: Schema.optional(Schema.Boolean), | 2927 | 2933 | }), | 2928 | 2934 | Schema.Struct({ | 2929 | 2935 | type: Schema.Literal("provider-session.detach"), | |
|