Repository navigation
Fix SDK DuckDB lock fallback and LiteLLM model prefix - #13
Merged
Merged
Conversation
Two fixes: 1. SDK bootstrap now detects if ocw serve is running (via /api/v1/status) and sends spans over HTTP instead of opening DuckDB directly. Falls back to HTTP on DuckDB lock errors too. This fixes the most common usage pattern: run ocw serve, then run your agent. 2. LiteLLM patch strips provider prefix from model names before setting the span attribute (openai/gpt-4o-mini -> gpt-4o-mini), consistent with patch_openai. Fixes double-prefix in pricing lookups. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
anilmurty
added a commit
that referenced
this pull request
Jun 19, 2026
…#10,#13) Smoke-test playbook (tests/manual-new-release-tests.md): - #3 (and #8/#9/#11/#12/#14/#16 — same root cause): code blocks are now command-only; the inline "# comments" and "# [ ]" checklists that the markdown copy button was pulling into copied commands moved to prose / "- [ ]" lists around each block. Added a note explaining the convention. - #10: corrected the Section 4 trim expectation — with [capture] prompts=false (default), trim checks the capture prereq first and prints the capture hint, NOT the tokenjam[bloat] install hint (only reachable once capture is on). - #13: export file is "claude-code-<date>.jsonc", not ".json". Doc-only; no code changes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
anilmurty
pushed a commit
that referenced
this pull request
Jul 2, 2026
The zero-install first run (`tj quickstart` / bare `tj`) backfills ~/.claude/projects/*.jsonl into a transient in-memory DB before printing the headline. Profiling a 3000-session synthetic history showed the backfill dominates (99.7s) while the diagnostic (0.45s) and timeline (0.04s) are trivial — the cost is the per-span SELECT+INSERT round-trips in `_insert_session_idempotent` (120k spans => 240k DuckDB statements). A first run over a large history blew well past the <30s time-to-first- value goal #6 targets. Add a most-recent-N-sessions cap to the first-run path: `iter_claude_code_ sessions` gains an optional `max_sessions` that walks files mtime-desc and stops once the cap is reached, bounding both parse and insert work regardless of how large ~/.claude is. `ingest_claude_code` threads it through and sets `BackfillResult.limit_reached`. `cmd_quickstart` caps at the most-recent 300 sessions by default (≈9s even on an 8000-session history), exposes `--full` to lift the cap, and discloses the truncation honestly ("Showing your most-recent N sessions … run tj quickstart --full or tj context for your full history") so it never reads as "this is everything". The full `tj backfill claude-code` path passes no cap and is byte-for-byte unchanged. Tests assert BOUNDED WORK (only N sessions/rows ingested on a large synthetic history, the cap keeps the freshest sessions, the limit flag and CLI disclosure render) rather than a flaky wall-clock number. Co-Authored-By: Claude <[email protected]>
anilmurty
pushed a commit
that referenced
this pull request
Jul 2, 2026
The Claude Code backfill ran one existence-check SELECT plus one INSERT per span in `_insert_session_idempotent` — ~2 DuckDB round-trips per span, so a large history (~120k spans) paid ~240k statements (~100s). #13 bounded only the quickstart first-run path; the full `tj backfill claude-code` / daemon path still paid the full per-span cost. Replace the per-span loop with a bulk path that processes a whole session in a BOUNDED number of statements regardless of span count: - Partition new-vs-existing span_ids in ONE chunked `WHERE span_id IN (...)` query (`_existing_span_ids`) instead of N existence SELECTs. - Bulk-insert the new spans in a single `executemany` (`_SPAN_INSERT_SQL` + `_span_insert_params`, kept in lock-step with `DuckDBBackend.insert_span`). - On `--reingest`, batch-load the existing rows' attributes in ONE chunked query (`_load_attrs_bulk`), compute the per-key attribute merge in Python, then apply the updates in a single `executemany`. The #10 idempotency + reingest contract is preserved exactly: new spans insert; existing spans without `--reingest` are skipped untouched; existing spans with `--reingest` get `sub_agent_id` updated and `attributes` per-key merged (overlay `{**stored, **parsed}`, parsed wins, never wipes a stored key). The no-`conn` fallback path is unchanged. Drops the now-unused single-span `_load_attrs` helper. Tests: all existing #3/#10/#13 backfill tests pass unchanged. Adds four #15 tests — bulk insert lands every new span; existing spans are skipped without `--reingest`; `--reingest` still merges attributes (overlay, no wipe) + updates sub_agent_id; and a counting-connection test asserting a 400-span session inserts in a BOUNDED number of statements (well under N execute() calls, via executemany) rather than ~2 per span. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 6f94fe0)
This was referenced Jul 9, 2026
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.
Summary
ocw serveis running (viaGET /api/v1/status) and routes spans over HTTP instead of opening DuckDB directly. Also falls back to HTTP when a DuckDB lock error occurs. AddsOcwHttpExporter(SpanExporter)that POSTs OTLP JSON to/api/v1/spans.openai/gpt-4o-mini→gpt-4o-mini), consistent withpatch_openai. Fixes double-prefix inocw costpricing lookups (openai/openai/gpt-4o-mini).Test plan
ruff checkcleanocw serve &, thenpython3 examples/single_provider/anthropic_agent.py— spans should appear (no DuckDB lock error)ocw cost— model names showgpt-4o-mininotopenai/gpt-4o-mini🤖 Generated with Claude Code