Repository navigation
Fix #775 (doctor DuckDB check) + friendly Langfuse auth error - #790
Merged
Merged
Conversation
tj doctor reported a healthy database as unwritable. main opens the backend with bounded settings (memory_limit, threads, temp_directory) before dispatching, and _check_db then opened a bare second connection to the same file. DuckDB keeps one instance per file per process and refuses a second connection with different settings, so every healthy install saw a red error. The probe now asks the live backend when it holds the same file, and otherwise opens the file with the backend's own settings via connect_bounded. The settings fallback in connect_bounded caught every duckdb.Error, so a held lock or a configuration mismatch was announced as the settings being rejected, followed by a "fallback" to the same values. It now degrades only on a genuine setting rejection, skips the pointless retry when the values already are the defaults, and says what it is doing. tj backfill langfuse let a 401/403 escape as an httpx traceback. The CLI now catches HTTPStatusError and prints one line naming the key-pair format (--api-key pk-lf-...:sk-lf-...), with a specific note for a single key, which is sent as Bearer and cannot read observations. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011uyjtSF8w9YGsDDujqydev
Contributor
[Medium impact] The PR appears safe to merge; no actionable defects were found.
|
This was referenced Nov 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A fresh, healthy install sees
tj doctorreport its database as unwritable. This PR fixes that check and the contradictory storage-settings warning that comes from the same cause. It also stopstj backfill langfusefrom dumping an httpx traceback when Langfuse refuses the key.Partially addresses #775 (items 1–2).
Summary
tj doctor's "DuckDB writable" check reuses the process's live backend connection when it holds the same file. Otherwise it opens the file with the backend's own settings (connect_bounded) instead of a bareduckdb.connect.connect_bounded(renamed from_connect_boundedso the CLI can share it) falls back to the default settings only when DuckDB rejected a setting. A held lock or a configuration mismatch now propagates unchanged and is no longer logged as "rejected".tj backfill langfusecatcheshttpx.HTTPStatusErrorat the CLI layer. It prints one line naming the key-pair format and exits 1 with no traceback.DuckDBBackend.db_pathread-only property so doctor can tell whether the live backend holds the file it is checking.#775 item 1: doctor's red "DuckDB writable"
Symptom.
✗ DuckDB writable: Cannot open database: Connection Error: Can't open a connection to same database file with a different configuration than existing connectionson a healthy install.Root cause.
mainopens the backend throughconnect_bounded, which setsmemory_limit,threadsandtemp_directory, before it dispatches to doctor._check_dbthen opened a bareduckdb.connect(path). DuckDB keeps one instance per file per process and refuses a second connection whose settings differ. The lock downgrade only matchedconflicting lock/could not set lock, so the error came out aslevel: error.Fix. If
ctx.obj["db"]is aDuckDBBackendholding the same resolved path, the probe runsSELECT 1on that connection. That connection was opened read-write at startup, so the file and its write lock are already held. Otherwise the probe opens the file throughconnect_boundedwith the configured settings, which DuckDB's instance cache accepts. Two behaviours are unchanged and covered by tests: an unopenable path is still reported aserror, and a lock held by another process is still downgraded toinfo.#775 item 2: the self-contradicting fallback warning
Symptom.
storage.memory_limit='2GB' / storage.threads=4 rejected by DuckDB; falling back to 2GB / 4.Root cause. The fallback in
connect_boundedcaught everyduckdb.Error. A lock held by the daemon (IOException) and a configuration mismatch (ConnectionException) were both reported as rejected settings. The connect was then retried with the identical values and failed again. The lock case also fires on every CLI command run whiletj serveholds the lock, just beforemainswitches to the API backend.Fix.
IOExceptionandConnectionExceptionare re-raised untouched. The error text still contains "lock", somain's lock detection and API fallback work as before. The retry is skipped when the values already are the defaults. A genuine rejection still degrades to the defaults, and the warning now includes DuckDB's reason:… rejected by DuckDB (<reason>); using the defaults 2GB / 4 instead.Friendly Langfuse auth error
Symptom. After #787, a 401/403 from Langfuse surfaced as a raw
httpx.HTTPStatusErrortraceback.Fix.
cmd_backfill.langfusecatches it and raises aClickException, so the user gets one line and exit 1. The core adapter is untouched, so the core/cli boundary holds. Wording matchesdocs/backfill/langfuse.mdand the adapter's_auth_headers:Langfuse rejected the key (HTTP 401). A single key is sent as a Bearer token, which cannot read observations; Langfuse's public API needs the project's public and secret key joined with a colon: --api-key pk-lf-...:sk-lf-...Langfuse rejected the key pair (HTTP 401). Check that --api-key is this project's public and secret key joined with a colon: --api-key pk-lf-...:sk-lf-...Langfuse refused the request without credentials (HTTP 401). Pass the project's public and secret key: --api-key pk-lf-...:sk-lf-...The secret is never echoed back.
What's also in this PR
exceptand printed asLangfuse returned HTTP <n> for <url>.with the query string dropped, instead of a traceback. It is the same handler, and leaving it out would have kept the traceback for every non-auth status.Tests / Verification
Added to
tests/unit/test_doctor_paths.py:test_check_db_is_ok_beside_the_backend_connection: opens viacore.db.open_db, then runs_check_dbwith that backend.test_check_db_is_ok_beside_a_live_connection_it_was_not_handed: same live connection, probe not given the backend.test_doctor_command_reports_the_database_writable: end to end throughtj --json doctor.test_check_db_still_reports_an_unopenable_database_as_an_errortest_check_db_still_downgrades_a_lock_held_elsewheretest_connect_bounded_does_not_blame_the_settings_for_a_config_mismatchtest_connect_bounded_does_not_blame_the_settings_for_a_held_locktest_connect_bounded_still_degrades_a_rejected_overrideAdded to
tests/unit/test_ingest_langfuse.py. These go through the Click runner with anhttpx.MockTransportclient injected into_fetch_url:test_cli_bearer_key_refusal_names_the_key_pair_format[401|403]test_cli_key_pair_refusal_says_check_the_pair[401|403]test_cli_missing_key_refusal_asks_for_the_key_pairtest_cli_other_http_error_is_conciseRun against
origin/main'stokenjam/, 12 of these fail and the regression guards for unchanged behaviour pass. The threeconnect_boundedtests fail on main partly because the public name does not exist there. The two "does not blame" cases also fail on main's behaviour, because main logs "rejected" in both of them.env -u FORCE_COLOR python -m pytest tests/unit/ tests/integration/ -q -n auto: 5894–5896 passed. A different 3–5 tests failed on each of two runs (test_xdist_isolation,test_summarize_relocate,test_summarize_cli). All of them pass serially, none touch these files, and the machine was running other agents' suites at the same time.test_cli.py,test_advertised_commands_are_invocable.pyandtest_no_tracker_ids_in_printed_strings.py: 490 passed.ruff check tokenjam/: clean.mypy tokenjam/: no issues in 288 files.tj --db <scratch> doctor:✓ DuckDB writable: Database accessible, with no fallback warning.tj backfill langfuse --source-url https://cloud.langfuse.com --api-key sk-lf-bogusagainst real Langfuse Cloud: it returned 401 and the command printed the single-key line above with exit 1. The bogus key-pair case printed the key-pair line.What's NOT in this PR
tj init --cloudignoring--db,tj commit-notesubcommand-level--json/-v,TJ_CONFIGleaking into the test isolation fixture, and dollar precision on Optimize vs Dashboard. They are separate code paths, so this PR does not close 0.7.0 fast-follow: doctor's DuckDB check, --db handling in init --cloud, and three smaller papercuts #775.core/ingest_adapters/langfuse.py) or its docs. The adapter keeps raisingHTTPStatusError, and an existing test pins that.🤖 Generated with Claude Code
https://claude.ai/code/session_011uyjtSF8w9YGsDDujqydev