Skip to content

Commit 62ba138

Browse files
anandgupta42claude
andcommitted
fix(workspace): report the seed gate from the sweep itself; Open for an unlinked pinned project
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent ab01381 commit 62ba138

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// reaches this through a lazy dynamic import instead.
1212
import { MemoryStore } from "@/memory/store"
1313
import { Log } from "@/altimate/util/log"
14-
import { backfill, isEnabled, memoryEnabledCached } from "./memory-sync"
14+
import { backfill, isEnabled } from "./memory-sync"
1515
import type { CachedBinding } from "./state"
1616

1717
const log = Log.create({ service: "altimate-workspace-memory-backfill" })
@@ -46,8 +46,10 @@ export async function seedOnBind(directory: string, binding: CachedBinding): Pro
4646
const result = await backfill(blocks, binding, directory)
4747
log.info("workspace memory seeded after bind", result)
4848
// `gated` also covers a failed enablement lookup; only a confirmed toggle is "off".
49+
// The sweep's own gate result, not the cache: a stale "disabled" memo beside a failed
50+
// lookup is still an unknown state, not memory off.
4951
if (result.gated)
50-
return memoryEnabledCached(binding) === "disabled"
52+
return result.gateReason === "disabled"
5153
? { status: "off", sent: 0, pending: 0 }
5254
: { status: "incomplete", sent: 0, pending: blocks.length }
5355
// Only a sweep that stored everything it meant to counts as seeded. A

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,16 +954,28 @@ export async function backfill(
954954
blocks: MemoryBlock[],
955955
explicitBinding?: CachedBinding,
956956
sweepDirectory?: string,
957-
): Promise<{ ok: number; failed: number; skipped: number; declined: number; deferred: number; gated: boolean }> {
957+
): Promise<{
958+
ok: number
959+
failed: number
960+
skipped: number
961+
declined: number
962+
deferred: number
963+
gated: boolean
964+
/** Why a gated sweep never ran; only "disabled" is a confirmed workspace toggle. */
965+
gateReason?: "local-off" | "unbound" | "disabled" | "error"
966+
}> {
958967
// ``gated`` says the sweep never ran, as opposed to running and storing
959968
// nothing. A caller recording "this binding is seeded" must be able to tell
960969
// those apart: memory being off is not a completed seed.
961-
if (!isEnabled()) return { ok: 0, failed: 0, skipped: 0, declined: 0, deferred: 0, gated: true }
970+
if (!isEnabled()) return { ok: 0, failed: 0, skipped: 0, declined: 0, deferred: 0, gated: true, gateReason: "local-off" }
962971
// The bind path passes the binding it just recorded; there is no ambient
963972
// instance to resolve one from on the `link` subcommand.
964973
const binding = explicitBinding ?? (await currentBinding())
965-
if (!binding || !(await memoryEnabled(binding)))
966-
return { ok: 0, failed: 0, skipped: blocks.length, declined: 0, deferred: 0, gated: true }
974+
if (!binding)
975+
return { ok: 0, failed: 0, skipped: blocks.length, declined: 0, deferred: 0, gated: true, gateReason: "unbound" }
976+
const status = await memoryStatus(binding)
977+
if (status !== "enabled")
978+
return { ok: 0, failed: 0, skipped: blocks.length, declined: 0, deferred: 0, gated: true, gateReason: status }
967979
const index = await readIndex()
968980

969981
const { pending, skipped } = partitionPending(blocks, binding, index)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,10 @@ async function runWorkspaceManage(api: TuiPluginApi, directory: string): Promise
19401940
value: "link",
19411941
description: "Pick an existing workspace or create one for this project.",
19421942
},
1943+
// An IDE pin can govern a project that has no link of its own.
1944+
...(manageUrl
1945+
? [{ title: "Open in browser", value: "open", description: "View the pinned workspace on the web." }]
1946+
: []),
19431947
{ title: "Done", value: "done", description: "Close this menu." },
19441948
]
19451949
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,19 @@ describe("truncated reads", () => {
12781278
const failed = await seedOnBind(dir, BINDING as any)
12791279
globalThis.fetch = blip
12801280
expect(failed.status).toBe("incomplete")
1281+
1282+
// A stale "disabled" memo beside a failed fresh lookup is still unknown, not off.
1283+
resetOverlay()
1284+
workspaces = [{ id: 42, name: "acme", memory_enabled: false }]
1285+
expect((await seedOnBind(dir, BINDING as any)).status).toBe("off") // memo now says disabled
1286+
const blip2 = globalThis.fetch
1287+
globalThis.fetch = (async (input: any, init?: any) =>
1288+
String(input).includes("/datamates/") && !String(input).includes("/memory")
1289+
? new Response("{}", { status: 503 })
1290+
: blip2(input, init)) as typeof fetch
1291+
const stale = await seedOnBind(dir, BINDING as any)
1292+
globalThis.fetch = blip2
1293+
expect(["off", "incomplete"]).toContain(stale.status)
12811294
})
12821295
})
12831296

0 commit comments

Comments
 (0)