Skip to content

Commit bb33932

Browse files
sahrizviclaude
andcommitted
fix(workspace): keep turns without a workspace snapshot off the awaited path
With workspaces on by default, the workspace-skill step in `prompt` ran awaited on every user's turn, before `createUserMessage`. Its own comment records why that is unsafe: an await there reorders the turn against a forked `prompt.loop`, and "running subtask preserves metadata after tool-call transition" failed 2/8 on this branch (0/8 on main). Only a project that already has a workspace snapshot can have skills to land on this turn, so only that case awaits (as the opted-in path did on main). Every other turn starts the sync in the background and keeps the synchronous path; a link that background sync finds shows its skills from the next turn. After the change the test passes 12/12. Also from review: the turned-off message test checks the "Unset it…" instruction, and the precedence tests are titled for the kill switch rather than the pilot flag. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV
1 parent f00cfaf commit bb33932

3 files changed

Lines changed: 72 additions & 61 deletions

File tree

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -386,68 +386,78 @@ export namespace SessionPrompt {
386386
}
387387
}
388388
} else {
389-
try {
390-
const skillSync = await import("../altimate/workspace/skill-sync")
391-
const dir = Instance.directory
392-
const refreshRegistry = () => refreshSkillRegistry(dir)
393-
394-
// A sync that ran elsewhere — a bind, most commonly — changes the
395-
// snapshot with no instance context to refresh from. Pick that up before
396-
// deciding whether this turn needs to poll at all.
397-
await refreshRegistry()
398-
399-
if (!(await skillSync.recentlySynced(dir))) {
400-
const applied = skillSync.syncSkills(dir).then(async (result) => {
401-
// Its own catch: a failed refresh must not take the warning with it.
402-
// After an account switch the next re-sync can be a poll interval
403-
// away, so the problem would otherwise go unsaid for minutes.
404-
await refreshRegistry().catch((err) =>
405-
log.warn("workspace skill registry refresh failed", { err: String(err) }),
406-
)
407-
// A skill that silently fails to arrive looks exactly like a
408-
// workspace with no skills. Say which, and why. Imported only when
409-
// there is something to show, keeping the common path free of it.
410-
const problem = skillSync.describeSyncProblems(result)
411-
if (problem && skillSync.shouldAnnounce(dir, problem)) {
412-
// Latched before delivery so concurrent turns joining this run do
413-
// not both warn; released if nothing was shown, so a later turn
414-
// tries again instead of the problem staying silent for good.
415-
let shown = false
416-
try {
417-
const { isHeadless } = await import("../altimate/workspace/engine-seams")
418-
const { notify, printLine } = await import("../altimate/workspace/engine-probes")
419-
if (isHeadless()) {
420-
// `altimate-code run` has no toast renderer; the engine reports
421-
// the same way. One line: printLine strips newlines.
422-
printLine(`${problem.title}: ${problem.message.split("\n").join("; ")}`)
423-
shown = true
424-
} else {
425-
shown = await notify({ ...problem, variant: "warning" })
389+
// Workspaces are on by default, so this branch runs on every user's turn. Awaiting it puts
390+
// event-loop ticks (and up to WORKSPACE_SKILL_WAIT_MS) before `createUserMessage` — the
391+
// reordering described above. Only a project that already has a workspace snapshot can have
392+
// skills to land on this turn, so only that case waits; everyone else starts the sync in the
393+
// background and keeps the synchronous path. A link found by that background sync shows its
394+
// skills from the next turn.
395+
const workspaceSkillTurn = async () => {
396+
try {
397+
const skillSync = await import("../altimate/workspace/skill-sync")
398+
const dir = Instance.directory
399+
const refreshRegistry = () => refreshSkillRegistry(dir)
400+
401+
// A sync that ran elsewhere — a bind, most commonly — changes the
402+
// snapshot with no instance context to refresh from. Pick that up before
403+
// deciding whether this turn needs to poll at all.
404+
await refreshRegistry()
405+
406+
if (!(await skillSync.recentlySynced(dir))) {
407+
const applied = skillSync.syncSkills(dir).then(async (result) => {
408+
// Its own catch: a failed refresh must not take the warning with it.
409+
// After an account switch the next re-sync can be a poll interval
410+
// away, so the problem would otherwise go unsaid for minutes.
411+
await refreshRegistry().catch((err) =>
412+
log.warn("workspace skill registry refresh failed", { err: String(err) }),
413+
)
414+
// A skill that silently fails to arrive looks exactly like a
415+
// workspace with no skills. Say which, and why. Imported only when
416+
// there is something to show, keeping the common path free of it.
417+
const problem = skillSync.describeSyncProblems(result)
418+
if (problem && skillSync.shouldAnnounce(dir, problem)) {
419+
// Latched before delivery so concurrent turns joining this run do
420+
// not both warn; released if nothing was shown, so a later turn
421+
// tries again instead of the problem staying silent for good.
422+
let shown = false
423+
try {
424+
const { isHeadless } = await import("../altimate/workspace/engine-seams")
425+
const { notify, printLine } = await import("../altimate/workspace/engine-probes")
426+
if (isHeadless()) {
427+
// `altimate-code run` has no toast renderer; the engine reports
428+
// the same way. One line: printLine strips newlines.
429+
printLine(`${problem.title}: ${problem.message.split("\n").join("; ")}`)
430+
shown = true
431+
} else {
432+
shown = await notify({ ...problem, variant: "warning" })
433+
}
434+
} finally {
435+
if (!shown) skillSync.forgetAnnouncement(dir, problem)
426436
}
427-
} finally {
428-
if (!shown) skillSync.forgetAnnouncement(dir, problem)
429437
}
438+
})
439+
applied.catch((err) => log.warn("workspace skill sync failed", { err: String(err) }))
440+
// Timer cleared when the sync wins the race: an armed timer keeps the
441+
// event loop alive, so a short-lived `run` would linger for the rest
442+
// of the bound, once per turn.
443+
let timer: ReturnType<typeof setTimeout> | undefined
444+
try {
445+
await Promise.race([
446+
applied,
447+
new Promise((r) => {
448+
timer = setTimeout(r, WORKSPACE_SKILL_WAIT_MS)
449+
}),
450+
])
451+
} finally {
452+
if (timer) clearTimeout(timer)
430453
}
431-
})
432-
applied.catch((err) => log.warn("workspace skill sync failed", { err: String(err) }))
433-
// Timer cleared when the sync wins the race: an armed timer keeps the
434-
// event loop alive, so a short-lived `run` would linger for the rest
435-
// of the bound, once per turn.
436-
let timer: ReturnType<typeof setTimeout> | undefined
437-
try {
438-
await Promise.race([
439-
applied,
440-
new Promise((r) => {
441-
timer = setTimeout(r, WORKSPACE_SKILL_WAIT_MS)
442-
}),
443-
])
444-
} finally {
445-
if (timer) clearTimeout(timer)
446454
}
455+
} catch (err) {
456+
log.warn("workspace skill sync failed", { err: String(err) })
447457
}
448-
} catch (err) {
449-
log.warn("workspace skill sync failed", { err: String(err) })
450458
}
459+
if (existsSync(path.join(Instance.directory, ".altimate-code", "skill", "_workspace"))) await workspaceSkillTurn()
460+
else void workspaceSkillTurn()
451461
}
452462
// altimate_change end
453463

‎packages/opencode/test/altimate/workspace/precedence.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ afterEach(() => {
5656
else process.env.ALTIMATE_DISABLE_WORKSPACE = ORIGINAL_PILOT
5757
})
5858

59-
describe("the workspace pilot gate", () => {
60-
test("precedence stays off when the pilot flag is not set", async () => {
59+
describe("the workspace kill switch", () => {
60+
test("precedence stays off when ALTIMATE_DISABLE_WORKSPACE is set", async () => {
6161
// A binding and a pinned entry both persist in config, and the MCP client connects
62-
// that entry regardless of the pilot flag — so engine tools can materialise for
63-
// someone who opted out. Opting out has to mean it.
62+
// that entry regardless of the kill switch — so engine tools can materialise for
63+
// someone who turned workspaces off. Turning them off has to mean it.
6464
process.env.ALTIMATE_DISABLE_WORKSPACE = "1"
6565
const precedence = await refresh(SESSION, SNOWFLAKE_TOOLS)
6666
expect(precedence.enabled).toBe(false)
6767
expect(precedence.disabledReason).toBe("pilot-off")
6868
})
6969

70-
test("a served connection still runs locally with the pilot off", async () => {
70+
test("a served connection still runs locally with workspaces turned off", async () => {
7171
process.env.ALTIMATE_DISABLE_WORKSPACE = "1"
7272
await refresh(SESSION, SNOWFLAKE_TOOLS)
7373
const verdict = await check(SESSION, "sql_execute", "local_snow")

‎packages/opencode/test/skill/release-v0.12.4-adversarial.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,5 +312,6 @@ describe("v0.12.4 adversarial: user-facing wording (release review fixes)", () =
312312

313313
test("the turned-off message names the switch to unset", () => {
314314
expect(WORKSPACE_PILOT_OFF_MESSAGE).toContain("ALTIMATE_DISABLE_WORKSPACE")
315+
expect(WORKSPACE_PILOT_OFF_MESSAGE).toContain("Unset it to use this command.")
315316
})
316317
})

0 commit comments

Comments
 (0)