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
3 changes: 2 additions & 1 deletion pkgs/mcpx/plugin/opencode/mcpx-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export default (async ({ directory, worktree, project, client }, options) => {
};
const forget = () => {
found = undefined;
missedAt = Date.now();
// A transient daemon failure is not a discovery miss; retry immediately.
missedAt = 0;
};

// One discovery at boot, awaited.
Expand Down
49 changes: 49 additions & 0 deletions pkgs/mcpx/plugin/opencode/v2/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,55 @@ describe("rediscovery precedence", () => {
await rt.look();
expect(rememberedSeen).toEqual([targetKey(picked)]);
});

test("a transient failure immediately rediscovers at the default miss cooldown", async () => {
let discoverCalls = 0;
let failExec = true;
const rt = runtime({
discoverFn: async () => {
discoverCalls += 1;
return discoveryWith([candidate(socketTarget)]);
},
clientFor: () =>
fakeClient({
exec: async () => {
if (failExec) {
failExec = false;
throw new Error("daemon went away");
}
return { output: "recovered through daemon" };
},
}),
});
const exec = rt.tools().find((t) => t.name === "exec")!;

await expect(
exec.execute({ source: "1" } as never, { sessionID: "s1" }),
).rejects.toThrow();
expect(discoverCalls).toBe(1);

const recovered = await exec.execute(
{ source: "1" } as never,
{ sessionID: "s1" },
);
expect(recovered.content).toContain("recovered through daemon");
expect(discoverCalls).toBe(2);
});

test("a genuine discovery miss still observes the default cooldown", async () => {
let discoverCalls = 0;
const rt = runtime({
discoverFn: async () => {
discoverCalls += 1;
return { candidates: [], rung: 6, reason: "none", ambiguous: false };
},
});

await rt.look();
await rt.look();

expect(discoverCalls).toBe(1);
});
});

describe("tool executors", () => {
Expand Down
4 changes: 3 additions & 1 deletion pkgs/mcpx/plugin/opencode/v2/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export function createToolRuntime(deps: ToolRuntimeDeps): ToolRuntime {

const forget = (): void => {
found = undefined;
missedAt = Date.now();
// A transient daemon failure is not a discovery miss; retry the ladder
// immediately on the next call.
missedAt = 0;
};

/**
Expand Down
Loading