← Back to Pull requests

Delegation: role bindings, groups and preset roles (twin of cloud#6665) #343

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 26, 2026 03:23 UTC
Author

What

The relay-control twin of AgentWorkforce/cloud#6665. It includes Cloud's review fixes 784b9415a, 6ecf6934f, c1de4d1f1, f37fb2a14 and 4acae109e.

Delegation becomes an IAM-like table:

  • who: one agent, a custom group, a connector kind, or every Relay agent;

  • which role: Trusted, Standard, Read-only, a custom role, or excluded;

  • what scope: everything the owner has standing over, or some repos;

  • until when: no expiry by default.
  • Built to Khaliq's answers in #owner-decisions 251526750352171008.

    This PR carries migration 0099 and an operator data step (the role seed). Do not merge, migrate or deploy without Khaliq's direct go. merge-train:hold stays on.

    Same as Cloud

  • Presets (src/delegation/roles.ts):
  • | Preset | Classes | Ask first | Limits |
    |---|---|---|---|
    | Trusted | merge, pr_ops, external_comms, deploy, release, destructive, secret_change, spend | deploy, release, destructive, secret_change, spend | merge requires ci_green and mergeable |
    | Standard | pr_ops, merge, deploy, destructive, secret_change | merge, deploy, destructive, secret_change | none |
    | Read-only | pr_ops | none | comment only |

    A parity test pins the presets and the class descriptions to Cloud's strings.

  • Precedence: explicit grant, then agent binding, then custom group (the strictest of two), then connector kind, then Relay agents. Nothing is unioned.

  • - An excluded binding gives nothing and never falls through.
    - Two groups with no overlapping classes or repos cover nothing (coversNothing), never every repo.
  • No inheritance: a launched agent gets Read-only, within its root binding's repos and expiry, unless its own group or binding says otherwise.

  • Legacy rules: a legacy rule keeps its old meaning until it is converted.

  • - Conversion happens through the role seed (dry run by default) or a PATCH.
    - Conversion carries the rule's owner_excluded exclusions into excluded agent bindings.
    - A legacy rule and a Relay agents binding never stand together: each refuses the other with 409 binding_exists.
  • Re-resolution: every binding, group or exclusion write re-resolves the owner's system grants at once, under an owner-scoped advisory lock. A materialization takes that lock shared and decides under it. A new grant is dated no earlier than:

  • - its bindings' creation and changes;
    - a group member's joining;
    - any earlier grant's end.
  • Answer 3: a Tier D approval from another owner's grant is refused with tier_o_required for a class the acting agent must ask its own owner about. This is checked before the deciding transaction and again inside it. approval.redeemed records tier and minter.

  • Routes: delegates/roles (each class with its description), bindings, bindings/{id}, groups, groups/{id}, agents, plus POST /internal/v1/delegation/role-seed. The field names, error codes and recommendation match Cloud's.

  • Admins: an admin acting for another owner may only exclude one agent (or use the existing grant revoke and revoke-all). Deleting a binding or a group, and every group change, is refused with 403.

  • Errors: any thrown error, a 40P01 deadlock included, answers unavailable at attest and redeem.
  • Where relay-control differs, and why

    1. Required conditions fail closed. relay-control reads no GitHub state, so ci_green and mergeable answer condition_unavailable. A Trusted merge cannot be redeemed through relay-control. Cloud checks them live.
    2. The connector kinds include cursor-cloud. relay-control's classifier knows it and Cloud's does not.
    3. A legacy rule's updated_at does not date new grants. In relay-control a legacy rule's Tier O PUT bumps updated_at and updates its grants in place, as before roles existed. Only a role binding's change dates a new grant. Cloud's decisionSince counts the legacy rule's updated_at too.

    Migration

    0099_delegation_role_bindings.sql is additive:

  • the binding columns, with defaults that read every existing row as a legacy rule;

  • the two group tables;

  • the live-principal index, replacing the live-owner index. It is a superset for legacy rows.
  • The two tables are added to CONTROL_TABLES. The schema manifest was regenerated with the PostgreSQL 15 dry-run harness; the diff is exactly 0099's objects (30 added, the old index removed). openapi.yaml and docs/owner-delegates.md are updated.

    Tests

  • test/delegation-role-bindings.test.ts: parity, precedence, no inheritance, coversNothing and the overlap, the op filter, field rules, the deadlock mapping.

  • test/delegation-role-bindings-postgres.test.ts (real PostgreSQL):

  • - precedence and immediate re-resolution, exclusion with no fall-through, no inheritance with group promotion and demotion;
    - two non-overlapping groups, the legacy guards, removal falling through, the duplicate principal race, a write racing a materialize in both orders;
    - the seed (dry run, apply, idempotent, skip), group revoke, legacy exclusions carried, group dating, the locked acting read.
  • test/owner-delegates.test.ts (HTTP):

  • - the route contract, exclusion through DELETE /delegates/{id}, the redeem audit minter;
    - the cross-owner Tier D refusal at attest and redeem;
    - admin narrowing only, the legacy and Relay agents 409.
  • Typecheck is clean. The delegation, owner-delegates, migrations and cloud-import-verify suites pass 197/197 with TEST_DATABASE_URL set (0 skipped).
  • 🤖 Generated with Claude Code

    <!-- codesmith:footer -->
    ---
    <a href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798255412&installation_model_id=441654&pr_number=343&ref=codesmith_pr_footer&repository=AgentWorkforce%2Frelay-control&return_to=https%3A%2F%2Fgithub.com%2FAgentWorkforce%2Frelay-control%2Fpull%2F343&variant=see_it_in_action&signature=27bdc8733ec5e2a42a9d344d0209f4310dcfcbe6720906c1b4c317457cd918e1"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-light.svg"><img alt="See it in action" src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-see-it-in-action-v2-dark-3x.png" width="132" height="28"></picture></a>
    <sup><a href="https://app.blacksmith.sh/AgentWorkforce/codesmith/relay-control/pr/343?autoLogin=true&ref=codesmith_pr_footer">Open in [code]smith</a> · Need help on this PR? Tag <code>@codesmith-bot</code> with what you need.</sup>

    <!-- codesmith:autofix:disabled -->
    <!-- /codesmith:footer -->

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Delegation gains IAM-like role bindings: a binding gives one agent, a custom group, a connector kind, or every Relay agent a Trusted, Standard, Read-only, custom, or excluded role over all or some repos, with an optional expiry. This is the relay-control twin of Cloud's cloud#6665.

    Key behaviors

  • Precedence is explicit grant, agent binding, custom group (strictest of two), connector kind, then Relay agents; nothing is unioned, and an excluded binding grants nothing and never falls through.

  • A launched agent gets Read-only within its root binding's scope unless its own binding says otherwise.

  • Legacy rules keep their old meaning until converted by the role seed (dry run by default) or a PATCH, which carries exclusions into excluded agent bindings; a legacy rule and a Relay agents binding refuse each other with 409 binding_exists.

  • Every binding, group, or exclusion write re-resolves the owner's system grants under an owner-scoped advisory lock.

  • Required conditions fail closed: ci_green and mergeable answer condition_unavailable, so a Trusted merge cannot be redeemed through relay-control.
  • Migration

  • Migration 0099 is additive: binding columns, delegation_groups and delegation_group_members, and a live-principal index replacing the live-owner index.

  • The two new tables join CONTROL_TABLES; schema manifest, openapi.yaml, and docs/owner-delegates.md are updated.

  • Do not merge, migrate, or deploy without direct go; this carries migration 0099 and the role seed, and merge-train:hold stays on.
  • <sup>Written for commit 6c5df0618fdbaa5860d0db1fd0f36b9977dadb40. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/AgentWorkforce/relay-control/pull/343?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/AgentWorkforce/relay-control/343?returnTo=https%3A%2F%2Fgithub.com%2FAgentWorkforce%2Frelay-control%2Fpull%2F343&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: devin-ai-integration[bot] Review duration: 3m
    All Vouch review confidence checks passed
    Residual risk 0.44 = Change Risk (0.52) × (1 − Review Confidence (0.15)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 24% · Reviewer familiarity: 35%
    15%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #343"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 15.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 15.3% · Lower = rushed or shallow review
    15.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 44.1% · Moderate risk
    44.1%