fix(server): reset OMP Fast to its starting value only when a held option is removed

Every options patch without fast_mode reset Fast to the value it had when the session started, so an unrelated patch undid a model family's own Fast setting. The reset now applies only when a fast_mode option that was held becomes absent.
This commit is contained in:
Mohamed Boudra
2026-11-01 10:31:28 +01:00
parent 822388e2f3
commit ba4348ee73
2 changed files with 27 additions and 2 deletions
@@ -659,6 +659,29 @@ describe("OMP agent client and session", () => {
expect(omp.runtime().setFastModeRequests).toEqual([true, false]);
});
test("an options patch that never held fast_mode leaves the runtime's Fast setting alone", async () => {
const omp = new OmpHarness();
await omp.start({ model: "openai/gpt-5" });
const session = omp.requireSession();
expect(omp.runtime().state.fastModeEnabled).toBe(false);
// Another model family has Fast on natively.
omp.runtime().setModelResult = { provider: "anthropic", id: "claude-x" };
omp.runtime().queueStateReports([
{
...omp.runtime().state,
model: omp.runtime().setModelResult,
fastModeEnabled: true,
fastModeActive: true,
},
]);
await session.setModel?.("anthropic/claude-x");
await session.applyOptions?.({ rpcTimeoutMs: 120000 });
expect(omp.runtime().setFastModeRequests).toEqual([]);
});
test("shows Fast only when OMP reports its state fields", async () => {
const omp = new OmpHarness();
await omp.start();
@@ -834,8 +834,10 @@ export class OmpAgentSession implements AgentSession {
if (requested !== undefined && typeof requested !== "boolean") {
throw new Error("OMP fast mode requires a boolean");
}
// An absent option means the runtime's own setting at session start.
const target = requested ?? this.fastModeBaseline;
// Removing a held option returns Fast to the runtime's own setting at session start; an
// option that was already absent leaves whatever the runtime reports alone.
const removed = requested === undefined && this.config.providerOptions?.fast_mode !== undefined;
const target = removed ? this.fastModeBaseline : requested;
if (target !== undefined && target !== this.state.fastModeEnabled) {
if (!hasOmpFastMode(this.state)) throw new Error("OMP fast mode is unavailable");
const result = await this.runtimeSession.setFastMode(target);