Skip to content

Commit c427a1b

Browse files
fix: dedupe precedence rows on the account-scoped workspace identity
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent 444bfd6 commit c427a1b

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-overlay.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export function linkedWorkspace(directory: string | null = currentDirectory()):
338338
}
339339

340340
/** The linked workspace's account-scoped identity (credential scope plus id), for telemetry's dedupe. */
341-
function linkedWorkspaceKey(directory: string | null = currentDirectory()): string | undefined {
341+
export function linkedWorkspaceKey(directory: string | null = currentDirectory()): string | undefined {
342342
if (!directory) return undefined
343343
return directories.get(directory)?.linked?.key
344344
}

‎packages/opencode/src/altimate/workspace/engine-telemetry.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ const MAX_SEEN_SESSIONS = 256
183183
export function trackPrecedence(
184184
sessionID: string,
185185
p: Pick<Precedence, "enabled" | "disabledReason" | "shadowed" | "extensions" | "workspaceId">,
186-
opts: { escapeHatch: boolean; connections: number },
186+
opts: { escapeHatch: boolean; connections: number; identity?: string },
187187
): boolean {
188188
try {
189-
// The local connections shadowed are part of what is reported, so a registry change that
190-
// moves the count re-reports the same snapshot.
191-
const signature = `${precedenceSignature(p)}|c=${opts.connections}|e=${opts.escapeHatch}`
189+
// The local connections shadowed and the escape hatch are part of what is reported, so a change
190+
// in either re-reports the same snapshot; the account-scoped identity (credential scope plus
191+
// id) tells the same id under another account apart.
192+
const signature = `${precedenceSignature(p)}|c=${opts.connections}|e=${opts.escapeHatch}|w=${opts.identity ?? ""}`
192193
if (precedenceSeen.get(sessionID) === signature) return false
193194
precedenceSeen.set(sessionID, signature)
194195
if (precedenceSeen.size > MAX_SEEN_SESSIONS) precedenceSeen.delete(precedenceSeen.keys().next().value!)

‎packages/opencode/src/altimate/workspace/precedence.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
settledOutcome,
6767
type EntryLike,
6868
type Outcome,
69+
linkedWorkspaceKey,
6970
} from "./engine-overlay"
7071
import { readLocalBindingScopedStrict, resolvePinnedBindingForRouting } from "./state"
7172
import { liveBridge } from "./engine-probes"
@@ -543,6 +544,7 @@ export async function refresh(
543544
escapeHatch: escapeHatchOn(),
544545
// The registry is read only when something can be shadowed: a disabled snapshot shadows nothing.
545546
connections: result.enabled ? countShadowedConnections(result) : 0,
547+
identity: linkedWorkspaceKey(),
546548
})
547549
// Mechanism 6 — say once, per session, what is now served where. Silence is the one
548550
// thing this design does not allow, but repeating it every turn would be noise.

‎packages/opencode/test/altimate/workspace/engine-telemetry.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ describe("workspace engine telemetry builders", () => {
146146
expect.objectContaining({ enabled: false, reason: "escape-hatch", shadowed_types: 0, escape_hatch: true }),
147147
)
148148
expect(trackPrecedence("s1", off, { escapeHatch: false, connections: 0 })).toBe(true) // the hatch toggled
149+
// The same id under another account is another workspace: reported again.
150+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, identity: "acme|7" })).toBe(true)
151+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, identity: "acme|7" })).toBe(false)
152+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, identity: "other|7" })).toBe(true)
149153
expect((events.at(-1) as any).escape_hatch).toBe(false)
150154
})
151155

0 commit comments

Comments
 (0)