Skip to content

Commit 3090eaa

Browse files
anandgupta42claude
andcommitted
fix(workspace): stamp failed memory loads; use the hidden-conflict check in the TUI
A failed load no longer reloads on every turn; TUI conflict toasts use the same hidden-workspace predicate as the CLI; the already-seeded message no longer claims all memory is synced. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent da83923 commit 3090eaa

5 files changed

Lines changed: 31 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ type LoadOutcome = (
11391139
/** Read this project's workspace memory. Pure: it publishes nothing, so a slow
11401140
* load that has been superseded cannot write over a newer result. */
11411141
async function loadWorkspaceMemory(directory?: string): Promise<LoadOutcome> {
1142+
const raw = directory ?? currentDirectory()
1143+
const dir = raw ? canonicalDirectory(raw) : null
11421144
try {
1143-
const raw = directory ?? currentDirectory()
1144-
const dir = raw ? canonicalDirectory(raw) : null
11451145
// The epoch must bracket the lookup: read only after it, a relink that lands while the
11461146
// lookup is pending would stamp the old binding as current. Read only before it, a lookup
11471147
// that adopts this project's server binding (which notifies a change) would stamp itself
@@ -1180,7 +1180,9 @@ async function loadWorkspaceMemory(directory?: string): Promise<LoadOutcome> {
11801180
return { status: "loaded", blocks, epoch, dir }
11811181
} catch (err) {
11821182
log.warn("workspace memory load failed", { err: String(err) })
1183-
return { status: "error" }
1183+
// Stamped like any other outcome: without an epoch the session would reload (and make
1184+
// the prompt wait) on every turn for as long as the service is down.
1185+
return { status: "error", epoch: epochFor(dir), dir }
11841186
}
11851187
}
11861188

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,9 @@ export function seedMessage(seed: SeedOutcome | null): string {
786786
return seed.sent > 0
787787
? `Sent ${seed.sent} saved memor${seed.sent === 1 ? "y" : "ies"} to the workspace.`
788788
: "Saved memory is in sync with the workspace."
789-
if (seed?.status === "already") return "Saved memory was already sent to this workspace."
789+
// `already` means the one-time bind seed ran before, not that every block is synced now.
790+
if (seed?.status === "already")
791+
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."
790792
if (seed?.status === "off") return "Workspace memory is off, so saved memory stays on this machine."
791793
if (seed?.status === "local-off")
792794
return "Memory sync is turned off on this machine (ALTIMATE_DISABLE_MEMORY or OPENCODE_DISABLE_MEMORY), so saved memory stays here."

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { createSignal, onCleanup, onMount } from "solid-js"
3434
import {
3535
ConflictError,
3636
HIDDEN_BINDING_MESSAGE,
37+
isHiddenBindingConflict,
3738
ForbiddenError,
3839
NotFoundError,
3940
PreconditionFailedError,
@@ -420,9 +421,9 @@ async function runBrowserHandoff(
420421
if (err instanceof ConflictError) {
421422
api.ui.toast({
422423
variant: "warning",
423-
message: err.detail.existing_datamate_name
424-
? `This project is already linked to "${err.detail.existing_datamate_name}". Run \`altimate-code link\` to change.`
425-
: HIDDEN_BINDING_MESSAGE,
424+
message: isHiddenBindingConflict(err)
425+
? HIDDEN_BINDING_MESSAGE
426+
: `This project is already linked to "${err.detail.existing_datamate_name ?? "another workspace"}". Run \`altimate-code link\` to change.`,
426427
})
427428
} else if (err instanceof NotFoundError) {
428429
api.ui.toast({
@@ -899,9 +900,9 @@ function PickerDialog(props: PickerProps) {
899900
// The picker doesn't have a "Re-link" option; the referral used to
900901
// point at OfferDialog's Re-link, which doesn't exist either. Point
901902
// at the concrete next action instead. (kilo cycle 6.)
902-
msg = err.detail.existing_datamate_name
903-
? `Already linked to "${err.detail.existing_datamate_name}". Re-run \`altimate-code link\` to change the workspace.`
904-
: HIDDEN_BINDING_MESSAGE
903+
msg = isHiddenBindingConflict(err)
904+
? HIDDEN_BINDING_MESSAGE
905+
: `Already linked to "${err.detail.existing_datamate_name ?? "another workspace"}". Re-run \`altimate-code link\` to change the workspace.`
905906
} else if (err instanceof PreconditionFailedError) {
906907
msg = "Someone else re-linked this project — reload and try again."
907908
} else if (err instanceof NotFoundError) {
@@ -1096,9 +1097,9 @@ async function bindOrRebindInline(
10961097
} catch (err) {
10971098
let msg: string
10981099
if (err instanceof ConflictError) {
1099-
msg = err.detail.existing_datamate_name
1100-
? `Already linked to "${err.detail.existing_datamate_name}".`
1101-
: HIDDEN_BINDING_MESSAGE
1100+
msg = isHiddenBindingConflict(err)
1101+
? HIDDEN_BINDING_MESSAGE
1102+
: `Already linked to "${err.detail.existing_datamate_name ?? "another workspace"}".`
11021103
} else if (err instanceof PreconditionFailedError) {
11031104
msg = "Someone else re-linked this project — reload and try again."
11041105
} else if (err instanceof NotFoundError) {

‎packages/opencode/test/altimate/workspace/link-seed-message.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ test("link reports a completed seed and memory that is off without a retry hint"
1414
expect(seedMessage({ status: "off", sent: 0, pending: 0 })).toBe(
1515
"Workspace memory is off, so saved memory stays on this machine.",
1616
)
17-
expect(seedMessage({ status: "already", sent: 0, pending: 0 })).toBe("Saved memory was already sent to this workspace.")
17+
// Does not claim everything is synced now: points at Sync for anything missed since.
18+
expect(seedMessage({ status: "already", sent: 0, pending: 0 })).toContain("when this workspace was first linked")
19+
expect(seedMessage({ status: "already", sent: 0, pending: 0 })).toContain("Sync")
1820
expect(seedMessage({ status: "local-off", sent: 0, pending: 0 })).toContain("turned off on this machine")
1921
// A seed that could not run is not "memory is off".
2022
expect(seedMessage(null)).not.toContain("is off")

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,16 @@ describe("epoch bracketing and scope", () => {
14471447
})
14481448
})
14491449

1450+
describe("hydration errors", () => {
1451+
test("a failed load is not retried on every turn", async () => {
1452+
listFails = true
1453+
await hydrate(SES)
1454+
await hydrate(SES)
1455+
await hydrate(SES)
1456+
expect(callsTo("/datamates/memory/list").length).toBe(1)
1457+
})
1458+
})
1459+
14501460
describe("session isolation and turn behaviour", () => {
14511461
test("a session hydrates once, however many turns it takes", async () => {
14521462
// The caller's enclosing block runs on EVERY user turn, not once per

0 commit comments

Comments
 (0)