Skip to content

Revert PR #14 (Pydantic AI migration) — restore subscription auth, keep index hardening#15

Merged
nickroci merged 2 commits into
mainfrom
revert/pr-14-pydantic-ai
May 28, 2026
Merged

Revert PR #14 (Pydantic AI migration) — restore subscription auth, keep index hardening#15
nickroci merged 2 commits into
mainfrom
revert/pr-14-pydantic-ai

Conversation

@nickroci

Copy link
Copy Markdown
Owner

Why

PR #14 migrated the daemon's Librarian + Scholar to pydantic-ai bound to anthropic: model strings. pydantic-ai's Anthropic provider authenticates only via the metered API (ANTHROPIC_API_KEY, or Bedrock/Vertex/Foundry clients) — it cannot use the Claude Code subscription the old claude-agent-sdk path ran on. That silently switched the daemon's billing from flat subscription to pay-per-token, and with no key set the daemon crashes on every non-empty Librarian/Scholar run (UserError: Set the ANTHROPIC_API_KEY...). Subscription auth is a hard requirement.

CI didn't catch this because model calls are mocked in tests — a billing-model swap is invisible to ruff/pyright/pytest.

What

Verification

  • daemon/ is byte-identical to pre-migration 238e7a0 (git diff 238e7a0 HEAD -- daemon/ is empty).
  • tools/search/ is identical to current main (pickle fix preserved).
  • claude-agent-sdk restored; pydantic-ai removed from daemon deps; uv.lock reverted to match.
  • pre-commit gates pass (ruff, pyright strict 0 errors, duplicate-code); pre-push pytest passed.

Note — the pydantic-ai work isn't lost

It remains in history and on the feat/scholar-pydantic-ai branch. If we want its typed-output / no-json-repair benefits later, the path that preserves subscription billing is: keep claude-agent-sdk for the model call and layer Pydantic validation on its tool-use — no framework swap, no billing change.

🤖 Generated with Claude Code

nickroci and others added 2 commits May 29, 2026 00:40
This reverts PR #14 (merge 5ed0923, mainline -m 1). The Pydantic AI migration
moved the daemon's Librarian + Scholar onto pydantic-ai's `anthropic:` provider,
which authenticates ONLY via the metered Anthropic API (ANTHROPIC_API_KEY, or
Bedrock/Vertex/Foundry) — it cannot use the Claude Code subscription the old
claude-agent-sdk path ran on. That silently switched the daemon's billing from
flat subscription to pay-per-token, and with no key set the daemon crashes every
non-empty Librarian/Scholar run. Subscription auth is a hard requirement, so
restore the claude-agent-sdk model layer.

The index/pickle hardening (d7f28ec) that rode in on the same PR is unrelated
and worth keeping; it is re-applied in the follow-up commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…safe

`load_pickled` only caught (OSError, UnpicklingError, EOFError, AttributeError,
ModuleNotFoundError), so a corrupt pickle that surfaced as UnicodeDecodeError
(a ValueError, not UnpicklingError) propagated instead of degrading to a
rebuild. In the daemon this silently disabled embedding retrieval until the
index was deleted by hand — priming fell back to BM25-only. Broaden to
`except Exception` to honour the documented "any read failure -> rebuild"
contract (BaseException still propagates).

Root cause of the corruption: save_index wrote a shared `<name>.tmp` before
the atomic rename, but the daemon saves from parallel Librarian threads
(+ priming + prewarm). Concurrent rebuilds of a stale index interleaved into
that one temp file, producing a half-written pickle. Add shared
`bm25.save_pickled` that writes a unique temp file per writer
(tempfile.mkstemp) then os.replace; route both BM25 and embedding save_index
through it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nickroci nickroci merged commit 604f23b into main May 28, 2026
4 checks passed
@nickroci nickroci deleted the revert/pr-14-pydantic-ai branch May 28, 2026 23:56
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