Skip to content

feat(BA-6628): conditional-bulk repository primitives#12429

Draft
jopemachine wants to merge 1 commit into
mainfrom
feat/BA-6628-conditional-bulk-primitives
Draft

feat(BA-6628): conditional-bulk repository primitives#12429
jopemachine wants to merge 1 commit into
mainfrom
feat/BA-6628-conditional-bulk-primitives

Conversation

@jopemachine

@jopemachine jopemachine commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Generic, domain-agnostic repository primitives for gated bulk writes, split out of #12426 (BA-6626) so app_config_fragment — and future domains — build on them. No app_config-specific code.

  • repositories/base: ConditionalCreator / ConditionalUpdater / ConditionalPurger and BulkConditional{Creator,Updater,Purger} — a write spec paired with an only_if existence gate.
  • WriteOps.bulk_conditional_create_partial / _update_partial / _purge_partial — each item runs in its own savepoint for partial success (gate-rejected / missing / failed items reported per-item; the rest proceed). Implemented directly in WriteOps with private _update_one/_purge_one row helpers (not delegating to the standalone execute_* functions).
  • Repository errors ConditionalWriteNotAllowed / ConditionalWriteTargetNotFound.
  • Ops-provider unit tests.

📚 Stacked PRs

Part of the AppConfigFragment / AppConfig stack under BEP-1052 (epic BA-5781). Merge in order:

  1. feat(BA-6552): add app_config_fragments DB model and Alembic migration #12306feat(BA-6552): app_config_fragments DB model and Alembic migration
  2. feat(BA-6553): add app_config_fragments repository layer #12307feat(BA-6553): repository layer
  3. refactor(BA-6619): consolidate AppConfigScopeType into common.data (single definition) #12403refactor(BA-6619): consolidate AppConfigScopeType into common.data
  4. refactor(BA-6620): ExistsQuerier ops primitive + AppConfigAllowList.exists #12405refactor(BA-6620): ExistsQuerier + AppConfigAllowList.exists
  5. feat(BA-6554): add app_config_fragment service layer #12358feat(BA-6554): AppConfigFragment service layer
  6. 👉 feat(BA-6628): conditional-bulk repository primitives #12429feat(BA-6628): conditional-bulk repository primitives ← you are here
  7. feat(BA-6626): app_config_fragment bulk repository layer #12426feat(BA-6626): app_config_fragment bulk repository layer
  8. feat(BA-6618): app_config_fragment bulk CRUD service layer #12401feat(BA-6618): AppConfigFragment bulk CRUD service layer
  9. feat(BA-6555): add app_config service layer #12359feat(BA-6555): app_config service layer
  10. feat(BA-6556): AppConfig REST v2 API (raw fragments and merged read/update) #12377feat(BA-6556): AppConfig REST v2 API

@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component labels Jun 26, 2026
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 018dd4f to 87bcc0c Compare June 26, 2026 07:23
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread changes/12429.feature.md
Comment thread src/ai/backend/manager/errors/repository.py Outdated
Comment thread src/ai/backend/manager/repositories/ops/base/provider.py Outdated
@jopemachine jopemachine requested a review from Copilot June 26, 2026 07:36
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 87bcc0c to c83c084 Compare June 26, 2026 07:37
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread tests/unit/manager/repositories/ops/test_provider.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds generic, domain-agnostic repository primitives for gated bulk writes as step 6 of the AppConfigFragment/AppConfig stack (BEP-1052). It introduces Conditional{Creator,Updater,Purger} (a write spec paired with an only_if existence gate) and their BulkConditional* bundles, plus three WriteOps.bulk_conditional_*_partial methods that isolate each item in its own savepoint so gate-rejected, missing, or failed items are reported per-item while the rest proceed. The update/purge ops paths are refactored to delegate to new private _update_one/_purge_one helpers. Two repository errors (ConditionalWriteNotAllowed, ConditionalWriteTargetNotFound) and ops-provider unit tests round it out.

Changes:

  • New conditional/bulk-conditional dataclasses in repositories/base for create/update/purge.
  • WriteOps.bulk_conditional_*_partial methods with per-item savepoint isolation, plus _update_one/_purge_one extracted from the standalone execute_* functions.
  • New ConditionalWriteNotAllowed / ConditionalWriteTargetNotFound errors and ops-provider tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ai/backend/manager/repositories/base/creator.py Adds ConditionalCreator/BulkConditionalCreator; docstring misstates semantics and references a non-existent function.
src/ai/backend/manager/repositories/base/updater.py Adds ConditionalUpdater/BulkConditionalUpdater; docstring misstates semantics and method name.
src/ai/backend/manager/repositories/base/purger.py Adds ConditionalPurger/BulkConditionalPurger; docstring misstates semantics and method name.
src/ai/backend/manager/repositories/base/init.py Exports the new conditional/bulk-conditional types.
src/ai/backend/manager/repositories/ops/base/provider.py Adds the three bulk_conditional_*_partial methods and _update_one/_purge_one helpers; update/purge now delegate to them.
src/ai/backend/manager/errors/repository.py Adds ConditionalWriteNotAllowed / ConditionalWriteTargetNotFound errors.
tests/unit/manager/repositories/ops/test_provider.py Adds tests for the three conditional-bulk ops (all-pass, partial gate failure, empty, missing row).
changes/12429.misc.md Adds the changelog entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ai/backend/manager/repositories/base/creator.py Outdated
Comment thread src/ai/backend/manager/repositories/base/updater.py Outdated
Comment thread src/ai/backend/manager/repositories/base/purger.py Outdated
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from c83c084 to 7cda3f9 Compare June 26, 2026 08:03
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 7cda3f9 to 614eaf0 Compare June 26, 2026 08:12
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 614eaf0 to 6d69904 Compare June 26, 2026 09:09
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 6d69904 to 47fa255 Compare June 26, 2026 09:27
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Generic, domain-agnostic primitives for gated bulk writes (split out of BA-6626):

- repositories/base: ConditionalCreator/Updater/Purger and BulkConditionalCreator/Updater/
  Purger (a write spec paired with an only_if existence gate).
- WriteOps.bulk_conditional_create_partial / _update_partial / _purge_partial — each item runs
  in its own savepoint for partial success, implemented directly in WriteOps (with private
  _execute_updater / _execute_purger row helpers; not delegating to the standalone execute_*
  functions). A rejected gate is recorded as ConditionalMutationForbidden and a missing
  update/purge target as ObjectNotFound; both are collected per-item, the rest proceed.
- Repository error ConditionalMutationForbidden.
- Ops-provider unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jopemachine jopemachine force-pushed the feat/BA-6628-conditional-bulk-primitives branch from 47fa255 to 0b72350 Compare June 26, 2026 09:50
jopemachine added a commit that referenced this pull request Jun 26, 2026
Build the app_config_fragment bulk repository on the conditional-bulk primitives (#12429):

- AppConfigFragmentCreatorSpec as a plain CreatorSpec with scope-based rank
  (public < domain < user).
- bulk_create / bulk_update / bulk_purge in db_source + repository, returning the
  AppConfigFragmentBulkWriteResult data type (succeeded + failed[index, message]) — partial
  success via the WriteOps.bulk_conditional_*_partial primitives.
- Single create rewritten to gate + plain create (no next-value); GatedWrite removed.
- Repository unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants