Skip to content

fix: route legacy-usearch notices to stderr for clean structured output - #17

Merged
DxTa merged 2 commits into
mainfrom
fix/legacy-notices-to-stderr
Jul 14, 2026
Merged

fix: route legacy-usearch notices to stderr for clean structured output#17
DxTa merged 2 commits into
mainfrom
fix/legacy-notices-to-stderr

Conversation

@DxTa

@DxTa DxTa commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Problem

--format json output was polluted by diagnostic notices (Detected legacy usearch index...) printed to stdout via the Rich console. This broke JSON consumers — e.g. the pi sia-code-proactive extension's JSON.parse hit the leading warning text and fell back to dumping the raw stdout (warnings + pretty JSON) as the tool result, adding ~580 chars of ANSI warnings and defeating compact/projection formatting.

Root cause

create_backend() in cli.py and runtime_context.py emitted the legacy-usearch compatibility notices with console.print(...) (stdout), even in structured output mode.

Fix

Route these notices to a stderr Rich console (err_console = Console(stderr=True, ...)):

  • stdout stays pure JSON for --format json / machine consumption.
  • stderr still shows the notices (with color) in the terminal — no UX regression for interactive use.
  • The existing suppress_stdout_notices guard is preserved unchanged.

Files

  • sia_code/cli.py — add err_console, 2 notice blocks → err_console.print
  • sia_code/runtime_context.py — same (duplicate backend-resolution path)

Verification

$ sia-code search --format json -k 5 -- "zsh alias" 2>err.txt > out.txt
$ head -1 out.txt
{
$ python -c "import json; print(len(json.load(open('out.txt'))['results']))"
5
$ head -3 err.txt   # notices now on stderr
Detected legacy usearch index with implicit storage backend. Using legacy backend for compatibility.
Set 'storage.backend=sqlite-vec' and run 'sia-code index --clean .' to migrate when ready.

Diff: +10/-8 across 2 files. Imports verified.

Notes

  • Complementary root-cause option (not in this PR): migrate the index with sia-code index --clean . to sqlite-vec, which eliminates the legacy notices entirely.
  • The pi extension also gained a belt-and-suspenders prefix-strip (maybeJson finds the first {), so older CLI versions that still print notices to stdout won't break parsing.

DxTa added 2 commits July 10, 2026 00:07
Diagnostic notices ('Detected legacy usearch index...') were printed to
stdout via the Rich console, polluting --format json output and breaking
JSON consumers (the pi extension's result parser fell back to a raw dump
when JSON.parse hit the leading warning text).

Route these notices to a stderr Rich console (err_console) so stdout stays
pure JSON while the notices remain visible in the terminal. The existing
suppress_stdout_notices guard is preserved.

Verified: sia-code search --format json -k 5 -- '...' now emits clean
parseable JSON on stdout and the legacy-usearch notices on stderr.
- route CLI and MCP git context through shared index resolution
- document and lock the complete MCP tool surface
- preserve machine-readable non-TTY JSON and isolate tests
@DxTa
DxTa merged commit d145858 into main Jul 14, 2026
15 checks passed
@DxTa
DxTa deleted the fix/legacy-notices-to-stderr branch July 14, 2026 19:33
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