Skip to content

Commit 39dd901

Browse files
anandgupta42claude
andcommitted
fix(workspace): surface an account-changed Attach; do not overstate unsent memory on gate errors
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1b1dfd6 commit 39dd901

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const log = Log.create({ service: "altimate-workspace-memory-backfill" })
2020
* for the workspace), `incomplete` is "ran and left blocks behind"; `link` reports the
2121
* two differently, since only the second needs the user to retry a Sync. */
2222
export type SeedOutcome = {
23-
status: "seeded" | "already" | "off" | "local-off" | "incomplete"
23+
status: "seeded" | "already" | "off" | "local-off" | "incomplete" | "account-changed"
2424
sent: number
2525
pending: number
2626
}
@@ -51,7 +51,8 @@ export async function seedOnBind(directory: string, binding: CachedBinding): Pro
5151
if (result.gated)
5252
return result.gateReason === "disabled"
5353
? { status: "off", sent: 0, pending: 0 }
54-
: { status: "incomplete", sent: 0, pending: blocks.length }
54+
: // How many are really unsent is unknown (some may be indexed from an earlier seed).
55+
{ status: "incomplete", sent: 0, pending: 0 }
5556
// Only a sweep that stored everything it meant to counts as seeded. A
5657
// failure here must leave the binding eligible for a retry, or local blocks
5758
// stay absent from the workspace until a rebind or an unrelated edit.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ export async function recordApprovedBinding(
11101110
if (!key) return null
11111111
if (opts?.account !== undefined && (await accountDigest()) !== opts.account) {
11121112
log.warn("the Altimate account changed before the link was recorded; not recording it")
1113-
return null
1113+
return { status: "account-changed", sent: 0, pending: 0 }
11141114
}
11151115
// An explicit link is the newest word on this project, so retire any memoized
11161116
// "no binding here" from before it and count the row as server-validated —
@@ -1201,7 +1201,7 @@ export async function recordApprovedBinding(
12011201
if (opts?.seed === false) return null
12021202
if (opts?.account !== undefined && (await accountDigest()) !== opts.account) {
12031203
log.warn("the Altimate account changed before the memory seed; not seeding")
1204-
return null
1204+
return { status: "account-changed", sent: 0, pending: 0 }
12051205
}
12061206
const seeded = import("./memory-backfill")
12071207
.then((m) => m.seedOnBind(canonicalizeKey(directory), binding))

‎packages/opencode/src/cli/cmd/link.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ export function seedMessage(seed: SeedOutcome | null): string {
790790
if (seed?.status === "already")
791791
return "This machine's saved memory was sent when this workspace was first linked. To resend anything missed since, run /workspace → Sync in the TUI."
792792
if (seed?.status === "off") return "Workspace memory is off, so saved memory stays on this machine."
793+
if (seed?.status === "account-changed")
794+
return "Your Altimate account changed during linking, so saved memory was not sent. Run /workspace → Sync in the TUI to retry."
793795
if (seed?.status === "local-off")
794796
return "Memory sync is turned off on this machine (ALTIMATE_DISABLE_MEMORY or OPENCODE_DISABLE_MEMORY), so saved memory stays here."
795797
// null: the seed could not run here (no resolvable credentials), which is not "off".

‎packages/opencode/src/plugin/tui/altimate/workspace.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,13 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
12421242
const who = await accountDigest()
12431243
const live = await WorkspaceApi.getBindingForProject(identifier).catch(() => undefined)
12441244
if (who !== null && who === flowAccount && live?.datamate.id === discovered.datamateId) {
1245-
await recordApprovedBinding(directory, discovered, { account: who })
1245+
const out = await recordApprovedBinding(directory, discovered, { account: who })
1246+
if (out?.status === "account-changed")
1247+
api.ui.toast({
1248+
variant: "warning",
1249+
message: "Your Altimate account changed while attaching, so saved memory was not sent. Try Attach again.",
1250+
duration: 8_000,
1251+
})
12461252
return
12471253
}
12481254
api.ui.toast({
@@ -1315,7 +1321,13 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
13151321
}
13161322
// Attach is the user's approval: the row is no longer merely adopted from the server.
13171323
if (live?.datamate.id === local.datamateId) {
1318-
await recordApprovedBinding(directory, { ...local, adopted: false }, { account: who })
1324+
const out = await recordApprovedBinding(directory, { ...local, adopted: false }, { account: who })
1325+
if (out?.status === "account-changed")
1326+
api.ui.toast({
1327+
variant: "warning",
1328+
message: "Your Altimate account changed while attaching, so saved memory was not sent. Try Attach again.",
1329+
duration: 8_000,
1330+
})
13191331
return
13201332
}
13211333
api.ui.toast({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ describe("workspace binding cache", () => {
358358
mkdirSync(proj, { recursive: true })
359359
const binding = { datamateId: 12, datamateName: "Pinned", repoRemote: null, projectPath: proj, linkedAt: 1 }
360360
const out = await recordApprovedBinding(proj, binding, { awaitBackfill: true, account: "not-the-current-account" })
361-
expect(out).toBeNull()
361+
expect(out?.status).toBe("account-changed")
362362
expect(await readLocalBinding(proj)).toBeNull()
363363
})
364364

0 commit comments

Comments
 (0)