fix: [#832] build agent 0% completion — legacy name leaking into telemetry

Merged
AN
6mo ago
+110-14

What does this PR do?

Fixes the phantom agent: "build" 0%-completion bucket flagged in the May 21 telemetry triage (133 invocations, 0/133 completed).

It's not a routing bug. The build agent was renamed to builder and Agent.get("build") aliases through to it, so execution works. But two places still write the literal "build" to user messages, which then flows verbatim into the agent_outcome telemetry event — creating a phantom dashboard row with no completions to its name. Real builder work is recorded correctly under the builder bucket.

The dominant source is plan_exit: every time a user approves a plan and exits plan mode, the synthetic user message hardcodes agent: "build". 133 plan-exits in 14 days, all funnelled into the wrong bucket.

Three fixes:

  1. tool/plan.ts:56 writes agent: "builder" instead of "build"
  2. session/prompt.ts:1153 normalizes at the telemetry-emit boundary — agent === "build" ? "builder" : agent — belt-and-suspenders for persisted sessions still carrying the legacy value
  3. cli/cmd/github.ts:954 updates a stale comment

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #832

How did you verify your code works?

  • tsgo --noEmit: pass
  • bun test test/session/plan-layer-e2e.test.ts test/telemetry/plan-skill-telemetry.test.ts test/altimate/plan-refinement.test.ts: 95 pass / 0 fail
  • bun test test/altimate/ test/agent/ test/tool/: 3,242 pass / 0 fail (1 unrelated flake — registry.test.ts timeout under parallel load; passes in isolation)
  • Updated test/session/plan-layer-e2e.test.ts to allow both the normalized and original forms in the agent_outcome block, and pinned that "builder" appears so the normalization isn't accidentally removed
  • Marker check: pass — altimate_change markers added on every changed line in upstream-shared files

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • Marker check passes
  • Linked to issue #832

Files changed (4):

  • packages/opencode/src/tool/plan.ts — write canonical "builder" + title/output text update
  • packages/opencode/src/session/prompt.ts — normalize agent at emit boundary
  • packages/opencode/src/cli/cmd/github.ts — fix stale "build" comment
  • packages/opencode/test/session/plan-layer-e2e.test.ts — update assertion to allow normalized form

Expected telemetry impact: the phantom agent: "build" 0%-completion row disappears. Plan-exit invocations fold back into builder's real completion rate.

Related P0 series:

  • Issue #827 / PR #828: finops_* 100% failure rate
  • Issue #830 / PR #831: project_scan 32% errors (437 users)
  • Issue #832 / this PR: build agent 0% completion measurement artifact

P0-3 in the May 21 triage (classifier 100% empty) was investigated and determined to be a telemetry-analysis schema mismatch (the analyst queried task_type/complexity fields that don't exist in the schema; the actual intent/confidence fields are populated correctly). No code change needed.

P0-5 (PII masker shredding error messages to ?) was addressed structurally by #831 — fixing the root cause (project_scan crashing) eliminated the dominant case where the masker was hiding diagnostic info. A broader masker change would risk leaking actual PII; leaving as-is.


Summary by cubic

Canonicalizes the agent name to builder and normalizes it (case-insensitive) at telemetry emit time to remove the phantom 0% build bucket. Closes #832.

  • Bug Fixes
    • tool/plan.ts: write agent: "builder" and update dialog/title/output to say “builder”.
    • session/prompt.ts: add normalizeAgentName() (case-insensitive) and use it in session_start and agent_outcome.
    • cli/cmd/tui/routes/session/index.tsx: set local.agent to "builder" on plan_exit.
    • config/config.ts: update default_agent fallback description to builder.
    • Tests: anchored checks for the shared normalizer, session_start parity, single-normalizer invariant, and case-folding.

Summary by CodeRabbit

  • Bug Fixes

    • Unified agent naming from "build" to "builder" in UI text and messaging to ensure consistent messaging and telemetry
    • Updated plan-exit messaging to reference "builder agent"
  • Tests

    • Expanded end-to-end tests to validate normalized agent reporting and telemetry routing
  • Chores

    • Added normalization for legacy agent names and updated schema description to reflect the new default agent name

Review Change Stack