Repository navigation
Resolve the org once per run and route every API call through it (#648) - #1041
Conversation
The run's API client now carries one ApiRoute, Org{slug} or Proxy,
decided once in get_api_client_with_overrides. With a token and no
--org / SOCKET_ORG_SLUG / socket-cli defaultOrg, a failed
GET /v0/organizations (network error, 401/403, no orgs, bad answer)
makes the whole run an anonymous public-proxy run with one warning,
instead of querying /v0/orgs/default/... for JSON while blobs, vendor
package references and telemetry went to the proxy. Offline runs with a
token and no slug use the proxy route without a network call.
- ApiClient: route replaces use_public_proxy + org_slug; a proxy client
never keeps the token. patches_path, the batch 404 message,
binary_url and vendor_package_url match on the route; the
org_slug_or_default fallback, the proxy_url_from_env re-derivation and
fetch_registry_references_for_org are gone.
- Telemetry takes a TelemetryAuth built from the run's client
(TelemetryAuth::for_client); list keeps a no-client constructor.
- Embedded --vex reuses the host command's client (VexBuildParams
api_client), so scan/apply/vendor --vex no longer resolve the org a
second time; standalone vex builds its client at most once and reports
telemetry on it. vendored repair hands the client it builds back to
repair.
- scan --json and get --json report the downgrade as api_auth_fallback
in warnings[].
The mid-run 401/403 proxy swap is unchanged (#647).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CLI_CONTRACT.md: the --org / SOCKET_ORG_SLUG rows and the api_auth_fallback warning cover the unresolved-org proxy run. docs/configuration.md and docs/migrating-to-v5.md describe the change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…n path (#648) get <uuid> --json (agent save, paid_required, not_found) and the search path's not_found / paid_required envelopes now carry the api_auth_fallback warning like the other get paths. Standalone vex --json notes it when it built the run's client itself; a host that seeded its client reports it and adds no duplicate. Human mode still warns once, from client construction. Tests pin the warning count and the new JSON entries. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
428e09c to
158ed10
Compare
|
[agent] CI status: rebased onto origin/main (05ecc6e) at 158ed10. The PR is MERGEABLE again. The only conflict was the CI on 158ed10: 8 jobs succeeded, including npm hosted/vendored, pnpm hosted and the GHA audit. Most other runs were cancelled manually at about 23:16–23:18Z as part of a bulk cancel across several branches (also #973 and ci/cut-pr-ci-waste). Generated by Claude Code |
Resolve import conflicts in rollback.rs, vendor.rs and scan/vendor_flow.rs (keep TelemetryAuth, take main's PurlKey in place of composer_purls_equivalent), and move main's new blob_fetcher test client onto ApiRoute::Proxy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
[agent] Merged main, CI green; ready for review. Generated by Claude Code |
apply and vendor seed their embedded --vex with the run's client, which suppresses the VEX plan's own api_auth_fallback note on the promise that the host reports it. scan and get copy org_unresolved() into warnings[], but apply and vendor (including the hosted-pin eject path) never did, so a token whose org failed to resolve was invisible to --json consumers. Add a shared api_auth_fallback_warning() helper and push it onto the apply and vendor envelopes under --json, plus an e2e test covering both. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
run_eject builds its client (and may fall back to the public proxy) before any envelope is printed, but only the wet-path envelope carried the api_auth_fallback warning. The dry-run success envelope and the fetch-failure / refused envelopes now carry it too, so --json consumers see the same downgrade stderr already reported. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
Conflicts in get.rs (imports: kept main's trimmed set plus this branch's TelemetryAuth) and remove.rs (kept main's emit_hosted_unwind_error with this branch's TelemetryAuth telemetry call). Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
|
[final reviewer] Tanmay Singla (@Tanmay182003) Two non-merge commits landed after your approval on
Please take another look at head Generated by Claude Code |
save_and_apply_patch folds the run's org warnings into the wet-run JSON envelope, but its --dry-run branch called agent_dry_run with empty warning slices. So `get <uuid> --json --dry-run --mode agent` after a failed org resolve dropped api_auth_fallback from warnings[], even though the client warned on stderr and the search dry-run path (which extends narrow_warnings with org_warnings) reports it. Pass org_warnings through so the preview envelope matches the wet run. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
[final reviewer] Tanmay Singla (@Tanmay182003) One non-merge commit landed after your approval on Generated by Claude Code |
|
bugbot run Generated by Claude Code |
Resolve get.rs and rollback.rs conflicts with #1027: keep this PR's shared telemetry handle and take main's {code, message} error codes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
[final reviewer] Merged Tanmay Singla (@Tanmay182003) the re-look request above for Generated by Claude Code |
|
bugbot run Generated by Claude Code |
When a token's org cannot be resolved, repair's download runs on the public proxy and only stderr said so; scan, get, apply and vendor already carry api_auth_fallback in the envelope's warnings[]. Copy it from the download phase's client (not the telemetry-only client, which fetched nothing). Bugbot finding on #1041. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5082b17. Configure here.
|
[final reviewer] Tanmay Singla (@Tanmay182003) One more non-merge commit landed after your approval on
CI is green and the PR is mergeable at Generated by Claude Code |
|
[burn-down agent] Labeled Ready for review at
Generated by Claude Code |
Main's #1041 moved get/repair telemetry onto TelemetryAuth while this branch dropped --download-mode. Keep TelemetryAuth and the org warnings from main, and drop the download_mode binding and the PatchSources import that only served the removed diff path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TL9oCf27A73hTwYqKgvxbx
The test came in from main with #1041 and still passed --download-mode file, which this PR removes, so repair rejected the argument and CI went red on the main merge. Repair always fetches per-file blobs now, so the flag is simply dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Assisted-by: Claude Code:claude-opus-5-5
Why
The maintainer decided on #648: resolve the org once at startup and use it for every later API call. Re-resolving the org or switching endpoints mid-run is wrong. On main, a token whose org can't be resolved splits one run four ways: JSON calls go to
/v0/orgs/default/…, blob/diff and vendor references re-derive the proxy from the env, telemetry decides on its own, and embedded--vexbuilds a second client that calls/v0/organizationsagain.What changed
Core (
api/client.rs)ApiRoute { Org { slug }, Proxy }replaces theuse_public_proxyflag and optionalorg_slug. A Proxy client never carries the token.get_api_client_with_overridesdecides the route once:GET /v0/organizations. Org on success. On failure, Proxy for the whole run plus one warning: "Could not determine your organization (…); using the public patch API proxy (free patches only). Pass --org or set SOCKET_ORG_SLUG." The hint about a token set to its storedsha512-hash is kept.defaultslug fallback, the proxy re-derivation from env inbinary_url/vendor_package_url, and the per-call overridefetch_registry_references_for_org.Telemetry
TelemetryAuth.for_clientuses the client's own route and base URL.from_credentialskeeps the no-network path forlistand other commands that never build a client.CLI: one client per run
VexBuildParamscarries the run's client. scan (JSON and human), hosted scan, the scan vendor flows, apply and vendor (including eject) pass theirs in, so embedded--vexno longer calls/v0/organizationsa second time.vexbuilds its client at most once, and its telemetry uses it.--jsonwarningscan --json,get --json(search, UUID, hosted and vendored paths, including not_found and paid_required) and standalonevex --jsonaddapi_auth_fallbacktowarnings[]when the run fell back to the proxy. Error envelopes stay minimal and don't carry it; the warning still prints on stderr.Not in scope: the mid-run 401/403 proxy swap is left for #647, which can build on
ApiRoute.User-visible changes
/v0/orgs/default/…. The whole run uses the public proxy (free patches only), warns once, and reportsapi_auth_fallbackin--json./v0/organizationsis called at most once per run, includingscan --vex.--api-url.Docs
crates/socket-patch-cli/CLI_CONTRACT.md: the--org/SOCKET_ORG_SLUGrows and theapi_auth_fallbacktext.docs/migrating-to-v5.mdanddocs/configuration.md.Tests
New:
route_decides_every_url: token+slug, failed resolve (500 and 401), offline, no token.for_client_follows_the_clients_route.unresolved_org_routes_the_whole_scan_vex_run_to_the_proxy_once:scan --json --vexwith a token, no org and a 500 from/v0/organizations. Checks one/v0/organizationscall, nothing to/v0/orgs/, the embedded VEX fetch goes to the proxy without the token, andapi_auth_fallbackis inwarnings[]./v0/organizationscall across two fetches and exactly one note.warnings[].Updated: failed-resolve tests now expect Proxy; the
binary_url/vendor_package_urltests build through the resolver;default-slug assertions now expect/patch/view; telemetry and vex_sources tests use the new arguments. Deleted the per-call org override test.Run:
cargo build --all-targetsandcargo test -p socket-patch-cli -p socket-patch-core --no-fail-fastafter rebasing onto main (the build passed; the full-suite run was still in progress when this PR was opened, and CI will cover it). Before the rebase, the targeted core and CLI lib and integration tests passed. Docker e2e suites were not run locally.cargo clippy --all-targetsshows no new warnings in changed code.Review findings fixed
get --jsonmissedapi_auth_fallbackon five outputs (UUID save, UUID paid_required, UUID not_found, search not_found, search paid_required). Fixed.vex --jsonnever reported the fallback when it built its own client. Fixed, JSON mode only, with no duplicate when a host passes its client.Left as is: commands that never build a client still send telemetry via env/config and ignore
--api-url(unchanged from main); after a mid-run 401/403 swap the telemetry route still points at the org (#647).Overlaps
PR #913 also touches
client.rs. Rebased onto main after #889 landed.Closes #648
🤖 Generated with Claude Code
Note
Medium Risk
Changes authentication routing and telemetry attribution across most network-touching commands; incorrect routing could affect patch access or event reporting, but behavior is more consistent than the prior split-endpoint model.
Overview
Resolves the org once per run and routes every patch API call, blob/vendor fetch, embedded
--vexrecord fetch, and telemetry event through that single decision—fixing runs where a token without--org/SOCKET_ORG_SLUGpreviously mixed/v0/orgs/default/…, proxy URLs, a second/v0/organizationsin VEX, and mismatched telemetry.Core:
ApiRoute(OrgvsProxy) replaces theuse_public_proxyflag; failed online org lookup puts the whole run on the anonymous public proxy (free patches only) with one stderr warning instead of falling back to adefaultorg slug.CLI: Commands thread a shared
ApiClientinto embedded VEX viaRunApiClient/to_build_params; telemetry usesTelemetryAuthinstead of raw token/org pairs.--jsonaddsapi_auth_fallbacktowarnings[]onscan,get,apply,vendor, and related paths when org resolution failed.CLI_CONTRACT.mddocuments the new--orgbehavior and warning semantics.Reviewed by Cursor Bugbot for commit 5082b17. Configure here.
Generated by Claude Code