-
Notifications
You must be signed in to change notification settings - Fork 29
Fix false "relay unreachable" error on agent creation #1433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,12 +382,21 @@ pub async fn sync_managed_agent_profile( | |
| avatar_url: Option<&str>, | ||
| auth_tag: Option<&str>, // NIP-OA auth tag JSON | ||
| ) -> Result<(), String> { | ||
| // Fail loudly on a blank relay URL — callers must resolve via `effective_agent_relay_url` first. | ||
| let base = relay_http_base_url(relay_url); | ||
| if base.is_empty() { | ||
| return Err( | ||
| "no relay configured for profile sync (resolve the agent's relay URL first)" | ||
| .to_string(), | ||
| ); | ||
| } | ||
|
|
||
| // Build a signed kind:0 profile event (with optional NIP-OA auth tag). | ||
| let event = build_profile_event(agent_keys, display_name, avatar_url, auth_tag)?; | ||
| let event_json = event.as_json(); | ||
| let body_bytes = event_json.into_bytes(); | ||
|
|
||
| let url = format!("{}/events", relay_http_base_url(relay_url)); | ||
| let url = format!("{}/events", base); | ||
| let auth = build_nip98_auth_header_for_keys(agent_keys, &Method::POST, &url, &body_bytes)?; | ||
|
|
||
| let mut request = state | ||
|
|
@@ -708,6 +717,30 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn blank_relay_http_base_is_empty() { | ||
| // A blank relay URL has no scheme to rewrite, so the HTTP base is empty. | ||
| assert_eq!(relay_http_base_url(""), ""); | ||
| assert_eq!(relay_http_base_url(" "), ""); | ||
| } | ||
|
|
||
| #[test] | ||
| fn ui_created_agent_blank_relay_resolves_to_reachable_host() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test does not fail against the pre-fix logic, contrary to the PR body. It only composes Not blocking — Phase 4 is a Tauri command that's genuinely hard to unit-test, and the new guard in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 74651f5. Both test comments now describe what the test verifies in one line, not the fix. Also corrected the PR body: the resolution test no longer claims it "fails against the pre-fix logic" — it pins the resolution contract (two pure helpers), and the real regression protection is called out as the blank-relay guard in |
||
| // A blank per-agent relay (the UI create case) resolves through | ||
| // `effective_agent_relay_url` to a real workspace host, not a hostless base. | ||
| let resolved_relay_url = ""; // UI create flow: no per-agent relay pinned | ||
| let workspace_relay = "wss://staging.example.com"; | ||
|
|
||
| let sync_relay_url = effective_agent_relay_url(resolved_relay_url, workspace_relay); | ||
| let base = relay_http_base_url(&sync_relay_url); | ||
|
|
||
| assert!( | ||
| !base.is_empty(), | ||
| "blank per-agent relay must resolve to a real workspace host, not a hostless base" | ||
| ); | ||
| assert_eq!(base, "https://staging.example.com"); | ||
| } | ||
|
|
||
| // ── classify_intercepted_response ──────────────────────────────────────── | ||
|
|
||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small things:
relay_http_base_url("wss://")returns"wss:"(the trailing-slash trim defeats the prefix strip), which is non-empty and sails past this guard into the same misclassified connect failure. Pre-existing edge and fine to leave unfixed — but the comment shouldn't claim coverage it doesn't have.// Fail loudly on a blank relay URL — callers must resolve via effective_agent_relay_url first.carries the load.Nit: the error string surfaces verbatim in the user-facing toast. Only reachable if a future caller regresses, so acceptable as a loud dev-facing failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 74651f5. Trimmed to one line and dropped the inaccurate "blank/hostless" wording — it now reads
// Fail loudly on a blank relay URL — callers must resolve via effective_agent_relay_url first.Good catch on thewss://→wss:edge; left the pre-existing behavior as-is since it is out of scope for this fix.