Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ describe("DesktopPreReadyPlatform", () => {
});
assert.deepEqual(events, ["pre-ready", "clerk"]);
assert.equal(registerSchemesMock.mock.calls.length, 1);
assert.equal(appendSwitchMock.mock.calls.length, 0);
// SCIENT-FORK:START — outside Linux, the only switch turns off soft-navigation detection.
assert.deepEqual(appendSwitchMock.mock.calls, [
["disable-features", "SoftNavigationDetection"],
]);
// SCIENT-FORK:END
assert.equal(setDesktopNameMock.mock.calls.length, 0);
}),
);
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/app/DesktopPreReadyPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { enableAutomaticSpellingLanguages } from "../scient/spelling/macSpelling
// SCIENT-FORK:START — development builds can trust a local test site's certificate.
import { developmentTrustedCertificates } from "../scient/browser/developmentCertificates.ts";
// SCIENT-FORK:END
// SCIENT-FORK:START — soft-navigation detection can crash a renderer.
import { disableFeaturesWithSoftNavigation } from "../scient/chromium/softNavigation.ts";
// SCIENT-FORK:END

export interface DesktopPreReadyCommandLineReader {
readonly hasSwitch: (switchName: string) => boolean;
Expand Down Expand Up @@ -203,6 +206,15 @@ export const make = Effect.gen(function* () {
}
}

// SCIENT-FORK:START — soft-navigation detection can crash a renderer, on every platform.
// Runs after the Linux merge: Chromium keeps only the last --disable-features value.
const disableFeatures = disableFeaturesWithSoftNavigation(
readCommandLineSwitchValue(Electron.app.commandLine, "disable-features"),
);
if (disableFeatures !== null)
Electron.app.commandLine.appendSwitch("disable-features", disableFeatures);
// SCIENT-FORK:END

return { linux, linuxPasswordStoreCommandLine };
});
}).pipe(Effect.withSpan("desktop.electron.configureBeforeReady"));
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src/scient/chromium/softNavigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from "@effect/vitest";

import { disableFeaturesWithSoftNavigation } from "./softNavigation.ts";

describe("disableFeaturesWithSoftNavigation", () => {
it("adds the feature and keeps features already disabled", () => {
expect(disableFeaturesWithSoftNavigation(null)).toBe("SoftNavigationDetection");
expect(disableFeaturesWithSoftNavigation("WaylandWpColorManagerV1")).toBe(
"WaylandWpColorManagerV1,SoftNavigationDetection",
);
expect(disableFeaturesWithSoftNavigation("A,SoftNavigationDetection")).toBeNull();
});
});
20 changes: 20 additions & 0 deletions apps/desktop/src/scient/chromium/softNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Chromium 152 stops a renderer when a route-changing input event predates the page's load
* (`CHECK_GT` in `SoftNavigationHeuristics`); macOS passes posted events' timestamps through
* unchecked. Scient reads no soft-navigation timing, so detection is off.
*/
const SOFT_NAVIGATION_FEATURE = "SoftNavigationDetection";

/**
* The `--disable-features` value that also turns off soft-navigation detection, keeping the
* features already listed (Chromium keeps only the last value of the switch), or null when it is
* already listed.
*/
export function disableFeaturesWithSoftNavigation(current: string | null): string | null {
const names = (current ?? "")
.split(",")
.map((name) => name.trim())
.filter((name) => name.length > 0);
if (names.some((name) => name.split("<")[0] === SOFT_NAVIGATION_FEATURE)) return null;
return [...names, SOFT_NAVIGATION_FEATURE].join(",");
}
2 changes: 2 additions & 0 deletions apps/desktop/src/window/DesktopWindow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ describe("DesktopWindow", () => {
type: "scientAppHealth",
component: "renderer",
failureClass: "resource-exhaustion",
exitReason: "oom",
exitCode: 137,
},
]);
}).pipe(Effect.provide(layer));
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/window/DesktopWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@ export const make = Effect.gen(function* () {
type: "scientAppHealth",
component: "renderer",
failureClass: details.reason === "oom" ? "resource-exhaustion" : "process-crash",
// `recoverable` admitted only these reasons.
exitReason: details.reason as "crashed" | "oom" | "killed" | "abnormal-exit",
exitCode: details.exitCode,
})
.pipe(Effect.ignoreCause()),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ export interface NativeSession {
input: ProviderAdapter.ProviderAdapterV2TurnInput,
nativeTurnId: string,
) => Effect.Effect<void, NativeSessionOperationError>;
/** Sent as the prompt of a manual continuation by a protocol that cannot continue without one. */
readonly continuationPrompt?: string;
readonly steer?: (
input: ProviderAdapter.ProviderAdapterV2SteerInput,
validateOwner?: () => Effect.Effect<void, NativeSessionOperationError>,
Expand Down Expand Up @@ -1962,6 +1964,7 @@ export function makeNativeSessionAdapterV2(
// SCIENT-FORK:END
const steer = native.steer;
const compact = native.compact;
const continuationPrompt = native.continuationPrompt;
const startTurn = Effect.fn("NativeSessionAdapterV2.startTurn")(
function* (
request: ProviderAdapter.ProviderAdapterV2TurnInput,
Expand Down Expand Up @@ -2210,6 +2213,17 @@ export function makeNativeSessionAdapterV2(
),
),
startTurn: (request) => startTurn(request, native.send),
...(continuationPrompt === undefined
? {}
: {
resumeTurn: (request: ProviderAdapter.ProviderAdapterV2ResumeTurnInput) => {
const turn = ProviderAdapter.resumeTurnInput(request);
return startTurn(
{ ...turn, message: { ...turn.message, text: continuationPrompt } },
native.send,
);
},
}),
...(compact === undefined
? {}
: {
Expand Down
57 changes: 57 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/OmpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,63 @@ it.layer(TestLayer)("OmpAdapterV2", (it) => {
}),
),
);
it.effect("continues a turn that ended early by prompting, since the RPC has no resume", () =>
Effect.scoped(
Effect.gen(function* () {
const peer = scriptedOmpRpc({
models: [{ provider: "test", id: "selected", input: ["text"], contextWindow: null }],
initial: { provider: "test", id: "selected" },
});
const h = yield* harness(false, {
makeProcess: peer.makeProcess,
target: scientAgentTarget,
});
const { message, ...turn } = h.input;
if (h.runtime.resumeTurn === undefined)
return yield* Effect.die("Scient Agent offers no manual continuation");
yield* h.runtime.resumeTurn({ ...turn, messageId: message.messageId });
yield* peer.finish();
const terminal = yield* h.takeUntil((event) => event.type === "turn.terminal");
assert.deepInclude(terminal, { status: "completed" });
assert.deepEqual(
peer.state.prompts.map((prompt) => [prompt.frame.type, prompt.frame.message]),
[["prompt", "Continue where you left off."]],
);
}),
),
);
it.effect("asks for the model catalog again once when a turn's discovery times out", () =>
Effect.scoped(
Effect.gen(function* () {
const silenced = yield* Deferred.make<void>();
let silenceNextDiscovery = false;
const discovery = (frame: { readonly type: string }) => {
if (frame.type !== "get_available_models" || !silenceNextDiscovery) return false;
silenceNextDiscovery = false;
return true;
};
const h = yield* modelHarness({
silentReply: discovery,
holdReply: (frame) =>
frame.type === "get_available_models" && silenceNextDiscovery
? Deferred.succeed(silenced, undefined).pipe(Effect.asVoid)
: Effect.void,
});
silenceNextDiscovery = true;
const starting = yield* h.start(1, "vendor/a", "high").pipe(Effect.forkScoped);
yield* Deferred.await(silenced);
yield* TestClock.adjust("30 seconds");
yield* Fiber.join(starting).pipe(Effect.timeout("2 seconds"), TestClock.withLive);
yield* h.peer.finish();
const terminal = yield* h.terminal();
assert.deepInclude(terminal, { status: "completed" });
assert.equal(
h.peer.state.log.filter((entry) => entry.startsWith("get_available_models")).length,
2,
);
}),
),
);
it.effect.each([
{
caseTitle: "carries the usage-limit reset time Scient Agent reports",
Expand Down
14 changes: 12 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/OmpAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ export const makeOmpAdapterV2 = Effect.fn("makeOmpAdapterV2")(function* (
catalogCurrent = true;
return available;
});
// A turn that needs the catalog asks again once after a timeout; the late first reply is ignored.
const refreshCatalogForTurn = () =>
refreshCatalog().pipe(
Effect.retry({
times: 1,
while: (cause) => cause._tag === "OmpRpcCommandError" && cause.code === "timeout",
}),
);

const home = expandHomePath(
options.homePath?.trim() ||
Expand Down Expand Up @@ -1648,7 +1656,7 @@ export const makeOmpAdapterV2 = Effect.fn("makeOmpAdapterV2")(function* (
model.input !== undefined,
)
)
yield* refreshCatalog().pipe(
yield* refreshCatalogForTurn().pipe(
Effect.mapError(
() =>
new NativeSessionOperationError({
Expand Down Expand Up @@ -1968,7 +1976,7 @@ export const makeOmpAdapterV2 = Effect.fn("makeOmpAdapterV2")(function* (
breaksSession: false,
});
if (level !== undefined) {
const available = yield* refreshCatalog();
const available = yield* refreshCatalogForTurn();
const selectedModel = available.models.find(
(candidate) =>
candidate.provider === model.provider && candidate.id === model.modelId,
Expand Down Expand Up @@ -2246,6 +2254,8 @@ export const makeOmpAdapterV2 = Effect.fn("makeOmpAdapterV2")(function* (
// SCIENT-FORK: a spoken conversation through Scient Agent's ChatGPT sign-in.
...(target.driverKind === "scient" ? { liveVoice: liveVoice.runtime } : {}),
interrupt: interrupt().pipe(Effect.mapError(safeFailure)),
// The RPC has no message-less continue, so Continue after a limit or Stop asks for one.
continuationPrompt: "Continue where you left off.",
resume,
rewindBefore: Effect.fn("OmpAdapterV2.rewindBefore")(
function* (entryId: string) {
Expand Down
96 changes: 96 additions & 0 deletions apps/server/src/provider/omp/OmpSessionRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,102 @@ describe("Oh My Pi session runtime outcomes", () => {
);
}

it.effect("a later run that recovers in the same turn outweighs the prompt's failed run", () =>
Effect.gen(function* () {
const h = yield* wireHarness();
yield* h.runtime.begin("recovered");
yield* h.runtime.accepted("prompt-recovered", true);
// The prompt's run gives up; a background result wakes the agent before the turn settles.
yield* h.wire.send(
{ type: "agent_start" },
assistantEnd({ stopReason: "error", errorMessage: "Couldn't reach chatgpt.com" }),
{ type: "auto_retry_end", success: false, attempt: 10, finalError: "Retry budget spent" },
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
{
type: "prompt_result",
id: "prompt-recovered",
agentInvoked: true,
status: "error",
error: { message: "Couldn't reach chatgpt.com", retryable: true, kinds: ["transient"] },
sessionSettled: false,
},
{ type: "agent_start" },
assistantEnd({ stopReason: "stop", content: [{ type: "text", text: "done" }] }),
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
);
const outcome = yield* h.outcome;
yield* Scope.close(h.scope, Exit.void);
expect(outcome).toEqual({
type: "turn-outcome",
outcome: "completed",
requestId: "prompt-recovered",
});
}),
);

it.effect("a later run that fails too keeps the prompt's usage limit and reset time", () =>
Effect.gen(function* () {
const h = yield* wireHarness();
yield* h.runtime.begin("limited");
yield* h.runtime.accepted("prompt-limited", true);
const limited = assistantEnd({ stopReason: "error", errorMessage: "429 rate limited" });
yield* h.wire.send(
{ type: "agent_start" },
limited,
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
{
type: "prompt_result",
id: "prompt-limited",
agentInvoked: true,
status: "error",
error: {
message: "429 rate limited",
retryable: false,
httpStatus: 429,
resetAt: Date.UTC(2026, 10, 17),
},
sessionSettled: false,
},
{ type: "agent_start" },
limited,
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
);
const outcome = yield* h.outcome;
yield* Scope.close(h.scope, Exit.void);
expect(outcome).toMatchObject({
outcome: "failed",
failureClass: "usage_limit",
resetAt: "2026-11-17T00:00:00.000Z",
});
}),
);

it.effect("a later run that fails after the prompt's run succeeded fails the turn", () =>
Effect.gen(function* () {
const h = yield* wireHarness();
yield* h.runtime.begin("woken");
yield* h.runtime.accepted("prompt-woken", true);
yield* h.wire.send(
{ type: "agent_start" },
assistantEnd({ stopReason: "stop", content: [{ type: "text", text: "started a job" }] }),
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
{
type: "prompt_result",
id: "prompt-woken",
agentInvoked: true,
status: "completed",
sessionSettled: false,
},
{ type: "agent_start" },
assistantEnd({ stopReason: "error", errorMessage: "Couldn't reach chatgpt.com" }),
{ type: "agent_end", messages: [], isTerminal: true, yielded: true },
);
const outcome = yield* h.outcome;
yield* Scope.close(h.scope, Exit.void);
expect(outcome).toMatchObject({ outcome: "failed", detail: "Couldn't reach chatgpt.com" });
}),
);

it.effect("a late prompt_result of a settled turn does not decide the next one", () =>
Effect.gen(function* () {
const h = yield* wireHarness();
Expand Down
Loading
Loading