Skip to content

feat(agent-handoff): Add public claim API - #131113

Merged
evanpurkhiser merged 2 commits into
masterfrom
git/feat-agent-handoff-return-claim-context-as-json
Nov 17, 2026
Merged

evanpurkhiser merged 2 commits into
masterfrom
git/feat-agent-handoff-return-claim-context-as-json

Conversation

@evanpurkhiser

@evanpurkhiser evanpurkhiser commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The CLI needs a stable machine-readable way to claim a handoff without coupling API behavior to the Markdown controller.

This adds public POST /api/0/agent-handoff/, accepting a JSON body containing handoff_code and returning the Sentry account, organization, setup credentials, and flow instructions as JSON. The existing /agent-handoff.md and /agent-handoff/ routes retain their current behavior during the CLI migration.

The endpoint publishes a typed OpenAPI request and response so the claim contract is generated into @sentry/api.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 13, 2026
@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch 3 times, most recently from 116ee4c to 21d6d69 Compare November 16, 2026 18:12
@evanpurkhiser
evanpurkhiser requested a review from a team as a code owner November 16, 2026 18:12
@evanpurkhiser evanpurkhiser changed the title feat(agent-handoff): Return claim context as JSON feat(agent-handoff): Add public claim API Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

No findings on the latest commit.

@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from 5da5010 to 3b2fe7c Compare November 16, 2026 18:14
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 16, 2026
@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from ccb6454 to 9d6ade7 Compare November 16, 2026 18:26
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components and removed Scope: Frontend Automatically applied to PRs that change frontend components labels Nov 16, 2026
Comment thread src/sentry/agent_handoff/claims.py Resolved
@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from 8266681 to 7c1d049 Compare November 16, 2026 20:54
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components and removed Scope: Frontend Automatically applied to PRs that change frontend components labels Nov 16, 2026
@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from fa14263 to 1180f21 Compare November 16, 2026 20:57
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components and removed Scope: Frontend Automatically applied to PRs that change frontend components labels Nov 16, 2026
Comment on lines +41 to +48
class AgentHandoffClaimRequest(TypedDict):
handoff_code: Annotated[str, ApiDescription("The private agent handoff code to claim.")]


class AgentHandoffClaimRequestSerializer(serializers.Serializer[AgentHandoffClaimRequest]):
handoff_code = serializers.CharField(
help_text="The private agent handoff code to claim.",
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait do we .. actually need both, is this a normal pattern?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the serializer is sufficient here. I removed the separate TypedDict and now validate request.data through the serializer.

def post(
self, request: Request
) -> Response[AgentHandoffClaimResponse] | Response[DetailResponse]:
"""Exchange a private handoff code for the context needed to authenticate the CLI."""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And determine the next steps to guide the user or agent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the endpoint description to cover determining the next steps used to guide the user or agent.

Comment on lines +46 to +48
handoff_code = serializers.CharField(
help_text="The private agent handoff code to claim.",
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be a regex field then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This now uses a RegexField with the exact handoff-code length and pattern, and the endpoint reads only validated_data.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7f2b365. Configure here.

@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from 7f2b365 to 954f923 Compare November 16, 2026 21:11
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

Comment on lines +109 to +110
if not media_type_matches("application/json", request.content_type):
return Response({"detail": "Invalid handoff code."}, status=400)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really necessary I think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Removed the explicit media-type check; JSONParser already owns content-type validation.

Comment on lines +90 to +91
if not serializer.is_valid():
return Response({"detail": "Invalid handoff code."}, status=400)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to just raise I think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This now uses is_valid(raise_exception=True) and lets DRF own the validation response.

@evanpurkhiser
evanpurkhiser force-pushed the git/feat-agent-handoff-return-claim-context-as-json branch from e6cbf43 to ca3272a Compare November 17, 2026 15:18
@evanpurkhiser
evanpurkhiser merged commit b95620b into master Nov 17, 2026
83 checks passed
@evanpurkhiser
evanpurkhiser deleted the git/feat-agent-handoff-return-claim-context-as-json branch November 17, 2026 15:28
joshuarli added a commit that referenced this pull request Nov 24, 2026
…132105)

Refreshes `.github/workflows/scripts/backend-test-durations.json` from
recent master runs, following #129569.

**Source data:** the per-file median of the `backend-test-durations-*`
artifacts from three green full-suite master `backend.yml` runs:
[45447921880](https://github.com/getsentry/sentry/actions/runs/45447921880),
[45445395411](https://github.com/getsentry/sentry/actions/runs/45445395411)
and
[45442363055](https://github.com/getsentry/sentry/actions/runs/45442363055)
(master `712e106928c` through `6a3df08320e`). All three ran 30 shards
with 4 workers on `ubuntu-26.04`. The file is the unedited output of the
`merge` then `median` commands in the `backend-test-durations.py`
docstring.

**What changed vs master** (last resync: #131174)
- **25 test files added, 6 removed** (the drift trigger). The added
files are all under 11s, the largest being
`integrations/supabase/test_integration.py` (10.1s) and
`integrations/supabase/test_client.py` (9.3s). The removed files, such
as the three `api/endpoints/release_thresholds/*` tests, no longer exist
on master.
- **`seconds_per_test`:** 0.400 → 0.451 (+12.7%), the other drift
trigger.
- **Files in both versions:** total time +12.9% (19,640s → 22,178s).
Four files moved by more than 25% and 30s:
- `tests/sentry/seer/endpoints/test_organization_agent_token.py` 493.8s
→ 748.5s, +52% (runs: 748.5 / 761.8 / 657.2). This crosses the
regression bar. Recent commits touching it include
#129239, #131473 and
#131113.
- `tests/snuba/api/endpoints/test_organization_events_span_indexed.py`
208.8s → 262.2s (+26%)
- `tests/relay_integration/test_integration.py` 136.7s → 65.3s and
`tests/relay_integration/test_message_filters.py` 111.3s → 49.2s. Both
drops line up with #131170.

**Acceptance durations aren't refreshed here.**
`acceptance-test-durations.json` (#132407) gets
refreshed from the median of 3 full master `acceptance.yml` runs that
upload `acceptance-test-durations-*`. No such run has finished yet, so
the coverage-instrumented seed stays in place. The weekly resync
replaces it once three exist.

**Not changed:** `WORKER_SECONDS_PER_SHARD` and `TESTS_PER_SHARD`.
Shared files shifted +12.9%, under the 15% bar for retuning the budget.

Opened by the weekly backend test durations resync.

<!-- junior-request-attribution:start -->
via [automation
`sched_24013c871420a6cbab8d518dae1de4ae`](https://junior-prod.sentry.dev/automations/sched_24013c871420a6cbab8d518dae1de4ae)
· Run ID `sched_24013c871420a6cbab8d518dae1de4ae:1795248000000`,
@joshuarli.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!--
junior-conversation-id:agent-dispatch%3Adispatch_6819e6c570f111d16716e7c099e1d6bc
-->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_6819e6c570f111d16716e7c099e1d6bc)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_6819e6c570f111d16716e7c099e1d6bc/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Joshua Li <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 5d5f20fd Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants