Skip to content

Commit dfa62c1

Browse files
sahrizviclaude
andcommitted
fix: report unsent memory from workspace status's count, not a failure set
Review follow-ups. The in-process `failedMirrors` set missed uploads that were deferred, declined or still pending when the exit flush gave up, kept blocks deleted since, and keyed by block id alone. `run` now asks, only when it mirrored something, for the same pending count `workspace status` shows (a local index read), and prints it, or says the count is unknown. - `workspace list` runs without opening a project. - stdin tests: the first chunk arrives at once, so timing margins are wide; the empty-stdin test asserts it returns at once. - Docs: re-linking to a different workspace needs `--yes`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011chv9Rmu7jQXokum1WNcs7
1 parent 885854d commit dfa62c1

8 files changed

Lines changed: 83 additions & 43 deletions

File tree

‎docs/docs/data-engineering/guides/using-with-claude-code.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Claude Code reaches a workspace through Altimate Code: every task the plugin han
130130
altimate-code link
131131
```
132132

133-
Pick the workspace, or create one. The picker needs an interactive terminal, so it does not run from Claude Code's `!` prompt or a script. There, list the workspaces with `altimate-code workspace list` and link with `altimate-code link --workspace <id or name>`, or create one with `altimate-code link --create`. Claude can run these for you: ask it to link the project to a workspace.
133+
Pick the workspace, or create one. The picker needs an interactive terminal, so it does not run from Claude Code's `!` prompt or a script. There, list the workspaces with `altimate-code workspace list` and link with `altimate-code link --workspace <id or name>`, or create one with `altimate-code link --create`. Moving a linked project to a different workspace also needs `--yes`. Claude can run these for you: ask it to link the project to a workspace.
134134
135135
3. **Check it.** `altimate-code workspace status` shows the linked workspace and when its skills last synced.
136136
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// altimate_change - new file
2+
import * as Manage from "@/altimate/workspace/manage"
3+
import { mirrorWasRequested } from "@/altimate/workspace/memory-sync"
4+
5+
/**
6+
* What `run` prints at exit about memory saved here that the workspace has not received, or null when
7+
* there is nothing to say. `unsynced` is `workspace status`'s count: an upload that failed, was deferred
8+
* or declined, or was still in flight when the exit flush gave up is pending there; a block deleted
9+
* since is not.
10+
*/
11+
export function unsentMemoryNotice(unsynced: number | null): string | null {
12+
if (unsynced === null)
13+
return "Could not confirm that the memory saved here reached the workspace. Run `altimate-code workspace status` to check."
14+
if (unsynced === 0) return null
15+
return (
16+
`${unsynced === 1 ? "1 memory saved here is" : `${unsynced} memories saved here are`} not in the workspace yet. ` +
17+
`Run \`altimate-code workspace sync\` to send ${unsynced === 1 ? "it" : "them"}.`
18+
)
19+
}
20+
21+
/** Counted only when this process saved memory for a linked workspace, so other runs pay nothing. */
22+
export async function unsentMemoryNoticeAfterRun(directory: string): Promise<string | null> {
23+
if (!mirrorWasRequested()) return null
24+
const report = await Manage.status(directory)
25+
if (!report.binding || !report.memory) return null
26+
return unsentMemoryNotice(report.memory.unsynced)
27+
}

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -837,16 +837,16 @@ function serialize<T>(scope: "global" | "project", blockId: string, op: () => Pr
837837
* `skill-sync.flushPendingSyncs` holds it for a cold skill sync. */
838838
const mirrorsInFlight = syncState.mirrorsInFlight
839839

840-
/** Blocks whose mirror failed in this process, by `<scope>/<id>`. Nothing retries them in a one-shot `run`
841-
* (the TUI and `serve` poll; `run` does not), so its exit reports them instead of letting the block stay on
842-
* this machine unannounced. Process-global for the same two-module-graph reason as `syncState`. */
843-
const failedMirrors: Set<string> = ((globalThis as unknown as Record<symbol, Set<string> | undefined>)[
844-
Symbol.for("altimate.memory-sync.failed-mirrors")
845-
] ??= new Set())
846-
847-
/** How many blocks this process saved locally but could not send to the workspace. */
848-
export function failedMirrorCount(): number {
849-
return failedMirrors.size
840+
/** Whether this process tried to mirror a block to a linked workspace. A one-shot `run` checks it at exit
841+
* and, only then, counts the memory still not in the workspace (`Manage.status`): nothing in `run` retries
842+
* an upload, so without the check a block left behind stays on this machine unannounced. Process-global for
843+
* the same two-module-graph reason as `syncState`. */
844+
const mirrorRequests: { count: number } = ((globalThis as unknown as Record<symbol, { count: number } | undefined>)[
845+
Symbol.for("altimate.memory-sync.mirror-requests")
846+
] ??= { count: 0 })
847+
848+
export function mirrorWasRequested(): boolean {
849+
return mirrorRequests.count > 0
850850
}
851851

852852
/** Hold a task in `mirrorsInFlight` for its lifetime. */
@@ -895,15 +895,10 @@ export async function mirrorBlock(block: MemoryBlock, directory?: string): Promi
895895
// binding governs only whether we upload at all.
896896
const binding = await currentBinding(directory)
897897
if (!binding) return
898+
// Counted before the memory-setting check: a check that fails also leaves the block unsent.
899+
mirrorRequests.count++
898900
if (!(await memoryEnabled(binding))) return
899-
const key = `${block.scope}/${block.id}`
900-
try {
901-
await push(block, binding, undefined, directory)
902-
failedMirrors.delete(key)
903-
} catch (err) {
904-
failedMirrors.add(key)
905-
throw err
906-
}
901+
await push(block, binding, undefined, directory)
907902
})
908903
return tracked(task)
909904
}

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,16 +2108,12 @@ You are speaking to a non-technical business executive. Follow these rules stric
21082108
.then((m) => m.flushPendingMirrors())
21092109
.catch(() => {}),
21102110
])
2111-
// A mirror that failed is not retried by this process, and nothing else
2112-
// tells the user the memory stayed on this machine.
2113-
const unsent = await import("../../altimate/workspace/memory-sync")
2114-
.then((m) => m.failedMirrorCount())
2115-
.catch(() => 0)
2116-
if (unsent > 0)
2117-
process.stderr.write(
2118-
`${unsent === 1 ? "1 memory was" : `${unsent} memories were`} saved here but could not be sent to the workspace. ` +
2119-
`Run \`altimate-code workspace sync\` to send ${unsent === 1 ? "it" : "them"}.${EOL}`,
2120-
)
2111+
// This process does not retry an upload, and nothing else tells the user
2112+
// that memory stayed on this machine.
2113+
const notice = await import("../../altimate/cli/unsent-memory")
2114+
.then((m) => m.unsentMemoryNoticeAfterRun(process.cwd()))
2115+
.catch(() => null)
2116+
if (notice) process.stderr.write(notice + EOL)
21212117
}
21222118
// altimate_change end
21232119

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ async function inProject(directory: string, json: boolean, run: () => Promise<nu
326326
const DIRECTORY = { alias: "d", type: "string", describe: "Project directory (defaults to cwd)" } as const
327327
const JSON_FLAG = { type: "boolean", default: false, describe: "Print the result as JSON" } as const
328328

329+
// Account-scoped, so it runs without opening a project: no plugins, LSP or watchers just to list workspaces.
329330
const ListCommand = cmd({
330331
command: "list",
331332
describe: "list the workspaces this account can link to",
332-
builder: (yargs) => yargs.option("directory", DIRECTORY).option("json", JSON_FLAG),
333+
builder: (yargs) => yargs.option("json", JSON_FLAG),
333334
handler: async (args) => {
334-
const directory = args.directory ?? process.cwd()
335-
await inProject(directory, args.json, () => runList(args.json))
335+
process.exitCode = await runList(args.json)
336336
},
337337
})
338338

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// altimate_change - new file
2+
import { describe, expect, test } from "bun:test"
3+
import { unsentMemoryNotice } from "../../../src/altimate/cli/unsent-memory"
4+
5+
describe("unsentMemoryNotice", () => {
6+
test("says nothing when every memory reached the workspace", () => {
7+
expect(unsentMemoryNotice(0)).toBeNull()
8+
})
9+
10+
test("counts what is pending and points at workspace sync", () => {
11+
expect(unsentMemoryNotice(1)).toBe(
12+
"1 memory saved here is not in the workspace yet. Run `altimate-code workspace sync` to send it.",
13+
)
14+
expect(unsentMemoryNotice(3)).toBe(
15+
"3 memories saved here are not in the workspace yet. Run `altimate-code workspace sync` to send them.",
16+
)
17+
})
18+
19+
test("an unknown count is reported as unknown, never as zero", () => {
20+
expect(unsentMemoryNotice(null)).toContain("workspace status")
21+
})
22+
})

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const {
4545
isEnabled,
4646
memoryEnabledCached,
4747
mirrorBlock,
48-
failedMirrorCount,
48+
mirrorWasRequested,
4949
flushPendingMirrors,
5050
overlayBlocks,
5151
refresh,
@@ -442,14 +442,11 @@ describe("blockTitle", () => {
442442

443443
// ── write path ──────────────────────────────────────────────────────────────
444444
describe("mirrorBlock", () => {
445-
test("a failed mirror is counted until the block is sent, so `run` can say it stayed local", async () => {
446-
const before = failedMirrorCount()
445+
test("a mirror to a linked workspace is recorded, failed or not, so `run`'s exit checks what stayed local", async () => {
447446
createFails = true
448447
await expect(mirrorBlock(block({ id: "unsent" }))).rejects.toThrow()
449-
expect(failedMirrorCount()).toBe(before + 1)
450448
createFails = false
451-
await mirrorBlock(block({ id: "unsent" }))
452-
expect(failedMirrorCount()).toBe(before)
449+
expect(mirrorWasRequested()).toBe(true)
453450
})
454451

455452
test("flushPendingMirrors waits for a mirror a short-lived process would abandon (#1332)", async () => {

‎packages/opencode/test/cli/run/run-stdin.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readRunStdin, type StdinSource } from "../../../src/altimate/cli/run-st
33

44
const encoder = new TextEncoder()
55

6-
/** A stdin whose stream yields `chunks`, each after `delayMs`, then ends unless `open` is set. */
6+
/** A stdin whose stream yields `chunks` (the first at once, each later one after `delayMs`), then ends unless `open` is set. */
77
function source(opts: { chunks?: string[]; delayMs?: number; open?: boolean; file?: string }): StdinSource & {
88
cancelled: () => boolean
99
} {
@@ -15,8 +15,8 @@ function source(opts: { chunks?: string[]; delayMs?: number; open?: boolean; fil
1515
stream: () =>
1616
new ReadableStream<Uint8Array>({
1717
async start(controller) {
18-
for (const chunk of opts.chunks ?? []) {
19-
await Bun.sleep(opts.delayMs ?? 0)
18+
for (const [i, chunk] of (opts.chunks ?? []).entries()) {
19+
if (i > 0) await Bun.sleep(opts.delayMs ?? 0)
2020
if (cancelled) return
2121
controller.enqueue(encoder.encode(chunk))
2222
}
@@ -41,13 +41,16 @@ describe("readRunStdin", () => {
4141
})
4242

4343
test("keeps reading after the first chunk even past the wait", async () => {
44-
const result = await readRunStdin(source({ chunks: ["a", "b", "c"], delayMs: 30 }), 50)
44+
// The first chunk is immediate, so only the later ones (160ms in all) outlast the 50ms wait.
45+
const result = await readRunStdin(source({ chunks: ["a", "b", "c"], delayMs: 80 }), 50)
4546
expect(result).toEqual({ text: "abc", timedOut: false })
4647
})
4748

4849
test("an empty stdin that closes returns at once", async () => {
49-
const result = await readRunStdin(source({ chunks: [] }), 1000)
50+
const started = Date.now()
51+
const result = await readRunStdin(source({ chunks: [] }), 5000)
5052
expect(result).toEqual({ text: "", timedOut: false })
53+
expect(Date.now() - started).toBeLessThan(1000)
5154
})
5255

5356
test("a stdin left open with no data gives up after the wait and releases the stream", async () => {

0 commit comments

Comments
 (0)