Skip to content

feat: record Claude Code's autocompact thrashing stop as an error on the trace (RIUS-1666) - #74

Merged
sudopower merged 3 commits into
mainfrom
factory/RIUS-1666
Oct 27, 2026
Merged

sudopower merged 3 commits into
mainfrom
factory/RIUS-1666

Conversation

@sudopower

@sudopower sudopower commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Linear: RIUS-1666 (item 2 of RIUS-1617)

Assumption A44 (no new semconv key). The stop is recorded with names that already exist in rius-semconv v1.10.0: error.type and the exception event (exception.type, exception.message). Nothing goes through rius-semconv.

What changed

When Claude Code's auto compaction thrashes it stops the turn and writes a synthetic assistant row with apiError: "autocompact_thrashing". No hook carries it. That row already became an LLM span (model <synthetic>, status OK, no sign of a failure). Now that span is:

  • status ERROR, error.type = "autocompact_thrashing";
  • one exception event at the row's timestamp, exception.type = "autocompact_thrashing", exception.message = Claude Code's text;
  • with content capture off, the text is withheld and only the type is sent (same rule as tool errors).

Only that exact apiError value is matched. Other API-error rows and every transcript without the row are exported as before.

Files: scripts/rius_cc/transcript.py (Entry.api_error()), scripts/rius_cc/spans.py (_generation_span).

Verified

  • pytest -q tests/test_autocompact_thrashing.py: 5 passed (fixture is the real row from session a3b6e6af, 2026-10-08T08:54:16Z, after an ordinary call).
  • With the spans.py change reverted, 2 of the 5 fail (the error span and the capture-gate test); restored, they pass.
  • pytest -q (whole suite, py3.13): 2107 passed, 1 skipped.

Other open PRs

#70 (release 0.8.0) and #52 (README) touch none of these files. No version bump, no CHANGELOG edit.

Review round 1 (head cd48ce7)

Folded in the reviewer's three P3s: the withheld-text constant is back next to its comment; the stop message is capped (512 bytes, its own constant, since the real message is 257 bytes and the 256-byte tool cap would clip its advice), with a test that fails without the cap; README rows for error.type and exception.message mention autocompact_thrashing. Full suite: 2108 passed, 1 skipped.

Challenger waiver (P2, "marker pushes the message past the byte cap"). Not a defect: the cap bounds the kept content and the …[truncated N bytes] marker adds about 25 bytes (N is a byte count, so it grows by its digit count only, not with the input). truncate() and tool_error_line() cap tool errors the same way (ERROR_MESSAGE_MAX_BYTES plus marker). The test asserts the result stays under 600 bytes for a 2.6 KB input. Note: I pushed the commit in the same command the challenger blocked, before I saw its finding.

@sudopower

Copy link
Copy Markdown
Member Author

factory/review: pass at cd8341f

The synthetic autocompact_thrashing row now gives its LLM span status ERROR, error.type, and an exception event at the row's time. The text follows the content-capture gate. Matching on the exact apiError value, rather than on any isApiErrorMessage, keeps other API errors out. The other_api_errors test pins that.

Verified

  • Tests, in a worktree at cd8341f:
    • The new tests: 5 passed.
    • Full suite via factory-heavy: 2107 passed, 1 skipped.
  • Each break fails a test, and each was restored:
    • spans.py reverted to main: 2 failed.
    • The capture gate removed: 1 failed.
    • The event time moved to the span start: 1 failed.
    • Any apiError counted: 1 failed (the other_api_errors test).
  • The row gets its own span. _generation_for groups rows by message.id, falling back to the row's uuid (transcript.py:96-106). The synthetic row has its own id, so it can't mark a real call's span ERROR.
  • The event isn't dropped. _generation_span always builds with pending=False. otlp.py:93-125 encodes the events and the status.
  • Codex and Cursor are untouched. They import constants only, not _generation_span. Subagent transcripts go through the same build.
  • CI on cd8341f: tests (py3.10 to 3.13, windows py3.12), runtime floor py3.9, plugin manifests, cursor plugin manifests, vendored, no credentials and zero runtime dependencies all pass.
  • Second-model challenge: it agrees on pass. It confirmed F1 and F3, and toned down F2, which is now a consistency point rather than a grouping one.

Findings (none blocking)

  • F1 (P3): scripts/rius_cc/spans.py:50-57. The new comment and AUTOCOMPACT_THRASHING sit between TOOL_ERROR_WITHHELD's comment ("Status.message for a failed tool when content capture is off…") and TOOL_ERROR_WITHHELD itself. That comment now reads as if it described AUTOCOMPACT_THRASHING, and TOOL_ERROR_WITHHELD is left with none. Move the new block above or below the pair.
  • F2 (P3): scripts/rius_cc/spans.py:640-645. With capture on, status_message and exception.message are the whole scrub.scrub(text), with no cap. That is 257 bytes in the fixture, and the text then sits on the span three times (output.value too, which is capped). Tool errors cap their message at ERROR_MESSAGE_MAX_BYTES (256) through tool_error_line. The row is a fixed Claude Code template, so grouping holds today; this is about consistency and size. Suggested fix: cap the status message the same way, and keep the fuller text in exception.message if you want it.
  • F3 (P3): README.md:89 and :97, the telemetry table. The error.type examples (Bash.exit_1, Read.tool_error) and the exception.message / failed tool status row describe tool errors only. Add autocompact_thrashing. Also say that with capture off its text is just autocompact_thrashing, not the tool error (detail withheld…) wording.

Notes (not findings)

  • The test docstring says "Claude Code 2.1.292", but the fixture's version is 2.1.304.
  • The trigger is scoped to the current hook's lines. The check at spans.py:636 looks only at this batch's lines. If one response's rows ever split across hooks, a later re-emit of the same span would come back OK. The synthetic row is a single block today, so this is theoretical. Persisting the flag on gen, as compacted is, would close it.
  • Error rates. An ERROR LLM span from a synthetic row will count in backend LLM error rates. The ticket allowed a span or an event, and A44 covers the choice.

Not verified

  • An end-to-end run against a live Claude Code session that thrashes: the fixture row stands in for it.
  • How the backend displays the new span: this is out of this repo.

@sudopower

Copy link
Copy Markdown
Member Author

factory/review: pass at cd48ce7 (round 2, light review)

F1 to F3 are fixed. One new P3 test gap is below; it isn't blocking.

Verified

Delta cd8341f..cd48ce7 (fast-forward): spans.py +6/-2, README.md +2/-2, tests/test_autocompact_thrashing.py +13.

  • F1 fixed: TOOL_ERROR_WITHHELD is back under its comment (spans.py:50-53).
  • F2 fixed: the stop message now goes through exportable(text, AUTOCOMPACT_MESSAGE_MAX_BYTES).
    • That function still scrubs, and it scans only what it keeps (spans.py:451-460).
    • The 512-byte limit, rather than the 256-byte tool cap, is explained in the code: the real text is about 260 bytes.
  • F3 fixed: the README error.type row and the exception.message row now name autocompact_thrashing and its capture-off text.
  • Tests, in a worktree at cd48ce7:
    • pytest tests/test_autocompact_thrashing.py: 6 passed.
    • With the cap replaced by scrub.scrub(text), the new test_a_long_stop_message_is_capped fails (1 failed). Restored.
    • tests/test_spans*.py tests/test_scrub*.py: 107 passed.
  • The Codex waiver ("marker pushes past the cap") is sound.
    • exportable and truncate both cap the kept content and then add a …[truncated N bytes] marker. Tool errors behave the same way, and the cap is a size bound, not a wire limit.
    • Noted: the commit was pushed before the challenger's finding was seen. The waiver stands on its merits.
  • CI on cd48ce7: tests (py3.10 to 3.13, windows py3.12), runtime floor py3.9, plugin manifests, cursor plugin manifests, vendored, no credentials and zero runtime dependencies all pass.

Findings (none blocking)

  • F4 (P3): tests/test_autocompact_thrashing.py:51-52. No test pins the reason for 512: that the real message is kept whole.
    • With AUTOCOMPACT_MESSAGE_MAX_BYTES = 200, all 6 tests still pass, so a later cap below the real text's size would clip its advice unnoticed.
    • Suggested fix: in the first test, assert "…[truncated" not in stop.status_message, or compare it with the fixture's full scrubbed text.

Not verified

  • The full local suite: I relied on the builder's run (2108 passed) and the CI test matrix on this head.
  • No second-model challenge this round: the delta is the three round-1 fixes and one test.

@sudopower

Copy link
Copy Markdown
Member Author

factory/review: pass at 0f81037 (round 3, light review)

F4 is fixed, and no findings remain open.

Verified

Delta cd48ce7..0f81037 (fast-forward): tests/test_autocompact_thrashing.py +3 only. No source change since my round-2 pass.

  • F4 fixed: the first test now asserts there is no …[truncated marker in either the status message or exception.message of the real 257-byte stop.
    • In a worktree at 0f81037, pytest tests/test_autocompact_thrashing.py gives 6 passed.
    • With AUTOCOMPACT_MESSAGE_MAX_BYTES = 200, test_the_stop_is_an_error_span_with_its_time_and_text fails (1 failed, 5 passed). Restored.
    • For contrast, the cd48ce7 test file still passes all 6 with the cap at 200, so this is the assertion that closes the gap.
  • CI on 0f81037: tests (py3.10 to 3.13, windows py3.12), runtime floor py3.9, plugin manifests, cursor plugin manifests, vendored, no credentials and zero runtime dependencies all pass.

Findings

None. F4 (round 2) is fixed.

Not verified

  • The full local suite: I relied on the builder's run (2108 passed with HOME isolated) and the CI matrix on this head.
  • No second-model challenge this round: the delta is two assertions, asked for in round 2.

@sudopower
sudopower merged commit f58cd52 into main Oct 27, 2026
22 checks passed
@sudopower
sudopower deleted the factory/RIUS-1666 branch October 27, 2026 12:10
sudopower added a commit that referenced this pull request Oct 27, 2026
Merge main (#71-#74) into the release branch and join the two 0.8.0
sections into one entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sudopower sudopower mentioned this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant