Skip to content

feat(mcp): targeted transactional upstream hot reload without global restart - #11

Merged
AKzar1el merged 61 commits into
mainfrom
feat/per-mcp-hot-reload-20261119
Nov 20, 2026
Merged

AKzar1el merged 61 commits into
mainfrom
feat/per-mcp-hot-reload-20261119

Conversation

@AKzar1el

@AKzar1el AKzar1el commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Targeted per-MCP hot reload — staged, not deployed

Isolation: This is a feature-only branch against original AKzar1el/codexify main. No shared Codexify service, GodPrompt instance, existing browser, tunnel, Windows scheduled task, or other worker's branch/worktree has been stopped or modified. Separate Windows orphan-process fix remains untouched.

Implemented

  • Operator-facing reload_mcp({source}) accepts only an existing configured MCP key. No executable, command, URL, or credentials can be supplied in a tool call.
  • Replacement starts a new stdio / Streamable HTTP MCP connection, performs initialize and tool discovery, checks readiness, constructs and atomically swaps a new validated tool view, and allows old in-flight calls to finish on their own generation without replaying writes.
  • Per-source reload locks, safe pre-swap rollback, previously failed-source reconnect, source/tool diff counts, redacted diagnostic codes, time and drain telemetry.
  • Existing HTTP connections, other MCP source services, sessions and tunnel are not restarted.
  • Direct, gateway and catalog source definitions participate in atomic rediscovery. ChatGPT may still require a connector refresh/new conversation to acquire new tool definitions; no unsupported live client update claim.
  • Hardening: independently pinned dynamic tool handles prevent unrelated long-running direct/gateway calls from retaining a retired source process. Retired-reference reporting distinguishes drained calls from retained catalog/snapshot handles. Source-specific stdio children use kill_on_drop for candidate cleanup. Generated gateway metadata shares one conversion path.
  • Documentation: docs/MCP_HOT_RELOAD.md.

Verification work

New local HTTP MCP test fixtures exercise successful replacement, multi-source isolation, old-call pinning/no replay, initial outage reconnect, canceled and invalid replacements, same-source contention, concurrent independent reloads, catalog/gateway metadata changes, repeated cycles, sanitized-name collision safety and old-process generation release, including during unrelated in-flight direct calls.

CI and real-process verification (updated November 20, 2026): Prior commit c85264f passed the complete GitHub Actions run 44636938266: Rust formatting, Clippy, full Rust suite, Chromium/WebKit, Windows/macOS service integration and security jobs. This success predates additional OS-process proof. We added scripts/fixtures/hot-reload-stdio-mcp.mjs and service_isolated_real_stdio_process_reload_preserves_unrelated_sources to launch three independent OS-level stdio MCP processes and validate selected-source process replacement/version/catalog, in-flight call draining, old-generation pinning, unchanged unrelated PIDs, rollback after failed spawn, and repeat reload. The fixture passed local Node syntax and JSON-RPC smoke checks. On commit 133b0e2, both Windows and macOS cargo test --all-targets service steps passed, running the new OS-process test. Follow-up commit 17b0d31 applies the exact Rustfmt suggestions and adds a stronger OS-level PID-liveness check asserting that the old child actually exits after its last generation handle is dropped. Exact-head CI run 44642153048 completed successfully on November 20: main Rust suite, strict Clippy, formatting, browser tests, Windows and macOS service integration, and security reports all passed, including the retired child-process termination assertion.

Isolated Windows host proof: On November 20, the user ran the one-click staging package against the pinned head. After an explicit binding to its existing, already-staged source directory (without cloning or modifying other checkouts), the RESULT.json and local Cargo test log were read through the live Codexify God v5 connector. The report recorded PASS and the log confirmed 1 passed; 0 failed for service_isolated_real_stdio_process_reload_preserves_unrelated_sources; the test includes process replacement, in-flight call handling, rollback, and retired-child termination. A PowerShell NativeCommandError in the log came from Cargo writing normal compilation progress to stderr; it did not change the successful test exit code. The production Codexify and GodPrompt installation/configuration were untouched by this validation, and production hot reload is not activated. The original Windows service health probe returned status=ok and both ports were listening. Additional testing still outside this PR's CI scope: repeat-cycle Windows process soak beyond existing tests, workload p50/p95/p99 latency / memory profiling, and candidate GodPrompt upgrade on the live Windows host. The actual isolated GodPrompt v1.0.3 to v1.1.1 upgrade/rollback has now passed on Linux CI (see below). An additional local-only real GodPrompt 1.0.3 → 1.1.1 test was prepared in the staging copy (not committed). Its Windows Rust test compilation was intentionally stopped when available physical memory fell below 1 GB (later measured ~0.26 GB) to protect the running service and parallel agent. The resulting canary runner FAILED receipt reflects deliberate compiler termination, not an observed runtime assertion failure; full details in the staged GODPROMPT_CANARY_STATUS.txt. Do not restart or redeploy based on this incomplete canary. Do not use shared production service as a substitute. The unrelated Windows supervisor-orphan branch is not integrated by this PR.

Real GodPrompt CI acceptance (new): Branch commits 4df4f73 / 39c2189 add an opt-in Rust canary in src/bridge/hot_reload_tests.rs plus an explicit Linux CI gate that installs the published, pinned god-prompt-mcp@1.0.3 and @1.1.1 packages into isolated temporary directories. It exercises actual stdio process upgrade, ping, tool discovery, unaffected beta/gamma MCP peers, and invalid-replacement rollback without invoking GodPrompt tool methods, touching operator config, or restarting production. Local test parameters are supplied only via CODEXIFY_CANARY_OLD_GODPROMPT and CODEXIFY_CANARY_NEW_GODPROMPT; when both are absent in other test jobs, it is dormant. The first CI pass found only a blank-line Rustfmt discrepancy, then Clippy's len_zero lint; both were corrected by commit 91cd90b. The exact-head CI run 44667621824 passed the strict Rustfmt, Clippy, full Rust suite and real GodPrompt acceptance step. The verified CI log records actual isolated stdio upgrade 1.0.3 -> 1.1.1, discovery 7 -> 9 tools, 116 ms measured total reload, and successful invalid-replacement rollback; no production source was touched. Entire exact-head CI run passed: Rust formatting, strict Clippy, complete Rust tests, real GodPrompt reload/rollback, Chromium/WebKit browser layout, Windows and macOS service integration, and security checks. No failed jobs.

CI merge gate satisfied: exact-head cargo fmt --check, strict Clippy, full Rust and browser suites, Windows/macOS integration and isolated real-process GodPrompt validation all passed in run 44667621824. This PR is ready for review/merge. Production activation remains separate: do not change the installed Codexify binary, restart the service, redeploy, or interfere with the parallel Windows supervisor/orphan-process work without a coordinated rollout.

Windows production-config compatibility (2026-11-20): During a local experimental preview activation, the preview binary passed isolated MCP hot-reload and rollback but failed to start using the current operator config. The exact service-log error was an unrecognized agentChat.automation.providerSendGatePath field; Windows supervisor restarted the preview repeatedly with exit code 1. The installed original was successfully restored and is healthy. Instead of stripping the operator's Send-gate config, the feature branch now includes compatibility commits ce590c5 and 29650c5: parse/validate the optional absolute gate path and forward it to the browser companion as CODEXIFY_BROWSER_SEND_GATE_PATH, matching the existing local Codexify behavior. Test coverage includes JSON roundtrip and invalid relative-path rejection. The new preview Windows build and exact-head CI have been triggered on 85a6608. No claim of green status or production installation until these finish and the new binary validates the unchanged operator config.

Copy link
Copy Markdown
Owner Author

Field reproduction relevant to targeted hot reload (2026-11-20; no shared restart performed):

Codexify v2.4.0 service PID 21824 started 2026-11-19 23:12:51 UTC. Its startup log at 23:15:40 UTC explicitly says: skipping MCP server 'god-prompt-mcp': timed out after 30s waiting for 'god-prompt-mcp' to initialise. The final startup table marks this source FAILED. The private catalog subsequently exposes 13 connected sources, excluding GodPrompt. The owner reports having restarted, but the inspected background process still had its earlier start time; importantly, mere client reconnection does not recover the failed source.

The enabled ~/.codex/config.toml GodPrompt entry now points to the installed Preview 10 stdio launcher and has startup_timeout_sec = 90.0, but that file was last written at 2026-11-20 00:40 local, after the observed process startup. Do not infer the 90-second setting was ignored in the earlier 30-second failure: the setting was not yet on disk for that run. No evidence currently shows the updated config failed after a fresh process start.

Standalone smoke tests using the exact configured Node executable, entrypoint, and opt-in environment successfully yielded MCP server version 1.1.1-checkpoint-preview.10, 10 tools including review_codexify_checkpoint, and a successful classify_task. Three independent initialize+list-tools probes took 2.202s, 1.634s, 1.207s, respectively. Package works; previous failure appears startup-conditional under resource contention rather than a deterministic package fault.

Requested non-disruptive recovery regression for this PR: start one source with an intentional startup timeout; verify it is absent/FAILED while all other MCPs stay healthy; correct its config; call reload_mcp with the exact failed source key; verify one successful new source generation (tool catalog 10), no global restart, no reconnection of unrelated sources, and clear pre-/post-reload diagnostics. Also verify an explicit startup_timeout_sec is honored by the reload path, and a second failure leaves registry/other sources intact. This targets a real incident and avoids asking the user to repeatedly reboot. I am not editing your active branch or merging/deploying anything.

Copy link
Copy Markdown
Owner Author

Field recovery follow-up (2026-11-20, actual connected Codexify v2.4.0): GodPrompt Preview 10 is now live. A new Windows codexify service restart reported success and Task Scheduler launched a fresh Codexify task, but the old orphaned codexify.exe service run supervisor and codexify.exe --config worker remained alive and kept port 3000. Thus service restart success did not establish listener/process replacement. After validating exact old process executable, orphaned parent and port ownership, a guarded one-shot cleanup of the stale pair let the existing scheduled task start a new worker; god-prompt-mcp then registered 10 live tools and real mcp_call_tool calls passed. Another formerly healthy source (memory) timed out at its default 20s during concurrent startup. I backed up the local config, set only that source's startup_timeout_sec = 90.0, and recycled only the supervised child worker; final private catalog was 14/14 connected, including GodPrompt 10 tools and memory 9 tools, with further GodPrompt transitive calls passing. Regression request: native Windows service restart must verify the actual old listener/process tree has gone away and a new listener generation is ready before reporting success; targeted reload_mcp should recover sources initially marked FAILED without restarting healthy sources, honoring per-source startup timeouts. No PR code was changed, merged or deployed by this field recovery.

@AKzar1el
AKzar1el marked this pull request as ready for review November 20, 2026 03:51

Copy link
Copy Markdown
Owner Author

Small, separate retention follow-up (not a request to expand this PR): As of 2026-11-20, the existing Codexify project audit.jsonl had grown to ~931 MiB and remains actively written. In src/audit.rs, AuditLogger::open holds an append File under Mutex<File>; external rename/truncate/delete of that open stream is unsafe. I left the active audit untouched. The GodPrompt scoped observer's own summary log now has separately tested 1 MiB + one-archive retention, but this does not cap Codexify's audit writer. Please coordinate a tiny writer-owned audit rotation change after PR #11: optional max-size/max-archives config (e.g., 128 MiB × 2 archives subject to owner review), rotate only under the writer lock between complete JSONL records, retain original handle if rollover fails, preserve redaction, verify Windows locks, concurrent writes and observer follow-across-rotation. Do not force a fleet restart or migrate the live 931 MiB file as part of this PR. I tried creating a standalone issue, but GitHub reports Issues are disabled (410), so recording this here for the Codexify owner/parallel agent.

@AKzar1el
AKzar1el merged commit 2906a5d into main Nov 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant