Skip to content

feat: add telemetry intelligence signals for debugging and improvements#564

Merged
anandgupta42 merged 16 commits intomainfrom
feat/telemetry-quality-signal
Mar 29, 2026
Merged

feat: add telemetry intelligence signals for debugging and improvements#564
anandgupta42 merged 16 commits intomainfrom
feat/telemetry-quality-signal

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 29, 2026

What does this PR do?

Adds 7 new PII-safe telemetry events to improve product debugging and understanding of how users interact with the CLI:

  1. Task Outcome Signal — behavioral signal (accepted/error/abandoned/cancelled) derived from session outcome
  2. Task Intent Classification — regex/keyword classifier for user intent (debug_dbt, write_sql, optimize_query, etc.)
  3. Tool Chain Effectiveness — ordered tool sequence with error/recovery tracking per session
  4. Error Pattern Fingerprint — SHA256-hashed error messages with recovery tool linking
  5. SQL Structure Fingerprint — AST shape via altimate-core (table count, aggregation, subqueries, node count)
  6. dbt Project Fingerprint — materialization distribution, snapshot/seed counts added to environment_census
  7. Schema Complexity Signal — bucketed table/column/schema counts from warehouse introspection

All signals computed locally from data already in memory — zero extra API calls, zero extra warehouse queries, <5ms overhead per session.

Type of change

  • New feature (non-breaking change that adds functionality)

Issue for this PR

Closes #563

How did you verify your code works?

  • 123 new telemetry-specific unit tests (all pass)
  • 5,400 total test suite (0 failures)
  • Adversarial testing: PII safety verification, edge cases (empty input, unicode, SQL injection, long strings)
  • E2E session simulation covering all 7 signals in realistic order
  • Privacy review: no PII, no table/column names, no SQL content, no user prompts, no file paths
  • 6-model code review (Claude, GPT 5.2 Codex, Gemini 3.1 Pro, Kimi K2.5, MiniMax M2.5, GLM-5)
  • TypeScript typecheck passes (0 errors)

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my code
  • New and existing tests pass locally
  • I have added tests that prove my fix/feature works

Summary by CodeRabbit

  • New Features

    • Enhanced session analytics to track task intent classification, outcome quality, and tool-chain effectiveness.
    • Improved error tracking and fingerprinting for better insights into execution failures and recovery patterns.
    • Added structural analysis for SQL queries and database schemas to better understand workload characteristics.
  • Documentation

    • Updated telemetry reference with new event types and enhanced metrics for environment and project analysis.

anandgupta42 and others added 7 commits March 28, 2026 19:46
Add `task_outcome_signal` event that maps agent outcomes to behavioral
signals (accepted/error/abandoned/cancelled). Emitted alongside
`agent_outcome` at session end with zero user cost — pure client-side
computation from data already in memory.

- New event type with `signal`, `tool_count`, `step_count`, `duration_ms`,
  `last_tool_category` fields
- Exported `deriveQualitySignal()` for testable outcome→signal mapping
- MCP tool detection via `mcp__` prefix for accurate categorization
- 8 unit tests covering all signal derivations and event shape

Closes AI-6028

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `task_classified` event emitted at session start with keyword/regex
classification of the first user message. Categories: debug_dbt, write_sql,
optimize_query, build_model, analyze_lineage, explore_schema, migrate_sql,
manage_warehouse, finops, general.

- `classifyTaskIntent()` — pure regex matcher, zero LLM cost, <1ms
- Includes warehouse type from fingerprint cache
- Strong/weak confidence levels (1.0 vs 0.5)
- 15 unit tests covering all intent categories + edge cases

Closes AI-6029

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `tool_chain_outcome` event that captures the ordered tool sequence,
error count, recovery count, and final outcome at session end. Only
emitted when tools were actually used (non-empty chain).

- Tracks up to 50 tool names in execution order
- Detects error→success recovery patterns for auto-fix insights
- Aggregates existing per-tool-call data — near-zero additional cost
- 3 unit tests for event shape and error/recovery tracking

Closes AI-6030

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `error_fingerprint` event emitted per unique error at session end.
SHA256-hashes normalized error messages for anonymous grouping, links
each error to its recovery tool (if the next tool succeeded).

- `hashError()` — 16-char hex hash of masked error messages
- Tracks error→recovery pairs during tool chain execution
- Capped at 20 fingerprints per session to bound telemetry volume
- 4 unit tests for hashing, event shape, and recovery tracking

Closes AI-6031

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `sql_fingerprint` event emitted after successful SQL execution via
`sql_execute`. Uses `extractMetadata()` + `getStatementTypes()` from
altimate-core NAPI — local parsing, no API calls, ~1-5ms.

- Captures: statement types, categories, table/function count,
  subqueries, aggregation, window functions, AST node count
- No table/column names or SQL content — PII-safe by design
- Wrapped in try/catch so fingerprinting never breaks query execution
- `computeSqlFingerprint()` exported from sql-classify for reuse
- 6 unit tests including PII safety verification

Closes AI-6032

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add optional dbt project metrics to the existing `environment_census`
event: snapshot/seed count buckets, materialization distribution
(table/view/incremental/ephemeral counts). Data already parsed at
startup — just extracts more fields from the same manifest parse.

- Backward compatible — new fields are optional
- No extra file reads or API calls

Closes AI-6033

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `schema_complexity` event emitted alongside `warehouse_introspection`
after successful schema indexing. Uses data already computed during
introspection — no extra warehouse queries.

- Bucketed table/column/schema counts + avg columns per table
- Division-by-zero guard for empty warehouses
- Emitted inside existing try/catch — never breaks introspection

Closes AI-6034

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces seven new PII-safe telemetry events and helper functions to improve product intelligence: task intent classification, outcome quality signals, tool chain effectiveness, error fingerprinting, SQL structure analysis, schema complexity metrics, and expanded dbt fingerprinting. It integrates emission logic across session, tool, and schema flows with comprehensive test coverage.

Changes

Cohort / File(s) Summary
Telemetry Core Infrastructure
packages/opencode/src/altimate/telemetry/index.ts
Extended Telemetry.Event union with six new event types (task_outcome_signal, task_classified, tool_chain_outcome, error_fingerprint, sql_fingerprint, schema_complexity). Added three exported helper functions: hashError() for SHA256-based error grouping, classifyTaskIntent() for regex-based intent classification with confidence scoring, and deriveQualitySignal() for outcome-to-signal mapping. Enhanced environment_census event with optional dbt metrics (snapshot/seed/macro counts and materialization distribution).
Tool Telemetry Integration
packages/opencode/src/altimate/tools/project-scan.ts, packages/opencode/src/altimate/tools/sql-classify.ts, packages/opencode/src/altimate/tools/sql-execute.ts, packages/opencode/src/altimate/native/schema/register.ts
Added SQL fingerprinting utility (computeSqlFingerprint()) capturing statement types, categories, table/function counts, and feature flags. Integrated SQL fingerprint emission in sql-execute after query formatting (fail-closed). Extended project-scan with dbt manifest metrics (snapshot/seed counts and materialization distribution). Added schema_complexity event emission in schema indexing with bucketed table/column/schema counts and average columns-per-table ratio.
Session-Level Instrumentation
packages/opencode/src/session/prompt.ts
Added comprehensive session instrumentation: task intent classification at session start (step 1) emitting task_classified event with warehouse type. Introduced per-step tool tracking with error detection, fingerprinting, and recovery recording. At session completion, emits task_outcome_signal (quality + timing), tool_chain_outcome (serialized tool chain + error/recovery counts), and up to 20 unique error_fingerprint events with recovery status.
Test Coverage
packages/opencode/test/altimate/telemetry-moat-signals.test.ts, packages/opencode/test/telemetry/telemetry.test.ts
Added extensive Bun integration test suite (telemetry-moat-signals.test.ts) intercepting Telemetry.track to validate signal outputs, SQL fingerprinting behavior (aggregation/subquery/window function detection, PII safety), dbt metrics bucketing, schema complexity, and end-to-end session simulation. Expanded unit tests in telemetry.test.ts covering deriveQualitySignal, classifyTaskIntent, and computeSqlFingerprint with edge cases and error resilience.
Documentation & Configuration
docs/docs/reference/telemetry.md, packages/opencode/package.json, .github/meta/commit.txt
Updated telemetry reference documentation with descriptions of six new event types and expanded environment_census fields. Bumped @altimateai/altimate-core dependency from 0.2.5 to 0.2.6. Updated commit message metadata reflecting new telemetry event addition.

Sequence Diagram(s)

sequenceDiagram
    participant Session as Session<br/>(prompt.ts)
    participant Telemetry as Telemetry<br/>(index.ts)
    participant Tools as Tools<br/>(sql-execute,<br/>project-scan,<br/>schema.index)
    participant Core as Core<br/>(`@altimateai/`<br/>altimate-core)

    Session->>Session: Step 1: Extract user text
    activate Session
    Session->>Telemetry: classifyTaskIntent(user_text)
    activate Telemetry
    Telemetry->>Core: regex/keyword matching
    Telemetry-->>Session: {intent, confidence}
    deactivate Telemetry
    Session->>Telemetry: track(task_classified)
    deactivate Session

    Session->>Tools: Execute tool calls
    activate Tools
    Tools->>Core: sql parse/classify
    Core-->>Tools: fingerprint data
    Tools->>Telemetry: track(sql_fingerprint)
    Tools->>Telemetry: track(schema_complexity)
    Tools->>Telemetry: track(environment_census)
    deactivate Tools

    Session->>Session: Track errors & recovery
    activate Session
    Session->>Telemetry: hashError(masked_error)
    activate Telemetry
    Telemetry-->>Session: error_hash
    deactivate Telemetry
    deactivate Session

    Session->>Telemetry: Session ends
    activate Telemetry
    Telemetry->>Telemetry: deriveQualitySignal(outcome)
    Telemetry->>Telemetry: track(task_outcome_signal)
    Telemetry->>Telemetry: track(tool_chain_outcome)
    Telemetry->>Telemetry: track(error_fingerprint[])
    deactivate Telemetry
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • suryaiyer95
  • mdesmet
  • kulvirgit

Poem

🐰 Hop along, dear data flows!
Seven signals bloom where telemetry grows,
Intent classified, quality cast,
Error fingerprints holding the past—
All PII-safe, locally computed fast! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add telemetry intelligence signals for debugging and improvements' accurately and concisely describes the main change: adding 7 new telemetry events for product debugging and understanding.
Description check ✅ Passed The PR description comprehensively covers all required template sections: summary of 7 telemetry signals, type of change (new feature), linked issue #563, detailed verification approach including 123 tests and privacy review, and completed checklist items.
Linked Issues check ✅ Passed The pull request fully implements all coding requirements from issue #563: 7 PII-safe telemetry events (task outcome, intent classification, tool chain, error fingerprinting, SQL structure, dbt project expansion, schema complexity) with comprehensive testing and privacy verification.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issue objectives: telemetry event definitions, helper functions, integration into session/tool flow, documentation updates, dependency bump for parsing fixes, and comprehensive test coverage—no extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/telemetry-quality-signal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@anandgupta42 anandgupta42 changed the title feat: add telemetry intelligence signals for product analytics feat: add telemetry intelligence signals for debugging and improvements Mar 29, 2026
anandgupta42 and others added 7 commits March 28, 2026 20:52
Add task_outcome_signal, task_classified, tool_chain_outcome,
error_fingerprint, sql_fingerprint, schema_complexity to the event
catalog. Update environment_census description for new dbt fields.
Update naming convention section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…y-signal

# Conflicts:
#	.github/meta/commit.txt
Add 38 integration tests that verify all 7 telemetry signals fire
through real code paths with spy on Telemetry.track():

- Signal 1: quality signal derivation + error/abandoned/cancelled cases
- Signal 2: intent classifier with 10 real DE prompts + PII safety
- Signal 3: tool chain collection with error recovery state machine
- Signal 4: error fingerprint hashing + consecutive error flush
- Signal 5: SQL fingerprint via altimate-core (aggregation, CTE, DDL)
- Signal 6: environment_census expansion + backward compatibility
- Signal 7: schema complexity bucketing + zero-table edge case
- Full E2E: complete session simulation with all 7 signals in order

Also fixes regex patterns for natural language flexibility:
- dbt debug: allows words between "dbt" and error keywords
- migrate: allows words between "to/from" and warehouse name

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify computeSqlFingerprint resilience when altimate-core NAPI:
- throws (segfault, OOM) — returns null, never leaks exception
- returns undefined — uses safe defaults (empty arrays, 0 counts)
- returns garbage data — handled gracefully via ?? fallbacks

Also verifies sql-execute.ts code structure ensures fingerprinting
runs AFTER query result and is wrapped in isolated try/catch.

Tests crash-resistant SQL inputs (control chars, empty, incomplete,
very wide queries) and deterministic output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
…y-signal

# Conflicts:
#	packages/opencode/src/altimate/telemetry/index.ts
@anandgupta42 anandgupta42 force-pushed the feat/telemetry-quality-signal branch from e5fe9f0 to 82f6a2b Compare March 29, 2026 05:31
anandgupta42 and others added 2 commits March 29, 2026 08:21
Picks up extractMetadata fixes:
- Aggregate function names (COUNT, SUM, AVG, etc.) now in functions array
- IN (SELECT ...) and EXISTS (SELECT ...) subquery detection
- Any/All quantified comparison subquery detection (guarded)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…y-signal

# Conflicts:
#	packages/opencode/src/altimate/tools/sql-execute.ts
@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Mar 29, 2026

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29326785 Triggered Generic Password 85cfe70 packages/opencode/test/altimate/connections.test.ts View secret
29327894 Triggered Generic Database Assignment 85cfe70 packages/opencode/test/altimate/connections.test.ts View secret
29327588 Triggered Generic Password 85cfe70 packages/opencode/test/altimate/connections.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@anandgupta42 anandgupta42 merged commit f41e03e into main Mar 29, 2026
11 of 13 checks passed
anandgupta42 added a commit that referenced this pull request Mar 29, 2026
…ts (#564)

* feat: add implicit quality signal telemetry event

Add `task_outcome_signal` event that maps agent outcomes to behavioral
signals (accepted/error/abandoned/cancelled). Emitted alongside
`agent_outcome` at session end with zero user cost — pure client-side
computation from data already in memory.

- New event type with `signal`, `tool_count`, `step_count`, `duration_ms`,
  `last_tool_category` fields
- Exported `deriveQualitySignal()` for testable outcome→signal mapping
- MCP tool detection via `mcp__` prefix for accurate categorization
- 8 unit tests covering all signal derivations and event shape

Closes AI-6028

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add task intent classification telemetry event

Add `task_classified` event emitted at session start with keyword/regex
classification of the first user message. Categories: debug_dbt, write_sql,
optimize_query, build_model, analyze_lineage, explore_schema, migrate_sql,
manage_warehouse, finops, general.

- `classifyTaskIntent()` — pure regex matcher, zero LLM cost, <1ms
- Includes warehouse type from fingerprint cache
- Strong/weak confidence levels (1.0 vs 0.5)
- 15 unit tests covering all intent categories + edge cases

Closes AI-6029

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit aggregated tool chain outcome at session end

Add `tool_chain_outcome` event that captures the ordered tool sequence,
error count, recovery count, and final outcome at session end. Only
emitted when tools were actually used (non-empty chain).

- Tracks up to 50 tool names in execution order
- Detects error→success recovery patterns for auto-fix insights
- Aggregates existing per-tool-call data — near-zero additional cost
- 3 unit tests for event shape and error/recovery tracking

Closes AI-6030

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: link error-recovery pairs with hashed fingerprint

Add `error_fingerprint` event emitted per unique error at session end.
SHA256-hashes normalized error messages for anonymous grouping, links
each error to its recovery tool (if the next tool succeeded).

- `hashError()` — 16-char hex hash of masked error messages
- Tracks error→recovery pairs during tool chain execution
- Capped at 20 fingerprints per session to bound telemetry volume
- 4 unit tests for hashing, event shape, and recovery tracking

Closes AI-6031

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit SQL structure fingerprint using altimate-core

Add `sql_fingerprint` event emitted after successful SQL execution via
`sql_execute`. Uses `extractMetadata()` + `getStatementTypes()` from
altimate-core NAPI — local parsing, no API calls, ~1-5ms.

- Captures: statement types, categories, table/function count,
  subqueries, aggregation, window functions, AST node count
- No table/column names or SQL content — PII-safe by design
- Wrapped in try/catch so fingerprinting never breaks query execution
- `computeSqlFingerprint()` exported from sql-classify for reuse
- 6 unit tests including PII safety verification

Closes AI-6032

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: expand environment_census with dbt project fingerprint

Add optional dbt project metrics to the existing `environment_census`
event: snapshot/seed count buckets, materialization distribution
(table/view/incremental/ephemeral counts). Data already parsed at
startup — just extracts more fields from the same manifest parse.

- Backward compatible — new fields are optional
- No extra file reads or API calls

Closes AI-6033

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit schema complexity signal during warehouse introspection

Add `schema_complexity` event emitted alongside `warehouse_introspection`
after successful schema indexing. Uses data already computed during
introspection — no extra warehouse queries.

- Bucketed table/column/schema counts + avg columns per table
- Division-by-zero guard for empty warehouses
- Emitted inside existing try/catch — never breaks introspection

Closes AI-6034

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: update telemetry reference with 7 new intelligence signals

Add task_outcome_signal, task_classified, tool_chain_outcome,
error_fingerprint, sql_fingerprint, schema_complexity to the event
catalog. Update environment_census description for new dbt fields.
Update naming convention section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add comprehensive integration tests for telemetry signals

Add 38 integration tests that verify all 7 telemetry signals fire
through real code paths with spy on Telemetry.track():

- Signal 1: quality signal derivation + error/abandoned/cancelled cases
- Signal 2: intent classifier with 10 real DE prompts + PII safety
- Signal 3: tool chain collection with error recovery state machine
- Signal 4: error fingerprint hashing + consecutive error flush
- Signal 5: SQL fingerprint via altimate-core (aggregation, CTE, DDL)
- Signal 6: environment_census expansion + backward compatibility
- Signal 7: schema complexity bucketing + zero-table edge case
- Full E2E: complete session simulation with all 7 signals in order

Also fixes regex patterns for natural language flexibility:
- dbt debug: allows words between "dbt" and error keywords
- migrate: allows words between "to/from" and warehouse name

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add altimate-core failure isolation tests

Verify computeSqlFingerprint resilience when altimate-core NAPI:
- throws (segfault, OOM) — returns null, never leaks exception
- returns undefined — uses safe defaults (empty arrays, 0 counts)
- returns garbage data — handled gracefully via ?? fallbacks

Also verifies sql-execute.ts code structure ensures fingerprinting
runs AFTER query result and is wrapped in isolated try/catch.

Tests crash-resistant SQL inputs (control chars, empty, incomplete,
very wide queries) and deterministic output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 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>

* chore: bump altimate-core to 0.2.6

Picks up extractMetadata fixes:
- Aggregate function names (COUNT, SUM, AVG, etc.) now in functions array
- IN (SELECT ...) and EXISTS (SELECT ...) subquery detection
- Any/All quantified comparison subquery detection (guarded)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
anandgupta42 added a commit that referenced this pull request Mar 29, 2026
…ccess retry (#571)

* fix: defensive null guards in tool formatters and DuckDB concurrent access retry (#570)

- Add null/undefined guards across 8 tool formatters to prevent literal
  `undefined` in user-facing output (sql-analyze, schema-inspect,
  sql-translate, dbt-manifest, finops-analyze-credits, warehouse-list,
  altimate-core-check, altimate-core-rewrite)
- Add `error: msg` to catch block metadata in schema-inspect,
  dbt-manifest, warehouse-list so telemetry can classify exceptions
- DuckDB driver: auto-retry in `READ_ONLY` mode on `database is locked`
  errors, with clear actionable error message
- Add simulation suite (839 mock + 346 real E2E scenarios) covering
  10 personas x 11 dialects x 14 use-case categories

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add telemetry intelligence signals for debugging and improvements (#564)

* feat: add implicit quality signal telemetry event

Add `task_outcome_signal` event that maps agent outcomes to behavioral
signals (accepted/error/abandoned/cancelled). Emitted alongside
`agent_outcome` at session end with zero user cost — pure client-side
computation from data already in memory.

- New event type with `signal`, `tool_count`, `step_count`, `duration_ms`,
  `last_tool_category` fields
- Exported `deriveQualitySignal()` for testable outcome→signal mapping
- MCP tool detection via `mcp__` prefix for accurate categorization
- 8 unit tests covering all signal derivations and event shape

Closes AI-6028

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add task intent classification telemetry event

Add `task_classified` event emitted at session start with keyword/regex
classification of the first user message. Categories: debug_dbt, write_sql,
optimize_query, build_model, analyze_lineage, explore_schema, migrate_sql,
manage_warehouse, finops, general.

- `classifyTaskIntent()` — pure regex matcher, zero LLM cost, <1ms
- Includes warehouse type from fingerprint cache
- Strong/weak confidence levels (1.0 vs 0.5)
- 15 unit tests covering all intent categories + edge cases

Closes AI-6029

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit aggregated tool chain outcome at session end

Add `tool_chain_outcome` event that captures the ordered tool sequence,
error count, recovery count, and final outcome at session end. Only
emitted when tools were actually used (non-empty chain).

- Tracks up to 50 tool names in execution order
- Detects error→success recovery patterns for auto-fix insights
- Aggregates existing per-tool-call data — near-zero additional cost
- 3 unit tests for event shape and error/recovery tracking

Closes AI-6030

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: link error-recovery pairs with hashed fingerprint

Add `error_fingerprint` event emitted per unique error at session end.
SHA256-hashes normalized error messages for anonymous grouping, links
each error to its recovery tool (if the next tool succeeded).

- `hashError()` — 16-char hex hash of masked error messages
- Tracks error→recovery pairs during tool chain execution
- Capped at 20 fingerprints per session to bound telemetry volume
- 4 unit tests for hashing, event shape, and recovery tracking

Closes AI-6031

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit SQL structure fingerprint using altimate-core

Add `sql_fingerprint` event emitted after successful SQL execution via
`sql_execute`. Uses `extractMetadata()` + `getStatementTypes()` from
altimate-core NAPI — local parsing, no API calls, ~1-5ms.

- Captures: statement types, categories, table/function count,
  subqueries, aggregation, window functions, AST node count
- No table/column names or SQL content — PII-safe by design
- Wrapped in try/catch so fingerprinting never breaks query execution
- `computeSqlFingerprint()` exported from sql-classify for reuse
- 6 unit tests including PII safety verification

Closes AI-6032

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: expand environment_census with dbt project fingerprint

Add optional dbt project metrics to the existing `environment_census`
event: snapshot/seed count buckets, materialization distribution
(table/view/incremental/ephemeral counts). Data already parsed at
startup — just extracts more fields from the same manifest parse.

- Backward compatible — new fields are optional
- No extra file reads or API calls

Closes AI-6033

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: emit schema complexity signal during warehouse introspection

Add `schema_complexity` event emitted alongside `warehouse_introspection`
after successful schema indexing. Uses data already computed during
introspection — no extra warehouse queries.

- Bucketed table/column/schema counts + avg columns per table
- Division-by-zero guard for empty warehouses
- Emitted inside existing try/catch — never breaks introspection

Closes AI-6034

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: update telemetry reference with 7 new intelligence signals

Add task_outcome_signal, task_classified, tool_chain_outcome,
error_fingerprint, sql_fingerprint, schema_complexity to the event
catalog. Update environment_census description for new dbt fields.
Update naming convention section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add comprehensive integration tests for telemetry signals

Add 38 integration tests that verify all 7 telemetry signals fire
through real code paths with spy on Telemetry.track():

- Signal 1: quality signal derivation + error/abandoned/cancelled cases
- Signal 2: intent classifier with 10 real DE prompts + PII safety
- Signal 3: tool chain collection with error recovery state machine
- Signal 4: error fingerprint hashing + consecutive error flush
- Signal 5: SQL fingerprint via altimate-core (aggregation, CTE, DDL)
- Signal 6: environment_census expansion + backward compatibility
- Signal 7: schema complexity bucketing + zero-table edge case
- Full E2E: complete session simulation with all 7 signals in order

Also fixes regex patterns for natural language flexibility:
- dbt debug: allows words between "dbt" and error keywords
- migrate: allows words between "to/from" and warehouse name

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add altimate-core failure isolation tests

Verify computeSqlFingerprint resilience when altimate-core NAPI:
- throws (segfault, OOM) — returns null, never leaks exception
- returns undefined — uses safe defaults (empty arrays, 0 counts)
- returns garbage data — handled gracefully via ?? fallbacks

Also verifies sql-execute.ts code structure ensures fingerprinting
runs AFTER query result and is wrapped in isolated try/catch.

Tests crash-resistant SQL inputs (control chars, empty, incomplete,
very wide queries) and deterministic output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 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>

* chore: bump altimate-core to 0.2.6

Picks up extractMetadata fixes:
- Aggregate function names (COUNT, SUM, AVG, etc.) now in functions array
- IN (SELECT ...) and EXISTS (SELECT ...) subquery detection
- Any/All quantified comparison subquery detection (guarded)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: resolve all 5 Verdaccio sanity test failures (#572)

- altimate-core NAPI binding: set `NODE_PATH` to global npm root so
  `require('@altimateai/altimate-core')` resolves after `npm install -g`
- upstream branding: replace "opencode" with "altimate-code" in user-facing
  `describe` strings (uninstall, tui, pr commands, config, server API docs)
- driver resolvability: set `NODE_PATH` in driver check loop and install
  `duckdb` alongside the main package so at least one peer dep is present
- hardcoded CI paths: restrict grep to JS/JSON files only — compiled Bun
  binaries embed build-machine paths in debug info which is unavoidable
- NAPI module exports: already had correct `NODE_PATH` in extended test;
  root cause was the base test (fix 1) which is now resolved

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add telemetry intelligence signals for improvement and debugging

1 participant