fix(server): an OMP replacement runtime starts with the Fast the session has now

A restart (for example an approval-mode change) restored Fast from the options the session opened with, turning back on a Fast the user had switched off. The session now keeps the Fast it applied or the provider changed, which is what a replacement reads.
This commit is contained in:
Mohamed Boudra
2026-11-01 18:57:05 +01:00
parent e4d4ba7489
commit 593773a381
2 changed files with 23 additions and 0 deletions
@@ -753,6 +753,20 @@ describe("OMP agent client and session", () => {
]);
});
test("a replacement runtime starts with the Fast the session has now, not the one it opened with", async () => {
const omp = new OmpHarness();
await omp.start({ modeId: "full", providerOptions: { fast_mode: true } });
const session = omp.requireSession();
omp.runtime().fastModeResult = { enabled: false, active: false };
await session.applyOptions?.({ fast_mode: false });
await omp.setMode("ask");
// The approval-mode restart starts a second runtime; it must not turn Fast back on.
expect(omp.runtimeLaunches()).toHaveLength(2);
expect(omp.runtime().setFastModeRequests).toEqual([]);
});
test("restores Fast from the initial OMP state on create and resume", async () => {
const created = new OmpHarness();
await created.start({ providerOptions: { fast_mode: true } });
@@ -847,9 +847,17 @@ export class OmpAgentSession implements AgentSession {
fastModeActive: result.active,
};
}
if (typeof this.state.fastModeEnabled === "boolean") {
this.rememberFastMode(this.state.fastModeEnabled);
}
return this.fastModeDifference(requested);
}
/** A replacement runtime starts from the Fast the session has now, not the one it opened with. */
private rememberFastMode(enabled: boolean): void {
this.config.providerOptions = { ...this.config.providerOptions, fast_mode: enabled };
}
/** The option patch when the runtime's fast mode is not what `given` stands for; unset is off. */
private fastModeDifference(given: unknown): Record<string, unknown> {
if (!hasOmpFastMode(this.state)) return {};
@@ -2257,6 +2265,7 @@ export class OmpAgentSession implements AgentSession {
const before = this.state.fastModeEnabled;
this.state = await this.runtimeSession.getState();
if (this.state.fastModeEnabled !== before && typeof this.state.fastModeEnabled === "boolean") {
this.rememberFastMode(this.state.fastModeEnabled);
this.emit({
type: "options_changed",
provider: this.provider,