Skip to content

fix(state): complete async SDK auth and plugin discovery cutovers - #169763

Closed
steipete wants to merge 256 commits into
mainfrom
dbasync/t1cut-state-complete
Closed

steipete wants to merge 256 commits into
mainfrom
dbasync/t1cut-state-complete

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cold discovery, model policy and whole-store auth saves still reached native SQLite through synchronous contracts. Bundled callers now prepare through existing worker owners and derive policy from captured facts. Released SDK APIs remain available with bounded deprecation warnings and documented async replacements. Internal discovery requires preparation; named native adapters serve boot, offline administration and deprecated compatibility. This follows #169580 and changes no schema, format, retention or dependency.

saveAuthProfileStoreAsync preserves whole-store replacement, including removal of omitted profiles and bookkeeping, and waits for committed-state publication. It captures input before awaiting; the auth owner retains shared/local ownership and external-profile filtering. Use updateAuthProfileStoreWithLock for partial mutation. Credential callbacks prepare before writer admission and then consume the transaction-current store. Synchronous saves retain one bounded deprecation warning.

Model policy carries the pinned account's prepared provider. Discovery carries captured metadata through loader awaits and scopes facts by state root. Concurrent same-key loads queue through the existing loader; effect owners retain credential, activation and execution authority. Supplied config skips cold default capture; otherwise resolvePluginRuntimeLoadContextAsync awaits captureRuntimeConfigAsyncReader() and carries that exact config into the metadata owner. No new cache or authority guard is introduced.

Provider hooks, TTS/speech, embeddings, media, web tools, Gateway and CLI consumers await existing metadata/registry owners. Model parsing offers an awaited one-shot API and prepared resolver. Bundled callers reuse their prepared result; internal cold fallbacks are removed. Native incognito removal is preserved.

The final cold-path fixes prepare the existing runtime owner before agent-command execution, channel discovery/install setup and Workshop work. Security audit remains config-only with manifest normalization disabled. Provider-auth input and Doctor install-candidate preparation carry their exact environment into the existing owner; helper lifetimes keep those prepared facts alive through consumption. These are supported entry-point repairs, with no added warm-path SQL claimed and no new measurement. Later cold-path fixes initialize the provider singleton through the existing default runtime, prepare the secrets-audit metadata scope, await the existing addDoctorLegacyIssues owner and Doctor catalog collection, and migrate the bundled node-native caller to snapshotAsync. These later fixes are unmeasured; no additional T1 or per-turn saving is claimed.

SDK migration

Subpath Deprecated synchronous API Awaited replacement
agent-runtime saveAuthProfileStore saveAuthProfileStoreAsync
agent-runtime parseModelRef parseModelRefAsync / prepareModelRefResolver
agent-runtime resolveModelRefFromString prepareModelRefResolver(...).resolveModelRefFromString
model-session-runtime applyModelOverrideWithAuthProfileCompatibility applyModelOverrideWithAuthProfileCompatibilityAsync
session-transcript-runtime createSessionCatalogSourceActorProjector prepareSessionCatalogSourceActorProjector
session-transcript-runtime createSessionCatalogGitHubLinker prepareSessionCatalogGitHubLinker
media-runtime resolveAutoMediaKeyProviders resolveAutoMediaKeyProvidersAsync
media-runtime resolveDefaultMediaModel resolveDefaultMediaModelAsync
provider-catalog-runtime resolvePluginProviders resolvePluginProvidersAsync
memory-core-host-engine-foundation resolveMemorySearchConfig resolveMemorySearchConfigAsync
realtime-voice getRealtimeVoiceProvider, listRealtimeVoiceProviders, canonicalizeRealtimeVoiceProviderId, resolveConfiguredRealtimeVoiceProvider Corresponding Async operations
realtime-transcription getRealtimeTranscriptionProvider, listRealtimeTranscriptionProviders getRealtimeTranscriptionProviderAsync, listRealtimeTranscriptionProvidersAsync
provider-http, provider-model-shared Endpoint/request-policy helpers prepareModelProviderRequestRouteFacts and captured providerMetadataOwners

The transcription sync pair is deprecated with bounded warnings and consumes already loaded providers; its async replacement pair owns cold provider preparation. Bundled callers await those replacements.

Legacy auth-save, model-reference, provider HTTP and realtime-voice signatures, immediate results and mutation timing remain available until a later stable release, including their named cold native adapters. Generic provider-catalog, speech and embedding discovery APIs consume an already prepared registry; their async replacements own cold discovery. Calls use the existing bounded DEP_PLUGIN_SDK warning per plugin/capability family. The async save does not accept a native transaction handle; transaction-local kernels retain their owner API. Media callers can supply a prepared registry. The catalog preparation helpers already existed; this change documents and registers the old factories' deprecation. Bundled callers use the async APIs. External plugins use the typed-public agent-runtime exports; bundled callers may use the existing private model-ref-parse seam. The earlier five public declarations and two deprecations, plus the two new public provider/memory pairs, have explicit named surface allowances. The shipped release snapshot is unchanged.

Removed checks and accepted edges

  • Pending status-read freshness: main refactor(gateway): finish GitHub publication worker cutover #169581 (5b242) retired held pending-read freshness; the retained delayed-read scaffolding is removed. Status preparation racing completion may require a refresh. Confirmation checks the live receipt before effects, and direct terminal-confirmation/no-extra-commands regression coverage remains.
  • Pairing preparation: concurrent unawaited calls using different adapter-preparation routes may reach writer admission in readiness order during a cold lookup. Writer FIFO begins at admission, and post-await effect authority remains intact.
  • Native discovery cache-miss fallbacks: an unprepared internal caller gets a preparation error; explicit native admission remains in the named boot, offline administration, test-fixture and deprecated SDK compatibility owners.
  • Discovery getter's cache-retirement AbortSignal recheck: a derivation racing retirement may finish with its captured policy; real-effect owners retain current authority checks.
  • Single-slot root replacement and its repeat policy read: admitted roots retain facts until the metadata lifecycle invalidates them; out-of-owner live database edits are outside the ownership contract.
  • Repeated model alias discovery in synchronous expressions: the resolver keeps its selected manifest source; a caller adopts later metadata by preparing again. Credential and execution authority remain with effect owners.
  • Implicit credential-provider reload in synchronous session policy: policy uses the provider recorded during preparation; the next preparation observes later changes, and authentication still uses its credential owner. No compensating generation or reread was added.
  • Immediate index-preparation assertions in config-wide metadata, metadata snapshots, persisted-index reads and install-record publication: preparation already checks the fact and the following derivations contain no await; a later receipt is observed by the next read. Activation and effect guards remain.
  • Immediate installed-index currency assertion: preparePluginCacheFact has already asserted the same fact with no intervening await; its returned guard still runs after async work at activation/effect boundaries. No SQL saving is claimed.
  • Registry publication retry/current checks are retained exactly from root 339e4f7, with both supported-write and cross-database tests. The returned witness feeds destructive survivor/file planning and final sharing guards, so this is a real user-data/disclosure boundary. No check or SQL reduction is claimed for it.
  • Duplicate outer fallback-notice validation is removed; the lower owner guard remains authoritative. Prepared metadata, including an explicit null result, is carried into fallback rows.
  • Repeated metadata selection during one request/setup interaction: the invocation retains its selected metadata and prepared plugin callbacks through completion; config/install changes appear on the next invocation. Credential and execution authority checks remain at their real effect boundaries.

T1 accounting

The discovery cutover removes two transitive native fallback branches. Its directly inventoried SQLite primitives remain 0 → 0. Moving a shared SQL kernel behind its worker is not a statement saving.

Across the original 23 state files and their successors, this follow-up is T1 26 → 26 and worker expressions 38 → 38. The parent state lane's scoped inventory has 25 T1 expressions in original filenames plus one relocated row reader, versus 33 on the source-aware 63a034f baseline and 54 in the original campaign census. The original comparison includes 21 classification corrections and seven removals/cutovers; it does not mean 28 fewer queries per turn. This follow-up does not claim an additional direct primitive reduction.

Remaining mixed kernels serve workers, released synchronous SDK contracts, native administration, or credential authority at a real effect. Boot admission, migrations, Doctor/CLI one-shots, and lock primitives remain allowed synchronous paths. Synchronous auth-save/model-policy, model-reference, HTTP-policy and realtime-voice compatibility remains through explicit native adapters. Generic provider-catalog/speech/embedding discovery consumes prepared facts and has no internal cold fallback. The lane does not claim zero native runtime SQL or count classification changes as eliminated statements.

Measurement

One live baseline/candidate pair under RELAXED TESTING v6, using isolated state and the shared harness. Base 63a034f64e3af869a5affb0968d0d3a199121358; measured candidate 1d4c0e3d1ab5d9655d6a3c00c35beb0cb154e70e.

Metric Base Measured candidate
Warmed all-thread statements/turn, median [min–max] 343 [303–489] 456.5 [424–549]
Warmed requests/turn, median [min–max] 95.5 [82–116] 113 [105–123]
Warmed MAIN statements/turn, median [min–max] 0 [0–2] 0 [0–2]
Whole-workload statements 10096 11817
Whole-workload requests 1943 2176
Whole-workload MAIN statements 1995 2104

The raw increase is real inherited work, not a saving or unexplained noise. Main commit 7aae49e8677b18ca992b72a49221e1b6de4b45e4 (#169660) added a transcript-triggered usage-cost sidecar: 122 SQL / 18 requests per warmed turn, plus 3 SQL / 3 plugin-state requests. Its new unscoped cache writes invalidate the session actor. This state lane adds no warmed owner-operation SQL or requests. Later type/fixture/conflict fixes preserve the measured ordinary SQL paths; a cold Dev-update fix removes a read, for which no saving is claimed.

Required shared-family means per warmed turn:

Family Base Candidate
Exact-entry facts SQL 11.4 10.1
Actor hydration SQL 5.3 6.5
Entry-cache snapshot SQL 1.2 1.2
Row-facts SQL / requests 26.5 / 5.3 26.5 / 5.3
Watermark SQL 7.3 6.3

The hydration increase is explicitly attributed: nine new borrowed-read and nine delivery-settlement hydrations follow usage-cache writes on the same writer thread; one follows an unchanged memory write; transcript-append hydrations fall by seven. Net: +12 across ten turns. The usage operations use the pre-existing unscoped write transaction, which bumps the revision used by all actor residency tokens. For example, turn 03 usage rollup at monotonic 481807197171208 precedes borrowed hydration at 481807222625583. This is a separate usage-owner optimization; no claim of a lane hydration saving is made.

Whole-workload state operation SQL/requests: machineState.read 0/0→5/5 (cold worker admission); userModelAccounts.links 8/2→4/1; config health/snapshot operations and profile authority/attribution reads unchanged; userProfiles.ensureOwner 34/1→37/1 (cold admission). Registry-deletion snapshot samples fall 60/9→48/7 because a startup maintenance sweep was skipped, so that drop is not credited.

Both runs completed 13 turns, the child flow, cron, compaction and shutdown with exact SQL count conservation. There were zero missing SQL contexts or duplicate sends; request send/receive tracing has two unmatched records on base and three on candidate. On the heavily loaded host, the candidate's first attempt exceeded readiness before any turns. The successful retry used the same build and only raised the copied harness readiness deadline from 300 to 900 seconds; the shared harness and workload deadlines stayed unchanged. No latency claim is made.

Limitations retained: one candidate startup maintenance sweep logged “Agent database registry changed during discovery” and skipped; the later cron workload passed. The existing guard protects deletion/retention against an invalidated registry snapshot and remains. Candidate Workshop review reached an existing synchronous transcript effect guard (130 MAIN SQL during cron/compaction), while base scheduled that same review but rejected its stale anchor before admission. Scheduler, review and guard sources are unchanged; the metadata-preparation await may affect timing, so this is reported as background-flow placement variation rather than zero whole-Gateway MAIN. Warmed MAIN outliers are unchanged secret-store timer work, outside this lane.

Evidence

Current pushed SDK head is d9c110158faeeea8eeddf89ef3e6625957e93182, based on root 8bf0a9ca0b7e75a7ba36cee505646ada2014cd44. The merge adopts main's isTtsProviderConfiguredAsync readiness helper and passes the existing prepared speech registry (6 additions/15 deletions); one deprecation comment also changes. No database operation, cache, request or owner design is added, and no SQL saving is claimed. Current static and behavior gates remain pending; prior results below are not final-head clearance.

Gate Source-pinned evidence and current limit
Current d9c1101 CI, static and behavior results pending; no mergeability or final-head pass claimed
Prior production CI db9c7b4, 38325886820: 7/7 types, 6/6 lint, source/export contracts, Madge, T1/dialect/worker ratchets and runtime API PASS
Prior SDK API/surface API diff 115064594072 PASS; surface 115064348735 PASS: public 154 entrypoints / 3,748 exports / 2,198 callables / 216 deprecated exports / 157 deprecated callables
Prior Knip SDK 115064594962 matches main 5cf 115053329496 by exact message: UI findings only, no new findings at that source
Security review Not eligible while based on the root branch; retargeting to main after root lands must trigger actual review
Published-driver update db9c7b4 38325882261 includes the cold-ingress owner hunks; actual survivor result remains pending. Both merges wait for it.

LOC at these exact current pins: 1,744 files, +21,756/−10,564 (net +11,192). Production: 605 files +9,369/−4,542; tests: 1,117 +11,918/−5,801; docs: 8 +228/−7; tooling: 14 +241/−214. Test/support/harness files count as tests. Prior 00cede88 update 38318174296 passed in 1,302s but is historical, not current qualification.

Two Codex review rounds are complete for their recorded scopes; the lane owner reviewed later fixes. The orphaned synchronous registry-ownership helper is removed; its awaited parent guard remains. The ACP assertion keeps exactly two terminal/cancelled records and actor-release barriers. The handoff lock remains unresolved: main passed the matching test, and source identity does not prove behavioral inheritance. No additional direct T1 saving is claimed for late repairs.

…t1cut-state

# Conflicts:
#	src/gateway/server-methods/push-authority-router.test.ts
#	src/gateway/server-methods/push.ts
…t1cut-state-complete

# Conflicts:
#	src/gateway/server-methods/push-authority-router.test.ts
#	src/gateway/server-methods/push.ts
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: voice-call Channel integration: voice-call gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling extensions: codex plugin: file-transfer labels Oct 12, 2026
# Conflicts:
#	extensions/qa-lab/test/runtime-tool-fixture-helpers.ts
#	packages/memory-host-sdk/src/host/embeddings-remote-client.ts
#	src/config/sessions/session-accessor.transcript-turn.ts
#	src/gateway/server.cron.test.ts
#	src/plugins/openai-compatible-embedding-provider.ts
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: d9c110158faeeea8eeddf89ef3e6625957e93182
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/agent-auth-credentials.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/agent-auth-discovery-core.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/agent-auth-discovery.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-health.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/ambient-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/candidate-stores.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-auth.native.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-cli-auth-selection.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/legacy-source-diagnostic.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/order.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/path-resolve.native.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/path-resolve.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/paths.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/personal-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/profile-list.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/profiles.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-read.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-read.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-read.worker.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-snapshot-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-snapshots.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/shared-store-bootstrap.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • 58 additional sensitive files; see the workflow summary.

Carefully review these changes before merging.

@steipete

Copy link
Copy Markdown
Contributor Author

Closing this broad migration experiment. It does not establish an additional end-to-end performance improvement, later main changes already cover parts of the asynchronous migration, and the remaining candidate still has unresolved compatibility and lifecycle regressions. Any remaining fix should be isolated and measured against current main.

Closed in a sweep of maintainer PRs open longer than a week. Reopen with a current reproduction if this still matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: active-memory extensions: agentsapi extensions: anthropic extensions: anthropic-vertex extensions: apple-fm extensions: baseten Extension: baseten extensions: codex extensions: cohere extensions: comfy extensions: copilot extensions: crabbox extensions: deepgram extensions: deepinfra extensions: deepseek extensions: github-copilot extensions: google extensions: kilocode extensions: kimi-coding extensions: litellm extensions: llama-cpp extensions: llm-task Extension: llm-task extensions: lmstudio extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: minimax extensions: moonshot extensions: ollama extensions: openai extensions: opencode-go extensions: openrouter extensions: openshell extensions: perplexity extensions: qa-lab extensions: qwen extensions: stepfun extensions: vydra extensions: xai extensions: xiaomi extensions: zai gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. plugin: facetime FaceTime plugin plugin: file-transfer rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts security-sensitive-changed size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant