Skip to content

feat(whoami): user_id for agents enrolled through a Control principal - #42

Merged
khaliqgant merged 2 commits into
mainfrom
feat/whoami-user-id
Nov 17, 2026
Merged

khaliqgant merged 2 commits into
mainfrom
feat/whoami-user-id

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What

GET /v1/whoami now includes user_id for agents enrolled with a relay-control credential:

  • device-enrolled (sh_at_): the user the device token introspected as
  • launched (sh_lt_): the launching person (the launch credential's sub)
  • enrollment-key agents: omitted
{"agent_id": "ag_...", "name": "<name>", "gid": 11, "groups": [], "group_names": ["local"], "guest": false,
 "user_id": "<control user id>",
 "relaygate": {"agent": "<name>", "groups": ["local"]}}

How

No schema change: the introspected user id is already persisted with the registration as the agent's key id (device:<userId> / launch:<userId>), which policy validation reserves (no enrollment key may use device:* / launch:*), and only the same person can recover the name. controlUserId(agent) reads it back. Self only (whoami answers for the caller's token), and kept off the relaygate provenance card that is stamped on forwarded messages.

Why

relay-control verifies gate-only desktop identities via /v1/whoami and will enforce whoami.user_id == caller user id once present, closing an ownership gap.

Tests

test/control.test.ts "GET /v1/whoami: the Control user behind the caller": device-enrolled includes user_id; launched includes the launching person's id (also after token refresh); key-enrolled omits it; two callers each see only their own; a file-backed store survives a restart with user_id intact and no re-introspection. npm run typecheck and npm test (158) pass.

Docs: docs/contract.md new "Who am I" subsection. README doesn't document whoami.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

GET /v1/whoami now includes user_id for agents enrolled with a relay-control credential, closing an ownership gap so relay-control can enforce whoami.user_id == caller user id.

  • Device-enrolled (sh_at_) agents report the user their token introspected as; launched (sh_lt_) agents report the launching person's id, unchanged after token refresh.
  • Key-enrolled agents omit user_id, and it never appears on the relaygate provenance card.
  • No schema change: the id is read back from the already-persisted key id, so it survives restarts without re-introspection.

Written for commit 1fe3651. Summary will update on new commits.

View guided diff Turn on auto-fix

GET /v1/whoami now returns user_id for device- and launch-enrolled agents:
the relay-control user their credential introspected as at registration,
already persisted as the agent's key id (device:<userId> / launch:<userId>,
ids no policy key may use). Key-enrolled agents omit it. Self only, and kept
off the provenance card stamped on forwarded messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a8d9387-c899-4df7-a731-830e600af659
Commits

Reviewing files that changed from the base of the PR and between 9d6902f and 1fe3651.

Files selected for processing: 3

  • docs/contract.md
  • src/app.ts
  • test/control.test.ts

No actionable comments were generated in the recent review.

Walkthrough

The contract documents GET /v1/whoami. The endpoint now conditionally returns user_id for agents whose key IDs use the device: or launch: prefix. Tests cover enrollment types, caller isolation, and persistence across a store restart.

Changes: Whoami Identity

Layer / File(s) Summary
Document and return user identity
docs/contract.md, src/app.ts
The contract describes the endpoint’s authorization and response. The application extracts a non-empty user ID from device: and launch: key IDs and adds it to the response when present.
Verify identity response and persistence
test/control.test.ts
The harness accepts an optional store. Tests check user ID inclusion for device-enrolled and launched agents, omission for key-enrolled agents, caller isolation, and persistence after reopening the store without introspection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

Merge Risk: Minimal · previous review 9d690

This adds an optional user_id to the whoami response for agents enrolled with relay-control credentials. Other agents see no change. The change is small, reversible and covered by tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding user_id to GET /v1/whoami for agents enrolled through a Control principal. The raw summary, objectives, and description all describe this change. The title is s…
Description check Passed The description states that GET /v1/whoami now includes user_id for relay-control enrolled agents. It explains the source of the ID, the self-only scope, the omission of the field from the provenance …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: adding user_id to GET /v1/whoami for agents enrolled through a Control principal. The raw summary, objectives, and description all describe this change. The title is specific and concise, and it follows the conventional commit style.

Full details: Description check

Explanation

The description states that GET /v1/whoami now includes user_id for relay-control enrolled agents. It explains the source of the ID, the self-only scope, the omission of the field from the provenance card, the motivation, and the tests. It matches the changeset in substance.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks its token’s trail,
user_id joins the caller’s tale.
Device and launch keys show the way,
While key-enrolled agents leave it away.
Through store restarts, the ID stays.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 021b4dca-07cb-4186-897c-5d5e0a9a7629
Commits

Reviewing files that changed from the base of the PR and between 4a301a4 and 9d6902f.

Files selected for processing: 3

  • docs/contract.md
  • src/app.ts
  • test/control.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T07:07:56.037015Z 9d6902f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@khaliqgant
khaliqgant merged commit 95f1794 into main Nov 17, 2026
4 checks passed
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