Provider Runtime Explicit Initialization Plan#
For agentic workers: REQUIRED SUB-SKILL: use
superpowers:test-driven-development; run specification review before quality review.
Goal: Remove provider registration and record/replay activation from import openprogram.providers, while preserving existing off/record behavior and keeping replay credential-free.
Approved design: docs/reference/design/providers/record-replay.html at design commit ea796046.
Base: 990bfe36e625579443e1cb01a1b3266c8dbd0e87 in isolated worktree /private/tmp/openprogram-provider-runtime-design-20260812.
Exclusions: No recording-format change, workflow/session/DAG replay, vendor request rewrite, runtime hot reload, Web/Node UI, resource-governance change, or auth account-management refactor. Do not modify the user's separate auth/send-queue worktree.
Task 1: Lifecycle and import boundary#
Files:
- Create
openprogram/providers/initialization.py - Modify
openprogram/providers/api_registry.py - Modify
openprogram/providers/register.py - Modify
openprogram/providers/__init__.py - Modify
openprogram/auth/credential_provider.py - Create
tests/providers/test_provider_initialization.py
- Add subprocess RED tests proving package import does not read record/replay config, open a recording, install a transform, or register provider/auth plugins.
- Add thread RED tests for one initializer, waiting callers, stable READY/FAILED results, interrupted initialization, and provider-batch publication failure.
- Implement
NEW → INITIALIZING → READY|FAILEDwiththreading.Condition; no production reset API. - Make
get_api_provider()initialize before registry lookup. Keep internal raw registry access private to initialization/register code so initialization does not recurse. - Make built-in registration locked, retry-safe before success, and batch-published. Replace auth's provider-package side-effect import with explicit auth-adapter registration.
- Remove both import-time calls from
providers/__init__.py. - Verify focused tests and existing registry/provider tests; commit.
Task 2: Replay-safe runtime factory#
Files:
- Modify
openprogram/providers/registry.py - Modify
tests/unit/test_create_runtime_routing.py - Modify
tests/providers/test_provider_initialization.py
- Add RED cases for explicit plain and all three subscription providers in replay, non-credential defaults, missing defaults, and off/record compatibility.
- Add
model_namespacemetadata to the three subscription entries. - Have
create_runtime()initialize first. In replay only, choose provider/model from explicit arguments or non-credential config defaults, then construct baseRuntimefrommodel_namespace:model; do not call CLI/AuthStore detection, credential resolution, orruntime_classimport/construction. - Keep off/record code paths unchanged. Let
ReplayProviderperform the existing full wire-level request comparison. - Verify focused factory, subscription, detection, structured-output, and record/replay tests; commit.
Task 3: Explicit process startup and management recovery#
Files:
- Modify
openprogram/webui/server.py - Modify
openprogram/worker/runner.py - Modify
openprogram/cli.py - Modify
tests/providers/test_record_replay_cli.py - Modify relevant worker/Web startup tests discovered from callers
- Add RED tests proving Web/worker initialize before starting restore/warm-up/channel threads, while recordings status/off never initialize providers.
- Call
initialize_provider_runtime()synchronously at Web/worker startup before their background threads. - Delete
_OPENPROGRAM_RECORDINGS_MANAGEMENT; dispatch recordings management directly. - Verify missing/corrupt/unsupported replay recovery through real CLI subprocesses and startup fail-fast behavior; commit.
Task 4: Evidence, reviews, and gates#
Files:
- Modify implementation-status/evidence blocks in
docs/reference/design/providers/record-replay.html,.md, and.zh.mdonly after code review passes.
- Run affected provider, factory, auth, CLI, worker, Web, usage, agent-loop, and runtime tests.
- Run an independent specification review against
ea796046; reproduce and repair only contract findings, then obtain PASS. - Run a fresh independent quality review; repair and re-review any load-bearing finding.
- Run the repository full Python gate, changed-file Ruff, docs build, checklinks,
git diff --check, and clean-status check. Record exact environment-only failures at both base and candidate. - Update implementation evidence and commit. Do not change the feature matrix: record/replay was already implemented and this task changes lifecycle quality, not capability scoring.