Skip to content

Commit a8f283a

Browse files
fix: name the linked workspace on a disabled precedence row
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent cd10a15 commit a8f283a

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ export function precedenceSignature(
158158

159159
export function precedenceEvent(
160160
p: Pick<Precedence, "enabled" | "disabledReason" | "shadowed" | "extensions" | "workspaceId">,
161-
opts: { escapeHatch: boolean; connections: number; types: number; sessionID?: string },
161+
opts: { escapeHatch: boolean; connections: number; types: number; sessionID?: string; workspaceId?: number },
162162
): Telemetry.Event {
163-
const id = Number(p.workspaceId)
163+
// The snapshot's own workspace, else the directory's linked one passed by refresh(): a disabled
164+
// snapshot (escape hatch, unattributed) names no workspace itself, and the row must not be left
165+
// to the process context.
166+
const own = Number(p.workspaceId)
167+
const id = Number.isInteger(own) && own > 0 ? own : opts.workspaceId
164168
return {
165169
type: "workspace_engine_precedence",
166170
timestamp: Date.now(),
@@ -173,7 +177,7 @@ export function precedenceEvent(
173177
shadowed_connections: opts.connections,
174178
extensions: p.extensions?.length ?? 0,
175179
escape_hatch: opts.escapeHatch,
176-
...(Number.isInteger(id) && id > 0 ? { workspace_id: id } : {}),
180+
...(id !== undefined && Number.isInteger(id) && id > 0 ? { workspace_id: id } : {}),
177181
}
178182
}
179183

@@ -185,7 +189,7 @@ const MAX_SEEN_SESSIONS = 256
185189
export function trackPrecedence(
186190
sessionID: string,
187191
p: Pick<Precedence, "enabled" | "disabledReason" | "shadowed" | "extensions" | "workspaceId">,
188-
opts: { escapeHatch: boolean; connections: number; types: number; identity?: string },
192+
opts: { escapeHatch: boolean; connections: number; types: number; identity?: string; workspaceId?: number },
189193
): boolean {
190194
try {
191195
// The local connections shadowed and the escape hatch are part of what is reported, so a change

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

Lines changed: 3 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+
linkedWorkspace,
6970
linkedWorkspaceKey,
7071
} from "./engine-overlay"
7172
import { readLocalBindingScopedStrict, resolvePinnedBindingForRouting } from "./state"
@@ -547,6 +548,8 @@ export async function refresh(
547548
// Types the session can route through the engine, as the inventory line counts them.
548549
types: result.enabled ? servedInventory(result).length : 0,
549550
identity: linkedWorkspaceKey(),
551+
// Named explicitly for disabled snapshots that carry no binding of their own.
552+
workspaceId: Number(linkedWorkspace()?.id) || undefined,
550553
})
551554
// Mechanism 6 — say once, per session, what is now served where. Silence is the one
552555
// 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ describe("workspace engine telemetry builders", () => {
125125
["dbt", new Map([["dbt_run", {} as any]])],
126126
])
127127
const on: any = { enabled: true, shadowed, extensions: [{ integration: "x", tools: [] }], workspaceId: "7" }
128+
// A disabled snapshot carries no binding; the directory's linked workspace names the row.
129+
const offSnap: any = { enabled: false, disabledReason: "escape-hatch" as const, shadowed: new Map() }
130+
expect(
131+
(precedenceEvent(offSnap, { escapeHatch: true, connections: 0, types: 0, workspaceId: 7 }) as any).workspace_id,
132+
).toBe(7)
133+
expect("workspace_id" in (precedenceEvent(offSnap, { escapeHatch: true, connections: 0, types: 0 }) as any)).toBe(
134+
false,
135+
)
128136
expect(precedenceEvent(on, { escapeHatch: false, connections: 1, types: 2 })).toEqual(
129137
expect.objectContaining({
130138
type: "workspace_engine_precedence",

0 commit comments

Comments
 (0)