feat(debug): debug mode that survives a crash, and `altimate debug bundle`

Merged
SA
2mo ago
+1430-6

Issue for this PR

No tracking issue. Found while investigating a field report of Altimate Code hanging and closing during Snowflake connections. The logs the user sent could not show what happened.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When Altimate Code hangs or closes, neither opencode.log nor telemetry shows what it was doing:

  • tool calls are not logged;
  • the log never records which version wrote it;
  • telemetry reports an attempt only once it finishes, so one that hangs or ends the process is invisible.

The user's logs had no line about the warehouse at all.

Debug mode (ALTIMATE_DEBUG=1)

  • Tool tracing: each tool call is written to opencode.log as it starts and ends, with its duration. While a call runs, a heartbeat every 15 s names what is still in progress (still running calls=bash#…:30s).
  • Crash-safe: lines are appended synchronously, so the last ones survive a kill or a crash.
  • Log level: raised to DEBUG unless --log-level is set.

Always on

  • One altimate-code started line per process (main and TUI worker): version, OS, terminal, TTY, debug flag.
  • Every event-loop stall is written to the log, before the telemetry cap.

altimate debug bundle [--output <path>] [--no-network]

Writes one Markdown report on the user's machine. Nothing is uploaded.

  • Findings first, in plain language:
    • runs that ended while a tool was still running;
    • connections with no password or sign-in details actually retrievable (password missing from config and credential store, or no sign-in method at all);
    • unfinished browser sign-ins;
    • connection failures by category;
    • unreachable hosts;
    • telemetry off;
    • MCP servers that keep failing;
    • long stalls, with a note that two threads stalling together usually means the machine slept;
    • repeated snapshot failures;
    • a prompt to rerun with debug mode on.
  • Then the evidence:
    • version and install method, OS and terminal;
    • proxy hosts, and settings in the environment (names only);
    • telemetry state and the Altimate account;
    • warehouse connections: type, sign-in method, field names, password retrievable or not;
    • MCP servers;
    • reachability of the hosts this install already uses (its warehouses, the Altimate API, telemetry, models.dev);
    • a log summary and the last 300 log lines.
  • Redaction: passwords, keys, tokens, PEM blocks, emails, URL queries, the home folder and the user name are removed from the whole report, not just the log lines.

Supporting change: fileLog appends lines to opencode.log in the Effect logger's format, with the same per-thread run id. Log.create writes to stderr only, and only with --print-logs, so it could not be used for either feature.

Docs: the troubleshooting "Debug Mode" section is rewritten (enable, reproduce, run the bundle, what it contains and removes). debug and ALTIMATE_DEBUG are added to the CLI reference.

How did you verify your code works?

End to end with a binary built from this branch, in a sandbox with a working key-pair Snowflake connection and a connection saved with no password:

  1. ALTIMATE_DEBUG=1 altimate run "Call warehouse_test on sfkp…": the log got the start line (version, terminal) and tool start / tool end status=success duration_ms=2403.
  2. A run of bash sleep 90, killed with kill -9 after about 30 s: the log kept tool start tool=bash and heartbeats at 15 s and 30 s up to the kill.
  3. altimate debug bundle: 2 problems found.
    • "Connection 'sfpw' has no password or other sign-in details"
    • "Altimate Code ended while a tool was still running (1 time)… during: bash"
    • All four network checks reported. Grepping the report found no username, email or home path.
    • --no-network skipped the checks.
  4. Found and fixed during that run:
    • the user name leaked inside a hyphenated folder name;
    • a connection with no sign-in method wasn't flagged;
    • the "Debug mode" row described the bundle process rather than the log.

Tests

  • test/altimate/debug/report.test.ts: redaction (secrets, keys, tokens, PEM, emails, URL queries, home and user name in every path spelling, longer words left alone); log analysis (starts per day, MCP failures, sign-ins, stalls, snapshot errors, connection-failure categories, ended-mid-tool vs finished runs); each finding; table escaping.
  • test/altimate/debug/mode.test.ts: the flag, and no tracing when off.
  • Mutation-checked: removing tool-end handling, secret / URL-query / user-name redaction, the password finding, or the sign-in finding each fails a test.

Related suites: 612 pass. Typecheck, marker guard and tracker-leak check clean. Full suite: 14,448 pass, 7 fail. 6 are MCP tests reading the developer's real ~/.claude.json (#1386). 1 was the CLI help snapshot, which now lists debug bundle; updated, and it passes (1/1).

Screenshots / recordings

N/A: CLI output and a Markdown report (excerpt above).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV


Summary by cubic

Adds ALTIMATE_DEBUG=1 mode that logs each tool call as it starts and ends (with duration), plus a 15s heartbeat while calls run. Writes are synchronous, so the log survives a hang or crash, and it now always records each process start and every event-loop stall.

Adds altimate debug bundle: writes a local Markdown report leading with detected problems, then evidence (version, warehouse connections, MCP servers, network reachability, log summary and tail). The command runs without starting the project, so a hang can't stop it, and --no-network makes no network requests at all. Connections are judged with secrets restored from the credential store, so working token, key-pair or BigQuery default-credential setups aren't flagged as missing a password. Passwords, keys, tokens, emails, URL queries, home folder, user name and computer name are redacted; the report is owner-readable only (0600) and nothing is uploaded.

Summary by CodeRabbit

  • New Features
    • Added altimate debug bundle to create a diagnostic report for support, with optional network checks and a custom output path.
    • Reports summarize system, connection, network, and log details, with sensitive information redacted. Raw logs remain available with --print-logs.
    • Set ALTIMATE_DEBUG=1 to record tool-call activity and long-running call heartbeats in the log.
  • Documentation
    • Updated troubleshooting and CLI guidance for debug mode and diagnostic reports.