fix(api): align POST /start with UI PTY path — MCP for all agents#56
fix(api): align POST /start with UI PTY path — MCP for all agents#56Zai69 wants to merge 1 commit into
Conversation
Replace one-shot bash -c spawn with persistent PTY init + buildInteractiveCommand + writeProgrammaticInput (same as ipc-handlers agent:start). Pass --mcp-config from ~/.claude/mcp.json to every agent, not only Super Agent / Automation. Fixes ZAIOS Mission Charlie85270#2 workers missing relay_runtime_tools when started via HTTP API (dorothy-mcp-attach, mission-02 delegate). Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Zai69 is attempting to deploy a commit to the Charlie Rabiller's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe ChangesAgent Start Route Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@electron/services/api-routes/agent-routes.ts`:
- Around line 248-250: The closure passed to setTimeout captures the ptyProcess
reference and can attempt to write to a killed or replaced PTY; modify the logic
around the delayed call (the setTimeout that calls
writeProgrammaticInput(ptyProcess, fullCommand)) to verify the PTY is still
valid before writing — e.g., check that the current ptyProcess is the same
instance and that it is not killed/closed (or add a boolean isRunning flag) and
cancel the pending timeout when /stop or a new /start replaces the PTY so
writeProgrammaticInput is only invoked against a live, current ptyProcess.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f2c2354d-3a3d-462b-a0bf-8f8b7ebbeb5e
📒 Files selected for processing (1)
electron/services/api-routes/agent-routes.ts
| setTimeout(() => { | ||
| writeProgrammaticInput(ptyProcess, fullCommand); | ||
| }, 500); |
There was a problem hiding this comment.
Potential race condition with captured PTY reference.
The ptyProcess reference is captured by the setTimeout closure. If /stop or another /start is called within 500ms, the captured reference points to a killed or replaced PTY, and writeProgrammaticInput may fail silently or throw an unhandled error.
Consider verifying the PTY is still valid before writing:
Proposed fix
setTimeout(() => {
- writeProgrammaticInput(ptyProcess, fullCommand);
+ const currentPty = ptyProcesses.get(ptyId);
+ if (currentPty === ptyProcess) {
+ writeProgrammaticInput(ptyProcess, fullCommand);
+ }
}, 500);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setTimeout(() => { | |
| writeProgrammaticInput(ptyProcess, fullCommand); | |
| }, 500); | |
| setTimeout(() => { | |
| const currentPty = ptyProcesses.get(ptyId); | |
| if (currentPty === ptyProcess) { | |
| writeProgrammaticInput(ptyProcess, fullCommand); | |
| } | |
| }, 500); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@electron/services/api-routes/agent-routes.ts` around lines 248 - 250, The
closure passed to setTimeout captures the ptyProcess reference and can attempt
to write to a killed or replaced PTY; modify the logic around the delayed call
(the setTimeout that calls writeProgrammaticInput(ptyProcess, fullCommand)) to
verify the PTY is still valid before writing — e.g., check that the current
ptyProcess is the same instance and that it is not killed/closed (or add a
boolean isRunning flag) and cancel the pending timeout when /stop or a new
/start replaces the PTY so writeProgrammaticInput is only invoked against a
live, current ptyProcess.
Summary
The HTTP API
POST /api/agents/:id/startpreviously spawned a one-shotbash -l -c "cd … && claude …"session and only passed--mcp-configfor Super Agent / Automation agents. Mission workers (Docs, Backend, Security, Frontend, QA) started via the API therefore had no MCP loaded — breaking ZAIOS Relay integration (relay_runtime_toolsinvisible).This PR aligns the HTTP
/startroute with the existing UI path (ipc-handlersagent:start):initAgentPtyCallback+ persistent PTYgetProvider('claude').buildInteractiveCommand({ mcpConfigPath, … })writeProgrammaticInput(pty, \cd '…' && ${command}`)` after 500ms settle--mcp-config ~/.claude/mcp.jsonfor all agents when the file existsContext
Validated in ZAIOS Mission #2 (
avec_svc) withdorothy-mcp-attachsmoke 6/6 and Dorothy live mobilize 6/6. ZAIOS canon: PRs #81–#83 onZai69/zaios.Test plan
tsc -p electron/tsconfig.jsonruns onelectron:start)~/.claude/mcp.jsonservers appear in Claude session (noMCP config file not found)make dorothy-mcp-attach→ 6/6 OKScope
Single file:
electron/services/api-routes/agent-routes.ts— no UI or ipc-handlers changes.Made with Cursor
Summary by CodeRabbit
Bug Fixes
Refactor