Skip to content

Manual attach without an endpoint: probe disk instead of leaking localEndpoint() error - #271

Merged
platypii merged 2 commits into
masterfrom
attach-already-attached-message
Jul 7, 2026
Merged

Manual attach without an endpoint: probe disk instead of leaking localEndpoint() error#271
platypii merged 2 commits into
masterfrom
attach-already-attached-message

Conversation

@platypii

Copy link
Copy Markdown
Contributor

Under a central-managed install the gateway binds an ephemeral port only the daemon knows, so manual hyp attach claude failed with the internal error:

error: attach client 'claude' failed: ai-gateway: localEndpoint() called before the gateway started

Now, when the gateway is not bound in the CLI process and no ai-gateway listen is configured, attach probes the client's on-disk attach state via its attach_probe:

  • already attached: no-op success ("claude is already attached (...); the daemon manages attach for this install"), with a matching --json shape
  • not attached: actionable error pointing at hyp start or pinning listen

The configured-listen fallback and the daemon's proven-bound path are unchanged (LLP 0045; doc updated in the same commit). Adds tests for both branches, the --json shape, and the existing config fallback.

…or the two daemon-managed exits
The daemon-managed attach branch reported an already-attached no-op with a
--json shape but left the not-attached failure emitting only plain stderr,
and neither exit emitted any span or log. Add a matching --json failure
object (status:failed, error_kind:no_endpoint) and a structured log line at
each exit. Adds a test for the JSON failure shape.
@platypii

Copy link
Copy Markdown
ContributorAuthor

Review

Verdict: solid, ready to merge. Well-scoped, follows repo conventions (no semicolons, no em dashes, a real @ref to LLP 0045), and the five new tests pass locally.

What it does: When hyp attach runs on a central-managed install where the gateway isn't bound in the CLI process and no listen is configured, it no longer leaks the internal localEndpoint() called before the gateway started error. Instead it probes the client's on-disk attach marker via attachProbe:

  • already attached → no-op success (with matching --json shape)
  • not attached → actionable error pointing at hyp start or pinning listen

The configured-listen fallback and the daemon's proven-bound path are unchanged.

Minor, non-blocking notes

  1. Output asymmetry on the not-attached failure. The --json branch sets exitCode = 1 and continues, but the non-JSON branch throws, which the generic catch wraps into error: attach client 'claude' failed: cannot resolve... — a slightly doubled prefix. Harmless, and it keeps the JSON payload clean, but worth a comment noting the intent.

  2. A malformed settings file reads as "not attached."probeClientAttachFromDescriptor catches a JSON parse error and returns { attached: false, error }, but the caller drops probe.error. So a corrupt marker file tells the user to start the daemon rather than that their settings file is broken. Edge case, low priority.

Test coverage

Good: already-attached (text + json), not-attached (text + json), and the configured-listen fallback. Optional gaps: the descriptor-absent and corrupt-file branches aren't exercised.

Sign up for freeto 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

@platypii