Skip to content

Commit f0c4052

Browse files
anandgupta42claude
andcommitted
fix(workspace): keep tools named after Object.prototype properties when pinning
The rebuild used `in` checks, which are true for inherited names such as `constructor` or `toString`, so a tool with that name was dropped on every step after the first. Use own-key checks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9d17846 commit f0c4052

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,15 @@ export function pinTurnTools<T>(sessionID: string, firstCatalog: boolean, tools:
458458
}
459459
const pinned = turnTools.get(sessionID)
460460
if (!pinned) return
461-
const next: Record<string, T> = Object.fromEntries(Object.entries(tools).filter(([key]) => !(key in engine)))
461+
// Own-key checks only: a tool may be named `constructor` or `toString`.
462+
const next: Record<string, T> = Object.fromEntries(
463+
Object.entries(tools).filter(([key]) => !Object.hasOwn(engine, key)),
464+
)
462465
for (const [key, tool] of Object.entries(pinned.engine)) next[key] = tool as T
463466
// Rebuild in first-catalog order; keys new since then go last, in arrival order.
464-
const ordered = [...pinned.order.filter((key) => key in next), ...Object.keys(next)]
467+
const ordered = new Set([...pinned.order.filter((key) => Object.hasOwn(next, key)), ...Object.keys(next)])
465468
for (const key of Object.keys(tools)) delete tools[key]
466-
for (const key of ordered) if (!(key in tools)) tools[key] = next[key]
469+
for (const key of ordered) tools[key] = next[key]
467470
}
468471

469472
async function reconcile(sessionID: string, directory: string, state: DirectoryState): Promise<void> {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,24 @@ describe("beforeTurn — what a turn boundary does", () => {
957957
expect(later.datamate_b).toEqual({ id: "b1" })
958958
})
959959

960+
test("pinning keeps tools whose names are Object.prototype properties", async () => {
961+
install({})
962+
const catalog = (): Record<string, { id: string }> =>
963+
Object.fromEntries([
964+
["constructor", { id: "ctor" }],
965+
["datamate_a", { id: "a1" }],
966+
["toString", { id: "str" }],
967+
])
968+
pinTurnTools("s1", true, catalog())
969+
const later = catalog()
970+
pinTurnTools("s1", false, later)
971+
expect(Object.entries(later)).toEqual([
972+
["constructor", { id: "ctor" }],
973+
["datamate_a", { id: "a1" }],
974+
["toString", { id: "str" }],
975+
])
976+
})
977+
960978
test("pinning is a no-op with the flag off and for a session with no step-1 snapshot", async () => {
961979
install({ flag: false })
962980
const tools: Record<string, { id: string }> = { datamate_a: { id: "a1" } }

0 commit comments

Comments
 (0)