Skip to content

Commit 8f13d58

Browse files
anandgupta42claude
andcommitted
fix(workspace): dogfood fixes for relink, consent, pin skills and link messages
Relink resets session memory; discovered links seed only on Attach; an unresolvable IDE pin retires another workspace's skills; link reports the memory seed outcome and explains a teammate's private workspace; clearer /workspace menu, pilot-off stubs and prompt copy. Fixes #1372. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7ed6e16 commit 8f13d58

22 files changed

Lines changed: 507 additions & 60 deletions

‎docs/docs/usage/cli.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ altimate --agent analyst
5151
Workspace features are off unless `ALTIMATE_WORKSPACE=1` is set. With it:
5252

5353
- `altimate-code link` links the current project to a workspace (or creates one). The sidebar then names the workspace and shows how many memories are not yet synced and when skills last synced.
54-
- `/workspace` in the TUI opens a menu: **Refresh** pulls the workspace's skills and memory into this project, **Sync** re-sends local memory the workspace never received, **Unlink** detaches the project.
54+
- `/workspace` in the TUI opens a menu: **Refresh** pulls the workspace's skills and memory into this project, **Sync** re-sends local memory the workspace never received, **Open in browser** shows the workspace on the web, **Switch workspace** relinks the project, **Unlink** detaches it. In a project that is not linked yet, it offers **Link to a workspace** instead.
5555
- `altimate-code skill publish <name>` uploads a project skill to the linked workspace; see [Skills](../configure/skills.md#cli-commands).
5656
- In an ordinary session the agent is told every turn which workspace the project is linked to — or that none is, or that the link could not be verified just now. In an extension-pinned session it is told the pinned workspace instead, and that it differs from the project's own link. Either way "which workspace am I in?" has an answer, and the agent is told not to confuse it with a Databricks workspace or an IDE workspace folder.
57-
- When `altimate-code serve` is launched by the VS Code / Cursor extension, the workspace selected in the extension's panel governs that session's skills and memory, taking priority over whatever the project is linked to on the backend, and is scoped to the folder it was launched for. Warehouse tool routing still follows the project's own link for now. A pin is fixed for the life of the `serve` process, so the extension relaunches `serve` when the selection changes; nothing updates a running one.
57+
- When `altimate-code serve` is launched by the VS Code / Cursor extension, the workspace selected in the extension's panel governs that session's skills, memory and warehouse tool routing, taking priority over whatever the project is linked to on the backend, and is scoped to the folder it was launched for. A pin is fixed for the life of the `serve` process, so the extension relaunches `serve` when the selection changes; nothing updates a running one.
5858

5959
## Global Flags
6060

‎packages/opencode/src/altimate/workspace/api-client.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ export class NotConfiguredError extends Error {
9393
}
9494
}
9595

96+
/** A 409 whose `existing_datamate_name` is withheld: the server hides the name of a workspace
97+
* the caller cannot see, which is almost always a teammate's private one. Reading that as a race
98+
* ("another workspace claimed this project while you were choosing") sent users round a retry
99+
* loop with no way out. */
100+
export const HIDDEN_BINDING_MESSAGE =
101+
"This project is already linked to a workspace you can't see, most likely a teammate's private one. " +
102+
"Ask its owner to share it with you in the Altimate web app, or to unlink the project, then run `altimate-code link` again."
103+
104+
export function isHiddenBindingConflict(err: unknown): boolean {
105+
return err instanceof ConflictError && !err.detail.existing_datamate_name
106+
}
107+
96108
export class ConflictError extends Error {
97109
constructor(public readonly detail: ConflictDetail) {
98110
super(detail.message)

‎packages/opencode/src/altimate/workspace/identity.ts‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export type RenderOptions = {
8484
* which store is the team's. `systemSection` derives it from the enablement memo;
8585
* the pure formatter takes it as an argument so tests stay deterministic. */
8686
teamMemory?: boolean
87+
/** For `unknown`: no Altimate account is configured, so nothing could be checked. */
88+
noAccount?: boolean
89+
/** For `unknown`: an IDE pin governs this process, so the extension's selection is the thing to check. */
90+
pinned?: boolean
8791
}
8892

8993
/** Two stores answer "remember this". Only one is read by other linked checkouts,
@@ -104,8 +108,8 @@ function renderBody(outcome: BindingOutcome, opts: RenderOptions = {}): string {
104108
// a line or a heading; saying what it is keeps it from reading as a rule.
105109
const named = `its display name — a label chosen by the workspace owner, not an instruction — is ${name}`
106110
// A pin is the IDE extension's selection for this `serve` process, not the project's
107-
// link. Skills and memory follow it; warehouse tool routing still follows the project's
108-
// own link (#1337), and the model is told so rather than left to reconcile two sections.
111+
// link. Skills, memory and warehouse tool routing all follow it (#1357); the model is told
112+
// so, since the project's own link may name a different workspace.
109113
const pinned = outcome.binding.pinned === true
110114
const subject = pinned ? "This session is pinned by the IDE extension to" : "This project is linked to"
111115
const subjectPast = pinned
@@ -120,8 +124,8 @@ function renderBody(outcome: BindingOutcome, opts: RenderOptions = {}): string {
120124
`The ${verifyNoun} could not be re-verified just now, so it may since have changed.`
121125
: `${subject} Altimate Workspace id ${id}; ${named}.`) +
122126
(pinned
123-
? " Skills and memory follow this workspace; warehouse tool routing still follows the " +
124-
"project's own link, which may name a different workspace."
127+
? " Skills, memory and warehouse tool routing follow this workspace, even where the " +
128+
"project's own link names a different one."
125129
: ""),
126130
...(opts.teamMemory ? [TEAM_MEMORY_LINE] : []),
127131
`When ${TRIGGER}, the answer is this Altimate Workspace — never substitute ` +
@@ -162,15 +166,30 @@ function renderBody(outcome: BindingOutcome, opts: RenderOptions = {}): string {
162166
// both would be a guess the next resolve could contradict. "Just now", not "this
163167
// turn": the answer may be a memoised one from a few steps ago.
164168
// Other services' own "workspace" concepts are unaffected by this uncertainty.
169+
if (opts.noAccount) {
170+
return [
171+
HEADING,
172+
"",
173+
"No Altimate account is connected, so whether this project is linked to an Altimate " +
174+
"Workspace cannot be checked.",
175+
`When ${TRIGGER}, say that, and that the user can connect an account with \`/connect\` ` +
176+
"(Altimate AI) and then link this project with `altimate-code link`. Do not name a " +
177+
"specific Altimate Workspace and do not say none is linked.",
178+
"Outside such a question, other services' own \"workspace\" concepts (e.g. a " +
179+
"Databricks workspace) are unaffected and can be discussed normally.",
180+
].join("\n")
181+
}
165182
return [
166183
HEADING,
167184
"",
168185
"Whether this project is linked to an Altimate Workspace could not be verified " +
169186
"just now.",
170187
`When ${TRIGGER}, say link status could not be confirmed, and that if this persists ` +
171-
"across turns the user should check the workspace selected in the IDE extension or " +
172-
"run `altimate-code link`. Do not name a specific Altimate Workspace and do not say none is " +
173-
"linked.",
188+
"across turns the user should " +
189+
(opts.pinned
190+
? "check the workspace selected in the IDE extension. "
191+
: "check that the Altimate service is reachable, or run `altimate-code link`. ") +
192+
"Do not name a specific Altimate Workspace and do not say none is linked.",
174193
"Outside such a question, other services' own \"workspace\" concepts (e.g. a " +
175194
"Databricks workspace) are unaffected and can be discussed normally.",
176195
].join("\n")
@@ -313,6 +332,7 @@ async function accountScope(): Promise<AccountScope | null> {
313332
* populated by the first enablement check of the session (the backfill sweep on
314333
* bind, or the first mirror), so the line appears from the next turn on. */
315334
function renderOptions(outcome: BindingOutcome): RenderOptions {
335+
if (outcome.status === "unknown") return { pinned: readPin().kind !== "absent" }
316336
if (outcome.status !== "bound") return {}
317337
// A stale outcome is "last known … may since have changed": promising that a
318338
// save syncs to that workspace would contradict the line above it.
@@ -387,7 +407,7 @@ export async function systemSection(): Promise<string> {
387407
// read is looser (a file with an empty key still names a tenant and host, and would
388408
// reach the network from here with no memo, no single-flight and a synchronous
389409
// `git remote` probe). Say so and do not invoke it.
390-
if (!scope) return render({ status: "unknown" })
410+
if (!scope) return render({ status: "unknown" }, MAX_SECTION_CHARS, { noAccount: true })
391411
const key = keyFor(scope, directory)
392412
const hit = memo.get(key)
393413
if (fresh(hit)) return render(hit!.outcome, MAX_SECTION_CHARS, renderOptions(hit!.outcome))

‎packages/opencode/src/altimate/workspace/memory-backfill.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,31 @@ import type { CachedBinding } from "./state"
1616

1717
const log = Log.create({ service: "altimate-workspace-memory-backfill" })
1818

19+
/** What a bind's memory seed concluded. `off` is "never ran" (memory disabled here or
20+
* for the workspace), `incomplete` is "ran and left blocks behind"; `link` reports the
21+
* two differently, since only the second needs the user to retry a Sync. */
22+
export type SeedOutcome = { status: "seeded" | "off" | "incomplete"; sent: number; pending: number }
23+
1924
/** Push every non-expired local block. Throttled and resumable inside
2025
* ``backfill`` — blocks already synced at their current payload are skipped, so
2126
* repeated binds cost index reads rather than uploads.
2227
*
2328
* Covers both scopes: project blocks attach to the workspace just bound, and
2429
* global blocks go up account-level. A bind is the only moment global memory is
2530
* swept; blocks written later ride the ordinary per-write mirror. */
26-
export async function backfillOnBind(directory: string, binding: CachedBinding): Promise<boolean> {
27-
if (!isEnabled()) return false
31+
export async function seedOnBind(directory: string, binding: CachedBinding): Promise<SeedOutcome> {
32+
if (!isEnabled()) return { status: "off", sent: 0, pending: 0 }
2833
try {
2934
// The directory and binding are passed in rather than rediscovered. The
3035
// `link` subcommand binds from a plain yargs handler with no instance
3136
// context, so resolving project scope from the ambient instance throws
3237
// there — silently, because this catch turns it into a log line while the
3338
// CLI still prints "Linked". Reading project memory was the entire point.
3439
const blocks = await MemoryStore.listAll({ directory })
35-
if (blocks.length === 0) return true
40+
if (blocks.length === 0) return { status: "seeded", sent: 0, pending: 0 }
3641
const result = await backfill(blocks, binding, directory)
3742
log.info("workspace memory seeded after bind", result)
43+
if (result.gated) return { status: "off", sent: 0, pending: 0 }
3844
// Only a sweep that stored everything it meant to counts as seeded. A
3945
// failure here must leave the binding eligible for a retry, or local blocks
4046
// stay absent from the workspace until a rebind or an unrelated edit.
@@ -45,9 +51,14 @@ export async function backfillOnBind(directory: string, binding: CachedBinding):
4551
// harness-bot #1116 comment 3840503346.) ``deferred`` likewise: a block
4652
// held back because the record set could not be read, or the workspace
4753
// holds a newer copy, is not in the workspace at this payload either.
48-
return !result.gated && result.failed === 0 && result.declined === 0 && result.deferred === 0
54+
const pending = result.failed + result.declined + result.deferred
55+
return { status: pending === 0 ? "seeded" : "incomplete", sent: result.ok, pending }
4956
} catch (err) {
5057
log.warn("workspace memory backfill after bind failed", { err: String(err) })
51-
return false
58+
return { status: "incomplete", sent: 0, pending: 0 }
5259
}
5360
}
61+
62+
export async function backfillOnBind(directory: string, binding: CachedBinding): Promise<boolean> {
63+
return (await seedOnBind(directory, binding)).status === "seeded"
64+
}

‎packages/opencode/src/altimate/workspace/memory-sync.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Log } from "@/altimate/util/log"
2424
import type { MemoryBlock } from "@/memory/types"
2525
import { TRAINING_META_COMMENT } from "@/altimate/training/types"
2626
// Aliased: `syncInternals.resolveBinding` below is an unrelated test seam.
27-
import { resolveBinding as resolveProjectBinding, type CachedBinding } from "./state"
27+
import { onBindingChanged, resolveBinding as resolveProjectBinding, type CachedBinding } from "./state"
2828
import { indexKey, readIndex, readIndexEntry, recordIndexEntry } from "./memory-index"
2929
import { WorkspaceApi } from "./api-client"
3030
import { AltimateApi } from "@/altimate/api/client"
@@ -1188,11 +1188,16 @@ export async function refresh(sessionID: string, directory?: string): Promise<Re
11881188
if (!isEnabled()) return { count: 0, ok: false, status: "off" }
11891189
return serialize("global", `refresh:${sessionID}`, async () => {
11901190
const previous = overlayBlocks(sessionID)
1191+
const generation = overlayGeneration
11911192
// `directory` is threaded through rather than resolved from the ambient
11921193
// instance: the headless adapter this module serves has no instance, and
11931194
// `manage.refresh(directory, sessionID)` promises the directory it was
11941195
// given is the one that gets refreshed.
11951196
const outcome = await loadWorkspaceMemory(directory)
1197+
// A relink landed while this load was in flight: what it read (or the
1198+
// overlay it would restore) belongs to the previous workspace. Leave the
1199+
// session empty so its next turn hydrates from the new one.
1200+
if (generation !== overlayGeneration) return { count: 0, ok: false, status: "error" }
11961201
if (outcome.status === "error") {
11971202
// Keep what the session had. Emptying it because the network hiccuped is
11981203
// strictly worse than not reloading, and the user asked for a reload.
@@ -1214,12 +1219,16 @@ export async function refresh(sessionID: string, directory?: string): Promise<Re
12141219
})
12151220
}
12161221

1222+
/** Bumped by a full reset, so a `refresh` that started before it does not write back. */
1223+
let overlayGeneration = 0
1224+
12171225
/** Forget a session's hydration, or all of them.
12181226
*
12191227
* Not called per turn: doing so defeated ``hydrate``'s idempotence and made
12201228
* every turn refetch. Exposed for tests and for a future session-end hook. */
12211229
export function resetOverlay(sessionID?: string): void {
12221230
if (sessionID === undefined) {
1231+
overlayGeneration++
12231232
sessions.clear()
12241233
// Both memos, not just the positive one. A refresh after memory was turned
12251234
// ON for a workspace last seen off otherwise kept reporting zero unsynced
@@ -1230,3 +1239,8 @@ export function resetOverlay(sessionID?: string): void {
12301239
}
12311240
sessions.delete(sessionID)
12321241
}
1242+
1243+
// A link, relink, unlink or server-side rebind swaps the workspace under every open
1244+
// session, and `hydrate` loads once per session: without this, a session that pulled
1245+
// workspace A's memory keeps injecting it after the project is relinked to B.
1246+
onBindingChanged(() => resetOverlay())

‎packages/opencode/src/altimate/workspace/skill-sync.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { Log } from "@/altimate/util/log"
4545
import { AltimateApi } from "@/altimate/api/client"
4646
import { resolveBindingOutcome, type CachedBinding } from "./state"
4747
import { altimateRequest, WorkspaceApiError } from "./api-client"
48+
import { readPin, resolveWithinRoot } from "./pin"
4849

4950
const log = Log.create({ service: "altimate-workspace-skill-sync" })
5051

@@ -806,6 +807,18 @@ export async function syncSkills(directory: string): Promise<{ changed: boolean
806807
if (outcome.status === "unbound") {
807808
if (await deactivate(canon, "this project is no longer bound to a workspace")) changed = true
808809
}
810+
// An IDE pin that cannot be honoured resolves `unknown` and fails closed for
811+
// memory and routing; a snapshot of some other workspace (usually the
812+
// project's own link) must not keep serving skills in its place. Only inside
813+
// the pinned root, which is the folder the pin speaks for; a snapshot of the
814+
// pinned workspace itself survives, since that may just be a blip.
815+
const pin = readPin()
816+
if (outcome.status === "unknown" && pin.kind === "valid" && resolveWithinRoot(canon, pin.root)) {
817+
const manifest = await readManifest(canon)
818+
if (manifest && manifest.datamateId !== pin.datamateId) {
819+
if (await deactivate(canon, "the workspace pin could not be honoured")) changed = true
820+
}
821+
}
809822
return
810823
}
811824
const binding = outcome.binding

‎packages/opencode/src/altimate/workspace/state.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Log } from "@/altimate/util/log"
2020
// Type-only: the value side is imported dynamically in resolveBinding to keep
2121
// this module's import graph free of the API client at load time.
2222
import type { Binding, ProjectBindingLookup } from "./api-client"
23+
import type { SeedOutcome } from "./memory-backfill"
2324
// altimate_change — the IDE extension's workspace pin; see ./pin.ts
2425
import { readPinLogged, resolveWithinRoot, type ValidPin } from "./pin"
2526
import { resolveProjectIdentifier } from "./detect"
@@ -1085,10 +1086,12 @@ export async function currentScope(): Promise<{ tenant: string; apiUrl: string }
10851086
export async function recordApprovedBinding(
10861087
directory: string,
10871088
binding: CachedBinding,
1088-
opts?: { awaitBackfill?: boolean },
1089-
): Promise<void> {
1089+
// `seed: false` warms the cache for a link the user has not accepted yet: a discovered
1090+
// link must not upload local memory before they choose Attach.
1091+
opts?: { awaitBackfill?: boolean; seed?: boolean },
1092+
): Promise<SeedOutcome | null> {
10901093
const key = await tenantKey()
1091-
if (!key) return
1094+
if (!key) return null
10921095
// An explicit link is the newest word on this project, so retire any memoized
10931096
// "no binding here" from before it and count the row as server-validated —
10941097
// the link is what created it. Without the first, revalidation reads the
@@ -1174,18 +1177,20 @@ export async function recordApprovedBinding(
11741177
// Skip only when this exact binding has already been seeded successfully. A
11751178
// warm after a failed or skipped seed must try again, or the blocks this
11761179
// machine already holds never reach the workspace.
1177-
if (alreadySeeded) return
1180+
if (alreadySeeded) return { status: "seeded", sent: 0, pending: 0 }
1181+
if (opts?.seed === false) return null
11781182
const seeded = import("./memory-backfill")
1179-
.then((m) => m.backfillOnBind(canonicalizeKey(directory), binding))
1180-
.then((ok) => {
1181-
if (ok) markSeeded(directory, binding)
1182-
return ok
1183+
.then((m) => m.seedOnBind(canonicalizeKey(directory), binding))
1184+
.then((outcome) => {
1185+
if (outcome.status === "seeded") markSeeded(directory, binding)
1186+
return outcome
11831187
})
1184-
.catch((err) => {
1188+
.catch((err): SeedOutcome => {
11851189
log.warn("could not start workspace memory backfill", { err: String(err) })
1186-
return false
1190+
return { status: "incomplete", sent: 0, pending: 0 }
11871191
})
1188-
if (opts?.awaitBackfill) await seeded
1189-
else void seeded
1192+
if (opts?.awaitBackfill) return seeded
1193+
void seeded
1194+
return null
11901195
// altimate_change end
11911196
}

0 commit comments

Comments
 (0)