Skip to content

feat(mcp): add agent identities and issue runtime support - #512

Closed
yxr-2025 wants to merge 24 commits into
Noveum:mainfrom
yxr-2025:feature/issue-runtime
Closed

yxr-2025 wants to merge 24 commits into
Noveum:mainfrom
yxr-2025:feature/issue-runtime

Conversation

@yxr-2025

@yxr-2025 yxr-2025 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

This is a Draft PR for early review of the Agent identity, data model, permission boundaries, and Issue runtime implementation. It is not ready to merge and does not claim to complete #215. Known Web integration gaps and remaining work are listed below.

Adds workspace Agent identities that can be assigned issues through MCP and appear as the actor for Issue mutations. The authorizing Human remains the permission principal, so Agent access is the intersection of the grant scopes, the Human's current permissions, and resource policy.

  • Personal Agents are selected or created during OAuth consent, bound to the original client, and managed from MCP settings. Owners and admins can pause, revoke, or delete them while preserving historical attribution.
  • The database, Core services, and MCP support Human or Agent creators and assignees. Agent assignments require a Human issue owner, and assignment policy permits only the Personal Agent's owner or that Agent to assign it. The Web Agent selection flow is not yet implemented.
  • Access and refresh credentials bind to the exact rotating grant. Legacy unbound credentials are invalidated, and lifecycle changes cannot race past an issue mutation.
  • Issue mutations, activity, audit, and Outbox writes commit together. A persistent Worker delivers events with retries; create_issue supports idempotency keys, and public events omit grant identifiers.
  • Adds Agent queue discovery, canonical server-side readers and analytics, release documentation, and separate Writer-on/Writer-off HTTP E2E scheduling in CI. Web consumers do not yet retain and render the complete canonical Actor contract.

Why

MCP actions currently appear to come from the authorizing person, and Agents cannot own an assignment queue. This work establishes the runtime and permission boundaries needed to make Agent work visible and assignable without granting additional access. This draft requests upstream feedback before completing the remaining UI integration.

Refs #215

Design documents

The implementation document describes existing behavior and incomplete workflows. The target document proposes Personal Agents as the first milestone; shared Workspace Agents and execution orchestration require separate design and maintainer agreement.

Feedback requested

  • The original issue describes admin-created identities. This implementation lets members explicitly select or create Personal Agents during OAuth consent, while admins govern their lifecycle and connections. Is this MVP creation model acceptable?
  • This MVP attributes Issue Aggregate mutations to Agents. Comments, attachments, documents, and other aggregates retain Human attribution. Is that scope acceptable for the first increment?
  • Each member currently has a limit of two active Personal Agents per workspace. Should this identity limit remain, given the contribution guide's policy against usage limits?

Known gaps and remaining work before ready for review

  • Retain canonical creator, assignee, owner, assigneeAgentId, and ownerId in the client Issue schema and update detail, list, and board consumers. Agent assignments currently render as Unassigned, and the Human Issue Owner has no display or transfer controls.
  • Add an Owner-authorized Personal Agent selection flow to the Web detail and card Assignee controls. They currently list only Human workspace members.
  • Render the Agent Creator's actual name, avatar, and Deleted state instead of only a generic Agent label.
  • Support ownerUserId: null for policy-controlled Owner clearing when there is no Agent Assignee. The current validator and transfer path do not support that input.
  • Add member-removal confirmation and preflight counts for affected Agents, connections, and open assignments, without leaking unreadable resources.
  • Move remaining profile and lock-holder action authorization into Shared Policy. These checks currently run on the server in Core; the finding is incomplete policy centralization, not a demonstrated permission bypass.
  • Add regressions that fail on these missing behaviors and rerun the affected verification before marking this PR ready for review. Align documentation with the agreed scope and completed surfaces.

How you know it works

Latest local repair validation (2026-10-02)

Candidate: 7d4dced5e1a8d260bc84deb3ce7d9d16502955ed. Repairs address the CodeQL dead token assignment, release-based CI database setup with isolated lanes, and the Next Node runtime during Bun-launched Playwright cold starts.

Check Actual candidate Result
bun run verify 7d4dced 6,540 passed, 0 failed, 0 skipped; all nine workspace packages executed on Linux
bun run test:e2e d8abd45 57 passed; three existing exclusions; exit 0
bun run test:e2e:agent-release d8abd45 Writer-on and a fresh Writer-off process both passed
Inbox conversations Playwright d8abd45 1 passed; exit 0
Web build, documentation build, navigation test d8abd45 Passed
Database catalog inspection 7d4dced All 13 databases complete; each has 261 foreign keys and 49 declared CHECK constraints, with both conflict arbiter indexes verified
git diff --check 7d4dced Passed

After d8abd45, only two unit test files changed. Browser, MCP, Inbox, build, and documentation results retain their actual execution SHA rather than being presented as final-SHA reruns. The final verification ran on Linux with Bun 1.3.14 and Node 22.23.3.

Hosted CI and the CodeQL rescan still need remote confirmation. The separate test:docker-gateway CI step was not run locally. The exact CI MinIO image could not be pulled; browser validation used cached MinIO RELEASE.2025-09-07T16-13-09Z, while unit S3 tests used LocalStack with signature validation enabled. These results do not claim production validation or completion of the workflow gaps above.

Earlier baseline validation

Validated on 203a066dcba7c7ffc4adcb5a28e81749f3392e79, including upstream d133153ef077637324f0eb34b79fbc82f45b1212.

Check Result
bun run verify 6,534 passed, 0 failed; all nine workspace packages executed on Linux
bun run test:e2e 57 passed, 0 failed, three existing skips; no added retries or exclusions
bun run test:e2e:agent-release Writer-on and a fresh Writer-off process both passed
Isolated empty-database db:release, repeated release, and db:check-drift Passed; 31 migrations applied, then zero pending; no required drift
bun run build, bun run docs:build, documentation navigation test Passed
git diff --check Passed

The regression coverage includes current-permission checks, identity lifecycle races, exact credential binding, Actor constraints and backfills, issue attribution, Agent queue access, idempotency, Outbox delivery and redaction, and real HTTP OAuth/MCP behavior with the Writer enabled and disabled.

The browser coverage also includes document access revoked during a reconnect, keyboard drag readiness and persistence, and Agent settings and Inbox behavior. The full verification includes real S3 round trips with signature validation enabled. The earlier persistent Worker image and recovery drill was not repeated for this merge candidate; it remains historical evidence, not a new result.

These passing results describe the current test suite, not complete coverage of #215. The existing MCP browser test checks the generic Agent Creator label and Activity badge, but does not assert Agent Assignee rendering, Human Owner controls, or Web Agent selection. Those gaps remain despite the green suite.

Screenshots

Before this change, MCP settings listed Human-authorized client connections without an Agent management surface, and MCP issue actions appeared to come from the Human.

After this change, settings show Agent identities, owners, lifecycle and connection state, locks, permissions, quota, and recent activity. Issue activity distinguishes the Agent actor from its Human principal.

Light and dark screenshots of Agent settings and issue attribution have been captured in the local review bundle. Uploading the four PNGs to this PR is pending. They use synthetic E2E data, not production records.

The screenshots cover existing Settings and Activity behavior only. They are not evidence that the Agent Assignee and Human Owner UI is complete.

Checklist

  • bun run verify is green, all four checks
  • Tests added or updated for the implemented runtime and lifecycle behavior
  • Missing Web and Owner workflows have failing regressions and complete coverage
  • No comments added to code, and no em-dash characters anywhere
  • No any, no non-null assertions
  • External input is parsed with a Zod schema from @orbit/shared
  • All authorization is enforced on the server through packages/shared/src/policy, including the remaining lifecycle action checks
  • Docs updated if behaviour, configuration or setup changed
  • bun run db:release and bun run db:check-drift passed against the target database before this ships. The isolated acceptance target passed; the deployment target remains a release-time check.

Anything reviewers should know

  • All four Agent feature gates default to off. Agent issue writes require all four gates and a separate persistent Outbox Worker; Cron provides recovery rather than the primary delivery process.
  • 0030_green_shaman.sql appends to the official migration chain. Existing upstream migrations are unchanged. The abandoned local development migration lineage is not a supported upgrade path.
  • Migrating invalidates legacy unbound MCP credentials even while feature gates are off. Existing clients must reconnect through consent.
  • Personal Agents do not consume seats or membership roles. Each member can have two active Personal Agents per workspace; disconnected identities still count while active. A Human issue owner can differ from the Agent owner.
  • me and list_my_issues keep their Human meanings; agent and list_agent_issues refer to the current Agent. Agent attribution covers issue mutations; comments, attachments, and documents retain Human attribution.
  • Owner departure deletes the Personal Agent in product terms and clears open Agent assignments, while tombstones and closed history remain. Resume requires fresh consent and does not restore assignments.
  • The three unchanged browser skips are rich-editor round-trip, synthetic mouse dragging, and notification conversations with their gate disabled. Hosted CI, production OAuth/S3, the public network entry point, and production deployment checks remain to be completed.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Thanks for your first pull request to Orbit.

Two things that will save you a review round: bun run verify runs the
same four checks CI does, and the repo has no comments in code by policy,
so bun run check-comments will flag any you added out of habit.

A maintainer will review this shortly. Ask anything on the thread.

@github-actions github-actions Bot added documentation Docs, the README, or anything that explains Orbit tests Test coverage and test infrastructure area: web The Next.js app and its UI area: realtime The socket, the hub, scopes and fan-out area: mcp The MCP server, its tools and its OAuth area: database Schema, migrations, queries, seed area: auth Sign-in, sessions, passkeys, OAuth area: policy Roles, permissions and authorization area: issues Issues, lists and boards labels Sep 30, 2026
@github-actions github-actions Bot added area: integrations GitHub, Slack and webhooks ci Workflows, tooling and repo automation dependencies Dependency updates labels Sep 30, 2026
@imshashank

Copy link
Copy Markdown
Contributor

This can be something amazing; you are basically adding an agent directly to Orbit. Is there a design doc?
Also look at Yodu; it's a harness built on top of OpenClaw and uses existing claude/codex subscriptions.

Initialize unit databases through release migrations and isolate package lanes. Keep Next on its Node shebang when Playwright runs under Bun. Assign HTTP MCP tokens at their effective authorization stages.
@yxr-2025

yxr-2025 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@imshashank

My ultimate goal is to let agents join a team’s existing workflow through MCP and become real collaborators in Orbit. The team should be able to see who is doing the work, which human remains responsible for the outcome, when help is needed, and which results need review.

Both design documents are now included in the latest PR update:

Yodu offers useful ideas around work handoffs, visibility into blockers, result review, and separating authorization from execution. I’d like to learn from those ideas as Orbit’s agent collaboration model develops.

For Orbit, I’d keep agent execution in external runtimes, while Orbit handles tasks, permissions, accountability, and human-agent collaboration. The first step is members bringing their own Personal Agents through MCP. The owner controls delegation, and the first version does not support other members directly invoking someone else’s agent.

Later, I’d like to explore team-shared Workspace Agents, execution sessions, progress updates, and requests for human input. These need separate design and agreement with you. I’m not assuming they are already approved or part of the current PR’s scope.

Does starting with owner-operated Personal Agents over MCP fit the scope you have in mind for #215? I’d like to confirm that first-stage boundary with you, while leaving shared Workspace Agents and execution orchestration for separate proposals.

English isn’t my strong suit, so I used GPT to help translate this reply.

@imshashank imshashank 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.

Thanks for the design docs, they made this much easier to review. Here is an early pass, since you asked for one on the draft.

What already looks right. The core permission model matches what we agreed on #215. Issue writes re-read the member, the agent identity and the grant FOR UPDATE inside the write transaction, then check through policy. So an owner demoted to guest, removed from the team or removed from the workspace takes the agent's write access with them, and there are tests for it. Assigning a personal agent is limited to its owner or the agent itself, across web create, PATCH and bulk. Tenant isolation is backed by a composite FK. The lock order is consistent, and the pause-vs-create and token-refresh races have real two-connection tests. Nice work.

What would break production today. These matter more than any code-level detail, because each one hits every existing user while all four feature gates are still off:

  1. The migration breaks issue creation on the code that's deployed. We run db:release against production before merging, so main's code runs on the new schema for a while. issue_creator_actor_check requires exactly one of creator_user_id and creator_agent_id, but main only writes creator_id, and the migration has a one-time backfill with no trigger keeping the columns in sync. In that window, every issue create fails the check, including each new workspace's starter issues. Dropping mcp_grant_client_user_unique also breaks main's consent upsert, which conflicts on (client_id, user_id). This needs an expand/contract split: nullable actor columns and dual-write or compat triggers first, then the CHECKs and the drops in a later migration once the new code is live.

  2. Every MCP connection drops on deploy, and nobody can reconnect while the gates are off. The migration revokes every grant without an agent_identity_id, which is every existing grant, and deletes their access tokens. Meanwhile the consent page shows "invalid or expired" unless agent_identity_read and agent_consent are both on, and finalizeMcpConsent refuses in the same case. So every Claude and ChatGPT connection breaks on deploy and stays broken until we flip the gates. Legacy grants need to keep working until consent is switched on, and revoking them should be a separate, announced step.

  3. MCP issue writes are refused for everyone with gates off. Every connection is now built as 'agent', and support.ts refuses agent issue writes unless all the gates are on, so create_issue and update_issue stop working for every current user. move_to_cycle is in the mutation list but missing from the agent allowlist, so it stays blocked even with the gates on.

  4. Human issue writes now always go through the outbox, gate or not. That changes main's behaviour in three ways:

    • publish returns before it stamps originClientId, so a tab's own echo arrives as a foreign change, which risks flicker and overwritten optimistic edits next to #479's undo.
    • With the gate off, the cron route returns 503 every minute and nothing retries a failed delivery, so a Redis blip loses the event for good.
    • Delivered rows are never pruned.

    Please keep the human path untouched until the outbox is ready to own it.

Design questions for me rather than for you:

  • The PR rewrites CLAUDE.md to make a persistent outbox worker mandatory. Orbit ships as one Vercel project with no long-running process. In-request drain plus the per-minute cron already deliver on Vercel, so I would rather the worker be optional (self-host only) than required, and keep CLAUDE.md's deployment section as it is.
  • #455 adds a generic idempotency table for every MCP write tool, and this PR adds its own for create_issue. Doing it inside the transaction, as you do, is stronger for creates, but we shouldn't ship two. Let's settle which one wins before either merges.

Things main has moved on since.

  • Merging main now conflicts in issue-service.ts, tools/issues.ts and docs/mcp.md.
  • #508 just added create_sub_issues and bulk_update_issues, which take assigneeId, so they need the agent context too.
  • mark_issue_duplicate isn't in ISSUE_MUTATION_TOOLS and runs as the human. You already flagged that.
  • Your migration is 0030, which collides with open PRs #448 and #485, so it will need regenerating against whatever lands first.

Suggested split. 35k lines in one PR is too much to review safely. Something like:

  1. Expand-only schema with dual-write: no CHECKs, no credential changes.
  2. The canonical actor reader, plus client schema and UI rendering.
  3. Identity, consent and grant binding, with legacy grants still working.
  4. Agent issue writes and responsibility, including move_to_cycle, mark_issue_duplicate and the #508 bulk tools.
  5. The outbox on its own.
  6. The contract migration.

Each of those can merge and deploy safely on its own. Happy to talk through the order on #215.

CREATE INDEX "issue_owner_user_idx" ON "issue" USING btree ("owner_user_id");--> statement-breakpoint
CREATE INDEX "issue_activity_assignee_attribution_idx" ON "issue_activity" USING btree ("organization_id","issue_id","created_at") WHERE "issue_activity"."field" = any (array['assigneeId', 'assignee']);--> statement-breakpoint
ALTER TABLE "mcp_grant" ADD CONSTRAINT "mcp_grant_active_binding_check" CHECK (("mcp_grant"."revoked_at" is null and "mcp_grant"."agent_identity_id" is not null and "mcp_grant"."user_id" is not null) or ("mcp_grant"."revoked_at" is not null and ("mcp_grant"."agent_identity_id" is not null or ("mcp_grant"."revoke_reason" is not null and "mcp_grant"."revoke_reason" = 'agent_identity_required'))));--> statement-breakpoint
ALTER TABLE "issue" ADD CONSTRAINT "issue_creator_actor_check" CHECK (("issue"."creator_user_id" is not null and "issue"."creator_agent_id" is null) or ("issue"."creator_user_id" is null and "issue"."creator_agent_id" is not null));--> statement-breakpoint

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.

Main's code only writes creator_id, and there's no trigger keeping creator_user_id in sync after the one-time backfill above. So once this migration is on production (we run it before merging), every issue create from the deployed code fails this check. Please move the CHECKs to a later contract migration and dual-write in the meantime.

--> statement-breakpoint
ALTER TABLE "mcp_grant" ALTER COLUMN "principal_name_snapshot" SET NOT NULL;
--> statement-breakpoint
UPDATE "mcp_grant"

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.

This revokes every existing grant, since none has an agent_identity_id yet, and the DELETE below removes their tokens. With the consent gates off by default, nobody can reconnect afterwards. Legacy grants need to keep working until consent is enabled, then be revoked in a separate step.

if (
consentCode === undefined ||
!agentFeatureEnabled('agent_identity_read') ||
!agentFeatureEnabled('agent_consent')

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.

With the gates off (the default), this shows "invalid or expired" to everyone. Combined with the migration revoking every grant, it means no user can reconnect their AI client after deploy.

identity.principal,
identity.scopes,
workspaceInstructions,
'agent',

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.

Every connection is built as an agent, so with the gates off support.ts refuses create_issue and update_issue for every current user. Unbound legacy grants should keep the human path until agent writes are enabled.

@yxr-2025

yxr-2025 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@imshashank
Thanks for the detailed review. I’ll follow the suggested split, starting with an expand-only schema PR that preserves existing issue creation, consent, and MCP connections. I’ll include compatibility tests against main’s current behavior and defer the contract changes until the new code is deployed.

Copy link
Copy Markdown
Contributor

Closing this since it has been split into #516, #523, #524 and #525 as agreed, and the open threads here are being answered in those. #516 is approved and goes in once the production release is run. Please keep the design docs linked from the split PRs so the discussion is not lost.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth Sign-in, sessions, passkeys, OAuth area: database Schema, migrations, queries, seed area: integrations GitHub, Slack and webhooks area: issues Issues, lists and boards area: mcp The MCP server, its tools and its OAuth area: policy Roles, permissions and authorization area: realtime The socket, the hub, scopes and fan-out area: web The Next.js app and its UI ci Workflows, tooling and repo automation dependencies Dependency updates documentation Docs, the README, or anything that explains Orbit tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants