Repository navigation
fix(server): preserve one-shot cooldown bypasses #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ import { | |
| import * as ProviderFailover from "./ProviderFailover.ts"; | ||
| import * as ProviderCooldown from "../provider/ProviderCooldown.ts"; | ||
| import * as KeyedLock from "@t3tools/shared/KeyedLock"; | ||
| import { modelSelectionsEqual } from "@t3tools/shared/model"; | ||
| import { draftModelPickMatchesThread, modelSelectionsEqual } from "@t3tools/shared/model"; | ||
| import { modelSwitchSince } from "./modelSwitch.ts"; | ||
| import { combinePullRequestWatchWakes, type PullRequestWatchWake } from "./pullRequestWatch.ts"; | ||
| import { recordThreadOpen } from "@t3tools/shared/paletteSearch"; | ||
|
|
@@ -1050,7 +1050,11 @@ function threadAtRunStart( | |
| ): OrchestrationV2ThreadProjection["thread"] { | ||
| const scheduled = projection.thread.scheduledModelSelection; | ||
| if (scheduled == null || starting.model === "server") return projection.thread; | ||
| const cleared = { ...projection.thread, scheduledModelSelection: null }; | ||
| const cleared = { | ||
| ...projection.thread, | ||
| scheduledModelSelection: null, | ||
| bypassProviderCooldown: false, | ||
| }; | ||
| if (starting.model === "named") { | ||
| return starting.ordinal !== null && starting.ordinal <= scheduled.queuedThroughOrdinal | ||
| ? projection.thread | ||
|
|
@@ -2529,6 +2533,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| (candidate) => candidate.id === storedQueuedRun.userMessageId, | ||
| ); | ||
| const requestedSelection = queuedRunModelSelection(projection, storedQueuedRun); | ||
| const recoveryRun = | ||
| storedQueuedRun.failoverOfRunId !== undefined || | ||
| storedQueuedRun.restartContinuationOfRunId !== undefined; | ||
| const consumesProviderCooldownBypass = | ||
| !recoveryRun && | ||
| (storedQueuedRun.explicitModelSelection !== true || | ||
| projection.thread.scheduledModelSelection == null || | ||
| storedQueuedRun.ordinal > | ||
| projection.thread.scheduledModelSelection.queuedThroughOrdinal) && | ||
| queuedMessage !== undefined && | ||
| ProviderFailover.resendable(queuedMessage) && | ||
| projection.thread.bypassProviderCooldown === true && | ||
| draftModelPickMatchesThread(requestedSelection, nextTurnModelSelection(projection.thread)); | ||
| const modelSelection = | ||
| queuedMessage === undefined | ||
| ? requestedSelection | ||
|
|
@@ -2540,13 +2557,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| run: { | ||
| ...storedQueuedRun, | ||
| bypassProviderCooldown: | ||
| storedQueuedRun.bypassProviderCooldown === true || | ||
| projection.thread.bypassProviderCooldown === true || | ||
| (projection.thread.scheduledModelSelection != null && | ||
| modelSelectionsEqual( | ||
| requestedSelection, | ||
| projection.thread.scheduledModelSelection.modelSelection, | ||
| )), | ||
| storedQueuedRun.bypassProviderCooldown === true || consumesProviderCooldownBypass, | ||
| }, | ||
| message: queuedMessage, | ||
| }); | ||
|
|
@@ -2739,8 +2750,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| const threadAtStart = threadAtRunStart(projection, { | ||
| runId: queuedRun.id, | ||
| ordinal: queuedRun.ordinal, | ||
| model: | ||
| queuedRun.explicitModelSelection !== true | ||
| model: recoveryRun | ||
| ? "server" | ||
| : queuedRun.explicitModelSelection !== true | ||
| ? "default" | ||
| : queuedMessage?.creationSource === "server" | ||
| ? "server" | ||
|
|
@@ -3216,7 +3228,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| [ | ||
| ...(selectionChanged || | ||
| threadAtStart !== projection.thread || | ||
| projection.thread.bypassProviderCooldown === true | ||
| consumesProviderCooldownBypass | ||
| ? [ | ||
| { | ||
| type: !selectionChanged | ||
|
|
@@ -3231,7 +3243,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| ...threadAtStart, | ||
| providerInstanceId: queuedRun.providerInstanceId, | ||
| modelSelection: queuedRun.modelSelection, | ||
| bypassProviderCooldown: false, | ||
| ...(consumesProviderCooldownBypass ? { bypassProviderCooldown: false } : {}), | ||
|
Comment on lines
3243
to
+3246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When scheduled selection B is pending and a later explicitly named queued run on A starts after the scheduling boundary, Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5d8bca8. threadAtRunStart clears bypassProviderCooldown whenever it clears or supersedes scheduledModelSelection, on both dispatch and queued starts. The scheduled-superseded regression proves the flag is cleared when a later explicit A replaces scheduled B; it failed before the repair and passes now. |
||
| updatedAt: now, | ||
| }, | ||
| }, | ||
|
|
@@ -5377,6 +5389,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| return { | ||
| ...thread, | ||
| scheduledModelSelection: providerSwitchPlan.scheduled, | ||
| bypassProviderCooldown: true, | ||
| updatedAt: now, | ||
| }; | ||
| } | ||
|
|
@@ -7929,30 +7942,33 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| ) { | ||
| modelSelection = queueTailModelSelection(projection); | ||
| } | ||
| const recoveryRun = | ||
| command.failoverOfRunId !== undefined || command.restartContinuationOfRunId !== undefined; | ||
| const resendablePrompt = ProviderFailover.resendable({ ...incomingMessage, role: "user" }); | ||
| const consumesProviderCooldownBypass = | ||
| !recoveryRun && | ||
| resendablePrompt && | ||
| projection.thread.bypassProviderCooldown === true && | ||
| draftModelPickMatchesThread(modelSelection, nextTurnModelSelection(projection.thread)); | ||
|
Comment on lines
+7948
to
+7952
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an automatic failover or restart continuation targets the same model as a pending scheduled pick, its copied user prompt passes Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5d8bca8. Failover and restart continuations cannot consume a pending bypass on dispatch or queued start, and schedule cleanup treats them as continuations too. The two failover and two restart cases assert an armed pick before recovery and its preservation afterward; all four failed before the repair and pass now.
Comment on lines
+7948
to
+7952
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an idle thread already has a one-shot bypass for selection B and the user sends a resendable prompt explicitly selecting C, this match is false, so Useful? React with 👍 / 👎. |
||
| const bypassProviderCooldown = | ||
| (command.modelSelection !== undefined && | ||
| !modelSelectionsEqual(command.modelSelection, projection.thread.modelSelection)) || | ||
| projection.thread.bypassProviderCooldown === true || | ||
| (projection.thread.scheduledModelSelection != null && | ||
| modelSelectionsEqual( | ||
| modelSelection, | ||
| projection.thread.scheduledModelSelection.modelSelection, | ||
| )); | ||
| if ( | ||
| command.failoverOfRunId === undefined && | ||
| command.restartContinuationOfRunId === undefined && | ||
| startsOrQueuesRun | ||
| ) { | ||
| (resendablePrompt && | ||
| command.modelSelection !== undefined && | ||
| !draftModelPickMatchesThread( | ||
| command.modelSelection, | ||
| nextTurnModelSelection(projection.thread), | ||
| )) || | ||
| consumesProviderCooldownBypass; | ||
| if (!recoveryRun && startsOrQueuesRun) { | ||
| modelSelection = yield* ProviderFailover.resolveProviderCooldownTarget({ | ||
| cooldown: providerCooldown, | ||
| settings: serverSettings, | ||
| projectId: projection.thread.projectId, | ||
| modelSelection, | ||
| run: { bypassProviderCooldown }, | ||
| message: { ...command, role: "user" }, | ||
| message: { ...incomingMessage, role: "user" }, | ||
| }); | ||
| } | ||
| if (projection.thread.bypassProviderCooldown === true && startsOrQueuesRun) { | ||
| if (consumesProviderCooldownBypass && startsOrQueuesRun) { | ||
| const now = yield* DateTime.now; | ||
| const event = yield* emit( | ||
| events, | ||
|
|
@@ -8383,8 +8399,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | |
| const threadAtStart = threadAtRunStart(projection, { | ||
| runId: null, | ||
| ordinal: null, | ||
| model: | ||
| command.modelSelection === undefined | ||
| model: recoveryRun | ||
| ? "server" | ||
| : command.modelSelection === undefined | ||
| ? "default" | ||
| : command.creationSource === "server" | ||
| ? "server" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an explicitly modeled queued run predates a scheduled change but happens to name the same selection, model equality here consumes the scheduled bypass even though
threadAtRunStartcorrectly keeps the schedule pending through that older run. The queued run already has its own explicit-pick bypass, so when the selected provider is cooling, the first default turn after the preexisting queue is incorrectly routed to the fallback. Only consume the scheduled bypass for a run that actually follows or supersedes the scheduled selection boundary.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 5d8bca8. An explicit queued run at or before queuedThroughOrdinal keeps its own run bypass and cannot claim the later scheduled bypass. The scheduled-older-explicit regression verifies that the pick survives that run and is consumed once by the next default prompt; it failed before the repair and passes now.