Skip to content

Commit cd10a15

Browse files
fix: count the shadowed types the session can route
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent c427a1b commit cd10a15

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

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

159159
export function precedenceEvent(
160160
p: Pick<Precedence, "enabled" | "disabledReason" | "shadowed" | "extensions" | "workspaceId">,
161-
opts: { escapeHatch: boolean; connections: number; sessionID?: string },
161+
opts: { escapeHatch: boolean; connections: number; types: number; sessionID?: string },
162162
): Telemetry.Event {
163163
const id = Number(p.workspaceId)
164164
return {
@@ -167,7 +167,9 @@ export function precedenceEvent(
167167
session_id: opts.sessionID ?? sessionId(),
168168
enabled: p.enabled,
169169
...(p.disabledReason ? { reason: p.disabledReason } : {}),
170-
shadowed_types: p.shadowed.size,
170+
// Types the session can route through the engine (the inventory line's count), not every
171+
// materialised type: a session whose rules deny the engine keys shadows nothing.
172+
shadowed_types: opts.types,
171173
shadowed_connections: opts.connections,
172174
extensions: p.extensions?.length ?? 0,
173175
escape_hatch: opts.escapeHatch,
@@ -183,13 +185,13 @@ const MAX_SEEN_SESSIONS = 256
183185
export function trackPrecedence(
184186
sessionID: string,
185187
p: Pick<Precedence, "enabled" | "disabledReason" | "shadowed" | "extensions" | "workspaceId">,
186-
opts: { escapeHatch: boolean; connections: number; identity?: string },
188+
opts: { escapeHatch: boolean; connections: number; types: number; identity?: string },
187189
): boolean {
188190
try {
189191
// The local connections shadowed and the escape hatch are part of what is reported, so a change
190192
// in either re-reports the same snapshot; the account-scoped identity (credential scope plus
191193
// id) tells the same id under another account apart.
192-
const signature = `${precedenceSignature(p)}|c=${opts.connections}|e=${opts.escapeHatch}|w=${opts.identity ?? ""}`
194+
const signature = `${precedenceSignature(p)}|c=${opts.connections}|t=${opts.types}|e=${opts.escapeHatch}|w=${opts.identity ?? ""}`
193195
if (precedenceSeen.get(sessionID) === signature) return false
194196
precedenceSeen.set(sessionID, signature)
195197
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
@@ -544,6 +544,8 @@ export async function refresh(
544544
escapeHatch: escapeHatchOn(),
545545
// The registry is read only when something can be shadowed: a disabled snapshot shadows nothing.
546546
connections: result.enabled ? countShadowedConnections(result) : 0,
547+
// Types the session can route through the engine, as the inventory line counts them.
548+
types: result.enabled ? servedInventory(result).length : 0,
547549
identity: linkedWorkspaceKey(),
548550
})
549551
// Mechanism 6 — say once, per session, what is now served where. Silence is the one

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ 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-
expect(precedenceEvent(on, { escapeHatch: false, connections: 1 })).toEqual(
128+
expect(precedenceEvent(on, { escapeHatch: false, connections: 1, types: 2 })).toEqual(
129129
expect.objectContaining({
130130
type: "workspace_engine_precedence",
131131
enabled: true,
@@ -136,20 +136,20 @@ describe("workspace engine telemetry builders", () => {
136136
workspace_id: 7,
137137
}),
138138
)
139-
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 1 })).toBe(true)
140-
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 1 })).toBe(false) // unchanged
141-
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 2 })).toBe(true) // a connection was added locally
142-
expect(trackPrecedence("s2", on, { escapeHatch: false, connections: 2 })).toBe(true) // another session
139+
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 1, types: 2 })).toBe(true)
140+
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 1, types: 2 })).toBe(false) // unchanged
141+
expect(trackPrecedence("s1", on, { escapeHatch: false, connections: 2, types: 2 })).toBe(true) // a connection was added locally
142+
expect(trackPrecedence("s2", on, { escapeHatch: false, connections: 2, types: 2 })).toBe(true) // another session
143143
const off: any = { enabled: false, disabledReason: "escape-hatch" as const, shadowed: new Map(), workspaceId: "7" }
144-
expect(trackPrecedence("s1", off, { escapeHatch: true, connections: 0 })).toBe(true)
144+
expect(trackPrecedence("s1", off, { escapeHatch: true, connections: 0, types: 0 })).toBe(true)
145145
expect(events.at(-1)).toEqual(
146146
expect.objectContaining({ enabled: false, reason: "escape-hatch", shadowed_types: 0, escape_hatch: true }),
147147
)
148-
expect(trackPrecedence("s1", off, { escapeHatch: false, connections: 0 })).toBe(true) // the hatch toggled
148+
expect(trackPrecedence("s1", off, { escapeHatch: false, connections: 0, types: 0 })).toBe(true) // the hatch toggled
149149
// 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)
150+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, types: 2, identity: "acme|7" })).toBe(true)
151+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, types: 2, identity: "acme|7" })).toBe(false)
152+
expect(trackPrecedence("s3", on, { escapeHatch: false, connections: 1, types: 2, identity: "other|7" })).toBe(true)
153153
expect((events.at(-1) as any).escape_hatch).toBe(false)
154154
})
155155

0 commit comments

Comments
 (0)