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
1 change: 1 addition & 0 deletions SCIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Everything else is upstream's code and behavior.
| Symbol | The sign-in page every browser sign-in ends on and the `stats` dashboard show Scient Agent's symbol (`packages/utils/src/scient/scient-agent-symbol.svg.txt`, the file Scient Desktop shows for the agent; copy it over when the symbol changes) in Scient's colors. |
| Shared workers | The tiny model worker, the embedding server and word prediction run in Oh My Pi's per-user daemon. The daemon's build carries Scient Agent's release, not the upstream package version, so a new Scient Agent release has an older release's daemon re-exec into it, which replaces its workers. |
| Daemon leases | A client that disconnects while Oh My Pi's per-user daemon is still starting a unit for it (a language server, a worker, a background process) no longer leaves that unit running for good: its lease is dropped as on any lost connection, after the usual reconnect grace. Offered to Oh My Pi as [#20263](https://github.com/can1357/oh-my-pi/pull/20263); to be realigned at the next alignment, retired if Oh My Pi merges it or replaced by Oh My Pi's own fix. |
| Language server reservations | A client that disconnects while the daemon resolves its working directory leaves the language server available for the next client. Offered to Oh My Pi as [#20277](https://github.com/can1357/oh-my-pi/pull/20277). At the next alignment, retire this change if Oh My Pi merged it or replace it with Oh My Pi's fix. |
| Updates | `scient-agent update` only updates plugins. The startup update check and the startup marketplace refresh are off, and Oh My Pi's background auto-update is never offered or started. A host or installer replaces the executable. |
| Reporting | Automatic tool-issue reports to OMP's service are off by default. |
| Shell traces | The bash tool records no execution trace unless the user turns `display.shellVisualization` on. Scient Agent's host draws no shell visualization, and every live frame of a running command would carry the whole trace, up to megabytes. |
Expand Down
18 changes: 17 additions & 1 deletion packages/coding-agent/src/daemon/modules/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import {
import type { LspJsonRpcId, LspJsonRpcNotification, LspJsonRpcRequest, LspJsonRpcResponse } from "../../lsp/types";
import { uriToFile } from "../../lsp/utils";
import { advertisesWatchedFiles, WATCHED_FILES_METHOD, WatchedFilesForwarder } from "../../lsp/watched-files";
// scient(SA-LSP-ACQUIRE-DISCONNECT): begin - Track LSP requests while their working directory resolves.
import { cancelLspAcquires, trackLspAcquire } from "../../scient/lsp-acquire";
// scient(SA-LSP-ACQUIRE-DISCONNECT): end
import type {
DaemonModule,
ManagedChild,
Expand Down Expand Up @@ -823,7 +826,17 @@ class LspServerUnit implements ModuleUnit {
async function acquire(context: ModuleContext, params: unknown, client: ModuleClient): Promise<LspAcquireResult> {
const server = ServerParams(params);
if (server instanceof type.errors) throw new Error(`invalid lsp acquire params: ${server.summary}`);
const scope = projectScope(await canonicalDir(server.cwd));
// scient(SA-LSP-ACQUIRE-DISCONNECT): begin - A client that disconnected while its cwd resolved gets no reservation: it would hold the key until it expires.
const pending = trackLspAcquire(client.connectionId);
let dir: string;
try {
dir = await canonicalDir(server.cwd);
} finally {
pending.finish();
}
pending.assertConnected();
const scope = projectScope(dir);
// scient(SA-LSP-ACQUIRE-DISCONNECT): end
const identity = muxServerKey(server);
// Synchronous from here: concurrent acquires each see the previous one's reservation.
for (let index = 0; ; index++) {
Expand Down Expand Up @@ -889,6 +902,9 @@ export const lspModule: DaemonModule = {
return new LspServerUnit({ child, slot: restored.slot, cwd: restored.cwd, label: restored.label, restored });
},
disconnected(client) {
// scient(SA-LSP-ACQUIRE-DISCONNECT): begin - Acquires of this client still resolving their cwd reserve nothing.
cancelLspAcquires(client.connectionId);
// scient(SA-LSP-ACQUIRE-DISCONNECT): end
for (const [slot, reservation] of reservations) {
if (reservation.connectionId === client.connectionId) releaseReservation(slot);
}
Expand Down
35 changes: 35 additions & 0 deletions packages/coding-agent/src/scient/lsp-acquire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
interface AcquireState {
disconnected: boolean;
}

interface PendingAcquire {
finish(): void;
assertConnected(): void;
}

const pendingAcquires = new Map<string, Set<AcquireState>>();

/** Track a request until its working directory resolves. */
export function trackLspAcquire(connectionId: string): PendingAcquire {
const pending = { disconnected: false };
const acquires = pendingAcquires.get(connectionId) ?? new Set<AcquireState>();
acquires.add(pending);
pendingAcquires.set(connectionId, acquires);

return {
finish() {
acquires.delete(pending);
if (acquires.size === 0 && pendingAcquires.get(connectionId) === acquires) {
pendingAcquires.delete(connectionId);
}
},
assertConnected() {
if (pending.disconnected) throw new Error("lsp acquire: client disconnected");
},
};
}

export function cancelLspAcquires(connectionId: string): void {
for (const pending of pendingAcquires.get(connectionId) ?? []) pending.disconnected = true;
pendingAcquires.delete(connectionId);
}
39 changes: 39 additions & 0 deletions packages/coding-agent/test/scient/lsp-acquire-disconnect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* An `lsp` acquire whose client disconnects while the acquire is still resolving its cwd
* reserves nothing: the instance key stays free for the next client (SA-LSP-ACQUIRE-DISCONNECT).
*/
import { afterEach, describe, expect, it } from "bun:test";
import * as os from "node:os";
import type { ModuleClient, ModuleContext } from "../../src/daemon/module";
import { lspModule } from "../../src/daemon/modules/lsp";
import { LSP_ACQUIRE_METHOD, type LspAcquireResult, lspInstanceKey, muxServerKey } from "../../src/lsp/mux/protocol";

const SERVER = { command: "fake-language-server", args: [], cwd: os.tmpdir() };

/** No units yet: every instance key is free unless reserved. */
const context = { unit: () => undefined } as unknown as ModuleContext;

function client(): ModuleClient {
return { connectionId: crypto.randomUUID(), pid: 0, build: "" };
}

function acquire(from: ModuleClient): Promise<LspAcquireResult> {
return lspModule.call!(context, LSP_ACQUIRE_METHOD, SERVER, from, undefined) as Promise<LspAcquireResult>;
}

afterEach(async () => {
await lspModule.dispose?.();
});

describe("lsp acquire after its client disconnected", () => {
it("reserves nothing for a client that disconnected while its acquire resolved the cwd", async () => {
const gone = client();
const abandoned = acquire(gone);
lspModule.disconnected!(gone);
await expect(abandoned).rejects.toThrow();

// The first instance is free for the next client, not held by an abandoned reservation.
const next = await acquire(client());
expect(next.key).toBe(lspInstanceKey(muxServerKey(SERVER), 0));
});
});
14 changes: 14 additions & 0 deletions scripts/scient/divergences.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@
"bun --cwd=packages/coding-agent test test/scient/daemon-open-lease.test.ts"
]
},
"SA-LSP-ACQUIRE-DISCONNECT": {
"status": "active",
"contract": "A client that disconnects while an LSP acquire resolves its working directory leaves the first free instance key available for the next client. Offered to Oh My Pi as https://github.com/can1357/oh-my-pi/pull/20277. At the next alignment, retire this contract as upstreamed if Oh My Pi merged the fix, or replace it with Oh My Pi's own fix if it fixed this differently.",
"owned": [
"packages/coding-agent/src/scient/lsp-acquire.ts",
"packages/coding-agent/test/scient/lsp-acquire-disconnect.test.ts"
],
"upstream": [
"packages/coding-agent/src/daemon/modules/lsp.ts"
],
"verification": [
"bun --cwd=packages/coding-agent test test/scient/lsp-acquire-disconnect.test.ts test/daemon/lsp-module.test.ts"
]
},
"SA-DAEMON-REJOIN": {
"status": "active",
"contract": "Oh My Pi's daemon test \"a client reconnecting within the grace adopts the same process\" reopens the unit only after describe shows the daemon dropped the closed connection's lease, as the grace test above it waits. The harness's close() settles when the client socket closes, before the daemon handles the close, so the open could be counted beside the stale lease (leases 2), which failed Scient's main on 2026-11-22. Test-only; the daemon's connection-bound lease accounting is unchanged. This inherited flake needs an upstream fix.",
Expand Down
Loading