Skip to content

Commit 30bde25

Browse files
sahrizviclaude
andcommitted
fix(workspace): a turn's background skill sync holds the exit flush until it lands (review)
- The background branch awaits the sync itself rather than the turn's 2s wait bound, so `run`'s one-time exit flush cannot return mid-sync - The workspaces-on subtask tests wait for the child's own prompt (past the workspace hook) before cancelling - Docs: an empty `ALTIMATE_DISABLE_WORKSPACE` leaves workspaces on Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV
1 parent 8cc5fd7 commit 30bde25

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

‎docs/docs/usage/cli.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ altimate --agent analyst
4949

5050
### Workspaces
5151

52-
Workspace features are on by default. When you are signed in to Altimate, each session asks the Altimate service whether the project is linked to a workspace: it sends the project's git `origin` URL (credentials removed), and only if that finds no link, the project's folder path. A "not linked" answer is remembered for 5 minutes; a failed request is retried on the next turn. Nothing is sent when you are not signed in. Set `ALTIMATE_DISABLE_WORKSPACE=1` to turn all of them off, these lookups included (any value except `0` or `false` counts as set): no post-scan prompt, no `link` or `skill publish`, no `/workspace` menu or sidebar, no skill or memory sync, and no workspace engine. In a project that is already linked, the link is ignored rather than removed: workspace skills already pulled into the project are taken out of service, the agent is not told about the workspace, and the MCP entries the workspace manages can be edited by hand again. Unset it and the link applies again.
52+
Workspace features are on by default. When you are signed in to Altimate, each session asks the Altimate service whether the project is linked to a workspace: it sends the project's git `origin` URL (credentials removed), and only if that finds no link, the project's folder path. A "not linked" answer is remembered for 5 minutes; a failed request is retried on the next turn. Nothing is sent when you are not signed in. Set `ALTIMATE_DISABLE_WORKSPACE=1` to turn all of them off, these lookups included (any value other than `0`, `false` or an empty value counts as set): no post-scan prompt, no `link` or `skill publish`, no `/workspace` menu or sidebar, no skill or memory sync, and no workspace engine. In a project that is already linked, the link is ignored rather than removed: workspace skills already pulled into the project are taken out of service, the agent is not told about the workspace, and the MCP entries the workspace manages can be edited by hand again. Unset it and the link applies again.
5353

5454
With workspaces on:
5555

@@ -100,7 +100,7 @@ Configuration can be controlled via environment variables:
100100
| `ALTIMATE_CLI_DISABLE_TERMINAL_TITLE` | Don't set terminal title |
101101
| `ALTIMATE_CLI_DISABLE_PRUNE` | Disable database pruning |
102102
| `ALTIMATE_CLI_DISABLE_MODELS_FETCH` | Don't fetch models from models.dev |
103-
| `ALTIMATE_DISABLE_WORKSPACE` | Set to `1` to turn off every workspace feature (linking, skill and memory sync, the workspace engine, and the project lookup each session makes). Any value except `0` or `false` counts as set. Workspaces are on by default |
103+
| `ALTIMATE_DISABLE_WORKSPACE` | Set to `1` to turn off every workspace feature (linking, skill and memory sync, the workspace engine, and the project lookup each session makes). Any value other than `0`, `false` or an empty value counts as set. Workspaces are on by default |
104104
| `ALTIMATE_WORKSPACE_WEB_URL` | Development only: the base URL of a local web app's Workspaces pages, used instead of the tenant's for `link`'s browser hand-off and workspace links. Include the mount path, e.g. `http://acme.localhost:3000/workspaces` |
105105
| `ALTIMATE_INTEGRATIONS` | Set to `local` to keep warehouse tools local rather than routing them through a bound workspace's engine |
106106
| `ALTIMATE_CODE_SERVE` | Set to `1` by `altimate-code serve` itself, whether the IDE extension or you launched it. Marks that process as the extension's host — so it is the one that reads the pin variables — and is stripped from every child the bash and shell tools start |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ export namespace SessionPrompt {
445445
}
446446
})
447447
applied.catch((err) => log.warn("workspace skill sync failed", { err: String(err) }))
448+
// In the background nothing waits on this turn but `run`'s exit flush, which snapshots the
449+
// tracked work once: settling at the bound below would let it return mid-sync.
450+
if (background) return void (await applied.catch(() => undefined))
448451
// Timer cleared when the sync wins the race: an armed timer keeps the
449452
// event loop alive, so a short-lived `run` would linger for the rest
450453
// of the bound, once per turn.

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

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,9 @@ noLLMServer.instance("prompt tools replace previous prompt tool rules", () =>
13371337
}),
13381338
)
13391339

1340-
const subtaskKeepsMetadata = () =>
1340+
// altimate_change start — `reachChildPrompt`: wait for the subtask's own prompt to start before cancelling
1341+
const subtaskKeepsMetadata = (reachChildPrompt = false) =>
1342+
// altimate_change end
13411343
Effect.gen(function* () {
13421344
const { llm } = yield* useServerConfig(providerCfg)
13431345
const prompt = yield* SessionPrompt.Service
@@ -1364,6 +1366,27 @@ const subtaskKeepsMetadata = () =>
13641366
expect(tool.state.title).toBeDefined()
13651367
expect(tool.state.metadata?.model).toBeDefined()
13661368

1369+
// altimate_change start — the task tool publishes this metadata before it calls the child's `prompt()`,
1370+
// where the workspace hook runs. The child's user message is created after that hook, so waiting for
1371+
// it proves the hook ran; the metadata must still be there afterwards.
1372+
if (reachChildPrompt) {
1373+
const child = tool.state.metadata!.sessionId as SessionID
1374+
yield* pollWithTimeout(
1375+
Effect.gen(function* () {
1376+
const msgs = yield* MessageV2.filterCompactedEffect(child)
1377+
if (msgs.some((item) => item.info.role === "user")) return true
1378+
}),
1379+
"timed out waiting for the subtask's own prompt",
1380+
"20 seconds",
1381+
)
1382+
const after = (yield* MessageV2.filterCompactedEffect(chat.id))
1383+
.find((item) => item.info.role === "assistant" && item.info.agent === "general")
1384+
?.parts.find((part): part is MessageV2.ToolPart => part.type === "tool")
1385+
expect(after?.state.status).toBe("running")
1386+
if (after?.state.status === "running") expect(after.state.metadata?.sessionId).toBe(child)
1387+
}
1388+
// altimate_change end
1389+
13671390
yield* prompt.cancel(chat.id)
13681391
yield* Fiber.await(fiber)
13691392
})
@@ -1391,13 +1414,13 @@ const withWorkspacesOn = <A, E, R>(body: Effect.Effect<A, E, R>) =>
13911414

13921415
it.instance(
13931416
"running subtask preserves metadata with workspaces on and no workspace snapshot (sync in the background)",
1394-
() => withWorkspacesOn(subtaskKeepsMetadata()),
1417+
() => withWorkspacesOn(subtaskKeepsMetadata(true)),
13951418
30_000,
13961419
)
13971420

13981421
it.instance(
13991422
"running subtask preserves metadata with workspaces on and a workspace snapshot (sync awaited)",
1400-
() => withWorkspacesOn(subtaskKeepsMetadata()),
1423+
() => withWorkspacesOn(subtaskKeepsMetadata(true)),
14011424
{
14021425
init: (directory: string) =>
14031426
Effect.sync(() => {
@@ -1407,6 +1430,50 @@ it.instance(
14071430
// Generous: a timed-out test is not interrupted, so it would keep the kill switch cleared for later files.
14081431
30_000,
14091432
)
1433+
1434+
// A one-shot `run` flushes tracked work once, on exit. A background sync that outlasts the turn's wait bound
1435+
// must keep the flush waiting until it lands, or the process exits with the sync half-done.
1436+
it.instance(
1437+
"a turn's background workspace sync holds the exit flush until it lands, past the turn's wait bound",
1438+
() =>
1439+
withWorkspacesOn(
1440+
Effect.gen(function* () {
1441+
const { llm } = yield* useServerConfig(providerCfg)
1442+
const { prompt, chat } = yield* boot()
1443+
const skillSync = yield* Effect.promise(() => import("../../src/altimate/workspace/skill-sync"))
1444+
let landed = false
1445+
const recent = spyOn(skillSync, "recentlySynced").mockResolvedValue(false)
1446+
const sync = spyOn(skillSync, "syncSkills").mockImplementation(
1447+
() =>
1448+
new Promise((resolve) =>
1449+
setTimeout(() => {
1450+
landed = true
1451+
resolve({ changed: false, skipped: [] } as unknown as Awaited<ReturnType<typeof skillSync.syncSkills>>)
1452+
}, 2_600),
1453+
),
1454+
)
1455+
yield* Effect.gen(function* () {
1456+
yield* llm.text("done")
1457+
yield* prompt.prompt({
1458+
sessionID: chat.id, agent: "build", model: promptRef,
1459+
parts: [{ type: "text", text: "Hello." }],
1460+
})
1461+
expect(landed).toBe(false)
1462+
yield* Effect.promise(() => skillSync.flushPendingSyncs(10_000))
1463+
expect(sync).toHaveBeenCalled()
1464+
expect(landed).toBe(true)
1465+
}).pipe(
1466+
Effect.ensuring(
1467+
Effect.sync(() => {
1468+
recent.mockRestore()
1469+
sync.mockRestore()
1470+
}),
1471+
),
1472+
)
1473+
}),
1474+
),
1475+
30_000,
1476+
)
14101477
// altimate_change end
14111478
it.instance.todo(
14121479
"running task tool preserves metadata after tool-call transition",

0 commit comments

Comments
 (0)