[PR #3305] feat: Improve logging #10595

Closed
opened 2026-02-16 18:15:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3305

State: closed
Merged: No


Changes

  • TUI Disruption Prevention: Logs were previously written directly to stderr, potentially corrupting the TUI display. Background mode buffers non-critical logs during TUI operation and flushes them afterward.
  • Log Importance: The opt() method allows marking logs as "important" (always visible, even without --print-logs), so users can discover issues more easily
    • The default importance behavior when not explicitly specified is to treat ERROR messages as important, i.e. logged to stderr even without --print-logs
    • State disposal warnings are marked important, so users understand why OC is hanging, and to reduce the steps needed to guide the user while debugging
    • Session.prompt errors are marked unimportant to avoid clutter (i.e. printed only with --print-logs)

Example broken TUI due to --print-logs (before change)

image

Example messages with the improved logging

(in order for the below example to actually be implemented, .opt({ important: true }) will need to be applied to those logs after https://github.com/sst/opencode/pull/3481 is merged)

$ opencode run hi
Hi!
WARN 2025-10-20T20:38:54 +1000ms service=default waiting for state disposal to complete... (this is usually a saving operation or subprocess shutdown)
WARN 2025-10-20T20:39:03 +8999ms service=default state disposal is taking an unusually long time - if it does not complete in a reasonable time, please report this as a bug
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3305 **State:** closed **Merged:** No --- ### Changes - **TUI Disruption Prevention**: Logs were previously written directly to stderr, potentially corrupting the TUI display. Background mode buffers non-critical logs during TUI operation and flushes them afterward. - **Log Importance**: The `opt()` method allows marking logs as "important" (always visible, even without --print-logs), so users can discover issues more easily - The default importance behavior when not explicitly specified is to treat ERROR messages as important, i.e. logged to stderr even without `--print-logs` - State disposal warnings are marked important, so users understand why OC is hanging, and to reduce the steps needed to guide the user while debugging - Session.prompt errors are marked unimportant to avoid clutter (i.e. printed only with `--print-logs`) ### Example broken TUI due to `--print-logs` (before change) <img width="1048" height="789" alt="image" src="https://github.com/user-attachments/assets/7e9ea01c-3f71-4a4e-9e5c-1d7c5827c082" /> ### Example messages with the improved logging (in order for the below example to actually be implemented, `.opt({ important: true })` will need to be applied to those logs after https://github.com/sst/opencode/pull/3481 is merged) ``` $ opencode run hi Hi! WARN 2025-10-20T20:38:54 +1000ms service=default waiting for state disposal to complete... (this is usually a saving operation or subprocess shutdown) WARN 2025-10-20T20:39:03 +8999ms service=default state disposal is taking an unusually long time - if it does not complete in a reasonable time, please report this as a bug ```
yindo added the pull-request label 2026-02-16 18:15:18 -05:00
yindo closed this issue 2026-02-16 18:15:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10595