Skip to content

Commit 45ffa61

Browse files
saravmajesticclaude
andcommitted
fix(workspace): version memory items by content and retire skill state on deactivate
- Memory items are versioned by `block_updated` plus a content digest, so a web edit that keeps the mirror timestamp is still reported as updated - Taking the skill snapshot out of service clears its sync-state record, so a relink to the same workspace starts from a fresh baseline Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9d36087 commit 45ffa61

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,11 @@ function memoryItemKey(block: RemoteMemoryBlock): string {
15091509
return `${block.scope}:${block.origin ?? "own"}:${block.id}`
15101510
}
15111511

1512+
/** Versioned by content as well as the mirror's timestamp: an edit made in the web app can keep
1513+
* the block's original `block_updated`, and the session still loads the new text. */
15121514
function memoryItem(block: RemoteMemoryBlock): { label: string; version: string } {
1513-
return { label: blockTitle(block), version: block.updated ?? "" }
1515+
const digest = createHash("sha256").update(block.content).digest("hex").slice(0, 16)
1516+
return { label: blockTitle(block), version: `${block.updated ?? ""}:${digest}` }
15141517
}
15151518
// altimate_change end
15161519

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,13 @@ async function deactivate(directory: string, why: string): Promise<boolean> {
10861086
// here, before the early return: relinking must sync again rather than repeat a stale "none".
10871087
const canon = path.resolve(directory)
10881088
await clearEmptyRecord(canon)
1089+
// altimate_change start — workspace sync state
1090+
// The snapshot is out of service, so its record no longer describes anything here: a relink to
1091+
// the same workspace starts from a fresh baseline instead of the old count.
1092+
await import("./sync-state")
1093+
.then((SyncState) => SyncState.forget(canon, "skills"))
1094+
.catch((err) => log.warn("could not clear the skill sync state", { err: String(err) }))
1095+
// altimate_change end
10891096
try {
10901097
await fs.stat(root)
10911098
} catch {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,18 @@ describe("sync state", () => {
20972097
expect(entity?.count).toBe(2)
20982098
})
20992099

2100+
test("an edit that keeps the mirror's timestamp is still recorded as updated", async () => {
2101+
const dir = mkdtempSync(path.join(SANDBOX, "memory-sync-state-edit-"))
2102+
listResponse = [note("a", "Naming conventions")]
2103+
await refresh(`${SES}-state-edit-1`, dir)
2104+
expect(await memoryState(dir)).toMatchObject({ status: "ok", changes: null })
2105+
2106+
listResponse = [{ ...note("a", "Naming conventions"), memory: "# Naming conventions\nnew body" }]
2107+
await refresh(`${SES}-state-edit-2`, dir)
2108+
const entity = await memoryState(dir, (e) => e.changes !== null)
2109+
expect(entity?.changes).toEqual({ added: [], removed: [], updated: ["Naming conventions"] })
2110+
})
2111+
21002112
test("a load for an unbound project records nothing", async () => {
21012113
const dir = mkdtempSync(path.join(SANDBOX, "memory-sync-state-off-"))
21022114
syncInternals.resolveBinding = async () => null

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,36 @@ describe("sync state", () => {
26242624
expect(entity?.changes).toEqual({ added: [], removed: [], updated: ["pub-1"] })
26252625
})
26262626

2627+
test("taking the snapshot out of service retires its record", async () => {
2628+
serve({ "pub-1": { "SKILL.md": "one" } })
2629+
await syncSkills(project)
2630+
expect(await read()).toMatchObject({ status: "ok", count: 1 })
2631+
2632+
// A pin that cannot be confirmed takes the snapshot out of service (see the pin tests above).
2633+
unbind()
2634+
globalThis.fetch = (async () => {
2635+
throw new Error("offline")
2636+
}) as unknown as typeof fetch
2637+
const pin = {
2638+
ALTIMATE_CODE_SERVE: "1",
2639+
ALTIMATE_PINNED_WORKSPACE_ID: "4243",
2640+
ALTIMATE_PINNED_WORKSPACE_NAME: "pinned",
2641+
ALTIMATE_PINNED_WORKSPACE_ROOT: project,
2642+
}
2643+
const saved = Object.fromEntries(Object.keys(pin).map((k) => [k, process.env[k]]))
2644+
Object.assign(process.env, pin)
2645+
try {
2646+
await syncSkills(project)
2647+
} finally {
2648+
for (const [k, v] of Object.entries(saved)) {
2649+
if (v === undefined) delete process.env[k]
2650+
else process.env[k] = v
2651+
}
2652+
}
2653+
expect(existsSync(skillFile("pub-1", "SKILL.md"))).toBe(false)
2654+
expect(await read()).toBeUndefined()
2655+
})
2656+
26272657
test("a skill kept at its previous copy is not reported as updated until the update lands", async () => {
26282658
serve({ "pub-1": { "SKILL.md": "one" } }, "2026-01-01T00:00:00Z")
26292659
await syncSkills(project)

0 commit comments

Comments
 (0)