Skip to content

fix(learn): keep traceback tail in tool-error digest preview - #2596

Merged
chopratejas merged 1 commit into
headroomlabs-ai:mainfrom
tenderdeve:fix/2590-analyzer-error-tail
Jul 27, 2026
Merged

chopratejas merged 1 commit into
headroomlabs-ai:mainfrom
tenderdeve:fix/2590-analyzer-error-tail

Conversation

@tenderdeve

Copy link
Copy Markdown
Contributor

Description

_format_tool_call in headroom/learn/analyzer.py built the error preview with a head-only slice — tc.output[:200]. For tracebacks the root cause (ExceptionType: message) is at the tail, so the digest showed only Traceback (most recent call last): plus the first frame and dropped the actual diagnosis. The issue reports 46% of 715 measured errors were truncated past the 200-char head.

Closes #2590

Type of Change

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

Changes Made

  • Added _truncate_head_tail() helper that collapses newlines and, when over budget, keeps both the head and the tail joined by ….
  • _format_tool_call now uses it for error output so the exception line survives truncation. Short errors are returned unchanged (no marker).

Testing

  • Unit tests pass (pytest)
  • Linting passes (ruff check .)
  • Type checking passes (mypy headroom)
  • New tests added for new functionality

Test Output

$ uv run pytest tests/test_learn/test_analyzer.py::TestDigestBuilder -q
9 passed in 1.47s

$ uv run ruff check headroom/learn/analyzer.py tests/test_learn/test_analyzer.py
All checks passed!

Real Behavior Proof

  • Environment: headroom @ main, Python 3.14, uv
  • Exact command / steps: added a long synthetic traceback (KeyError: 'the-actual-root-cause' at the tail) as a failing tool call and built the digest.
  • Observed result: digest now contains both Traceback and KeyError: 'the-actual-root-cause', separated by …; short errors have no ….
  • Not tested: mypy not run locally.

Review Readiness

  • I have performed a self-review
  • This PR is ready for human review

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • 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
  • I did not edit CHANGELOG.md

Additional Notes

Truncation budget stays at 200 chars (now split head/tail). mypy not run locally; happy to adjust if CI flags anything.

The error preview in _format_tool_call sliced output[:200] head-only, so a
traceback's root cause (ExceptionType: message), which sits at the tail, was
discarded and the digest showed only the preamble. Truncate keeping both head
and tail so the diagnosis survives.

Fixes headroomlabs-ai#2590
@github-actions

Copy link
Copy Markdown
Contributor

PR governance

This PR follows the template and is marked ready for human review.

@github-actions github-actions Bot added the status: ready for review Pull request body is complete and the author marked it ready for human review label Jul 27, 2026
@codecov-commenter

codecov-commenter commented Jul 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chopratejas
chopratejas merged commit 85e8699 into headroomlabs-ai:main Jul 27, 2026
27 checks passed
@chopratejas chopratejas mentioned this pull request Jul 27, 2026
chopratejas added a commit that referenced this pull request Jul 29, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>0.33.0</summary>

##
[0.33.0](v0.32.0...v0.33.0)
(2026-07-29)


### Features

* **lossless:** factor shared directory prefix in the grep search fold
([#2547](#2547))
([7dc9a97](7dc9a97))
* **metrics:** record per-extension token savings
([#2371](#2371))
([02eb90f](02eb90f))
* **opencode:** ship the transport plugin in pip installs
([#2601](#2601))
([f54f04f](f54f04f))
* **opencode:** support Copilot subscription backend for headroom models
([#2441](#2441))
([#2445](#2445))
([9089e7f](9089e7f))
* **proxy/hooks:** run fold-only (stream-safe) turn hooks on streaming
OpenAI chat
([#2549](#2549))
([a6d4921](a6d4921))
* **proxy/savings:** aggregate tool-schema savings into Metrics + all
reporting sinks
([#2546](#2546))
([9f1ffef](9f1ffef))
* **proxy:** label GitHub Copilot traffic as "copilot" in the outcome…
([#2377](#2377))
([d7a8cdb](d7a8cdb))
* **proxy:** make /v1/compress usable as a gateway/Kong sidecar
([#2458](#2458))
([1329ed7](1329ed7))
* **proxy:** model-aware cold-prefix hook — reasoning compaction
(Kimi/GLM) + cold recompaction (CC)
([#2555](#2555))
([cb8f4b6](cb8f4b6))
* **proxy:** route selected external compressors through the content
router
([#2388](#2388))
([e3c7964](e3c7964))
* **proxy:** select built-in compressors via --compressor + registry
inventory
([#2373](#2373))
([56c7d4a](56c7d4a))
* **rust:** add structured prose offload plumbing
([#334](#334))
([#2378](#2378))
([9e07785](9e07785))
* **rust:** port CodeCompressor AST compressor to Rust (parity-only)
([#1154](#1154))
([e530de5](e530de5))
* **rust:** port Kompress ML prose compressor to Rust (parity-only)
([#1153](#1153))
([83e27e5](83e27e5))
* **telemetry:** record provider cache read/write/uncached tokens per
request
([#2450](#2450))
([bec4cce](bec4cce))
* **transforms:** add compressed signal + dispatch code_aware/html/diff
via registry
([#2400](#2400))
([7ebda67](7ebda67))
* **transforms:** add pluggable compressor registry +
headroom.compressor entry point
([#2370](#2370))
([a02073e](a02073e))
* **transforms:** dispatch kompress/text via the compressor registry +
forward question
([#2411](#2411))
([446ec26](446ec26))
* **transforms:** dispatch smart_crusher via the compressor registry
(defer kompress/text ML boundary)
([#2404](#2404))
([7c7bf43](7c7bf43))
* **transforms:** make built-in compressors real Compressor
implementations (adapters)
([#2391](#2391))
([981616c](981616c))
* **wrap:** boost Serena — symbol-first guidance, wrap-time pre-index,
repo-language scoping
([#2425](#2425))
([fd0e1a8](fd0e1a8))
* **wrap:** default code-memory to Serena (dashboard browser off) behind
unified --code-memory
([#2413](#2413))
([6e4425a](6e4425a))
* **wrap:** reduce-at-source — SAFE quiet-CLI env defaults for the
launched agent
([#2548](#2548))
([c990cfb](c990cfb))


### Bug Fixes

* **backends/litellm:** guard None completion_tokens in usage mapping
([#2322](#2322))
([44a174f](44a174f))
* **backends:** don't crash the OpenAI-&gt;Anthropic converter on empty
choices
([#2484](#2484))
([43a7b57](43a7b57))
* **cache:** preserve cache_control ttl when re-anchoring a breakpoint
([#2651](#2651))
([e0d2cd0](e0d2cd0))
* **cache:** preserve client cache_control ttl when consolidating
breakpoints
([#2382](#2382))
([8906d3a](8906d3a))
* **ccr:** guard empty/malformed OpenAI choices in
_extract_assistant_message
([#2389](#2389))
([89319fb](89319fb))
* **ccr:** sliding idle-window TTL with max-lifetime ceiling in the Rust
core backends
([#2604](#2604))
([#2631](#2631))
([e825588](e825588))
* **ci:** align Ruff tooling versions
([#2406](#2406))
([2bb14d1](2bb14d1))
* **cli:** warn when Headroom proxy URL leaks into the shell after
unwrap claude
([#2238](#2238))
([#2571](#2571))
([904bc67](904bc67))
* **codex:** detect keyring-backed ChatGPT auth
([#2478](#2478))
([46293f4](46293f4))
* **compression:** report source-line span in CCR compression marker
([#2597](#2597))
([18e1c3c](18e1c3c))
* **copilot:** derive GHE credential host from API URL
([#800](#800))
([#2511](#2511))
([4a8157f](4a8157f))
* **copilot:** normalize subscription API routing
([#2441](#2441))
([#2455](#2455))
([2eca5ee](2eca5ee))
* **copilot:** preserve /v1 for the Anthropic /v1/messages endpoint
([#2409](#2409))
([#2414](#2414))
([c400f90](c400f90))
* **deps:** bump mcp to 1.28.1 to clear 3 high-severity CVEs
([#2348](#2348))
([a90be94](a90be94))
* **grok:** preserve business-seat auth while routing only inference
([#2514](#2514))
([e4076bb](e4076bb))
* **image:** reuse image models instead of rebuilding them per request
([#2513](#2513))
([#2536](#2536))
([2a63ec7](2a63ec7))
* **install:** carry upstream-routing env overrides into supervised
deployments
([#2429](#2429))
([170b04a](170b04a))
* **install:** default to cache mode, matching `headroom proxy`
([#1893](#1893)
follow-up)
([#2563](#2563))
([b121223](b121223))
* **install:** migrate deployments off the retired chopratejas image
repo ([#2427](#2427))
([17ff13c](17ff13c))
* **install:** use CREATE_NO_WINDOW instead of DETACHED_PROCESS on
Windows
([#2527](#2527))
([045f3df](045f3df))
* **kompress:** raise the default execution-slot wait
([#2456](#2456))
([5bd2266](5bd2266))
* **learn:** detect the active OpenCode database
([#2587](#2587))
([f74d874](f74d874))
* **learn:** keep traceback tail in tool-error digest preview
([#2596](#2596))
([85e8699](85e8699))
* **learn:** treat unreadable candidate paths as absent in project
decode
([#2446](#2446))
([a09ba6c](a09ba6c))
* **mcp:** pin mcp dependency to &lt;2.0.0 to prevent server startup
crash ([#2642](#2642))
([b3f016b](b3f016b))
* **proxy/cost:** count Gemini thinking tokens in output usage
([#2639](#2639))
([22b707f](22b707f))
* **proxy/cost:** record each request's savings exactly once (drop 3
double-counts)
([#2545](#2545))
([0845b26](0845b26))
* **proxy/cost:** warn once per model when pricing lookup fails
([#2504](#2504))
([#2535](#2535))
([fa47637](fa47637))
* **proxy/gemini:** None-guard token counts from usageMetadata
([#2347](#2347))
([f64aac9](f64aac9))
* **proxy/gemini:** tolerate malformed parts on the compression path
([#2486](#2486))
([07cf547](07cf547))
* **proxy/metrics:** move the savings-ledger append off the event loop
([#2439](#2439))
([4aac068](4aac068))
* **proxy/openai:** cache under looked-up messages
([#2420](#2420))
([7052d52](7052d52))
* **proxy/openai:** don't record Codex WS savings without input
accounting
([#2493](#2493))
([2195ba7](2195ba7))
* **proxy/openai:** feed chat/completions traffic into the traffic
learner
([#2333](#2333))
([6cdfd3f](6cdfd3f))
* **proxy/openai:** None-guard usage token counts on the chat path
([#2431](#2431))
([313c290](313c290))
* **proxy/openai:** replay incremental events in buffered Responses SSE
([#2410](#2410))
([#2415](#2415))
([0cbc0e8](0cbc0e8))
* **proxy/output-shaping:** tolerate a non-string system block text in
steering
([#2435](#2435))
([3e97671](3e97671))
* **proxy/perf:** count turn-hook message folds in token accounting
([#2520](#2520))
([c371d5a](c371d5a))
* **proxy/perf:** tokenizer-consistent token accounting + surface
tool-schema savings
([#2542](#2542))
([1cc53c9](1cc53c9))
* **proxy/streaming:** tolerate malformed content in _response_to_sse
([#2481](#2481))
([77b26c0](77b26c0))
* **proxy:** keep buffered CCR streams alive
([#2479](#2479))
([a2e42fb](a2e42fb))
* **proxy:** keep core tools and the client's ToolSearch resident for
PascalCase clients
([#2647](#2647))
([1d29738](1d29738))
* **proxy:** offload OpenAI and Gemini tokenizer counting off the event
loop ([#2498](#2498))
([806d2e4](806d2e4))
* **proxy:** promote Kompress health after runtime load
([#2402](#2402))
([54526bc](54526bc))
* **proxy:** reassemble server_tool_use.input from streamed partial_json
([#2449](#2449))
([8c8fae0](8c8fae0))
* **proxy:** report deferred Kompress status and promote health from
cache ([#2564](#2564))
([d50cfab](d50cfab))
* **proxy:** skip max_tokens rename for backend-routed openai chat
([#2401](#2401))
([d6a1af4](d6a1af4))
* **release:** publish Windows wheel + sdist (disable PyPI attestations,
[#112](#112))
([#2405](#2405))
([f9cbdd6](f9cbdd6))
* **release:** sync generated version metadata on the release branch
([#2659](#2659))
([5383c6b](5383c6b))
* **rust:** port CJK-aware relevance-query matching to CodeCompressor
([#2634](#2634))
([e86c639](e86c639))
* **security:** exclude compromised ast-grep-cli 0.44.1 (supply-chain
trojan)
([#2342](#2342))
([494fb5a](494fb5a))
* **tokenizers:** price Claude against a real BPE (tiktoken o200k) not a
char estimate
([#2543](#2543))
([285176b](285176b))
* **transforms/cross-turn-dedup:** don't renumber-fold zero-padded line
prefixes
([#2369](#2369))
([f4070c4](f4070c4))
* **transforms/kompress-remote:** keep compress fail-open on malformed
200 ([#2320](#2320))
([b759990](b759990))
* **wrap:** emit bare dotted keys for Codex --config overrides
([#2383](#2383))
([f57e959](f57e959))
* **wrap:** make RTK opt-in (off by default) across wrap subcommands
([#2344](#2344))
([44136ed](44136ed))
* **wrap:** skip Serena project setup outside real project roots
([#2574](#2574))
([0994ea0](0994ea0))
* **wrap:** stop same-port persistent routing during claude unwrap
([#2340](#2340))
([#2350](#2350))
([cf5fa64](cf5fa64))


### Performance Improvements

* **content_router:** dedupe content detection
([#2419](#2419))
([9b016f2](9b016f2))


### Dependencies

* bump the cargo-minor-patch group with 10 updates
([#2284](#2284))
([3266ed7](3266ed7))
* bump the npm-minor-patch group across 3 directories with 7 updates
([#2276](#2276))
([961866b](961866b))


### Code Refactoring

* **transforms:** dispatch simple built-in strategies via the compressor
registry
([#2399](#2399))
([fc9c63f](fc9c63f))
* **wrap:** retire tokensave; Serena is the code-memory MCP
([#2499](#2499))
([5d23a0a](5d23a0a))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Pull request body is complete and the author marked it ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyzer.py: head-only [:200] error truncation discards traceback root causes

3 participants