Skip to content

Commit 0d54c65

Browse files
anandgupta42claude
andcommitted
fix(workspace): revalidate online Attach; Open follows the IDE pin; signal-based race tests
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 2ede9c7 commit 0d54c65

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ import {
5656
projectNameFromRemote,
5757
resolveProjectIdentifier,
5858
} from "@/altimate/workspace/detect"
59-
import { accountDigest, readLocalBinding, recordApprovedBinding } from "@/altimate/workspace/state"
59+
import {
60+
accountDigest,
61+
readLocalBinding,
62+
recordApprovedBinding,
63+
resolvePinnedBindingForRouting,
64+
} from "@/altimate/workspace/state"
6065
import {
6166
describeOffer,
6267
installCommand,
@@ -1215,6 +1220,8 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
12151220
// Resolved before the dialog renders — see AlreadyLinkedDialog's comment
12161221
// on why this can't be fetched async inside the dialog itself.
12171222
const manageUrl = await resolveManageUrl(serverBinding.datamate.id)
1223+
// Same pinning as the offline branch: Attach may come long after this pre-check.
1224+
const discoveredAs = await accountDigest()
12181225
api.ui.dialog.replace(() => (
12191226
<AlreadyLinkedDialog
12201227
api={api}
@@ -1225,7 +1232,26 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
12251232
hasDrift={hasDrift}
12261233
driftedWas={hasDrift ? boundIdent : undefined}
12271234
manageUrl={manageUrl}
1228-
onAttach={() => recordApprovedBinding(directory, discovered)}
1235+
onAttach={async () => {
1236+
// Re-confirm before seeding: the account or the project's link can change between the
1237+
// pre-check and the click, and the seed must go to the link that still stands.
1238+
const who = await accountDigest()
1239+
const live = await WorkspaceApi.getBindingForProject(identifier).catch(() => undefined)
1240+
if (who !== null && who === discoveredAs && live?.datamate.id === discovered.datamateId) {
1241+
await recordApprovedBinding(directory, discovered, { account: who })
1242+
return
1243+
}
1244+
api.ui.toast({
1245+
variant: "warning",
1246+
message:
1247+
who !== discoveredAs
1248+
? "Your Altimate account changed while attaching, so saved memory was not sent. Try Attach again."
1249+
: live === undefined
1250+
? "Could not confirm the link with the workspace service, so saved memory was not sent. Try Attach again once it is reachable."
1251+
: "This project is no longer linked to that workspace, so nothing was attached. Run /workspace to see its current link.",
1252+
duration: 8_000,
1253+
})
1254+
}}
12291255
/>
12301256
))
12311257
return
@@ -1870,7 +1896,10 @@ async function runWorkspaceManage(api: TuiPluginApi, directory: string): Promise
18701896
const linked = report.binding !== null
18711897
// Resolved before render, like AlreadyLinkedDialog's: an option appearing after
18721898
// paint would shift the row under the user's cursor.
1873-
const manageUrl = report.binding ? await resolveManageUrl(report.binding.datamateId) : null
1899+
// Under an IDE pin, skills, memory and routing follow the pinned workspace, so Open must too.
1900+
const pinned = await resolvePinnedBindingForRouting(directory).catch(() => null)
1901+
const openId = pinned?.status === "bound" ? pinned.binding.datamateId : report.binding?.datamateId
1902+
const manageUrl = openId !== undefined ? await resolveManageUrl(openId) : null
18741903

18751904
api.ui.dialog.replace(() => (
18761905
<api.ui.DialogSelect

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,12 +1347,17 @@ describe("refresh racing a relink", () => {
13471347
let release: (() => void) | undefined
13481348
const gate = new Promise<void>((r) => (release = r))
13491349
const inner = globalThis.fetch
1350+
let entered: (() => void) | undefined
1351+
const reachedList = new Promise<void>((r) => (entered = r))
13501352
globalThis.fetch = (async (input: any, init?: any) => {
1351-
if (String(input).includes("/datamates/memory/list")) await gate
1353+
if (String(input).includes("/datamates/memory/list")) {
1354+
entered?.()
1355+
await gate
1356+
}
13521357
return inner(input, init)
13531358
}) as typeof fetch
13541359
const pending = refresh(SES)
1355-
await new Promise((r) => setTimeout(r, 10))
1360+
await reachedList
13561361
const { recordApprovedBinding } = await import("../../../src/altimate/workspace/state")
13571362
const dir = mkdtempSync(path.join(SANDBOX, "race-"))
13581363
await recordApprovedBinding(dir, { ...BINDING, datamateId: 44, projectPath: dir, linkedAt: 4 }, { seed: false })
@@ -1391,12 +1396,17 @@ describe("overlay invalidation", () => {
13911396
let release: (() => void) | undefined
13921397
const gate = new Promise<void>((r) => (release = r))
13931398
const inner = globalThis.fetch
1399+
let entered: (() => void) | undefined
1400+
const reachedList = new Promise<void>((r) => (entered = r))
13941401
globalThis.fetch = (async (input: any, init?: any) => {
1395-
if (String(input).includes("/datamates/memory/list")) await gate
1402+
if (String(input).includes("/datamates/memory/list")) {
1403+
entered?.()
1404+
await gate
1405+
}
13961406
return inner(input, init)
13971407
}) as typeof fetch
13981408
const pending = refresh(SES)
1399-
await new Promise((r) => setTimeout(r, 10))
1409+
await reachedList
14001410
resetOverlay() // what Unlink does
14011411
release?.()
14021412
await pending

0 commit comments

Comments
 (0)