Skip to content

Command Code: Two critical bugs in a heavy session. Autocompact loop (16 compactions in 3 min) + uncaught exception crash on a large write_file (traceID provided) | Video and Session files provided #767

Description

@problaems

bug windows

Summary

Two distinct failures in one heavy session (session 0f4fcfc7 "Fix Herdr Paste", working directory C:\Users\probs, model byok/glm-5.3-flash via a BYOK OpenAI-compatible provider):

  1. Autocompact loop — auto-compaction fired 16 times in one session, 14 of them back-to-back within ~3 minutes (02:01:57Z → 02:05:08Z), one after nearly every single message, each producing a byte-identical summary. Later the session degenerated into 30 duplicate "This is an auto-compacted summary…" user messages injected at a single timestamp, and the session ends with no assistant reply.
  2. Uncaught exception — while rewriting a large file (~1000+ lines requested), Command Code crashed with an uncaught exception after the write had already succeeded on disk. The crashed turn never committed to the transcript.

The two bugs are likely unrelated (the screen recording of bug 2 was made later and does not show the autocompact loop), but both occurred in the same session, so they're filed together.

Expected Behavior

Bug 1: Auto-compaction runs once when context approaches the limit; after compacting, the session continues on the shrunken context and compaction does not re-trigger until substantial new content has accumulated. Compaction stats in the session meta should agree with the transcript.

Bug 2: A large write_file either succeeds cleanly (turn commits, tool result tells the model what was written) or fails with a handled error. Under no circumstance should the CLI die from an uncaught exception after the file is already written to disk.

Actual Behavior

Bug 1 — autocompact loop (transcript lines 419–460):

  • 16 {"type":"compaction"} entries total; 14 between 02:01:57.980Z and 02:05:08.120Z — roughly one after every message: tool_resultcompaction → next tool call → tool_resultcompaction
  • Every one of those 14 compactions produced an identical summary (same "## Goal / Two-part task on the user's Windows setup…" text), i.e. it kept re-compacting an already-compacted context.
  • No manual /compact was run — every compaction in the transcript was automatic.
  • At the tail of the session (lines 807–836), 30 consecutive user-role messages reading "This is an auto-compacted summary of the earlier conversation that ran out of context." were injected — 15 stamped exactly 2026-08-29T02:54:26.503Z and 15 stamped exactly 2026-08-29T03:03:26.159Z — alternating between two different summary texts. No assistant entry follows. The session was unusable and ended there.
  • Discrepancy: the session meta (0f4fcfc7….meta.json) records compaction.count: 2, tokensSaved: 202577, lastCompactedAt: 2026-08-29T02:48:35.515Z — which does not match the 16 compaction entries in the transcript.

Config context (possibly relevant to Bug 1): At the time this happened I had not set contextWindow for the models in my ~/.commandcode/providers.json — most entries declare only reasoningEfforts, and per the BYOK docs an omitted contextWindow defaults to 200K:

"openrouter": {
  "models": {
    "anthropic/claude-sonnet-5": { "reasoningEfforts": ["low","medium","high","xhigh","max"] },
    ...
  }
}

(The file has since been updated, after this issue occurred.) Node.js version: v24.16.0.

Bug 2 — uncaught exception on a large write_file (transcript lines 804–806, then nothing):

  • I asked the model to write a single ADOC file of over 1000 lines
  • The model's first write_file call contained 531 lines / 51,593 chars of content. The tool result returned only "File created successfully at: C:\Users\probs\Downloads\luvus-windows-paste-analysis.adoc"no line/byte count.
  • Important clarification: the write_file tool call does show the true file size in the TUI (~500 lines) — but that information is not sent back to the model, so the model had no idea what it had actually written.
  • Right after the write, the model announced (visible in the screen recording): "Draft landed but it's ~200 lines — short of the 1000+ you asked for. Rewriting it now, atomized one fact per line, plus appendices." This message is not in the transcript — that turn never committed, likely compacted away with the crash — but it shows in the video. It confirms the model genuinely believed the file was far short of the target and rewrote because it had no accurate size feedback. It believed it was only 200 lines.
  • Please note that the model believing it only wrote 200 lines despite writing 530 is a separate bug on it's own and needs it's own pull request, which I didn't make. I would greatly appreciate if you could look into this more as it heavily disrupts my workflow which depends on strict line counts for write_file.
  • The transcript does not show whether the rewrite was from scratch or appended — the entire rewrite turn is missing; it never committed.
  • After the crash, the file on disk was 1,223 lines / 64,668 bytes, mtime 02:53:53 UTC — i.e. the second write did save successfully, but its turn never committed and Command Code crashed with an uncaught exception. The session transcript simply ends.
  • Screen recording attached: it starts at the exact moment the model finishes the ~531-line write it mistakenly believed was far shorter, and shows the uncaught exception. (Recorded after the autocompact episodes; it does not show Bug 1.)

Steps to reproduce the issue

  1. Windows, Command Code 1.38.2, Node v24.16.0, BYOK OpenAI-compatible provider, launched from $HOME.
  2. Run a long autonomous session with many tool calls and let the context grow. Auto-compaction fires after nearly every message (16x, identical summaries), then the same "auto-compacted summary" gets injected as 30 duplicate user messages at a single timestamp. Session becomes unusable.
  3. In a heavy session, ask the model to write a single >1000-line file. The write_file emits ~530 lines; the success result carries no size info; the model misjudges what it wrote, announces it's short, and rewrites; during/after the rewrite Command Code throws an uncaught exception and dies — while the file is fully written on disk.

Command Code Version

1.38.2

Operating System

Windows

Terminal/IDE

Windows Terminal — Command Code running inside a Herdr pane (Herdr v0.8.2 — https://github.com/herdrdev/herdr)

Shell

PowerShell 7 (pwsh)

Session file (optional)

Attached: command-code-session-0f4fcfc7.jsonl (2.2 MB, 836 entries, session id 0f4fcfc7-9998-4f86-af97-7812de571287, exported via /export jsonl).

  • Compaction loop: lines 419–457 (14 compactions in ~3 min, identical summaries)
  • Final legit compaction: line 460 (02:48:35Z)
  • Last successful write_file: line 805 (531-line content), result at line 806
  • 30 duplicate auto-compacted-summary injections: lines 807–836, then the transcript ends mid-session with no assistant reply
  • A second transcript (the debugging session that produced this report) is attached as well.

Fix prompt (optional)

  • Autocompact: add hysteresis/cooldown — after a compaction, do not re-evaluate the threshold until the post-compaction context has grown by a meaningful margin; verify the compacted context is actually replaced in the working set (the loop suggests it kept re-crossing the threshold immediately); dedupe re-injected summary messages on resume (identical text ×30); reconcile the meta compaction.count with transcript compaction entries.
  • write_file: return the written size (lines/bytes) in the tool result so the model knows what it actually wrote (the TUI shows it, the model never sees it); and wrap the write→commit pipeline so a failure after the file hits disk surfaces as a tool error instead of an uncaught exception that kills the CLI and loses the turn.

Additional context

  • Trace ID for the crash: d9385c0f2f7ac02654868345330e2291 (from /trace; the session meta also lists ec0f627e22192746865c5690046d5f40). Per the docs, /trace copies the current OpenTelemetry trace id "required for support debugging" — please correlate on your telemetry side.
  • Attachments: screen recording of Bug 2 (starts as the ~531-line write finishes) and both session transcripts.
  • Data was only lost in the autocompact loop. No data was lost in the crash: the final file on disk is complete at 1,223 lines — only the transcript turn was lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions