--- sidebar: false --- # AI Provider runtime implementation ledger Approved target: [repository contract](./ai-provider-target-architecture.md). Its header preserves the unchanged original artifact fingerprint. Backend worktree: `feat/ai-provider-runtime`, baseline `d8532ddbf`. Console local review candidate: `d59c47a1b4c7f4892a0f198f888cb9211f165574` in `feat/ai-provider-console`. Neither branch was pushed or deployed. ROOT performs independent verification and final review; all implementation is delegated. | Requirement | Implementation owner | Current state | Evidence / remaining verification | | --- | --- | --- | --- | | Service / Account / Profile graph, typed authoring, exact Driver contracts | provider_local_design | Implemented, local build/tests | `packages/im/ai/src/provider/`; no old provider singleton or parallel runtime authority | | Optional plugin Driver feature and operation-only client | provider_local_design + subscription_provider_research | Implemented, local integration tested | `packages/im/ai-provider`; Core/Tool private operation resources retain the actual generation and trusted principal | | Graph, receipt and sealed credentials in one SQL transaction | subscription_plan_review | Implemented, actual SQLite tested | Repository CAS, rollback, restart, lost acknowledgment, unavailable receipt lookup and identity replacement tests | | Host-private root key, OAuth bundle / client metadata | subscription_plan_review | Implemented, actual cipher/SQLite tested | AAD binds root/owner/account/incarnation/revision/auth contract; no real credentials read | | Refresh singleflight / cancellation / unknown outcomes | subscription_plan_review | Implemented, synthetic/local tested | Late login/refresh, cancel, disconnect tombstones, ambiguous exchange, known rejection, cleanup failure and exact contract fixtures | | Login and Antigravity preparation | subscription_plan_review + subscription_provider_research | Implemented, synthetic HTTP tested | Exact stored callback/state, one exchange; readonly preparation preserves an already exchanged bundle; no real OAuth registration/acceptance tested | | Personal / Host identity, network and quota | subscription_plan_review + provider_local_design + subscription_provider_research | Implemented, integration tested | Personal env reference refused before lookup; HTTPS/public DNS/same-origin boundary; actual Command/Tool owner/scope and quota submission tests | | Private actual credential-version association | subscription_plan_review + subscription_provider_research | Implemented, synthetic/local tested | Original issued grant → final Request → post-target/DNS/quota transport-attempted fact; no public graph/history/trace field and no new 401 reauthorization/replay policy | | Native Request follower lifetime | subscription_plan_review + subscription_provider_research | Implemented, local aggregate tested | Actual SDK/native loopback plus GC: timeout, disconnect, discovery and OAuth body cancellation. Isolated omission of network Request ownership hangs; production test passes | | Authenticated management / descriptors / review / apply / export | subscription_plan_review | Implemented, actual HTTP/SQLite tested | Driver-owned contextual `profileSchema`; stable IDs/receipt; exact dependency contract recheck; committed result survives reconciliation failure | | Definitive rejection versus unknown save | subscription_plan_review | Implemented, HTTP + production Hook + browser tested | Only proven precommit/not-dispatched clears a fresh pending ID; unknown keeps original receipt, never reapplies; existing IDs are recovered by query | | Runtime graph only; no startup-file write or process restart on normal edits | subscription_plan_review | Implemented, composition + browser tested | Process-owned Host and per-operation scope; `ai.plan.yml` is explicit import/export, not startup authority | | Single graph across pre-routing / personal main turn | provider_local_design + subscription_provider_research + subscription_plan_review | Implemented, local integration tested | Opaque captured graph binds real operation/session/generation; principal is independently reconstructed, never inherited from Host pre-routing | | Main / auxiliary / delegated / scheduled / recovery paths | provider_local_design + subscription_plan_review | Production cutover implemented; final inventory/gates pending | Actual model scopes replace old Provider/SDK directory; delegated tasks retain the originating generation; CLI/Workroom callers use trusted deployment operations | | Six decision tasks and independent ambient language purpose | subscription_provider_research + provider_local_design | Implemented, deterministic tests | Native DecisionResult only; task schemas/modes stay with Agent policy; ambient inherits deployment chat only when unset | | Profile generation parameters and perception chain | provider_local_design + subscription_provider_research | Implemented, local tests | Removes framework temperature/output overrides; only the approved explicit perception fallback chain remains | | Profile model update / persistent Session following | provider_local_design + subscription_plan_review | Implemented, persistence/in-flight tests | Same Profile may change native model; next operation follows, in-flight binding remains fixed; account incarnation and opaque-model state stay isolated | | Console configuration | subscription_plan_review | Local candidate reviewed; no remaining findings | 650 Console tests, typecheck, Farm build; ROOT browser verified service editor, contextual parameters, roundtrip, wrong-state login, personal scope and save recovery; independent reviewer cleared the three corrections on candidate `d59c47a1` | | One-time official resource migration | subscription_plan_review + provider_local_design | Implemented, actual SQLite + real CLI tested | Source-only preview; SQLite readonly selected-root metadata / explicit snapshot; explicit credential transfer, journal + receipt, separate file finalize / backup | | Existing third-party Profile → old Session manual binding | provider_local_design + subscription_plan_review | Implemented, local integration tested | 17 cases include real CLI / SQLite CAS / unknown recovery; non-SQLite preview defers target validation to apply; generic port fixture is not a real MySQL/PostgreSQL acceptance | | Scaffolding / examples / public schema / docs | provider_local_design | Implemented, local build/tests | Independent plan proposal; runtime startup rejects old authority; official authoring and upgrade documentation updated | | `eval:chat` local Host gateway | provider_local_design | Implemented; two files / 29 local tests passed | Actual persisted SQLite graph → official headless Host → operation scope; Profile IDs and configured parameters recorded; explicit --model works without a default chat purpose; no dotenv or project setup; real-provider runs remain unauthorized | | Full CI-selected build / check:all / eval:agent | ROOT | CI-selected build 114/114 and reviewed candidate contracts passed; check:all in progress | Candidate `564476d32` contracts passed; check:all found six internal plan pages without the established sidebar metadata, corrected here without changing product navigation. Unit tests are still running; final complete gate and eval results are not yet claimed | | Independent final code review | Dedicated non-implementing reviewers | Completed; reported findings corrected and re-reviewed | Backend execution and security reviewers cleared the fixes; final authoring declaration delta passed the execution review's 7 tests and diff check. Console reviewer separately cleared candidate `d59c47a1`; review clearance does not substitute for the remaining full gates | | Real login / inference / billing / migration / release / deployment | Future separately authorized acceptance | Not executed | No actual user source migration, credential read, paid provider call, push, merge, release or deployment | ## Evidence and limits - Independent validation checkpoint through backend `564476d32`: ROOT's actual CI-selected build completed 114/114 tasks; final contracts passed (`/tmp/zhin-provider-final-ci-contracts.log`). Full `check:all` remains in progress (`/tmp/zhin-provider-final-check-all.log`), so its completion and final eval outcomes remain unverified at this edit. - **Historical checkpoint before Database type isolation:** the actual 26-package Agent tarball closure was reinstalled with the corrected authoring declaration. Its strict compiler result retained four baseline optional-dialect dependency errors (`mongodb`, `mysql2/promise`, `pg`, `redis`); the nonexistent root `AIHookEvent` reference was gone. Four formal Agent runtime entry imports passed with zero provider calls. This checkpoint did not establish a green full Agent strict closure; no optional databases, shim or skipLibCheck hid those errors (`/tmp/zhin-provider-final-agent-archive-strict.log`). The subsequently approved Database isolation is implemented: neutral root plus Memory/SQLite, explicit external-dialect entries, and the separate PostgreSQL declaration contract. The 29-package real-tarball matrix passed its six consumers; see the [current Database contract and evidence](./database-optional-dialect-types.md). - Owned-source Host checkpoint after security review: 27 files / 190 tests passed, including Session-only real CLI, Host HMR / approval, native Fetch + GC, ambient metadata and SQLite dialect contracts. Focused ESLint passed. The Agent dependency build completed 32 tasks, then CLI typecheck passed against its rebuilt child-perception declarations. These are local checkpoints, not the final immutable-candidate repository gates. - Repository/auth/management checks use synthetic data with real local SQLite and the Host cipher. HTTP tests use temporary loopback listeners. Native transport acceptance uses an actual local HTTP server and forced GC; it is not a vendor call. - Real CLI upgrade test executes `zhin migrate inference` preview → apply → finalize, then `runStartCommand`; authenticated management works, anonymous access is 401 and external request count is zero. ROOT independently reproduced this. It uses development source entry points, not a released tarball. - Original startup failure was reproduced before correcting cleanup registration: `handoff.activateNext` cannot add to an already sealed DisposeStack. Cleanup is now registered in preparation; activation only captures its exact Driver ownership. - SQLite JSON red/green checks use actual `StatementSync.columns()` table/original-column metadata. Same-name JSON/TEXT columns, aliases, joins, expressions without provenance and attached databases preserve their own contracts; the existing Session text store has no compensating decoder. - Management view projects one captured graph for all account statuses. The 100-account actual SQLite test observes one graph read and 100 credential reads; ordinary status, inference and writes retain live identity checks. - OAuth window dismissal hides a resumable, single account-owned challenge. Only explicit cancel, disconnect, removal or Host close ends it. No TTL was invented; an uncompleted challenge does not survive process restart. - Credential transport facts are private and in-flight. Request-to-version association lasts while its final Request remains held. It is not persistent auditing and does not provide historical querying when no private observer is installed. Observer sync/async failures cannot change transport results or authentication state. - `ai.plan.yml` exports metadata and explicit bindings, never Key/token/client-secret or sealed private records. Cross-Host import must deliberately bind actual destination identities or create new ones. - Source preview never loads `.env`, another CLI's authorization cache or executable project plugins. It reports unresolved mapping/owner/session references instead of replacing them with defaults. Official automatic import and explicit existing-Profile Session binding remain different reviewed units sharing the same journal/CAS mechanism. - Normal API saves do not write the startup file. Offline migration finalization is a separate explicit operation, preserves the original source in a private backup, and does not restart the process. Database and file cutover are not claimed to be one transaction. - Existing process-owned AssistantStatus ambient scenario configuration is still bound by ingress construction; candidate-config residue is a pre-existing boundary outside this change. New model metadata uses the actual Console operation scope and canonical ambient selection rather than the removed static judge selector. ## Security review corrections | Expected invariant | Actual local evidence | Result and limits | | --- | --- | --- | | Refresh cannot change a proven subject within one Account incarnation | Real SQLite/cipher regression first issued subject B's grant, then rejects `identity-change`; persisted state is uncertain with subject A and neither token, and a rebuilt runtime does not replay. Missing/same subject retains the proven identity | Passed synthetic exchange tests; vendor identity authenticity is not live-verified | | Every affected Account method is supported by the exact held Driver, including Accounts with no Profile | Real builtin Codex `none` / API Key review rejected before credential access; a same-contract Driver methods change rejects an unsubmitted prepared Account, while its old committed receipt still recovers first | Passed metadata/SQLite tests with zero credential/provider calls | | Parent `--dry-run` never dispatches an inference migration or creates a preview artifact | Actual Commander red cases committed graph, finalized configuration and changed a Session; repaired cases leave database/journal/source unchanged. Empty-Root preview refusal leaves output and `.zhin` absent | Passed development CLI subprocess tests; ordinary explicit preview/apply remain available | | Child perception is created from its acquired child scope | CLI configureRouting regression first lacked the callback, then uses the generation-local scoped factory with the child's Session and existing settings/resilience | Passed integration wiring test; Agent child execution evidence is recorded separately in behavior migration notes |