Skip to content

fix(agent-hooks): discover endpoint file from script location so daemon-revived PTYs keep reporting#1229

Open
brennanb2025 wants to merge 2 commits intomainfrom
brennanb2025/brennanb2025-agent-dashboard-daemon-new-terminals
Open

fix(agent-hooks): discover endpoint file from script location so daemon-revived PTYs keep reporting#1229
brennanb2025 wants to merge 2 commits intomainfrom
brennanb2025/brennanb2025-agent-dashboard-daemon-new-terminals

Conversation

@brennanb2025
Copy link
Copy Markdown
Contributor

@brennanb2025 brennanb2025 commented Apr 28, 2026

Summary

  • PTYs kept alive by the persistent-terminal daemon survive Orca restarts, so the ORCA_AGENT_HOOK_PORT/TOKEN baked into their env at spawn go stale the moment Orca restarts and rebinds the hook server. PTYs spawned before feat(agent-hooks): on-disk endpoint discovery for surviving PTYs (v2) #1196 also have no ORCA_AGENT_HOOK_ENDPOINT at all, so their managed hook scripts post to a dead port and the dashboard silently stops updating.
  • Fix: managed hook scripts now derive the endpoint file path from their own location at invocation time ($(dirname "$0")/endpoint.env on POSIX, %~dp0endpoint.cmd on Windows) as a fallback when the env var is absent. Co-location of the endpoint file and managed scripts in userData/agent-hooks/ is what makes this discovery work.
  • Centralize the directory + filename helpers in installer-utils.ts (getAgentHooksDir, getEndpointFileName, getEndpointFilePath, getManagedScriptPathForAgent, getEndpointDiscoveryShellSnippet, getEndpointDiscoveryCmdSnippet) so the server (writer) and all four hook-services (readers) share one source of truth; createManagedCommandMatcher now uses the same AGENT_HOOKS_DIR_NAME constant.
  • Windows snippet gates its _orca_loaded flag on call … && set _orca_loaded=1 so a parse error in the env-var endpoint correctly falls through to the script-adjacent file instead of being masked.

Test plan

  • pnpm test src/main/agent-hooks/installer-utils.test.ts — new tests cover both discovery snippets and the co-location invariant.
  • Golden path: Claude Code session, send a message → dashboard updates (env-var branch still works).
  • Daemon-revived PTY (the fix): start Claude Code, send a message, Cmd+Q Orca, relaunch pnpm dev, send another message in the revived terminal → dashboard updates. Confirmed staleness directly in the revived PTY:
    • PTY env: ORCA_AGENT_HOOK_PORT=63237 (old)
    • Endpoint file: ORCA_AGENT_HOOK_PORT=63407 (new, rewritten on relaunch)
    • Script-adjacent fallback sourced the new port and posted to the live server.
  • Windows smoke: verify %~dp0endpoint.cmd loads and _orca_loaded gating falls through on a malformed env-var endpoint. (not verified — no Windows environment available)

brennanb2025 and others added 2 commits April 28, 2026 13:19
Co-authored-by: Orca <help@stably.ai>
- Extract AGENT_HOOKS_DIR_NAME so getAgentHooksDir and createManagedCommandMatcher cannot drift.
- Windows snippet: gate the fallback via `&&` so a parse error in the env-var endpoint falls through to the script-adjacent file instead of being masked.
- Add a matcher test that a command built from getAgentHooksDir is swept by createManagedCommandMatcher.
- Drop stray 00-review-context.md artifact.

Co-authored-by: Orca <help@stably.ai>
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