Skip to content

fix: let read-only consumers build the provider registry without writing#791

Merged
lewisjared merged 2 commits into
mainfrom
fix/read-only-provider-registry
Jul 6, 2026
Merged

fix: let read-only consumers build the provider registry without writing#791
lewisjared merged 2 commits into
mainfrom
fix/read-only-provider-registry

Conversation

@lewisjared

@lewisjared lewisjared commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

ProviderRegistry.build_from_config unconditionally upserts provider and diagnostic rows via _register_provider, which is the only step in that method that writes to the database. That makes it impossible for a read-only consumer — notably the ref-app API serving a database mounted read-only — to build the registry: startup crashes with attempt to write a readonly database even though the rows it needs are already registered by ref providers setup and the workers.

This adds a register argument to build_from_config (default True, so every existing caller is unchanged). Read-only consumers pass register=False to hydrate the registry from imported providers without touching the database.

Changes

  • ProviderRegistry.build_from_config gains register: bool = True; the _register_provider write loop is skipped when it is False.
  • Unit test for the register=False path, plus a TestProviderRegistryReadOnly integration test that migrates and registers a real database, reopens it read-only, and asserts that register=False builds with no write while register=True raises OperationalError (the exact crash this fixes).

Context

This is the climate-ref half of the fix for Climate-REF/ref-app#31; the ref-app API is updated separately to pass register=False on its read-only path.

Summary by CodeRabbit

  • New Features

    • You can now build the provider registry without writing to the database, which supports read-only environments.
    • The registry still loads provider configuration and works in memory as before.
  • Bug Fixes

    • Improved handling for read-only databases by avoiding write transactions when registration is disabled.
    • Added coverage to confirm database writes fail as expected in read-only mode when registration is enabled.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@lewisjared, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 58883631-6899-4469-b22c-471e7c5da26f

📥 Commits

Reviewing files that changed from the base of the PR and between 3628226 and cd9e80d.

📒 Files selected for processing (3)
  • changelog/791.improvement.md
  • packages/climate-ref/src/climate_ref/provider_registry.py
  • packages/climate-ref/tests/unit/test_provider_registry.py
📝 Walkthrough

Walkthrough

Adds a register: bool = True parameter to ProviderRegistry.build_from_config, gating the database write transaction so read-only consumers can build the registry without writing to the database. Includes new unit tests for read-only database scenarios and a changelog entry.

Changes

Read-only registry build support

Layer / File(s) Summary
Add register flag to build_from_config
packages/climate-ref/src/climate_ref/provider_registry.py
Adds a register: bool = True parameter, updates the docstring, and wraps the db.session.begin() upsert logic in an if register: conditional so registration only writes to the database when enabled.
Tests validating register flag and read-only DB behaviour
packages/climate-ref/tests/unit/test_provider_registry.py
Adds test_create_no_register, a TestProviderRegistryReadOnly suite with a _read_only_db helper, and tests confirming no transaction starts when register=False and that register=True against a read-only DB raises OperationalError.
Changelog entry
changelog/791.improvement.md
Documents the new register argument and its use for read-only consumers.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ProviderRegistry
  participant Database

  Caller->>ProviderRegistry: build_from_config(config, db, register=False)
  ProviderRegistry->>ProviderRegistry: import/configure providers
  alt register is True
    ProviderRegistry->>Database: db.session.begin()
    ProviderRegistry->>Database: upsert provider/diagnostic rows
  else register is False
    ProviderRegistry-->>Caller: skip database write
  end
  ProviderRegistry-->>Caller: return ProviderRegistry instance
Loading

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: allowing read-only consumers to build the provider registry without database writes.
Description check ✅ Passed It covers the problem, solution, tests, and context, and mentions the changelog and doc updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/read-only-provider-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
core 92.44% <100.00%> (+<0.01%) ⬆️
providers 86.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...s/climate-ref/src/climate_ref/provider_registry.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lewisjared

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lewisjared

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

`ProviderRegistry.build_from_config` unconditionally upserts provider and diagnostic rows, which is the only step that writes to the database. This crashed API startup when the database was opened read-only, since registration is already performed by `ref providers setup` and the workers.

Add a `register` argument (default `True`, preserving existing behaviour) so read-only consumers such as the API can hydrate the registry with `register=False` and serve a database mounted read-only.

Relates to Climate-REF/ref-app#31.
@lewisjared lewisjared force-pushed the fix/read-only-provider-registry branch from 3628226 to cd9e80d Compare July 6, 2026 06:07
@lewisjared lewisjared merged commit 93040ab into main Jul 6, 2026
26 checks passed
@lewisjared lewisjared deleted the fix/read-only-provider-registry branch July 6, 2026 06:17
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