Prevent OAuth browser waits during Codex MCP activation #316
No reviewers
Labels
No labels
area:authentication
area:flake-utilities
area:performance
area:tbd
host:chaos
host:cosmos
host:electra
host:fleet
host:lena
host:lyra
host:mass-storage
host:media1
host:nimmog-de
host:nova
host:pangolin
host:pangolin-vps
host:phone
host:router
host:vega
investigation
phase:cutover
phase:deploy
phase:mcp
phase:module
phase:packaging
phase:prep
phase:validation
priority:high
priority:medium
project:attic-postgres-lyra-rollout
project:auto-update-reliability
project:auto-update-remediation
project:declarative-purity-cleanup
project:external-review
project:fleet-boundary-cleanup
project:host-facts-refactor
project:lyra-nixos-deploy
project:lyra-service-stack-migration
project:nebula-mesh-network
project:nix-idioms-hygiene
project:nixos-build-deployment-pipeline
project:security-hardening
project:service-stack-migration
project:vega-sillytavern-cutover
project:wiki-rebuild
repo:numtide/flake-utils
repo:numtide/nix-auth
repo:numtide/nixos-passthru-cache
repo:numtide/nix-relay
service:auto-update
service:gitlab
service:hermes
service:mem0
service:nix
service:sillytavern
service:slskd
service:synthseek
service:tdarr
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
nimmo/nixos-config!316
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/noninteractive-codex-mcp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lyra's unattended update timed out after five minutes when
codex mcp add cloudflare --url ...started an interactive OAuth login inside Home Manager activation. Vega and Lyra are headless. The retry succeeded because the endpoint had already been written, but the original switch still reported failure.HTTP MCP activation now writes configuration directly through the existing TOML-preserving helper, without discovery or login. Generic entries whose URL and bearer environment variable match are left entirely untouched, preserving user headers and OAuth settings. Transport mismatches repair stale settings; Redview's custom-header path still reconciles its declarative headers. Authentication is an explicit operator step; README documents an SSH-forwarded callback for headless Codex login.
Refs #315 and #312. Milestone: Cloudflare Agent Tooling. Keep #315 open until deployment evidence is complete.
Validation:
Live test activation is now confirmed: the user completed Lyra's test deploy on 2026-10-12. Read-only checks confirm running configurationRevision
52c0440590and Home Manager generation bnry5g4k46snlpzx3kvjpkv5hb9gw1j3. Home Manager activation completed 07:36:22–07:36:24 BST with Result=success and ExecMainStatus=0; codexMcpConfig advanced without a browser wait. Home Manager and Paseo are active. A follow-up invocation of the deployed Cloudflare registration function against the real user config preserved both content and mtime; Codex confirmed a valid streamable_http endpoint. This follow-up exercised the registration hook, not a second complete system activation. CI passed for the exact tested head.The affected-host test canary is satisfied. Remaining before closing #315: persistent deployment evidence and the required full deployment no-op follow-up. No merge has been performed; test deployment should not be represented as persistent switch deployment.
Automated code review
Reviewed commit:
9844b568aa582a1c77f30a3999bc32cb792aa59bVerdict: Requires further work
Resolve the blocking or important findings and investigate failed deterministic checks before merging.
Overall assessment
The supplied diff replaces the
codex mcp get/codex mcp addround-trip inensure_http_mcp(modules/profiles/ai-agents.nix:92-100) with a direct call toscripts/ensure-codex-http-mcp.py, adds an optionalbearer_token_env_varparameter to that helper, and extendsscripts/test-codex-http-mcp.pywith two regression tests. Caller signatures were checked:modules/mcp/default.nix:253emitsensure_http_mcp <name> <url> [tokenEnvVar], matching the unchanged three-argument shell signature, and the pre-existing custom snippet atmodules/mcp/redview.nix:47still passes four arguments, which the defaulted fifth parameter accepts.${python}/bin/pythonwithpkgs.python3.withPackages (ps: [ ps.tomlkit ])and the relative path../../scripts/ensure-codex-http-mcp.pymirror the existing redview pattern, andflake.nix:231-237already copies both scripts into theredview-mcpcheck, so the new tests are wired intonix flake check. No evaluation-breaking or secret-leaking defect was identified in the changed code; the open items are the deployment evidence AGENTS.md requires for a multi-host/auto-update change and a behavioural narrowing in which the helper now rewrites header keys unconditionally instead of only on mismatch.Blocking findings
None.
Important findings
The rewritten activation helper at modules/profiles/ai-agents.nix:92-100 is emitted for every enabled HTTP server via modules/mcp/default.nix:253 (
ensure_http_mcp), and the README diff itself states the change targets 'unattended updates on headless Vega and Lyra'. AGENTS.md:43 states: 'For multi-host or auto-update changes, record one genuine deployment and a no-op follow-up before closing the issue.' The only executable evidence supplied with the change is the Python regression tests in scripts/test-codex-http-mcp.py, which run the helper against a temp config.toml and never exercise a NixOS activation, the auto-update path, or the generated shell snippet.Impact: The failure mode being prevented (an unattended auto-update activation timeout) lives in the activation path that the supplied evidence does not exercise, so a regression in the rewritten shell snippet - a python invocation failure, a wrong store path, or an aborted activation - would first surface at the next unattended update on Vega/Lyra rather than in
nix flake check. The repository rule for this class of change is not yet satisfied by anything in the supplied material.Suggested fix: Before closing the issue, produce the evidence AGENTS.md:43 requires: create an auto-update hold, run
just teston one affected headless host (plusjust test-remoteif the controller path is in scope), release the hold, then record one genuineswitchdeployment and a no-op follow-up activation showing~/.codex/config.tomlis left byte-identical and untouched (mtime unchanged) by the rewritten helper.Suggestions
The removed code in the modules/profiles/ai-agents.nix diff re-registered a server only when
codex mcp getreported a mismatching url orbearer_token_env_var, so an already-matching entry was left completely untouched. The replacement always invokes the helper, which unconditionally popsbearer_token_env_varandhttp_headers(scripts/ensure-codex-http-mcp.py:19-20) and assignsserver["env_http_headers"] = env_headers(line 22), while modules/profiles/ai-agents.nix:100 passes the literal'{}'for every server emitted bycodexEnsureSnippet. The new test at scripts/test-codex-http-mcp.py assertsbearer_token_env_varis dropped for cloudflare when the argument is empty.Impact: Any
http_headersorbearer_token_env_vara user had set inside[mcp_servers.<name>]for a generic HTTP server is now deleted on every activation, where previously it survived while url and bearer variable still matched. The README only claims that 'user preferences and OAuth settings' are preserved, so this header/auth loss is not covered by the stated contract; no supplied evidence shows anyone currently sets such keys on those servers, so the practical impact may be nil.Suggested fix: If declarative ownership of these keys is intended, no code change is needed; make it explicit by adding a regression test to scripts/test-codex-http-mcp.py that pins the intended outcome for pre-existing
http_headers/bearer_token_env_varon a server registered through the generic path. If user-set headers should survive, skip the assignment/pop whenenv_headersandbearer_token_env_varare empty for the generic path (redview.nix:47 passes non-empty headers and must keep rewriting them).Tests and validation
Questions
codex mcp login cloudflarewrite anything into the[mcp_servers.cloudflare]table itself (e.g.bearer_token_env_var,http_headers) rather than only a separate sub-table such as[mcp_servers.cloudflare.oauth]? scripts/ensure-codex-http-mcp.py:19-20 pops those keys on every activation, so any live auth material stored under them would be dropped by the next unattended update..transport.type == "streamable_http"on the entry Codex had registered. Can a live host confirm thatcodex mcp get <name> --jsonreportsstreamable_httpfor an entry written by the new helper, which emits onlyurl,env_http_headersand optionallybearer_token_env_varwith no transport discriminator?Review limitations
nix flake check, the regression tests, and any canary or deployment result are taken from the supplied diff and repository text as untrusted evidence, not verified.mcp get/mcp login/mcp addbehaviour are not present in the repository material, so claims about which keys Codex writes into[mcp_servers.<name>]are phrased as questions rather than findings.~/.codex/config.toml, active auto-update holds, running generations) is not supplied, so the practical effect of the header-rewriting behaviour on the deployed fleet could not be confirmed.Diff coverage
README.md: reviewed — included in a context-limited batchmodules/profiles/ai-agents.nix: reviewed — included in a context-limited batchscripts/ensure-codex-http-mcp.py: reviewed — included in a context-limited batchscripts/test-codex-http-mcp.py: reviewed — included in a context-limited batchReview metadata
Reviewed the feedback on
9844b56.The header-preservation suggestion is valid and is fixed in the next push. Generic HTTP registration now has an explicit preservation mode matching the old guard: if the entry is HTTP and its URL and bearer environment variable already match, the entire entry and file remain untouched. User literal/environment headers and OAuth settings survive. Transport mismatches still repair stale fields, as before. Redview's custom-header path retains declarative reconciliation. Two new regressions cover matching headers (with and without bearer authentication) and mismatched stale authentication; the URL-only CLI test now exercises preservation mode.
Validation: all seven helper tests and full nix flake check passed; the revised Lyra activation package built. Lyra's Codex CLI also confirmed
.transport.type == "streamable_http"for the helper's URL/empty-header schema, without any transport discriminator, browser, network discovery, or persisted config change. The exact generated HTTP function passed a fresh disposable Lyra registration and a no-op repeat with user-added headers: contents and mtime unchanged; Home Manager/Paseo remained active. Preserving a matching entry also avoids depending on where an OAuth client might keep its table settings.The deployment finding is a valid operational acceptance gate, already explicitly pending in this MR and #315. The earlier review did not receive the MR body: it therefore omitted the existing exact-generated-function canary, which exercises the shell invocation/store paths but is still not a genuine system deployment. No generation deployment is claimed. Keep #315 open and require an affected-host deployment plus no-op follow-up before closure, and an appropriate canary before merge. This feedback loop authorizes review fixes and pushes; it does not authorize a live deployment or merge.
Posting this explanation before pushing the preservation fix to trigger another review.
Canary correction: I posted the revised-canary result before checking its first run's exit status. That first run failed because my disposable fixture declared an empty header table twice, not because activation failed. I corrected the fixture to set its user headers through TOMLKit and reran the exact generated function successfully on Lyra. Header preservation, unchanged content/mtime, and active Home Manager/Paseo are now confirmed. Repository checks and the seven regression tests passed independently. Fix commit:
52c0440.Automated code review
Reviewed commit:
52c04405903c1506b023a36b9cecb1797c2bd7f5Verdict: Requires further work
Resolve the blocking or important findings and investigate failed deterministic checks before merging.
Overall assessment
The change replaces the
codex mcp get/remove/addguard inensure_http_mcp(modules/profiles/ai-agents.nix:92-101) with the existing TOML-preserving helperscripts/ensure-codex-http-mcp.py, adding an optionalbearer_token_env_varpositional and a--preserve-matching-headersguard, and documents the headless-OAuth workaround in README. I traced both call sites: the unchanged generic caller at modules/mcp/default.nix:253 passes name/url/optional token, which matches the new shell function and the new argparse CLI (the optional positional keeps that 3-argument form working), and Redview's own snippet at modules/mcp/redview.nix:46 keeps its 4-argument, non-preserving, header-reconciling path. Only Redview declares Codex-side headers (grep headers modules/mcpmatches redview.nix plus the agy/opencode/hermes blocks in default.nix), so no declarative headers are dropped by the new path; cloudflare.nix declares notokenEnvVar, so it takes the URL-only path. The new tests in scripts/test-codex-http-mcp.py exercise both the library API and the CLI form used by the activation (including the--preserve-matching-headersflag and the no-op mtime check), and they run undernix flake checkviachecks.x86_64-linux.redview-mcp(flake.nix:234-236). The same TOML shape the new path writes (url+env_http_headers, no transport discriminator) is already produced by the pre-existing Redview snippet, so the new registration form is not novel. I found no defect demonstrable in the changed code; the remaining gap is that the changed code is ahome.activationDAG entry whose end-to-end activation path is not evidenced in the supplied material, which AGENTS.md explicitly requires for deployment-affecting changes.Blocking findings
None.
Important findings
The changed code is inside
home.activation.codexMcpConfig = hmLib.hm.dag.entryAfter [ "writeBoundary" ], i.e. it only runs during Home Manager activation on hosts enabling the shared AI-client profile (README.md:151 lists Codex on Electra, Lena, Vega, Lyra). AGENTS.md:43 states 'Before merging a deployment-affecting change: Confirm local validation, required MR checks, and a canary appropriate to the risk', AGENTS.md:45 states 'Usejust testrather than rawnixos-rebuild test', and README.md:306 describes the hold/test/deploy/no-op-follow-up sequence. The supplied material contains only the diff and the helper's unit tests (flake.nix:234-236 runstest-codex-http-mcp.pyin a fixture directory); nothing supplied shows an activation of an affected host generation.Impact: The failure mode this change targets (an interactive browser wait inside unattended activation on a headless host) lives in the activation script, which the supplied evidence never exercises; a regression there would keep breaking unattended auto-updates even though
nix flake checkand the helper tests pass.Suggested fix: Per AGENTS.md: create an auto-update hold, run
just teston one affected headless host (Vega or Lyra), and record that activation completes without an interactive wait and that the HTTP entries appear in~/.codex/config.toml; then record the no-op follow-up required by AGENTS.md:43 before the issue is closed, and release the hold only after validation.Suggestions
None.
Tests and validation
Questions
enabled = falseacross a URL/transport repair intended for the generic path? The removed code didcodex mcp remove "$name"thencodex mcp add, which reset the entry, whereas the new repair branch pops onlycommand,args,env,env_vars,cwd,bearer_token_env_var,http_headersand keepsenabled(scripts/test-codex-http-mcp.py assertsself.assertFalse(server["enabled"])after a URL change).env_http_headerswith{}while the matching path preserves them; is that asymmetry acceptable, or should user env-backed headers be merged rather than replaced?codex -c mcp_oauth_callback_port=4321 mcp login cloudflarewithssh -L 4321:127.0.0.1:4321 <host>) actually exercised on a headless host, as AGENTS.md:43 requires for documented user-facing commands, and is port 4321 free of conflicts on Vega/Lyra?ensure_mcpstill shells out tocodex mcp get/addduring activation; is that known to be prompt-free, given only the HTTP path was changed?Review limitations
nix flake check, the helper's unit tests, or anyjust test/activation, so the PR's validation claims were not independently verified.config.tomlschema is not defined anywhere in this repository, so I cannot verify from supplied evidence that an entry written asurl+env_http_headers = {}with no transport discriminator is accepted, nor that the pop list inensure_servercovers every stdio key Codex may write (e.g. atypeorenvironmentkey).~/.codex/config.tomlon Vega or Lyra, nor what the previously timed-out switch left behind.checks.x86_64-linux.redview-mcpbeyond its source, which is unchanged by this diff.Diff coverage
README.md: reviewed — included in a context-limited batchmodules/profiles/ai-agents.nix: reviewed — included in a context-limited batchscripts/ensure-codex-http-mcp.py: reviewed — included in a context-limited batchscripts/test-codex-http-mcp.py: reviewed — included in a context-limited batchReview metadata
Reviewed the second report on final head
52c0440. It identifies no demonstrable code defect and no further suggestions; CI and the review job both passed. The one important finding is the same outstanding end-to-end activation evidence already recorded in the MR/#315. I am not treating the isolated generated-function canary as a NixOS generation deployment, and will not close #315 or claim that operational gate is satisfied.Answers to the questions:
enabled = falseacross repair is intentional: an operator's disablement is a user preference, not a stale transport field. The explicit regression pins this behavior. Repair updates the declared transport rather than re-enabling a server the operator disabled.No additional code change is warranted by these questions, so there is no empty push to retrigger review. Monitoring remains active within the latest push's 30-minute window; genuine activation evidence remains explicitly pending.
The outstanding test-activation evidence from review 61 is now available. The user completed Lyra's test deployment; live verification confirms configurationRevision
52c0440590(the reviewed/current MR head) and the exact revised Home Manager generation. Activation ran 07:36:22–07:36:24 BST with Result=success, ExecMainStatus=0; codexMcpConfig proceeded to installPackages without an OAuth/browser wait. Home Manager and Paseo are active.I also repeated the deployed Cloudflare registration function against Lyra's real ~/.codex/config.toml: content and mtime remained unchanged, and Codex reported the expected streamable_http endpoint. This is a hook no-op check, not a second full system activation. CI is successful on the same SHA.
This resolves the pre-merge affected-host canary gap. The MR body is updated. Keep #315 open for persistent deployment and full no-op follow-up evidence; no merge or persistent switch is claimed here.