Skip to content

Commit 179e433

Browse files
fix: reject corrupt sidecar records the probe cannot verify (codex r3)
- A present pid must be a positive live integer: the bridge extension always writes one, so a string, null, or object pid is a corrupt record — and unlike the engine, the probe has no connection attempt behind it to catch a bad guess. Absent pid stays live (engine parity). - Folder entries must be nonempty absolute strings: resolve("") is the process cwd, so an empty or relative entry could spuriously match and bypass the two-bridge decline. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MaT4GH2aCGEmTg6bBPZBeU
1 parent b56be7d commit 179e433

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-probes.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,21 @@ export function liveBridge(cwd: string, dir: string = join(homedir(), ".altimate
186186
}
187187
if (typeof data.socketPath !== "string" || !data.socketPath) continue
188188
// A sidecar without a pid counts as live, matching the engine's own
189-
// discovery; a recorded pid disqualifies unless it names a live real
190-
// process. Non-positive pids never do — kill(0)/kill(-1) probe process
191-
// groups, which would read any garbage pid as alive. (bot review)
192-
if (typeof data.pid === "number" && !(Number.isInteger(data.pid) && data.pid > 0 && pidAlive(data.pid)))
189+
// discovery. A PRESENT pid must be a live real process: the bridge
190+
// extension always writes a positive integer, so a string, null, or
191+
// non-positive value is a corrupt record, not a legacy shape — and
192+
// unlike the engine, this probe has no connection attempt behind it
193+
// to catch a bad guess. kill(0)/kill(-1) probe process groups, which
194+
// would read garbage pids as alive. (codex r3, cubic)
195+
if ("pid" in data && !(typeof data.pid === "number" && Number.isInteger(data.pid) && data.pid > 0 && pidAlive(data.pid)))
193196
continue
194197
// Validate the folders shape: this is an unvalidated JSON file, and a
195-
// non-array here must degrade to "live bridge, no recorded folders",
196-
// not throw out of the probe. (bot review)
198+
// non-array must degrade to "live bridge, no recorded folders", not
199+
// throw out of the probe. Only nonempty absolute strings survive —
200+
// resolve("") is the process cwd, so an empty or relative entry would
201+
// spuriously match and bypass the two-bridge decline. (codex r3)
197202
const folders = Array.isArray(data.workspaceFolders)
198-
? data.workspaceFolders.filter((f): f is string => typeof f === "string")
203+
? data.workspaceFolders.filter((f): f is string => typeof f === "string" && isAbsolute(f))
199204
: []
200205
bridges.push(folders)
201206
} catch {

‎packages/opencode/test/altimate/workspace/engine-probes.test.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,30 @@ describe("liveBridge", () => {
9999
expect(statSync(path.join(dir, "a.json")).isFile()).toBe(true)
100100
})
101101

102-
test("a non-positive or non-integer pid is never alive — kill(0)/kill(-1) probe process groups", () => {
102+
test("a present-but-invalid pid is a corrupt record, never a live pid-less sidecar", () => {
103103
const cwd = mkdtempSync(path.join(os.tmpdir(), "bridge-ws-"))
104-
for (const pid of [0, -1, 1.5]) {
104+
// Non-positive and non-integer: kill(0)/kill(-1) probe process groups.
105+
// Wrong type entirely: the extension always writes a positive integer.
106+
for (const pid of [0, -1, 1.5, "1234", null, {}] as unknown[]) {
105107
const dir = sidecars({
106-
"a.json": { socketPath: "/tmp/a.sock", workspaceFolders: [cwd], pid },
108+
"a.json": { socketPath: "/tmp/a.sock", workspaceFolders: [cwd], pid: pid as number },
107109
})
108110
expect(liveBridge(cwd, dir)).toBe(false)
109111
}
110112
})
111113

114+
test("empty and relative folder strings are dropped — resolve('') is the process cwd", () => {
115+
const cwd = mkdtempSync(path.join(os.tmpdir(), "bridge-ws-"))
116+
// Bridge A is malformed, bridge B is live elsewhere: A must not match via
117+
// resolve("") and must not defeat the two-bridge decline.
118+
const dir = sidecars({
119+
"a.json": { socketPath: "/tmp/a.sock", workspaceFolders: ["", "relative/dir"], pid: process.pid },
120+
"b.json": { socketPath: "/tmp/b.sock", workspaceFolders: ["/somewhere/else"], pid: process.pid },
121+
})
122+
expect(liveBridge(process.cwd(), dir)).toBe(false)
123+
expect(liveBridge(cwd, dir)).toBe(false)
124+
})
125+
112126
test("the sole live bridge counts even for an unrelated directory; two decline to guess", () => {
113127
const cwd = mkdtempSync(path.join(os.tmpdir(), "bridge-ws-"))
114128
const one = sidecars({

0 commit comments

Comments
 (0)