Skip to content

Conversation

@veracioux
Copy link
Contributor

@veracioux veracioux commented Oct 20, 2025

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 #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

- Implement background log collection to prevent logs from disrupting
  TUI display
- Add `setBackgroundMode()` and `flushBackgroundLogs()` to buffer logs
  during TUI operation
- Introduce `opt()` method to mark logs as important
  (always print to stderr)
- Refactor log writing to support both file and stderr output with
  importance levels
- Mark state disposal warnings as important to ensure visibility
- Mark session prompt errors as non-important to reduce noise
@veracioux veracioux force-pushed the feat/improve-logging branch from 985812e to e9fd45a Compare October 27, 2025 21:56
@veracioux veracioux marked this pull request as ready for review October 27, 2025 21:59
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