Repository navigation
✨ feat(launchd): resident HTTP service lifecycle (PR2 — launchd) - #15
Merged
Merged
Conversation
The single resident HTTP instance can now stay lightweight when idle. Gated by CODE_EXECUTOR_POOL_IDLE_MS (0 = disabled = eager, the default and the unchanged stdio behavior): - Lazy build: the downstream MCP pool is initialized on the FIRST tool call (SharedCore.ensurePoolReady, idempotent for concurrent callers) instead of eagerly at startup. - Idle teardown: when the last HTTP session closes, an idle timer tears the pool down (MCPClientPool.disconnect) after the configured window, reclaiming the ~15 downstream children; the next tool call rebuilds it. Teardown is deferred while an execution is in flight and cancelled on reconnect or full shutdown. - Session accounting is driven from the Streamable HTTP transport (onSessionOpen/onSessionClose), gated once per session on the sessions map. SharedCore gains optional constructor injection (pool + connection pool) for testability; production call sites are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the macOS launchd lifecycle for the single shared HTTP instance so it can run as an always-resident, managed service (a host cannot spawn an HTTP MCP server the way a stdio host does, so the server must already be running). - LaunchdService: renders a resident-daemon plist (RunAtLoad + KeepAlive, ProgramArguments=[binary], EnvironmentVariables carrying the http role, port, bearer token, MCP_CONFIG_PATH and CODE_EXECUTOR_ALLOW_NESTED) and manages it via modern launchctl verbs (bootstrap/bootout/kickstart/print). Distinct from the StartCalendarInterval sync scheduler. Plist written 0600 (it embeds the token); all interpolated values XML-escaped; label charset-validated so it cannot traverse out of ~/Library/LaunchAgents; launchctl runner + platform injectable for tests. - ensureHttpToken: read-or-generate a 256-bit bearer token persisted 0600 at ~/.code-executor/http-token (idempotent). - `code-executor-mcp service install|uninstall|status|restart` CLI (argv- dispatched like setup/sync-wrappers), with --port/--config/--binary/--no-auth and a connection hint for wiring a host. Verified live: install → launchd loads it → GET /health 200 → uninstall removes it cleanly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR2 — launchd lifecycle
Supersedes #14 (auto-closed when #13's branch was deleted on merge). Now targets
maindirectly (PR1 is merged). Adds only the 2 launchd-lifecycle commits (a3ef868,04ecaec) on top of main.Makes the single shared HTTP instance an always-resident, launchd-managed macOS service, and lets an idle resident stay lightweight.
1. Lazy/idle downstream pool (
✨ feat(core))Gated by
CODE_EXECUTOR_POOL_IDLE_MS(0 = disabled = eager, the default; stdio behavior byte-for-byte unchanged). Lazy build on the first tool call (SharedCore.ensurePoolReady, idempotent); idle teardown after the last HTTP session closes (deferred while an exec is in flight; cancelled on reconnect/shutdown). Session accounting wired from the Streamable HTTP transport.SharedCoregains optional ctor injection for tests.2. Resident launchd service +
serviceCLI (✨ feat(service))LaunchdServicerenders a resident-daemon plist (RunAtLoad+KeepAlive,ProgramArguments=[binary], env = http role/port/token/MCP_CONFIG_PATH/ALLOW_NESTED), managed via modernlaunchctlverbs. Plist0600(embeds token), XML-escaped, label charset-validated; runner + platform injectable.ensureHttpTokenpersists a 256-bit token0600.code-executor-mcp service install|uninstall|status|restartCLI.Verification
typecheckclean; 30 new unit tests; binary integration 7/7; full suite sandbox-off = no new regressions (only the knownfilesystem.test.ts); live resident smoke (install → launchd loads →/health200 → uninstall clean).🤖 Generated with Claude Code