Repository navigation
fix: re-read the user store on restart; contain credential failures (see Consiliency/pmcp#487) - #489
Conversation
P1 of the approved plan for #487 (plan section 3.6 and the P1 row of section 4). No op:// resolution, no 1Password. - Origin registry: every name pmcp puts into os.environ is recorded as external, home_dotenv, user_store or auth_connect_project; _load_operator_text takes the caller's class. - credential_value(environ=True) answers user-store names from the CURRENT store (strict read, parsed and expanded as at startup against the external env, the static ~/.env values and the current store), cached by stat + lstat identity. An absent key continues to the tenant/project layers and the legacy key, as after a restart. - An unreadable store is a typed credential_unavailable (store_unreadable) that stops the lookup, refuses the spawn and is contained to that server's entry (#342): config loads keep the entry typed and never start it; connect_server, restart_server, provision, health and status report it; refresh leaves a running instance up. - The availability check's reload of the user store is removed. - gateway.auth_connect never overwrites an external or ~/.env value; user scope records user_store, project scope keeps its value. - New AuthState / AuthEventKind credential_unavailable with semantics. - pmcp doctor: inherited runtime variables, op:// values and OP_* keys by server and source, and credentials held in more than one place. - pmcp secrets check reports unavailable_keys. See #487. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…exc_info The full suite on ai found two problems with the previous commit: - A test that monkeypatch.delenv()s an absent key and then drives gateway.auth_connect leaked the write into later tests, whose startup load then recorded it as external. An autouse fixture now restores os.environ to its pre-test state. - The typed-failure branch of the provision handoff passed exc_info through a conditional, which tests/test_exception_text_sinks.py rejects. It now uses two logger calls. See #487. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b286fca to
b399bb4
Compare
Refs #487 (P1, PR #489 review round 1). - loader: a configured entry's own literal credential satisfies auth before any store lookup, so an unreadable user store no longer refuses it (ASTRA-1). - pmcp status: credential_unavailable entries are reported with auth_state credential_unavailable and credential_reason, and --probe never connects them (CLAUDE-C1). - provision / configured-duplicate gate: typed store failures report credential_unavailable before any ensure_connected, never missing_auth (GEMINI-G1, CLAUDE-C2, C4 docstring). - lifecycle: when a credential is now missing from every layer, restart and connect stop a running instance and drop its stale lazy registration; disconnect is exempt from missing-auth refusals. An unreadable store still leaves the instance up (GROK-B1). - refresh: a startup copy of a user-store value is not the ambient baseline in _refresh_config_unchanged, so a deleted or rotated same-name key reaches a running lazy server (GROK-B2, GEMINI-G2). - doctor: an unreadable store is not reported as holding a key; a tenant store holding a key is a named layer (ASTRA-2, GROK-N2). - refresh summary logs the credential_unavailable count (GROK-N3). - docs: lazy first start, crash reconnect and connect-on-online reuse the credential resolved at the last startup/refresh (CLAUDE-C3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a57a06f26
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if status is None or status.status in ( | ||
| ServerStatusEnum.OFFLINE, | ||
| ServerStatusEnum.LAZY, | ||
| ): | ||
| return failure |
There was a problem hiding this comment.
Prune stale lazy configs before returning missing_auth
If a configured server is still lazy when its credential is deleted, calling gateway.restart_server or gateway.connect_server reports missing_auth but returns here without removing its previously resolved lazy config. A subsequent tool call reaches _ensure_server_for_tool, and ClientManager.ensure_connected starts that cached config with the deleted credential. Prune the lazy registration even when there is no running instance to disconnect, so an explicit lifecycle call that observes the deletion cannot leave a stale credential available for the next spawn.
Useful? React with 👍 / 👎.
P1 of the approved plan for #487 (
plans/detailed-pmcp-487-op-secret-references-20261108.mdrev 5, head 6ee0f59): plan section 3.6 and the P1 row of section 4. Noop://resolution, no 1Password, no token handling (P2+).What changes
Rotation of plain user-store values
env_store._ENV_ORIGINS): every insertion intoos.environis recorded asexternal(present before the startup load),home_dotenv,user_storeorauth_connect_project._load_operator_texttakes the caller's class.credential_value(name, environ=True): a name with originexternal/home_dotenv/auth_connect_project(or unrecorded) answers fromos.environas before. Every other name reads the current user store. The read is strict, parsedinterpolate=False, then expanded as python-dotenv does at startup, against the external env, the static~/.envvalues and the current store (never a stale startup copy). It is cached byos.stat+os.lstatidentity. A read within 2 s of the file's mtime is not cached ("racy" timestamps), and ownership of home is checked on every lookup..env/.env.pmcp, then the next lookup key, matching a restart (plan section 9).environ=False(tenant isolation) never reads the store.handlers.py:2792-2794) is removed.gateway.auth_connectnever overwrites anexternalorhome_dotenvvalue; it says the environment value still wins. User scope recordsuser_store, so later store rotations apply to it. Project scope recordsauth_connect_projectand keeps its in-process value.Typed failure, contained (#342)
pmcp/credential_state.py:CredentialUnavailableError(reason)andSTORE_UNREADABLE. A store that exists but cannot be read (EACCES, directory/fifo at the path, ELOOP, not UTF-8) raises it. The lookup stops there and never tries the legacy key.AuthState/AuthEventKindvaluecredential_unavailable, with semantics._auth_event_for_statemaps it. Acredential_reasonfield is added on lifecycle, provision, health and status entries.config/loader.pybuild_resolved_config: the entry is kept withResolvedServerConfig.credential_unavailable(excluded from dumps) and never started. Previously it was started without its credential.CREDENTIAL_UNAVAILABLEskip instead of being dropped.add_config: skips typed entries, both lazy and eager. Its lookup-key loop stops at the first typed answer.resolve_remote_headersrecordsunavailable_env_vars.installer.build_install_child_env/check_api_keyrefuse the spawn.handlerslifecycle (connect/restart/update via_resolve_lifecycle_target) andprovision(includingmanifest_server_to_configat the old 3333/4383 lines) reportcredential_unavailable. Provision-status adoption logs it without a traceback.cli.pyinit andpmcp secrets check(unavailable_keys) report the typed state.gateway.refreshleaves a running server up when its lookup is now typed.restart_serverresolves before teardown, so a running instance is left up.pmcp doctor(names only, never values; newcredentialschecks):env_varset as external env and not a user-store name (inherited by every child);op://value andOP_*key in a server's own env, by server and config source, and everyop://credential lookup by server and layer;Docs: CHANGELOG (Unreleased/Fixed), README (credential scopes), MIGRATING ("A rotated user-store key is used at the next server restart"). Each says that deleting one store entry is not revocation when a lower layer or legacy key holds the same credential.
Tests
New
tests/test_user_store_rotation_487.py(33 tests) covers:API_TOKENserves brightdata);API_TOKEN, thenmissing_auth);.env.pmcpwith a store present;${VAR}header with a store present;environ=Falsenever reads the store;~/.envvalue, and no stale-copy interpolation;~/.env, key in both, external wins, origin classes;auth_connectthen rotation, and project-scopeauth_connectin-process;auth_connectnever overwrites external or~/.envvalues;connect_server/restart_server/provisionreportcredential_unavailable;secrets checkunavailable_keys;#342 guard extended in
tests/test_catalog_overlay_discovery.py:-cshape) plus a healthy server, with an unreadable store:load_configskeeps both and marks brightdata;GatewayServer.initialize,gateway.refreshandrestart_serverof the healthy server succeed, and brightdata reportsstore_unreadableviaconnect_serverand health;Updated inventories and tests for the removed reload and the new consumers:
test_store_reader_inventory(internals, home-memo exemption with reason, handlers no longer a store reader);test_parse_error_echoexemptions;test_credential_rootsgrid (new rows: lifecycle, config_status predicate, doctor);handlers.load_storenow patch the live read; conftest restoresos.environafter each test.Mutation controls (scratch, restored from saved copies):
Evidence
-n 2; isolated HOME;scripts/pytest_temp.py), all green: test_store_reader_inventory, test_parse_error_echo, test_file_content_echo, test_credential_parity, test_env_leak_229, test_auth, test_store_readers_confined, test_credential_roots, test_manifest, test_config_loader, test_credential_gates_startup, test_credential_gates_handlers, test_startup_resolver, test_lazy_start, test_credential_optionality_e2e, test_manifest_provision, test_tools, test_phase4_e2e, test_catalog_overlay_discovery, test_cli, test_migration_doc, test_code_snippets_execute, test_baseline_constraints, test_env_overlay_provenance, test_feedback_provenance, test_user_store_rotation_487. (test_tools'update_servertests need dev0'snpm_config_*vars unset; known host issue, they fail the same way without this change.)ruff check,ruff format --check,mypy src/pmcp --exclude baml_client: clean.ai(py3.12,-n 8,systemd-run MemoryMax=16G, isolated HOME):3 failed, 14716 passed, 57 skipped, 1 xfailed. Two causes, both fixed in b286fca:test_exception_text_sinks: a conditionalexc_info=did not go throughsafe_exc_info.test_trust_boundaries_composition(2 tests): an earlier test'sauth_connectwrite leaked intoos.environpastmonkeypatch.delenv(raising=False). The next startup load then recorded it asexternal, which auth_connect correctly refuses to overwrite. New autouse_restore_process_environmentfixture intests/conftest.py.14719 passed, 57 skipped, 1 xfailed in 170.72s, exit 0. Logs:ai:/tmp/pmcp-ai-viperjuice/487-p1-full{,-r2}.log.Not in this PR: anything P2+ (
op://, token, grammar,reference_not_allowed_here, the.env.pmcpop://#342 variant), thesecret_refscapability,migrate-op.🤖 Generated with Claude Code