Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed crates/openhuman-core/src/inference/provider/README.md,crates/openhuman-core/sr

Steven Enamakeleb4f7df7f7cb
diff --git a/crates/openhuman-core/src/inference/provider/README.md b/crates/openhuman-core/src/inference/provider/README.md
index bad303cc87..cec815ab2d 100644
--- a/crates/openhuman-core/src/inference/provider/README.md
+++ b/crates/openhuman-core/src/inference/provider/README.md
@@ -18,12 +18,12 @@ domain.
and applies the BYOK sentinel, Privacy-Mode `LocalOnly`
(`enforce_local_only_inference`), and managed-session (`verify_session_active`)
gates before building a model.
-- **Models**, `OpenHumanBackendModel` + `PROVIDER_LABEL`
+- **Models**: `OpenHumanBackendModel` + `PROVIDER_LABEL`
(`openhuman_backend_model.rs`); OpenAI-compatible and Anthropic builders live
in `tinyinference_llm::providers` and are called directly.
-- **DTOs** (`types.rs`), `ChatRequest`, `ChatResponse`, `ProviderDelta`,
+- **DTOs** (`types.rs`): `ChatRequest`, `ChatResponse`, `ProviderDelta`,
`ToolCall`, `UsageInfo`, `AGENT_TURN_MAX_OUTPUT_TOKENS`.
-- **Error classifiers**, reusable classifiers live in
+- **Error classifiers**: reusable classifiers live in
`tinyinference_llm::classification`; this directory retains OpenHuman managed-backend and telemetry policy.
## Transports
diff --git a/crates/openhuman-core/src/security/keyring/README.md b/crates/openhuman-core/src/security/keyring/README.md
index 7d346b7646..d484734184 100644
--- a/crates/openhuman-core/src/security/keyring/README.md
+++ b/crates/openhuman-core/src/security/keyring/README.md
@@ -1,45 +1,45 @@
# keyring
-OS-keychain-backed secret storage with pluggable test/debug backends, plus a ChaCha20-Poly1305 encrypted secret store for config-field encryption. This is an **infrastructure domain** — it has no RPC controllers, no agent tools, and no event-bus subscribers. It provides a namespaced, user-scoped, `get`/`set`/`delete` interface over a backend selected once per process, and a separate `SecretStore` type that other domains use to encrypt/decrypt secret values stored in config. All keys are scoped under a `user_id` so multiple users coexist without collision; the backend entry key format is `"{user_id}:{logical_key}"`.
+OS-keychain-backed secret storage with pluggable test and debug backends, plus a ChaCha20-Poly1305 encrypted secret store for config-field encryption. This is an infrastructure domain: it has no RPC controllers, no agent tools, and no event-bus subscribers. It provides a namespaced, user-scoped `get`/`set`/`delete` interface over a backend selected once per process, and a separate `SecretStore` type that other domains use to encrypt and decrypt secret values stored in config. All keys are scoped under a `user_id` so multiple users coexist without collision; the backend entry key format is `"{user_id}:{logical_key}"`.
## Responsibilities
- Provide `get` / `set` / `delete` / `get_or_create_random` over a process-global secret-storage backend.
-- Select the backend exactly once at first use (env override → `cfg(test)` → staging/prod vs dev) and freeze it in a `OnceLock`.
+- Select the backend exactly once at first use (env override, then `cfg(test)`, then staging/prod vs dev) and freeze it in a `OnceLock`.
- Probe and cache backend availability (`is_available`) so callers (wallet guards, snapshot loops) can fall back to file storage without re-triggering OS keychain prompts.
- Migrate a secret from a plaintext file into the active backend (`migrate_from_file`), verifying the write before deleting the source.
-- Encrypt/decrypt config-field secrets via `SecretStore` (ChaCha20-Poly1305, `enc2:` prefix), including migration of the legacy XOR `enc:` format.
-- Load/cache a single app-scoped master encryption key from the OS keychain at startup (`init_master_key`) for the `encrypted_file` backend, reducing keychain access to one call per process.
+- Encrypt and decrypt config-field secrets via `SecretStore` (ChaCha20-Poly1305, `enc2:` prefix), including migration of the legacy XOR `enc:` format.
+- Load and cache a single app-scoped master encryption key from the OS keychain at startup (`init_master_key`) for the `encrypted_file` backend, reducing keychain access to one call per process.
- Migrate the legacy plaintext `dev-keychain.json` into the encrypted `secrets.enc` file on first use.
## Key files
-| File | Role |
-| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `crates/openhuman-core/src/security/keyring/mod.rs` | Module docstring + exports only. Documents backend-selection priority and the Linux-headless availability note. Re-exports the public surface. |
-| `crates/openhuman-core/src/security/keyring/ops.rs` | Core operations: `get`/`set`/`delete`/`is_available`/`get_or_create_random`/`migrate_from_file`, the `MigrationOutcome` enum, `namespaced_key` helper, cached availability probe, and `force_backend_for_test`. |
-| `crates/openhuman-core/src/security/keyring/store.rs` | Backend selection + global state. Owns `WORKSPACE_DIR` and `BACKEND` `OnceLock`s, `init_workspace`, `backend()`, `build_backend()`/`build_backend_at()`, and `workspace_dir_for_file_backend()` path derivation. Also the `cfg(test)`-only `test_scope` module (thread-scoped test workspaces). |
-| `crates/openhuman-core/src/security/keyring/backend.rs` | `KeyringBackend` trait + `OsBackend` (native keychain via the `keyring` crate, service name `"openhuman"`), `FileBackend` (plaintext `dev-keychain.json`, test/debug only), and test-only `MockBackend`. |
-| `crates/openhuman-core/src/security/keyring/encrypted_file_backend.rs` | `EncryptedFileBackend` — all secrets in one ChaCha20-Poly1305 `secrets.enc` file keyed by an app master key; `init_master_key`/`is_master_key_available`; legacy `dev-keychain.json` migration; corrupt-file quarantine. |
-| `crates/openhuman-core/src/security/keyring/encrypted_store.rs` | `SecretStore` — config-field encryption (`enc2:` ChaCha20-Poly1305, legacy `enc:` XOR migration), keychain-backed master key with legacy `.secret_key` file migration, process-wide key cache, Windows ACL repair (`icacls`). |
-| `crates/openhuman-core/src/security/keyring/file_store.rs` | Shared secrets-file primitives for both file backends: the cross-process advisory write lock (`lock_for_write`, on a sidecar `<path>.lock`), the `0600` unique-temp-then-rename `write_atomic`, and `quarantine_corrupt`. |
-| `crates/openhuman-core/src/security/keyring/crypto.rs` | Shared ChaCha20-Poly1305 helpers (`chacha20_encrypt`/`chacha20_decrypt`), random-byte generation, hex encode/decode. Used by both `encrypted_store` and `encrypted_file_backend`. |
-| `crates/openhuman-core/src/security/keyring/error.rs` | `KeyringError` (thiserror) with variants `Os`/`InvalidUtf8`/`MigrationReadFailed`/`VerifyFailed`/`MigrationDeleteFailed`/`RandomGeneration`/`Crypto`/`Backend`, plus a log-safe `diagnostic()` that preserves the `keyring::Error` variant + `OSStatus`. |
-| `crates/openhuman-core/src/security/keyring/keyring_tests.rs` | Module tests (backend isolation via `force_backend_for_test`). |
-| `crates/openhuman-core/src/security/keyring/store_tests.rs`, `store_tests_2_tests.rs`, `store_test_scope_tests.rs` | Test-isolation regressions: test builds ignore `OPENHUMAN_WORKSPACE`, production resolution still honours it, scoped workspaces do not share secrets, and a deleted scoped workspace cannot reset the default store. |
-| `crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs`, `encrypted_store_crypto_migration_tests.rs`, `encrypted_store_key_management_tests.rs` | `SecretStore` tests (wired via `#[path]` from `encrypted_store.rs`). |
+| File | Role |
+| --- | --- |
+| `crates/openhuman-core/src/security/keyring/mod.rs` | Module docstring and exports only. Documents backend-selection priority and the Linux-headless availability note. Re-exports the public surface. |
+| `crates/openhuman-core/src/security/keyring/ops.rs` | Core operations: `get`/`set`/`delete`/`is_available`/`get_or_create_random`/`migrate_from_file`, the `MigrationOutcome` enum, the `namespaced_key` helper, the cached availability probe, and `force_backend_for_test`. |
+| `crates/openhuman-core/src/security/keyring/store.rs` | Backend selection and global state. Owns the `WORKSPACE_DIR` and `BACKEND` `OnceLock`s, `init_workspace`, `backend()`, `build_backend()`/`build_backend_at()`, and `workspace_dir_for_file_backend()` path derivation. Also the `cfg(test)`-only `test_scope` module (thread-scoped test workspaces). |
+| `crates/openhuman-core/src/security/keyring/backend.rs` | `KeyringBackend` trait plus `OsBackend` (native keychain via the `keyring` crate, service name `"openhuman"`), `FileBackend` (plaintext `dev-keychain.json`, test/debug only), and test-only `MockBackend`. |
+| `crates/openhuman-core/src/security/keyring/encrypted_file_backend.rs` | `EncryptedFileBackend`: all secrets in one ChaCha20-Poly1305 `secrets.enc` file keyed by an app master key; `init_master_key`/`is_master_key_available`; legacy `dev-keychain.json` migration; corrupt-file quarantine. |
+| `crates/openhuman-core/src/security/keyring/encrypted_store.rs` | `SecretStore`: config-field encryption (`enc2:` ChaCha20-Poly1305, legacy `enc:` XOR migration), keychain-backed master key with legacy `.secret_key` file migration, process-wide key cache, Windows ACL repair (`icacls`). |
+| `crates/openhuman-core/src/security/keyring/file_store.rs` | Shared secrets-file primitives for both file backends: the cross-process advisory write lock (`lock_for_write`, on a sidecar `<path>.lock`), the `0600` unique-temp-then-rename `write_atomic`, and `quarantine_corrupt`. |
+| `crates/openhuman-core/src/security/keyring/crypto.rs` | Shared ChaCha20-Poly1305 helpers (`chacha20_encrypt`/`chacha20_decrypt`), random-byte generation, hex encode/decode. Used by both `encrypted_store` and `encrypted_file_backend`. |
+| `crates/openhuman-core/src/security/keyring/error.rs` | `KeyringError` (thiserror) with variants `Os`/`InvalidUtf8`/`MigrationReadFailed`/`VerifyFailed`/`MigrationDeleteFailed`/`RandomGeneration`/`Crypto`/`Backend`, plus a log-safe `diagnostic()` that preserves the `keyring::Error` variant and `OSStatus`. |
+| `crates/openhuman-core/src/security/keyring/keyring_tests.rs` | Module tests (backend isolation via `force_backend_for_test`). |
+| `crates/openhuman-core/src/security/keyring/store_tests.rs`, `store_tests_2_tests.rs`, `store_test_scope_tests.rs` | Test-isolation regressions: test builds ignore `OPENHUMAN_WORKSPACE`, production resolution still honours it, scoped workspaces do not share secrets, and a deleted scoped workspace cannot reset the default store. |
+| `crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs`, `encrypted_store_crypto_migration_tests.rs`, `encrypted_store_key_management_tests.rs` | `SecretStore` tests (wired via `#[path]` from `encrypted_store.rs`). |
## Public surface
Re-exported from `mod.rs`:
-- `KeyringBackend` — backend trait (`get`/`set`/`delete`/`name`).
-- `SecretStore` — config-field encrypt/decrypt; `encrypt`/`decrypt`/`decrypt_and_migrate`/`needs_migration`/`is_encrypted`/`is_secure_encrypted`/`new`.
-- `KeyringError` — error enum with `diagnostic()`.
-- `init_master_key` — load the app master key from the OS keychain at startup (staging/prod only).
-- `init_workspace` — register the workspace dir for file/encrypted-file backends.
+- `KeyringBackend`: backend trait (`get`/`set`/`delete`/`name`).
+- `SecretStore`: config-field encrypt/decrypt; `encrypt`/`decrypt`/`decrypt_and_migrate`/`needs_migration`/`is_encrypted`/`is_secure_encrypted`/`new`.
+- `KeyringError`: error enum with `diagnostic()`.
+- `init_master_key`: load the app master key from the OS keychain at startup (staging/prod only).
+- `init_workspace`: register the workspace dir for file and encrypted-file backends.
- `get`, `set`, `delete`, `get_or_create_random`, `is_available`, `migrate_from_file`, `MigrationOutcome`.
-- `force_backend_for_test` — `pub(crate)`, test-only.
+- `force_backend_for_test`: `pub(crate)`, test-only.
## RPC / controllers
@@ -51,51 +51,51 @@ None.
## Events
-None — no `bus.rs`, publishes/subscribes to no `DomainEvent`.
+None. There is no `bus.rs`, and the module publishes and subscribes to no `DomainEvent`.
## Persistence
Secret storage backend, selected once and frozen in a `OnceLock`:
-- **`os`** (production default outside staging/prod special-casing): native OS credential store — macOS Keychain, Windows Credential Manager, Linux Secret Service — under service name `"openhuman"`.
-- **`encrypted_file`** (staging/production, and via `OPENHUMAN_KEYRING_BACKEND=encrypted_file`): single ChaCha20-Poly1305 file `{workspace}/secrets.enc`, encrypted with a master key loaded once from the OS keychain (`openhuman` / `app:master_key`). Files written `0600` on Unix via temp-file + atomic rename.
-- **`file`** (dev default, `cfg(test)`, or `OPENHUMAN_KEYRING_BACKEND=file`): plaintext JSON `{workspace}/dev-keychain.json`. **Not encrypted — test/debug only.**
-- **`mock`** (test-only): in-memory `HashMap`.
+- `os` (production default outside staging/prod special-casing): native OS credential store, macOS Keychain, Windows Credential Manager, or Linux Secret Service, under service name `"openhuman"`.
+- `encrypted_file` (staging/production, and via `OPENHUMAN_KEYRING_BACKEND=encrypted_file`): single ChaCha20-Poly1305 file `{workspace}/secrets.enc`, encrypted with a master key loaded once from the OS keychain (`openhuman` / `app:master_key`). Files are written `0600` on Unix via temp-file plus atomic rename.
+- `file` (dev default, `cfg(test)`, or `OPENHUMAN_KEYRING_BACKEND=file`): plaintext JSON `{workspace}/dev-keychain.json`. Not encrypted; test and debug use only.
+- `mock` (test-only): in-memory `HashMap`.
-`SecretStore` additionally manages a master encryption key: keychain-backed (slot `secretstore.master_key`) in normal builds with one-time migration from the legacy `{data_dir}/openhuman/.secret_key` file; the file path is retained only for unit tests. Decoded keys are cached process-wide keyed by normalized path.
+`SecretStore` additionally manages a master encryption key: keychain-backed (slot `secretstore.master_key`) in normal builds with one-time migration from the legacy `{data_dir}/openhuman/.secret_key` file; the file path is retained only for unit tests. Decoded keys are cached process-wide, keyed by normalized path.
-Workspace dir resolves from `init_workspace`, else `OPENHUMAN_WORKSPACE`, else `~/.openhuman` (or `~/.openhuman-staging` under `OPENHUMAN_APP_ENV=staging`). **In `cfg(test)` builds only**, that rule is bypassed — see the test-isolation note below.
+The workspace dir resolves from `init_workspace`, else `OPENHUMAN_WORKSPACE`, else `~/.openhuman` (or `~/.openhuman-staging` under `OPENHUMAN_APP_ENV=staging`). In `cfg(test)` builds only, that rule is bypassed; see the test-isolation note below.
-Both file backends keep every secret in one file, so a `set` of one key rewrites all of them. That read-modify-write cycle is guarded by `file_store::lock_for_write` — an in-process mutex is not sufficient, because a desktop core, another process embedding the same core, and a `cargo test` run that inherited `OPENHUMAN_WORKSPACE` all address the same path.
+Both file backends keep every secret in one file, so a `set` of one key rewrites all of them. That read-modify-write cycle is guarded by `file_store::lock_for_write`. An in-process mutex is not sufficient, because a desktop core, another process embedding the same core, and a `cargo test` run that inherited `OPENHUMAN_WORKSPACE` can all address the same path.
## Dependencies
-Internal openhuman/core modules: **none** — the keyring module's own files only `use crate::security::keyring::*` (self-internal). It is a leaf infrastructure module. External crates: `keyring`, `chacha20poly1305`, `serde_json`, `parking_lot`, `thiserror`, `anyhow`, `chrono`, `dirs`.
+Internal openhuman/core modules: none. The keyring module's own files only `use crate::security::keyring::*` (self-internal). It is a leaf infrastructure module. External crates: `keyring`, `chacha20poly1305`, `serde_json`, `parking_lot`, `thiserror`, `anyhow`, `chrono`, `dirs`.
## Used by
Discovered consumers (`crate::security::keyring::*`):
-- `crates/openhuman-core/src/lib.rs` and `crates/openhuman-core/src/core/runtime/context.rs` — call `init_master_key()` at startup.
-- `crates/openhuman-core/src/security/secrets.rs`, `crates/openhuman-core/src/security/mod.rs` — secret handling.
-- `crates/openhuman-core/src/config/schema/load/secrets.rs` — `SecretStore::new` / `is_encrypted` to encrypt/decrypt config fields on load.
-- `crates/openhuman-core/src/security/credentials/profiles.rs`, `credentials/ops.rs` — `SecretStore`, `is_available`, `get`/`set`/`delete` for per-profile credential storage.
-- `crates/openhuman-core/src/security/keyring_consent/` — gates the OS-keyring-to-local fallback behind user consent and reports `backend_name()`/`is_available()` as a `KeyringStatus`; see [`../keyring_consent/README.md`](../keyring_consent/README.md).
-- `crates/openhuman-core/src/web3/wallet/ops/state.rs` — `is_available`/`get`/`set` for the wallet mnemonic.
-- `crates/openhuman-core/src/security/devices/rpc.rs` — device secret handling.
-
-## Notes / gotchas
-
-- **Backend is frozen on first use (production).** Selection order: `OPENHUMAN_KEYRING_BACKEND` (`os`/`file`/`encrypted_file`) → `cfg(test)` → `file` → staging/prod → `encrypted_file`, dev → `file`. Once `BACKEND` is set it cannot change for the process lifetime. A process serves one workspace, so this `OnceLock` is a pure cache.
-- **Test builds resolve the workspace per thread, not per process.** `WORKSPACE_DIR` and `OPENHUMAN_WORKSPACE` are shared by every concurrently-running test, so consulting them made the whole test binary share one credential store pinned to whichever workspace won the race. When the winner was a `TempDir` held by a test's env guard, that directory was deleted at the end of that test and — because `FileBackend::read_map` treats a missing file as an empty map — the next write silently reset the store, so unrelated tests read their own freshly-written secrets back as `None`. Under `cfg(test)`, `workspace_dir_for_file_backend()` therefore ignores both and uses `test_scope::current_workspace()`: a thread-local override when a test binds one with `test_scope::ScopedWorkspace`, otherwise a stable per-process directory under the system temp dir. Backends are then cached **per resolved directory**. Two consequences worth knowing: test runs never read or write the developer's real `~/.openhuman/dev-keychain.json`, and a test wanting a private credential store must use `ScopedWorkspace` — setting `OPENHUMAN_WORKSPACE` no longer steers the keyring. Production selection is unchanged.
-- **Cleaning up historical leakage:** `node scripts/prune-dev-keychain.mjs` reports (and with `--apply` removes, after taking a backup) `dev-keychain.json` entries keyed by dead `TempDir` basenames, left behind before the isolation fix. Dry run by default.
-- **`is_available()` is cached after the first probe.** The probe performs delete/set/get/delete round-trips on the `os` backend; running it per-call triggered repeated macOS permission dialogs and starved frequent pollers. Non-os backends short-circuit to `true`. A failed probe is logged at `warn` because it silently flips `use_keychain` off.
-- **`is_available()` answers "is the active backend usable", never "are secrets in the OS keychain".** Because the file backends short-circuit to `true`, availability says nothing about *where* secrets are — which is why `keyring_consent::policy::active_mode_for` derives `active_mode` from `backend_name()` and consults availability only for the `os` backend. Deriving it from `is_available()` alone is #6076: the shipped staging/production app told users their secrets were in the OS keychain while they were in `{workspace}/secrets.enc`. Consumers that genuinely want the usability answer (wallet guards, snapshot loops) read `available` and are unaffected.
-- **`force_backend_for_test` panics if `BACKEND` is already initialized** — it must run before any keyring call in the same process (dedicated test binary or very top of a test).
-- **`migrate_from_file` never deletes the source unless the verified write succeeds**, so failures are retryable.
-- **`encrypted_file` corrupt/undecryptable files are quarantined** (renamed `secrets.enc.corrupt.<ts>`) and treated as empty rather than crashing.
-- **A corrupt file is never *overwritten*.** `file` reads degrade to an empty map (so a missing token means "sign in again"), but a `set`/`delete` over an unparseable file quarantines it and returns an error. Returning empty on the write path is what turned a corrupt file into a wipe: the write that followed persisted a map holding nothing but the key being set.
-- **Mutations hold a cross-process lock**, on `<secrets file>.lock` rather than the secrets file itself — `write_atomic` replaces the file by rename, so a lock on the old inode would guard nothing. Callers must hold it across the read *and* the write.
-- **`SecretStore` master-key file is write-once**; on Windows it survives transient AV-scanner sharing violations via retry/backoff and attempts `icacls` ACL self-repair on permission errors. Decoded keys are cached so repeated decrypts (e.g. snapshot polls) hit memory.
-- **Legacy formats:** `SecretStore` migrates `enc:` (XOR) → `enc2:` (ChaCha20-Poly1305) on decrypt; `EncryptedFileBackend` migrates plaintext `dev-keychain.json` → `secrets.enc` (renaming the legacy file `.json.migrated`).
-- **Errors never carry secret values** — only namespaced keys; `diagnostic()` is safe to log and preserves the underlying `keyring::Error` variant/`OSStatus`.
+- `crates/openhuman-core/src/lib.rs` and `crates/openhuman-core/src/core/runtime/context.rs`: call `init_master_key()` at startup.
+- `crates/openhuman-core/src/security/secrets.rs`, `crates/openhuman-core/src/security/mod.rs`: secret handling.
+- `crates/openhuman-core/src/config/schema/load/secrets.rs`: `SecretStore::new` / `is_encrypted` to encrypt and decrypt config fields on load.
+- `crates/openhuman-core/src/security/credentials/profiles.rs`, `credentials/ops.rs`: `SecretStore`, `is_available`, `get`/`set`/`delete` for per-profile credential storage.
+- `crates/openhuman-core/src/security/keyring_consent/`: gates the OS-keyring-to-local fallback behind user consent and reports `backend_name()`/`is_available()` as a `KeyringStatus`; see [`../keyring_consent/README.md`](../keyring_consent/README.md).
+- `crates/openhuman-core/src/web3/wallet/ops/state.rs`: `is_available`/`get`/`set` for the wallet mnemonic.
+- `crates/openhuman-core/src/security/devices/rpc.rs`: device secret handling.
+
+## Notes and gotchas
+
+- Backend is frozen on first use in production. Selection order: `OPENHUMAN_KEYRING_BACKEND` (`os`/`file`/`encrypted_file`), then `cfg(test)` gives `file`, then staging/prod gives `encrypted_file`, and dev gives `file`. Once `BACKEND` is set it cannot change for the process lifetime. A process serves one workspace, so this `OnceLock` is a pure cache.
+- Test builds resolve the workspace per thread, not per process. `WORKSPACE_DIR` and `OPENHUMAN_WORKSPACE` are shared by every concurrently running test, so consulting them made the whole test binary share one credential store pinned to whichever workspace won the race. When the winner was a `TempDir` held by a test's env guard, that directory was deleted at the end of that test, and because `FileBackend::read_map` treats a missing file as an empty map, the next write silently reset the store, so unrelated tests read their own freshly-written secrets back as `None`. Under `cfg(test)`, `workspace_dir_for_file_backend()` therefore ignores both and uses `test_scope::current_workspace()`: a thread-local override when a test binds one with `test_scope::ScopedWorkspace`, otherwise a stable per-process directory under the system temp dir. Backends are then cached per resolved directory. Two consequences worth knowing: test runs never read or write the developer's real `~/.openhuman/dev-keychain.json`, and a test that wants a private credential store must use `ScopedWorkspace`, since setting `OPENHUMAN_WORKSPACE` no longer steers the keyring. Production selection is unchanged.
+- Cleaning up historical leakage: `node scripts/prune-dev-keychain.mjs` reports (and with `--apply` removes, after taking a backup) `dev-keychain.json` entries keyed by dead `TempDir` basenames, left behind before the isolation fix. Dry run by default.
+- `is_available()` is cached after the first probe. The probe performs delete/set/get/delete round-trips on the `os` backend; running it per-call triggered repeated macOS permission dialogs and starved frequent pollers. Non-os backends short-circuit to `true`. A failed probe is logged at `warn` because it silently flips `use_keychain` off.
+- `is_available()` answers "is the active backend usable", never "are secrets in the OS keychain". Because the file backends short-circuit to `true`, availability says nothing about where secrets are, which is why `keyring_consent::policy::active_mode_for` derives `active_mode` from `backend_name()` and consults availability only for the `os` backend. Deriving it from `is_available()` alone was issue #6076: the shipped staging/production app told users their secrets were in the OS keychain while they were in `{workspace}/secrets.enc`. Consumers that genuinely want the usability answer (wallet guards, snapshot loops) read `available` and are unaffected.
+- `force_backend_for_test` panics if `BACKEND` is already initialized. It must run before any keyring call in the same process (dedicated test binary or very top of a test).
+- `migrate_from_file` never deletes the source unless the verified write succeeds, so failures are retryable.
+- `encrypted_file` corrupt or undecryptable files are quarantined (renamed `secrets.enc.corrupt.<ts>`) and treated as empty rather than crashing.
+- A corrupt file is never overwritten. `file` reads degrade to an empty map (so a missing token means "sign in again"), but a `set`/`delete` over an unparseable file quarantines it and returns an error. Returning empty on the write path is what turned a corrupt file into a wipe: the write that followed persisted a map holding nothing but the key being set.
+- Mutations hold a cross-process lock, on `<secrets file>.lock` rather than the secrets file itself, because `write_atomic` replaces the file by rename, so a lock on the old inode would guard nothing. Callers must hold it across the read and the write.
+- The `SecretStore` master-key file is write-once. On Windows it survives transient AV-scanner sharing violations via retry/backoff and attempts `icacls` ACL self-repair on permission errors. Decoded keys are cached so repeated decrypts (for example, snapshot polls) hit memory.
+- Legacy formats: `SecretStore` migrates `enc:` (XOR) to `enc2:` (ChaCha20-Poly1305) on decrypt; `EncryptedFileBackend` migrates plaintext `dev-keychain.json` to `secrets.enc` (renaming the legacy file `.json.migrated`).
+- Errors never carry secret values, only namespaced keys. `diagnostic()` is safe to log and preserves the underlying `keyring::Error` variant and `OSStatus`.
diff --git a/crates/openhuman-core/src/skills/webhooks/README.md b/crates/openhuman-core/src/skills/webhooks/README.md
index 4278ebbc63..51585e0419 100644
--- a/crates/openhuman-core/src/skills/webhooks/README.md
+++ b/crates/openhuman-core/src/skills/webhooks/README.md
@@ -74,7 +74,7 @@ The router also runs a separate `tokio::sync::broadcast` channel of `WebhookDebu
## Persistence
-`WebhookRouter` serializes its registrations to a JSON file (`PersistedRoutes`) at the optional `persist_path` passed to `new()`, and reloads them from that file when constructed. Writes are best-effort and fire-and-forget: offloaded to `spawn_blocking` inside a tokio runtime (inline otherwise), guarded by a monotonic generation counter so stale writes under rapid churn are dropped. Debug logs are **not** persisted: they live only in an in-memory `VecDeque` capped at 250 entries.
+`WebhookRouter` serializes its registrations to a JSON file (`PersistedRoutes`) at the optional `persist_path` passed to `new()`, and reloads them from that file when constructed. Writes are best-effort and fire-and-forget: offloaded to `spawn_blocking` inside a tokio runtime (inline otherwise), guarded by a monotonic generation counter so stale writes under rapid churn are dropped. Debug logs are not persisted. They live only in an in-memory `VecDeque` capped at 250 entries.
Note that nothing in the production startup path currently constructs a `WebhookRouter` or calls `SocketManager::set_webhook_router`; the only caller is `tests/raw_coverage/webhooks_ingress_e2e.rs`. Until a router is attached, the local RPCs return empty results (see above) and the subscriber answers every incoming request with `404`.
diff --git a/crates/openhuman-core/src/web3/README.md b/crates/openhuman-core/src/web3/README.md
index c5f6c5aae5..9881a9a254 100644
--- a/crates/openhuman-core/src/web3/README.md
+++ b/crates/openhuman-core/src/web3/README.md
@@ -1,18 +1,18 @@
# web3
-High-level web3 surface built **on top of** the [`wallet`](wallet/README.md)
+High-level web3 surface built on top of the [`wallet`](wallet/README.md)
module. The wallet stays basic (keys, balances, transfers, tx inspection); this
-module focuses on EVM/Solana(/BTC) dapp interactions: **swaps**, **bridges**, and
-generic **dapp contract calls**.
+module focuses on EVM/Solana(/BTC) dapp interactions: swaps, bridges, and
+generic dapp contract calls.
-Quotes and ready-to-sign **unsigned transactions** come from the openhuman
+Quotes and ready-to-sign unsigned transactions come from the openhuman
backend's deBridge proxy (`/agent-integrations/crypto/{routes,swap,bridge}`,
backend PR #852). This module only resolves the caller's wallet address,
-forwards the request, and stores a confirm→execute quote. On execute it hands
-the unsigned transaction to the wallet's crate-internal signing primitives —
-`wallet::sign_and_broadcast_evm` (EVM `to`/`data`/`value`) or
-`wallet::sign_and_broadcast_solana` (a hex `VersionedTransaction`) — so private
-keys never leave the wallet.
+forwards the request, and stores a confirm-then-execute quote. On execute it
+hands the unsigned transaction to the wallet's crate-internal signing
+primitives: `wallet::sign_and_broadcast_evm` for an EVM `to`/`data`/`value`
+transaction, or `wallet::sign_and_broadcast_solana` for a hex
+`VersionedTransaction`. Private keys never leave the wallet.
## Five family members
@@ -22,24 +22,24 @@ Three members (`swap`, `bridge`, `dapp`) are documented here; `wallet` and
| Module | Namespace | Purpose |
| --- | --- | --- |
| `swap/` | `web3_swap` | Single-chain swaps via deBridge. Cross-chain requests are rejected with a pointer to `web3_bridge`. |
-| `bridge/` | `web3_bridge` | Cross-chain bridges via deBridge DLN. Same-chain requests rejected. Signs+broadcasts on the **source** chain. |
+| `bridge/` | `web3_bridge` | Cross-chain bridges via deBridge DLN. Same-chain requests rejected. Signs and broadcasts on the source chain. |
| `dapp/` | `web3_dapp` | Generic EVM contract calls from caller-supplied calldata (no backend). |
| [`wallet/`](wallet/README.md) | `wallet` | Basic multi-chain key/account management and primitive on-chain operations. |
| [`x402/`](x402/README.md) | `x402` | HTTP-402 payment protocol: intercept, pay, retry, ledger. |
-`wallet` and `x402` are declared *ungated* in `mod.rs`, unlike `swap`/`bridge`/
+`wallet` and `x402` are declared ungated in `mod.rs`, unlike `swap`/`bridge`/
`dapp`/`ops`/etc., which are `#[cfg(feature = "web3")]`. As `mod.rs` puts it:
-> Ungated family members: `wallet` and `x402` are facades in their own
-> right — each keeps its own `stub.rs` and gates its real submodules on the
-> same default-ON `web3` feature. Always-compiled callers resolve through
-> those stubs (`tools/impl/network/http_request.rs` -> `x402`), so these
+> Ungated family members: `wallet` and `x402` are facades in their own right.
+> Each keeps its own `stub.rs` and gates its real submodules on the same
+> default-ON `web3` feature. Always-compiled callers resolve through those
+> stubs (`tools/impl/network/http_request.rs` calls into `x402`), so these
> declarations must NOT carry a `#[cfg]`.
## Compile-time gate (`web3` feature)
-`pub mod web3;` (declared in `crates/openhuman-core/src/lib.rs`) is ALWAYS
-compiled — it is a facade. The real swap/bridge/dapp implementation is gated
+`pub mod web3;` (declared in `crates/openhuman-core/src/lib.rs`) is always
+compiled: it is a facade. The real swap/bridge/dapp implementation is gated
behind the default-ON `web3` Cargo feature. When the feature is off,
`stub.rs` takes its place and exposes
`all_web3_registered_controllers` / `all_web3_controller_schemas` /
@@ -52,27 +52,28 @@ is the only thing that catches drift between the real and stub signatures.
| File | Role |
| --- | --- |
| `mod.rs` | Export-focused root: aggregates `all_web3_controller_schemas` / `all_web3_registered_controllers` / `all_web3_agent_tools`, plus shared schema/tool helpers. |
-| `types.rs` | deBridge chain-id ↔ local signer mapping (`chain_family`, `DEBRIDGE_SOLANA_CHAIN_ID`), request params, `UnsignedTx`, `Web3QuoteKind`. |
-| `client.rs` | `CryptoClient` — thin wrapper over the shared `IntegrationClient` for `/agent-integrations/crypto/*` (Bearer JWT auth, envelope unwrap). |
-| `store.rs` | In-memory prepared-quote store (TTL'd, capped, chat-thread owner-bound like the wallet) + the shared confirm→execute path. |
+| `types.rs` | deBridge chain-id to local signer mapping (`chain_family`, `DEBRIDGE_SOLANA_CHAIN_ID`), request params, `UnsignedTx`, `Web3QuoteKind`. |
+| `client.rs` | `CryptoClient`, a thin wrapper over the shared `IntegrationClient` for `/agent-integrations/crypto/*` (Bearer JWT auth, envelope unwrap). |
+| `store.rs` | In-memory prepared-quote store (TTL'd, capped, chat-thread owner-bound like the wallet) plus the shared confirm-then-execute path. |
| `ops.rs` | Shared op logic: `routes`, `quote_swap`, `quote_bridge`, `prepare_dapp_call` (address defaulting, backend call, unsigned-tx extraction). |
| `stub.rs` | Disabled facade compiled when `web3` is off; empty `all_web3_registered_controllers` / `all_web3_controller_schemas` / `all_web3_agent_tools`. See Compile-time gate above. |
| `web3_tests.rs` | `#[cfg(all(test, feature = "web3"))]` tests for `chain_family` mapping and the quote store's confirm/execute gate. |
| `ops_tests.rs` | Tests for the shared op logic in `ops.rs` (unsigned-tx extraction, dapp/swap/bridge param rejection). |
| `stub_tests.rs` | Runs only in the disabled build; pins that the three stub entry points return empty collections. |
-| `{swap,bridge,dapp}/schemas.rs` | Per-namespace RPC controllers + handlers. |
+| `{swap,bridge,dapp}/schemas.rs` | Per-namespace RPC controllers and handlers. |
| `{swap,bridge,dapp}/tools.rs` | Per-namespace agent tools. |
## RPC / controllers
-- `web3_swap`: `quote`, `execute`, `routes` (`openhuman.web3_swap_quote`, …).
+- `web3_swap`: `quote`, `execute`, `routes` (`openhuman.web3_swap_quote`, and so on).
- `web3_bridge`: `quote`, `execute`.
- `web3_dapp`: `call`, `execute`.
Quote/call methods return a `quoteId`; the matching `*_execute` (with
`confirmed: true`) signs and broadcasts. Quotes are bound to the chat thread
-that prepared them (no cross-session hijack of a leaked `quoteId`), TTL'd at
-5 minutes, and restored with a refreshed TTL on broadcast failure.
+that prepared them, so a leaked `quoteId` cannot be hijacked from another
+session. They expire after 5 minutes, and a failed broadcast restores the
+quote with a refreshed TTL.
## Agent tools
@@ -85,25 +86,25 @@ backend per-invocation and error gracefully when the user is not signed in.
deBridge uses real EVM chain ids (1 ETH, 10 Optimism, 56 BNB, 137 Polygon,
8453 Base, 42161 Arbitrum) and a synthetic Solana id (`7565164`). `chain_family`
-maps a deBridge id to the local signer family; ids we can't sign for are
-rejected at quote time.
+maps a deBridge id to the local signer family; ids the wallet can't sign for
+are rejected at quote time.
## Wiring
-- `crates/openhuman-core/src/core/all.rs`: `crate::web3::wallet::all_wallet_registered_controllers()` (~line 884), `crate::web3::all_web3_registered_controllers()` (~line 890), `crate::web3::x402::all_x402_registered_controllers()` (~line 569) — each pushed onto the controller registry under `DomainGroup::Web3`.
+- `crates/openhuman-core/src/core/all.rs`: `crate::web3::wallet::all_wallet_registered_controllers()` (around line 884), `crate::web3::all_web3_registered_controllers()` (around line 890), `crate::web3::x402::all_x402_registered_controllers()` (around line 569), each pushed onto the controller registry under `DomainGroup::Web3`.
- `crates/openhuman-core/src/tools/mod.rs` lines 59-60: `#[cfg(feature = "web3")] pub use crate::web3::wallet::tools::*;` re-exports the wallet agent tool structs.
- `crates/openhuman-core/src/tools/ops.rs`: calls `crate::web3::all_web3_agent_tools()` to register the swap/bridge/dapp agent tools, alongside the wallet and x402 tool registrations.
## Dependencies
-- [`crate::web3::wallet`] — `sign_and_broadcast_evm` / `sign_and_broadcast_solana` (crate-internal), `status` for address resolution, `EvmNetwork` / `WalletChain`.
-- [`crate::integrations`] (`IntegrationClient`, `build_client`) — backend auth + transport.
-- `crate::security::approval::APPROVAL_CHAT_CONTEXT` — quote-owner binding.
-- `crate::core::all` / `crate::core` — RPC controller registry wiring.
-- `tinywallet-bus` (`crates/openhuman-core/Cargo.toml` ~line 864, optional, gated by the `web3` feature; features `btc`, `evm`, `solana`, `tron`, `keccak`, `net`, `wire`, `eip712`, `abi`, `tx-codec`) — not imported by `web3/*.rs` itself, but the contract crate its `wallet/` and `x402/` members build on: address validation, the `SecretMaterial`/`TransactionSpec` wire types handed to the wallet module, the `Transport` seam, the EIP-712/ERC-20 encoders used by x402, and the Tron verifier.
+- [`crate::web3::wallet`]: `sign_and_broadcast_evm` / `sign_and_broadcast_solana` (crate-internal), `status` for address resolution, `EvmNetwork` / `WalletChain`.
+- [`crate::integrations`] (`IntegrationClient`, `build_client`): backend auth and transport.
+- `crate::security::approval::APPROVAL_CHAT_CONTEXT`: quote-owner binding.
+- `crate::core::all` / `crate::core`: RPC controller registry wiring.
+- `tinywallet-bus` (`crates/openhuman-core/Cargo.toml` around line 864, optional, gated by the `web3` feature; features `btc`, `evm`, `solana`, `tron`, `keccak`, `net`, `wire`, `eip712`, `abi`, `tx-codec`): not imported by `web3/*.rs` itself, but the contract crate its `wallet/` and `x402/` members build on. It supplies address validation, the `SecretMaterial`/`TransactionSpec` wire types handed to the wallet module, the `Transport` seam, the EIP-712/ERC-20 encoders used by x402, and the Tron verifier.
## Notes / gotchas
- The backend injects a configurable affiliate fee (default 1%) collected on-chain by deBridge on the source chain; this module passes the quote through unchanged.
- deBridge returns a large nested object; everything not explicitly consumed is passed through as `serde_json::Value`.
-- Same-chain `web3_bridge` requests and cross-chain `web3_swap` requests are rejected (mirrors deBridge's single-chain swap vs. cross-chain DLN split).
+- Same-chain `web3_bridge` requests and cross-chain `web3_swap` requests are rejected, mirroring deBridge's split between single-chain swaps and cross-chain DLN orders.