Skip to content

Commit a0ff464

Browse files
anandgupta42claude
andcommitted
fix: address stakeholder review findings
Fixes from 5-stakeholder review (architect, privacy, perf, markers, tests): - Marker fix: remove nested altimate_change start/end, fold new variables into existing session telemetry tracking block - Performance: cap errorRecords at 200 entries (prevent unbounded growth) - Performance: slice intent classifier input to 2000 chars (bound regex) - Architecture: fix import path in sql-execute.ts (../telemetry not ../../altimate/telemetry) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e5c1027 commit a0ff464

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

packages/opencode/src/altimate/telemetry/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export namespace Telemetry {
555555
export function classifyTaskIntent(
556556
text: string,
557557
): { intent: string; confidence: number } {
558-
const lower = text.toLowerCase()
558+
const lower = text.slice(0, 2000).toLowerCase()
559559

560560
// Order matters: more specific patterns first
561561
const patterns: Array<{ intent: string; strong: RegExp[]; weak: RegExp[] }> = [

packages/opencode/src/altimate/tools/sql-execute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Dispatcher } from "../native"
44
import type { SqlExecuteResult } from "../native/types"
55
// altimate_change start - SQL write access control + fingerprinting
66
import { classifyAndCheck, computeSqlFingerprint } from "./sql-classify"
7-
import { Telemetry } from "../../altimate/telemetry"
7+
import { Telemetry } from "../telemetry"
88
// altimate_change end
99

1010
export const SqlExecuteTool = Tool.define("sql_execute", {

packages/opencode/src/session/prompt.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,16 @@ export namespace SessionPrompt {
321321
let sessionAgentName = ""
322322
let sessionHadError = false
323323
let emergencySessionEndFired = false
324-
// Quality signal tracking
324+
// altimate_change start — quality signal, tool chain, error fingerprint tracking
325325
let lastToolCategory = ""
326-
// Tool chain tracking
327326
const toolChain: string[] = []
328327
let toolErrorCount = 0
329328
let errorRecoveryCount = 0
330329
let lastToolWasError = false
331-
// Error fingerprint tracking
332330
interface ErrorRecord { toolName: string; toolCategory: string; errorClass: string; errorHash: string; recovered: boolean; recoveryTool: string }
333331
const errorRecords: ErrorRecord[] = []
334332
let pendingError: Omit<ErrorRecord, "recovered" | "recoveryTool"> | null = null
333+
// altimate_change end
335334
const emergencySessionEnd = () => {
336335
if (emergencySessionEndFired) return
337336
emergencySessionEndFired = true
@@ -696,7 +695,7 @@ export namespace SessionPrompt {
696695
agent: lastUser.agent,
697696
project_id: Instance.project?.id ?? "",
698697
})
699-
// Task intent classification keyword/regex, zero LLM cost
698+
// altimate_change start — task intent classification (keyword/regex, zero LLM cost)
700699
const userMsg = msgs.find((m) => m.info.id === lastUser!.id)
701700
if (userMsg) {
702701
const userText = userMsg.parts
@@ -719,6 +718,7 @@ export namespace SessionPrompt {
719718
})
720719
}
721720
}
721+
// altimate_change end — task intent classification
722722
// altimate_change end
723723
}
724724

@@ -830,7 +830,7 @@ export namespace SessionPrompt {
830830
const stepParts = await MessageV2.parts(processor.message.id)
831831
toolCallCount += stepParts.filter((p) => p.type === "tool").length
832832
if (processor.message.error) sessionHadError = true
833-
// Quality signal + tool chain + error fingerprints
833+
// altimate_change start — quality signal + tool chain + error fingerprints
834834
const toolParts = stepParts.filter((p) => p.type === "tool")
835835
for (const part of toolParts) {
836836
if (part.type !== "tool") continue
@@ -843,7 +843,7 @@ export namespace SessionPrompt {
843843
toolErrorCount++
844844
// Flush previous unrecovered error before recording new one
845845
if (pendingError) {
846-
errorRecords.push({ ...pendingError, recovered: false, recoveryTool: "" })
846+
if (errorRecords.length < 200) errorRecords.push({ ...pendingError, recovered: false, recoveryTool: "" })
847847
}
848848
lastToolWasError = true
849849
const errorMsg = part.state.status === "error" && typeof part.state.error === "string" ? part.state.error : "unknown"
@@ -857,7 +857,7 @@ export namespace SessionPrompt {
857857
} else {
858858
if (lastToolWasError && pendingError) {
859859
errorRecoveryCount++
860-
errorRecords.push({ ...pendingError, recovered: true, recoveryTool: part.tool })
860+
if (errorRecords.length < 200) errorRecords.push({ ...pendingError, recovered: true, recoveryTool: part.tool })
861861
pendingError = null
862862
}
863863
lastToolWasError = false
@@ -868,6 +868,7 @@ export namespace SessionPrompt {
868868
errorRecords.push({ ...pendingError, recovered: false, recoveryTool: "" })
869869
pendingError = null
870870
}
871+
// altimate_change end — quality signal + tool chain + error fingerprints
871872
// altimate_change end
872873

873874
if (result === "stop") break
@@ -894,7 +895,7 @@ export namespace SessionPrompt {
894895
: sessionTotalCost === 0 && toolCallCount === 0
895896
? "abandoned"
896897
: "completed"
897-
// altimate_change start — implicit quality signal
898+
// altimate_change start — emit quality signal, tool chain, and error fingerprint events
898899
Telemetry.track({
899900
type: "task_outcome_signal",
900901
timestamp: Date.now(),
@@ -938,7 +939,7 @@ export namespace SessionPrompt {
938939
recovery_tool: err.recoveryTool,
939940
})
940941
}
941-
// altimate_change end
942+
// altimate_change end — emit quality signal, tool chain, and error fingerprint events
942943
Telemetry.track({
943944
type: "agent_outcome",
944945
timestamp: Date.now(),

0 commit comments

Comments
 (0)