Skip to content

fix: suppress console logging that corrupts TUI display#269

Merged
anandgupta42 merged 2 commits intomainfrom
fix/suppress-console-log-leaks
Mar 18, 2026
Merged

fix: suppress console logging that corrupts TUI display#269
anandgupta42 merged 2 commits intomainfrom
fix/suppress-console-log-leaks

Conversation

@anandgupta42
Copy link
Contributor

What does this PR do?

Fixes raw JSON log lines from third-party libraries (e.g. {"level":"INFO","message":"Creating new connection object"}) leaking into the chat UI, corrupting the TUI display. Suppresses console output from 4 sources:

  • snowflake-sdk: Winston logger with additionalLogToConsole=true by default → set logLevel: "OFF"
  • @databricks/sql: Winston Console transport at info level → create DBSQLLogger with error-only level
  • dbt-tools adapter: console.error("[dbt]", msg) on every dbt operation → buffer in memory ring buffer
  • Tracing module: console.debug/console.warn on trace errors → route through Log.Default (log file only)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #249

How did you verify your code works?

  • Confirmed snowflake-sdk and @databricks/sql both use Winston Console transport by default (verified in node_modules source)
  • Confirmed dbt-tools adapter writes console.error on every dbt-integration callback
  • Confirmed tracing module has 2 console.debug/console.warn calls
  • All 5 packages pass turbo typecheck
  • Biome lint passes on all changed files

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

🤖 Generated with Claude Code

…TUI display (#249)

- `snowflake-sdk`: configure Winston log level to OFF (was writing JSON to stdout)
- `@databricks/sql`: create `DBSQLLogger` with error-only level (Winston console transport)
- `dbt-tools` adapter: replace `console.error` calls with in-memory ring buffer
- Tracing module: route `console.debug`/`console.warn` through `Log.Default` (log file only)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines +79 to 81
log: (msg: string) => bufferLog(`[dbt] ${msg}`),
trace: () => {},
debug: () => {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Error logs from dbt operations are now buffered but never retrieved, as the new getRecentDbtLogs() function is never called. This results in silent failures with no diagnostic output.
Severity: HIGH

Suggested Fix

The code that calls dbt operations and handles their failures (e.g., in tryExecuteViaDbt() or CLI command handlers) must be updated. In the catch blocks or after detecting a failure via stderr, these callers should invoke getRecentDbtLogs() and log the retrieved error messages to provide necessary diagnostic information.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/dbt-tools/src/adapter.ts#L79-L81

Potential issue: The modification to the dbt adapter's `terminal()` function routes all
error logs into an in-memory buffer, `dbtLogBuffer`, instead of `console.error`. While a
new function, `getRecentDbtLogs()`, was added to retrieve these buffered logs, it is
never called anywhere in the codebase. As a result, when any dbt operation fails (e.g.,
in `tryExecuteViaDbt()` or CLI commands), the error messages are silently buffered and
lost. This completely removes error visibility for debugging dbt failures, as the
diagnostic information is never retrieved or displayed to the user or developer.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 2d36571getRecentDbtLogs() is now wired into the bail() error handler in index.ts, so buffered logs are included in diagnostic JSON output on failure. The buffer was also extracted to its own log-buffer.ts module with 7 unit tests.

- Extract dbt log buffer into `log-buffer.ts` for testable isolation
- Wire `getRecentDbtLogs()` into `bail()` error path so buffered logs
  are included in diagnostic output instead of being silently lost
- Add `clearDbtLogs()` for session isolation
- Fix buffer order: evict before push (never exceeds `DBT_LOG_BUFFER_SIZE`)
- Databricks: use no-op logger `{ log: () => {} }` instead of
  `DBSQLLogger({ level: "error" })` for complete stdout suppression
- Snowflake: check `typeof configure === "function"` before calling
- Add 7 unit tests for buffer behavior (FIFO, cap, clear, copy semantics)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@anandgupta42 anandgupta42 merged commit 0612f4e into main Mar 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chatbox displaying raw JSON log messages in UI

1 participant