Replace the DB-persistence approach for built-in actors with in-memory virtual
resolution. Built-in actors (e.g. openai/gpt-4o, anthropic/claude-sonnet) are
now resolved on-demand from ProviderRegistry at query time and merged with
persisted custom actors — no database writes occur for built-in actors.
Key changes:
- Add ActorRegistry._resolve_virtual_builtin_actors(): generates virtual Actor
objects in-memory from configured providers (is_built_in=True, id=None)
- ActorRegistry.list()/list_actors(): merges virtual built-ins with custom DB
actors; custom actors win on name collision; result sorted alphabetically
- ActorRegistry.get()/get_actor(): DB-first, virtual built-in fallback,
NotFoundError if neither
- ActorRegistry.remove()/remove_actor(): rejects virtual built-in names with
ValidationError
- ActorRegistry.set_default_actor(): stores only the actor name string via new
actor_preferences singleton table; no actor row created for virtual built-ins
- ActorRegistry.get_default_actor(): reads preference name, resolves via
DB→virtual chain, returns actor with is_default=True
- Remove ensure_built_in_actors() entirely — 20+ call sites cleaned up including
plan.py
- Remove ActorRepository.upsert_built_in() — no longer needed
- Remove is_built_in from ActorModel DB column (kept on Actor domain model for
virtual actors)
- New Alembic migration m10_001_virtual_builtin_actors: drops is_built_in column,
adds actor_preferences singleton table
- Add ActorService.set_default_actor_name() and get_default_actor_name() for
preference storage without requiring a DB actor row
- Update 15+ Behave step files and 5 feature files; add new
features/virtual_builtin_actors.feature with 8 scenarios covering list, show,
remove, set-default, get-default, no-DB-writes guarantees
- Rewrite tests/actor/test_registry_builtin_yaml.py: TestEnsureBuiltInActorsWithYaml
→ TestResolveVirtualBuiltinActors plus new TestListActors, TestGetActor,
TestRemoveActor, TestDefaultActor test classes
Quality gates: lint ✓, typecheck ✓, unit_tests ✓ (15674 scenarios), coverage ✓
(97.10%), integration_tests ✓ (1997 tests)
ISSUES CLOSED: #10923
Merge the two separate database transactions in ensure_default_mock_actor()
into a single atomic transaction to prevent Time-of-Check-Time-of-Use (TOCTOU)
race conditions in concurrent environments (e.g., parallel test workers).
The original implementation had a gap between checking for an existing default
actor and creating a new mock actor. In concurrent scenarios, multiple threads
could both observe no default and attempt to create one, leading to potential
constraint violations or inconsistent state.
The fix consolidates both operations into a single transaction, ensuring that
the check and creation are atomic and safe for concurrent callers.
Added BDD test scenarios to verify idempotency and concurrent safety:
- Idempotency: calling ensure_default_mock_actor multiple times produces same result
- Existing default safety: respects existing default actors
- Single actor creation: ensures only one mock actor is created
Closes#8448