Skip to content

Commit 2571792

Browse files
Mika Hertlerclaude
andcommitted
fix: address second-round review findings on per-task model routing
- Routing is kept only on tasks that start a new thread per run, at the save itself: an explicit routing on a one-thread task is refused, and a save that moves a task to one thread drops it (a replayed bound create or a destination change in the editor no longer leaves an inert list). - An account whose reported windows all limit other models (only a spent Fable window, say) counts as without usage data, not as 100% left. - A malformed stored routing value no longer makes a save that leaves routing out fail with malformed JSON; only an object is carried over. - The schedule_task binding default and the editor help say what routing changes (no binding by default; accounts without data before the most-headroom fallback). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6c4e0bd commit 2571792

17 files changed

Lines changed: 91 additions & 25 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"claudeSystemAppendBytes": 6245,
33
"codexAdditionalContextBytes": 7639,
4-
"mcpToolListJsonBytes": 62199
4+
"mcpToolListJsonBytes": 62220
55
}

‎apps/server/src/scheduledTasks/ScheduledTaskService.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,4 +1552,45 @@ describe("per-task model routing", () => {
15521552
);
15531553
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
15541554
);
1555+
1556+
it.effect("keeps routing only on tasks that start a new thread per run", () =>
1557+
Effect.gen(function* () {
1558+
const sql = yield* SqlClient.SqlClient;
1559+
const providers = yield* Ref.make<ReadonlyArray<ServerProvider>>([]);
1560+
const launched = yield* Ref.make<ReadonlyArray<ThreadLaunchService.ThreadLaunchInput>>([]);
1561+
yield* Effect.gen(function* () {
1562+
const service = yield* ScheduledTaskService.ScheduledTaskService;
1563+
const refused = yield* service
1564+
.upsert(taskInput({ threadMode: "fresh_session", modelRouting: routing }))
1565+
.pipe(Effect.flip);
1566+
assert.include(refused.message, "new thread");
1567+
yield* service.upsert(taskInput({ modelRouting: routing }));
1568+
// Moving the task to one thread drops the routing its runs would no longer use.
1569+
const moved = yield* service.upsert(taskInput({ threadMode: "fresh_session" }));
1570+
assert.isUndefined(moved.task.modelRouting);
1571+
const [row] = yield* sql<{
1572+
model_selection_json: string;
1573+
}>`SELECT model_selection_json FROM scheduled_tasks`;
1574+
assert.notInclude(row?.model_selection_json ?? "", "scheduledTaskRouting");
1575+
}).pipe(Effect.provide(serviceLayer(providers, launched)));
1576+
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
1577+
);
1578+
1579+
it.effect("a malformed stored routing reads as none and does not block a save", () =>
1580+
Effect.gen(function* () {
1581+
const sql = yield* SqlClient.SqlClient;
1582+
const providers = yield* Ref.make<ReadonlyArray<ServerProvider>>([]);
1583+
const launched = yield* Ref.make<ReadonlyArray<ThreadLaunchService.ThreadLaunchInput>>([]);
1584+
yield* Effect.gen(function* () {
1585+
const service = yield* ScheduledTaskService.ScheduledTaskService;
1586+
const { task } = yield* service.upsert(taskInput());
1587+
yield* sql`UPDATE scheduled_tasks SET model_selection_json = ${JSON.stringify({ ...stored, scheduledTaskRouting: "bad" })}`;
1588+
const { tasks } = yield* service.list();
1589+
assert.isUndefined(tasks.find((entry) => entry.id === task.id)?.modelRouting);
1590+
const saved = yield* service.upsert(taskInput({ title: "Renamed" }));
1591+
assert.equal(saved.task.title, "Renamed");
1592+
assert.deepEqual(saved.task.modelSelection, stored);
1593+
}).pipe(Effect.provide(serviceLayer(providers, launched)));
1594+
}).pipe(Effect.provide(SqlitePersistence.layerMemory)),
1595+
);
15551596
});

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ export const layer = Layer.effect(
541541
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
542542
const providerRegistry = yield* Effect.serviceOption(ProviderRegistry.ProviderRegistry);
543543
/**
544-
* New-thread runs: a webhook's `t3` routing, the task's own priority list, then the automatic
545-
* account setting, all limited to the allowed models. Falls back to the stored model only when the settings or providers
544+
* New-thread runs: a webhook's `t3` routing, the task's own list, then the automatic account
545+
* setting, within the allowed models. The stored model runs only when settings or providers
546546
* cannot be read; a run no allowed model can take fails with the reason instead of starting.
547547
*/
548548
const routedModelSelection = Effect.fn("ScheduledTaskService.routedModelSelection")(function* (
@@ -802,13 +802,13 @@ export const layer = Layer.effect(
802802
-- A save that left the routing out keeps the row's, even one saved while it ran.
803803
model_selection_json = CASE
804804
WHEN ${keepRouting ? 0 : 1} = 1 THEN excluded.model_selection_json
805-
WHEN json_type(scheduled_tasks.model_selection_json, ${`$.${MODEL_ROUTING_KEY}`}) IS NULL
806-
THEN json_remove(excluded.model_selection_json, ${`$.${MODEL_ROUTING_KEY}`})
807-
ELSE json_set(
805+
WHEN json_type(scheduled_tasks.model_selection_json, ${`$.${MODEL_ROUTING_KEY}`}) = 'object'
806+
THEN json_set(
808807
excluded.model_selection_json,
809808
${`$.${MODEL_ROUTING_KEY}`},
810809
json(json_extract(scheduled_tasks.model_selection_json, ${`$.${MODEL_ROUTING_KEY}`}))
811810
)
811+
ELSE json_remove(excluded.model_selection_json, ${`$.${MODEL_ROUTING_KEY}`})
812812
END,
813813
runtime_mode = excluded.runtime_mode,
814814
interaction_mode = excluded.interaction_mode,
@@ -1578,6 +1578,15 @@ export const layer = Layer.effect(
15781578
// of silently resetting an existing row.
15791579
const existingTask = yield* findTask(id);
15801580
const threadMode = resolveThreadMode(input, existingTask);
1581+
// Routing picks the model of a run that starts a thread, so only new-thread tasks keep it.
1582+
// Checked before the save consumes a webhook secret.
1583+
const routesRuns = threadMode === "new_thread";
1584+
if (!routesRuns && input.modelRouting != null) {
1585+
return yield* taskError(
1586+
"Model routing applies only to tasks that start a new thread for each run.",
1587+
{ taskId: id },
1588+
);
1589+
}
15811590
const keptThreadId =
15821591
input.threadId ?? (input.unbindThread === true ? null : (existingTask?.threadId ?? null));
15831592
// A bound thread belongs to its project, so moving the task leaves it for a new one.
@@ -1677,8 +1686,9 @@ export const layer = Layer.effect(
16771686
? { type: "root" }
16781687
: input.workspaceStrategy;
16791688
// Omitted keeps the stored routing, so clients that predate it can re-save the task.
1680-
const modelRouting =
1681-
input.modelRouting === undefined
1689+
const modelRouting = !routesRuns
1690+
? undefined
1691+
: input.modelRouting === undefined
16821692
? existingTask?.modelRouting
16831693
: (input.modelRouting ?? undefined);
16841694
const scheduleUnchanged =
@@ -1719,7 +1729,7 @@ export const layer = Layer.effect(
17191729
scheduleUnchanged ? existingTask.schedule : null,
17201730
threadId === null && input.unbindThread === true ? (existingTask?.threadId ?? null) : null,
17211731
webhook,
1722-
input.modelRouting === undefined,
1732+
routesRuns && input.modelRouting === undefined,
17231733
);
17241734
yield* notifyChanged;
17251735
return { task: (yield* findTask(id)) ?? task };

‎apps/web/src/components/settings/ScheduledTasksSettings.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,9 +2035,9 @@ function ScheduledTaskEditorForm({
20352035
<p className="text-xs text-muted-foreground">
20362036
<T>
20372037
Each run starts its thread on the first listed account or model with at least this
2038-
much usage left, or on the one with the most left when none has. Entries: account,
2039-
account/model or driver:kind. Empty: the model above, with the automatic account
2040-
settings.
2038+
much usage left; if none has, one without usage data, else the one with the most
2039+
left. Entries: account, account/model or driver:kind. Empty: the model above, with
2040+
the automatic account settings.
20412041
</T>
20422042
</p>
20432043
</Field>

‎apps/web/src/i18n/translations/de.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, one {Versucht, {attachments} Anhang zu senden} other {Versucht, {attachments} Anhänge zu senden}}",
339339
"cbba2216dafdd91d": "{count, plural, one {Anhänge {count}-mal gesendet} other {Anhänge {count}-mal gesendet}}",
340340
"f6589d3539e5e4b0": "{count, plural, one {Versucht, Anhänge {count}-mal zu senden} other {Versucht, Anhänge {count}-mal zu senden}}",
341+
"f658a09944ffe93e": "Jeder Lauf startet seinen Thread auf dem ersten aufgeführten Konto oder Modell mit mindestens so viel verbleibender Nutzung; hat keines so viel, auf einem ohne Nutzungsdaten, sonst auf dem mit der meisten. Einträge: Konto, Konto/Modell oder driver:kind. Leer: das Modell oben, mit den Einstellungen zur automatischen Kontowahl.",
341342
"bba19d414974a12c": "Verknüpfte Pull Requests",
342343
"3ab4b1ee5133f899": "Versucht, Pull Requests zu verknüpfen",
343344
"72d699ac25327b32": "{count, plural, one {{count} Pull Request verknüpft} other {{count} Pull Requests verknüpft}}",
@@ -6448,7 +6449,6 @@
64486449
"bce5d650902cc4c1": "Im Browser von {environment} öffnen",
64496450
"6232b16804aa22c2": "Auf diesem Computer öffnen",
64506451
"4bfd0547f8b625bf": "Browser-Tab kann nicht verschoben werden",
6451-
"4c060d82e9392799": "Jeder Lauf startet seinen Thread auf dem ersten aufgeführten Konto oder Modell mit mindestens so viel verbleibender Nutzung, oder auf dem mit der meisten, wenn keines so viel hat. Einträge: Konto, Konto/Modell oder driver:kind. Leer: das Modell oben, mit den Einstellungen zur automatischen Kontowahl.",
64526452
"a3aa54c6c5bd04e0": "Ausgelagerte Vorschau kann nicht aktualisiert werden",
64536453
"7588b19c1e03be40": "Aufnahmepfad kann nicht kopiert werden",
64546454
"f1307c250974b2ba": "Aufnahme gespeichert",

‎apps/web/src/i18n/translations/en.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, one {Tried to send {attachments} attachment} other {Tried to send {attachments} attachments}}",
339339
"cbba2216dafdd91d": "{count, plural, one {Sent attachments {count} time} other {Sent attachments {count} times}}",
340340
"f6589d3539e5e4b0": "{count, plural, one {Tried to send attachments {count} time} other {Tried to send attachments {count} times}}",
341+
"f658a09944ffe93e": "Each run starts its thread on the first listed account or model with at least this much usage left; if none has, one without usage data, else the one with the most left. Entries: account, account/model or driver:kind. Empty: the model above, with the automatic account settings.",
341342
"bba19d414974a12c": "Linked pull requests",
342343
"3ab4b1ee5133f899": "Tried to link pull requests",
343344
"72d699ac25327b32": "{count, plural, one {Linked {count} pull request} other {Linked {count} pull requests}}",
@@ -6452,7 +6453,6 @@
64526453
"bce5d650902cc4c1": "Open in {environment}''s browser",
64536454
"6232b16804aa22c2": "Open on this computer",
64546455
"4bfd0547f8b625bf": "Unable to move the browser tab",
6455-
"4c060d82e9392799": "Each run starts its thread on the first listed account or model with at least this much usage left, or on the one with the most left when none has. Entries: account, account/model or driver:kind. Empty: the model above, with the automatic account settings.",
64566456
"a3aa54c6c5bd04e0": "Unable to update popped-out preview",
64576457
"7588b19c1e03be40": "Unable to copy recording path",
64586458
"f1307c250974b2ba": "Recording saved",

‎apps/web/src/i18n/translations/es.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, one {Intentó enviar {attachments} adjunto} other {Intentó enviar {attachments} adjuntos}}",
339339
"cbba2216dafdd91d": "{count, plural, one {Envió adjuntos {count} vez} other {Envió adjuntos {count} veces}}",
340340
"f6589d3539e5e4b0": "{count, plural, one {Intentó enviar adjuntos {count} vez} other {Intentó enviar adjuntos {count} veces}}",
341+
"f658a09944ffe93e": "Cada ejecución inicia su hilo en la primera cuenta o modelo de la lista con al menos ese uso restante; si ninguno lo alcanza, en uno sin datos de uso y, si no, en el que tenga más. Entradas: cuenta, cuenta/modelo o driver:kind. Vacío: el modelo de arriba, con los ajustes de cuenta automática.",
341342
"bba19d414974a12c": "Pull requests vinculadas",
342343
"3ab4b1ee5133f899": "Intentó vincular pull requests",
343344
"72d699ac25327b32": "{count, plural, one {Se vinculó {count} pull request} other {Se vincularon {count} pull requests}}",
@@ -6449,7 +6450,6 @@
64496450
"bce5d650902cc4c1": "Abrir en el navegador de {environment}",
64506451
"6232b16804aa22c2": "Abrir en este equipo",
64516452
"4bfd0547f8b625bf": "No se puede mover la pestaña del navegador",
6452-
"4c060d82e9392799": "Cada ejecución inicia su hilo en la primera cuenta o modelo de la lista con al menos ese uso restante, o en el que tenga más si ninguno lo alcanza. Entradas: cuenta, cuenta/modelo o driver:kind. Vacío: el modelo de arriba, con los ajustes de cuenta automática.",
64536453
"a3aa54c6c5bd04e0": "No se puede actualizar la vista previa separada",
64546454
"7588b19c1e03be40": "No se puede copiar la ruta de la grabación",
64556455
"f1307c250974b2ba": "Grabación guardada",

‎apps/web/src/i18n/translations/fr.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, one {Tentative d’envoi de {attachments} pièce jointe} other {Tentative d’envoi de {attachments} pièces jointes}}",
339339
"cbba2216dafdd91d": "{count, plural, one {Pièces jointes envoyées {count} fois} other {Pièces jointes envoyées {count} fois}}",
340340
"f6589d3539e5e4b0": "{count, plural, one {Tentative d’envoi de pièces jointes {count} fois} other {Tentative d’envoi de pièces jointes {count} fois}}",
341+
"f658a09944ffe93e": "Chaque exécution démarre son fil sur le premier compte ou modèle de la liste ayant au moins cette utilisation restante ; sinon sur un compte sans données d’utilisation, à défaut sur celui qui en a le plus. Entrées : compte, compte/modèle ou driver:kind. Vide : le modèle ci-dessus, avec les réglages de compte automatique.",
341342
"bba19d414974a12c": "Pull requests associées",
342343
"3ab4b1ee5133f899": "Tentative d’association de pull requests",
343344
"72d699ac25327b32": "{count, plural, one {{count} pull request associée} other {{count} pull requests associées}}",
@@ -6450,7 +6451,6 @@
64506451
"bce5d650902cc4c1": "Ouvrir dans le navigateur de {environment}",
64516452
"6232b16804aa22c2": "Ouvrir sur cet ordinateur",
64526453
"4bfd0547f8b625bf": "Impossible de déplacer l’onglet du navigateur",
6453-
"4c060d82e9392799": "Chaque exécution démarre son fil sur le premier compte ou modèle de la liste ayant au moins cette utilisation restante, ou sur celui qui en a le plus si aucun ne l’atteint. Entrées : compte, compte/modèle ou driver:kind. Vide : le modèle ci-dessus, avec les réglages de compte automatique.",
64546454
"a3aa54c6c5bd04e0": "Impossible de mettre à jour l’aperçu détaché",
64556455
"7588b19c1e03be40": "Impossible de copier le chemin de l’enregistrement",
64566456
"f1307c250974b2ba": "Enregistrement sauvegardé",

‎apps/web/src/i18n/translations/ja.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, other {{attachments} 件の添付ファイルを送信しようとしました}}",
339339
"cbba2216dafdd91d": "{count, plural, other {添付ファイルを {count} 回送信しました}}",
340340
"f6589d3539e5e4b0": "{count, plural, other {添付ファイルを {count} 回送信しようとしました}}",
341+
"f658a09944ffe93e": "各実行は、残り使用量がこの値以上ある最初のアカウントまたはモデルでスレッドを開始します。どれも満たさない場合は使用量データのないもの、それもなければ残りが最も多いものを使います。エントリ: アカウント、アカウント/モデル、driver:kind。空欄の場合は、上のモデルを自動アカウント設定とともに使います。",
341342
"bba19d414974a12c": "リンクされたプルリクエスト",
342343
"3ab4b1ee5133f899": "プルリクエストをリンクしようとしました",
343344
"72d699ac25327b32": "{count, plural, other {{count} 件のプルリクエストをリンクしました}}",
@@ -6422,7 +6423,6 @@
64226423
"bce5d650902cc4c1": "{environment} のブラウザーで開く",
64236424
"6232b16804aa22c2": "このコンピューターで開く",
64246425
"4bfd0547f8b625bf": "ブラウザータブを移動できません",
6425-
"4c060d82e9392799": "各実行は、残り使用量がこの値以上ある最初のアカウントまたはモデルでスレッドを開始します。どれも満たさない場合は、残りが最も多いものを使います。エントリ: アカウント、アカウント/モデル、driver:kind。空欄の場合は、上のモデルを自動アカウント設定とともに使います。",
64266426
"a3aa54c6c5bd04e0": "ポップアウトしたプレビューを更新できません",
64276427
"7588b19c1e03be40": "録画のパスをコピーできません",
64286428
"f1307c250974b2ba": "録画を保存しました",

‎apps/web/src/i18n/translations/ko.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"8c2760322f4c65a0": "{attachments, plural, other {첨부 파일 {attachments}개 보내기 시도함}}",
339339
"cbba2216dafdd91d": "{count, plural, other {첨부 파일을 {count}회 보냄}}",
340340
"f6589d3539e5e4b0": "{count, plural, other {첨부 파일 보내기 {count}회 시도함}}",
341+
"f658a09944ffe93e": "각 실행은 남은 사용량이 이 값 이상인 첫 번째 계정 또는 모델에서 스레드를 시작합니다. 해당하는 항목이 없으면 사용량 데이터가 없는 항목, 그것도 없으면 남은 사용량이 가장 많은 항목에서 시작합니다. 항목: 계정, 계정/모델 또는 driver:kind. 비워 두면 위의 모델을 자동 계정 설정과 함께 사용합니다.",
341342
"bba19d414974a12c": "연결된 풀 리퀘스트",
342343
"3ab4b1ee5133f899": "풀 리퀘스트 연결 시도함",
343344
"72d699ac25327b32": "{count, plural, other {풀 리퀘스트 {count}개 연결함}}",
@@ -6421,7 +6422,6 @@
64216422
"bce5d650902cc4c1": "{environment}의 브라우저에서 열기",
64226423
"6232b16804aa22c2": "이 컴퓨터에서 열기",
64236424
"4bfd0547f8b625bf": "브라우저 탭을 이동할 수 없습니다",
6424-
"4c060d82e9392799": "각 실행은 남은 사용량이 이 값 이상인 첫 번째 계정 또는 모델에서 스레드를 시작합니다. 해당하는 항목이 없으면 남은 사용량이 가장 많은 항목에서 시작합니다. 항목: 계정, 계정/모델 또는 driver:kind. 비워 두면 위의 모델을 자동 계정 설정과 함께 사용합니다.",
64256425
"a3aa54c6c5bd04e0": "분리된 미리 보기를 업데이트할 수 없습니다",
64266426
"7588b19c1e03be40": "녹화 경로를 복사할 수 없습니다",
64276427
"f1307c250974b2ba": "녹화 저장됨",

0 commit comments

Comments
 (0)