mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-27 10:45:29 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6390a85d1 |
@@ -80,7 +80,9 @@ Provider checks follow the signals their runtimes expose:
|
||||
- Codex queries background terminals for loaded threads, including native children, and protects
|
||||
pending provider requests. App servers without the terminal-list RPC stay resident.
|
||||
- OpenCode checks active executions and descendants. V1 checks PTYs; v2 also checks shell and
|
||||
inbox inventories. The shared server remains leased while a session vetoes collection.
|
||||
inbox inventories. The shared server remains leased while a session vetoes collection. V2 lets
|
||||
another session's execution veto only when releasing the lease would stop the server; the shared
|
||||
server stays up after its last lease goes.
|
||||
- Pi checks streaming, compaction, pending replies, and adapter-owned operations. Known native
|
||||
subagent signals also protect their parent through the daemon's subagent store.
|
||||
- OMP additionally requires `get_state.isSettled: true` and `hasPendingAsyncWork: false`.
|
||||
|
||||
@@ -32,6 +32,7 @@ export class V2Harness {
|
||||
readonly environments: Array<{ sessionID: string; variables: Record<string, string> }> = [];
|
||||
readonly instructions = new Map<string, string>();
|
||||
releases = 0;
|
||||
releaseStopsServer = false;
|
||||
active = false;
|
||||
activeReads = 0;
|
||||
autoComplete = true;
|
||||
@@ -250,6 +251,7 @@ export class V2Harness {
|
||||
this.releases += 1;
|
||||
},
|
||||
retain: () => this.connection,
|
||||
releaseStopsServer: () => this.releaseStopsServer,
|
||||
exited: new Promise<Error>(() => undefined),
|
||||
};
|
||||
readonly runtime = { acquire: async () => this.connection, shutdown: async () => undefined };
|
||||
|
||||
@@ -2130,7 +2130,7 @@ describe("OpenCode v2 session lifecycle", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("OpenCode v2 runtime safety retains shells, queued reports and shared executions", async () => {
|
||||
test("OpenCode v2 runtime safety retains shells, queued reports and its own executions", async () => {
|
||||
const harness = new V2Harness();
|
||||
const client = new OpenCodeV2AgentClient({
|
||||
logger: createTestLogger(),
|
||||
@@ -2168,9 +2168,7 @@ test("OpenCode v2 runtime safety retains shells, queued reports and shared execu
|
||||
];
|
||||
expect(await session.canStopRuntime!()).toBe(false);
|
||||
harness.api.session.inbox.list = async () => [];
|
||||
harness.api.session.active = async () => ({
|
||||
"unrelated-autonomous-session": { type: "running" },
|
||||
});
|
||||
harness.api.session.active = async () => ({ [session.id!]: { type: "running" } });
|
||||
expect(await session.canStopRuntime!()).toBe(false);
|
||||
harness.api.session.active = async () => ({});
|
||||
expect(await session.canStopRuntime!()).toBe(true);
|
||||
@@ -2183,6 +2181,27 @@ test("OpenCode v2 runtime safety retains shells, queued reports and shared execu
|
||||
}
|
||||
});
|
||||
|
||||
test("OpenCode v2 runtime safety vetoes another session's execution only when the release stops the server", async () => {
|
||||
const harness = new V2Harness();
|
||||
const client = new OpenCodeV2AgentClient({
|
||||
logger: createTestLogger(),
|
||||
runtime: harness.runtime,
|
||||
});
|
||||
const session = await client.createSession({ provider: "opencode", cwd: "/tmp/project" });
|
||||
try {
|
||||
harness.api.session.active = async () => ({
|
||||
"unrelated-autonomous-session": { type: "running" },
|
||||
});
|
||||
// The shared server keeps running after this lease goes, so the other execution is safe.
|
||||
expect(await session.canStopRuntime!()).toBe(true);
|
||||
// Releasing the last lease of a dedicated server stops it, with the other execution inside.
|
||||
harness.releaseStopsServer = true;
|
||||
expect(await session.canStopRuntime!()).toBe(false);
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("OpenCode v2 runtime safety follows descendant locations before releasing the last lease", async () => {
|
||||
const harness = new V2Harness();
|
||||
const child = {
|
||||
|
||||
@@ -125,9 +125,15 @@ test("a wrapped caller gets its own helper behind the wrap, and other callers ke
|
||||
expect(launched.profile).toBe("agent");
|
||||
expect(launched.argv.slice(0, 4)).toEqual(["--profile", process.execPath, script, "serve"]);
|
||||
|
||||
const wrappedAgain = wrapped.retain();
|
||||
expect(wrapped.releaseStopsServer()).toBe(false);
|
||||
await wrappedAgain.release();
|
||||
expect(wrapped.releaseStopsServer()).toBe(true);
|
||||
await wrapped.release();
|
||||
await expect(wrapped.exited).resolves.toBeInstanceOf(Error);
|
||||
await shared.release();
|
||||
// The shared helper stays up for the next caller after its last lease goes.
|
||||
expect(sharedAgain.releaseStopsServer()).toBe(false);
|
||||
await sharedAgain.release();
|
||||
} finally {
|
||||
await runtime.shutdown();
|
||||
|
||||
@@ -37,6 +37,8 @@ export interface V2Connection {
|
||||
client: V2Api;
|
||||
release(): Promise<void>;
|
||||
retain(): V2Connection;
|
||||
/** True when releasing this lease would stop the server, with every execution inside it. */
|
||||
releaseStopsServer(): boolean;
|
||||
bindSession(sessionId: string, cwd: string): Promise<void>;
|
||||
unbindSession(sessionId: string, cwd: string): Promise<void>;
|
||||
refreshLocation(cwd: string, signal?: AbortSignal): Promise<void>;
|
||||
@@ -174,6 +176,7 @@ export class V2Runtime {
|
||||
client: generation.client,
|
||||
release,
|
||||
retain: () => this.lease(generation, pending),
|
||||
releaseStopsServer: () => !released && generation.users === 1 && this.current !== pending,
|
||||
bindSession: generation.bindSession,
|
||||
unbindSession: generation.unbindSession,
|
||||
refreshLocation: generation.refreshLocation,
|
||||
|
||||
@@ -751,12 +751,14 @@ export class OpenCodeV2Session implements AgentSession {
|
||||
if (this.closed || this.exited || this.reconnecting || this.turns.id || this.dirty)
|
||||
return false;
|
||||
const request = { signal: AbortSignal.timeout(10_000) };
|
||||
// Active executions are server-wide. Releasing the last lease must not stop an
|
||||
// autonomous execution merely because it belongs to another session or location.
|
||||
if (Object.keys(await this.client.session.active(request)).length > 0) return false;
|
||||
const active = await this.client.session.active(request);
|
||||
// Releasing the last lease of a server stops it, so it must not stop an autonomous
|
||||
// execution merely because it belongs to another session or location.
|
||||
if (this.connection.releaseStopsServer() && Object.keys(active).length > 0) return false;
|
||||
const family = new Map([[this.info.id, this.info]]);
|
||||
const directories = new Set<string>();
|
||||
for (const info of family.values()) {
|
||||
if (active[info.id]) return false;
|
||||
if ((await this.client.session.inbox.list({ sessionID: info.id }, request)).length)
|
||||
return false;
|
||||
directories.add(info.location.directory);
|
||||
|
||||
Reference in New Issue
Block a user