Skip to content

Add workspace role provisioning - #63

Merged
russellhaering merged 4 commits into
mainfrom
russell_h/linear-role-provisioning
Nov 22, 2026
Merged

russellhaering merged 4 commits into
mainfrom
russell_h/linear-role-provisioning

Conversation

@russellhaering

Copy link
Copy Markdown
Contributor

Summary

  • Provision mutually exclusive Linear workspace roles with userChangeRole; requires an Admin-permission API key from a workspace admin/owner, with an owner's key for owner.
  • Read the current role for idempotency. Revoke resets matching roles to user (revoking guest increases access); baseline user revocation and app-account/app changes are unsupported.
  • Check GraphQL errors, surface permission failures, preserve rate-limit annotations, and update capabilities and setup documentation.

Validation

go test ./..., uncached verbose tests, CI JSON/coverage tests, scoped race tests, go build ./cmd/baton-linear, make lint, shared-workflow MDX validation, and offline capability/config checks pass. HTTP fixtures cover success, idempotency, invalid inputs, permission/rate-limit failures, and unchanged team operations. No live-provider testing.

russellhaering and others added 2 commits November 22, 2026 17:15
Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@russellhaering
russellhaering requested a review from a team November 22, 2026 17:22
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 09590c7a74c9

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: full
View review run

Review Summary

This PR makes the role resource provisionable. Grant reads the user's current role with a fresh user(id) query and returns GrantAlreadyExists when it already matches; otherwise it calls userChangeRole. Revoke resets a matching guest/admin/owner role to user and returns GrantAlreadyRevoked when the role doesn't match. It rejects app accounts and the app role, and refuses to revoke the baseline user role. The PR also adds a per-org exclusion group to role entitlements, sets a native ExternalId on user resources, adds a GraphQL-error-aware request path (pkg/linear/roles.go) that maps errors to RATELIMITED→Unavailable, 403/FORBIDDEN→PermissionDenied and 401→Unauthenticated, and updates the README, docs/connector.mdx and capabilities.

I scanned the full PR diff for security and correctness and read the surrounding sync code (user.go role grants, client.go, the vendored uhttp Do/WrapErrorsWithRateLimitInfo). I applied the repo-local criteria:

  • PR1–PR3: Correct. WHO comes from principal.Id, WHAT from entitlement.Resource.Id, and no context comes from ParentResourceId.
  • P3: Idempotency annotations are present.
  • E2: Rate limits map to Unavailable.
  • R13: WithExternalID is justified because roleProvisioningTarget reads GetExternalId().
  • D1–D4: The docs are updated.
  • B-series: No breaking change. Sync paths and the scopes they need are unchanged.
  • A, C, S: Not applicable. There is no new logging, spans or List/Grants change.

WrapErrorsWithRateLimitInfo dereferences resp, but this can't panic: response.Errors is only populated after Do has returned a non-nil resp. No coverage gaps.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence): pkg/linear/roles.go:78 and :132. The userChangeRole success=false result and the catch-all GraphQL error are plain fmt.Errorf values without a gRPC status code, so provisioning failures show up as codes.Unknown (criteria E3/P4).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/linear/roles.go`:
- Around line 78: `userChangeRole returned success=false` is a plain fmt.Errorf with no gRPC code. Return `status.Error(codes.Internal, "baton-linear: userChangeRole returned success=false")` (or another appropriate code) so Grant/Revoke failures carry a status code.
- Around line 132: the catch-all `role request failed` GraphQL error is a plain fmt.Errorf. Wrap it with a gRPC status (e.g. `status.Errorf(codes.Unknown, ...)` or a more specific code if Linear's extensions identify one). Update the `codes.Unknown` expectations in pkg/connector/role_test.go if the code changes.

Comment thread pkg/linear/roles.go Outdated
return rlData, err
}
if !data.UserChangeRole.Success {
return rlData, fmt.Errorf("baton-linear: userChangeRole returned success=false")

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.

🟡 Suggestion: Two errors here have no gRPC status code, so Grant/Revoke report them as codes.Unknown: this success=false result, and the catch-all GraphQL error at line 132. Repo criteria E3/P4 ask provisioning errors to carry a code, e.g. status.Error(codes.Internal, ...) here and codes.Unknown/FailedPrecondition as appropriate at L132, so C1 shows the failure correctly. (Confidence: medium; non-blocking.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 0ad6640. Inferred unsuccessful/missing-data responses now carry Internal, and unclassified GraphQL errors carry an explicit Unknown status. Decode failures use uhttp.WrapErrors. Fixtures now assert status.FromError recognizes these errors, in addition to checking their codes. Full tests, scoped race tests, build, and lint pass.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 0ad66403b94d

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: full
View review run

Review Summary

This PR makes the role resource provisionable. Grant reads the user's current role with a fresh user(id) query and returns GrantAlreadyExists when it already matches; otherwise it calls userChangeRole. Revoke resets a matching guest/admin/owner role to user and returns GrantAlreadyRevoked when the role doesn't match. It rejects app accounts and the app role, and refuses to revoke the baseline user role. The PR also adds a per-org exclusion group to role entitlements, sets a native ExternalId on user resources, adds a GraphQL-error-aware request path (pkg/linear/roles.go) that maps errors to RATELIMITED→Unavailable, 403/FORBIDDEN→PermissionDenied and 401→Unauthenticated, and updates the README, docs/connector.mdx and capabilities.

I scanned the full PR diff for security and correctness and read the surrounding sync code (user.go role grants, client.go, the vendored uhttp Do/WrapErrorsWithRateLimitInfo). I applied the repo-local criteria:

  • PR1–PR3: Correct. WHO comes from principal.Id, WHAT from entitlement.Resource.Id, and no context comes from ParentResourceId.
  • P3: Idempotency annotations are present.
  • E2: Rate limits map to Unavailable.
  • R13: WithExternalID is justified because roleProvisioningTarget reads GetExternalId().
  • D1–D4: The docs are updated.
  • B-series: No breaking change. Sync paths and the scopes they need are unchanged.
  • A, C, S: Not applicable. There is no new logging, spans or List/Grants change.

WrapErrorsWithRateLimitInfo dereferences resp, but this can't panic: response.Errors is only populated after Do has returned a non-nil resp. No coverage gaps.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence): pkg/linear/roles.go:78 and :132. The userChangeRole success=false result and the catch-all GraphQL error are plain fmt.Errorf values without a gRPC status code, so provisioning failures show up as codes.Unknown (criteria E3/P4).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/linear/roles.go`:
- Around line 78: `userChangeRole returned success=false` is a plain fmt.Errorf with no gRPC code. Return `status.Error(codes.Internal, "baton-linear: userChangeRole returned success=false")` (or another appropriate code) so Grant/Revoke failures carry a status code.
- Around line 132: the catch-all `role request failed` GraphQL error is a plain fmt.Errorf. Wrap it with a gRPC status (e.g. `status.Errorf(codes.Unknown, ...)` or a more specific code if Linear's extensions identify one). Update the `codes.Unknown` expectations in pkg/connector/role_test.go if the code changes.

Reviewed commit: 09590c7a74c9

@github-actions github-actions 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.

No blocking issues found — see the full review report

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 0ad66403b94d

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: incremental since 09590c7
View review run

Review Summary

The PR adds Grant/Revoke for Linear workspace roles. It reads the user's current role with a live GraphQL query, then calls userChangeRole. It also adds an external ID to user resources and updates the docs and capabilities. The new commit attaches explicit gRPC codes to role errors in pkg/linear/roles.go: Internal for success=false, no data, and decode failures, and Unknown for the catch-all GraphQL error. It also updates the matching test expectations and adds a check that those errors carry an explicit status.

The full PR diff was scanned for security and correctness. The repo-local criteria were applied:

  • PR1–PR3: WHO comes from principal.Id/ExternalId and WHAT from entitlement.Resource.Id, with no ParentResourceId context.
  • E2/E3: codes checked.
  • S/R7: no change to List, Entitlements or Grants; role Grants() returning empty is unchanged from base.
  • L, T and J: these sections are not affected (no new logging or spans).

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence): pkg/linear/roles.go:131-133. The GraphQL-errors catch-all returns before requestErr is checked. A 5xx response with an errors body therefore becomes codes.Unknown instead of uhttp's Unavailable, so pkg/retry will not retry Grant/Revoke on a transient Linear outage (E2).

Resolved prior findings

  • Fixed: "success=false and the catch-all GraphQL error have no gRPC code". pkg/linear/roles.go:78 now returns status.Error(codes.Internal, …) and :132 returns status.Errorf(codes.Unknown, …). Both are covered by pkg/connector/role_test.go:55,59 and the explicit-status check at :134-139.
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/linear/roles.go`:
- Around line 131-133: The catch-all `if len(response.Errors) > 0` returns codes.Unknown before `requestErr` is checked. A 5xx response that also has a GraphQL errors body therefore loses uhttp's codes.Unavailable, and the retryer will not back off. Check for `resp != nil && resp.StatusCode >= 500 && requestErr != nil` first and return `requestErr`, keeping the GraphQL message if useful. Alternatively, use codes.Unknown only when `requestErr` is nil or the status is 4xx. Add a role_test.go case for HTTP 502 with an errors body that expects codes.Unavailable.

Comment thread pkg/linear/roles.go Outdated
}
}
if len(response.Errors) > 0 {
return rlData, status.Errorf(codes.Unknown, "baton-linear: role request failed: %s", response.Errors[0].Message)

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.

🟡 Suggestion (medium confidence): The catch-all runs before requestErr is checked. So if a 5xx response also has a GraphQL errors body, it comes back as codes.Unknown and the Unavailable code from uhttp is lost. Per E2, pkg/retry only retries Unavailable, so Grant/Revoke would not back off on a transient Linear outage. Return requestErr first when resp.StatusCode >= 500, or only fall back to Unknown when requestErr is nil or a 4xx.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 494f19b1a948

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: incremental since 09590c7
View review run

Review Summary

The PR adds Grant/Revoke for Linear workspace roles. It reads the user's current role with a live GraphQL query, then calls userChangeRole. It also adds an external ID to user resources and updates the docs and capabilities. The new commit attaches explicit gRPC codes to role errors in pkg/linear/roles.go: Internal for success=false, no data, and decode failures, and Unknown for the catch-all GraphQL error. It also updates the matching test expectations and adds a check that those errors carry an explicit status.

The full PR diff was scanned for security and correctness. The repo-local criteria were applied:

  • PR1–PR3: WHO comes from principal.Id/ExternalId and WHAT from entitlement.Resource.Id, with no ParentResourceId context.
  • E2/E3: codes checked.
  • S/R7: no change to List, Entitlements or Grants; role Grants() returning empty is unchanged from base.
  • L, T and J: these sections are not affected (no new logging or spans).

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence): pkg/linear/roles.go:131-133. The GraphQL-errors catch-all returns before requestErr is checked. A 5xx response with an errors body therefore becomes codes.Unknown instead of uhttp's Unavailable, so pkg/retry will not retry Grant/Revoke on a transient Linear outage (E2).

Resolved prior findings

  • Fixed: "success=false and the catch-all GraphQL error have no gRPC code". pkg/linear/roles.go:78 now returns status.Error(codes.Internal, …) and :132 returns status.Errorf(codes.Unknown, …). Both are covered by pkg/connector/role_test.go:55,59 and the explicit-status check at :134-139.
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/linear/roles.go`:
- Around line 131-133: The catch-all `if len(response.Errors) > 0` returns codes.Unknown before `requestErr` is checked. A 5xx response that also has a GraphQL errors body therefore loses uhttp's codes.Unavailable, and the retryer will not back off. Check for `resp != nil && resp.StatusCode >= 500 && requestErr != nil` first and return `requestErr`, keeping the GraphQL message if useful. Alternatively, use codes.Unknown only when `requestErr` is nil or the status is 4xx. Add a role_test.go case for HTTP 502 with an errors body that expects codes.Unavailable.

Reviewed commit: 0ad66403b94d

@github-actions github-actions 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.

No blocking issues found — see the full review report

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 494f19b1a948

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: incremental since 0ad6640
View review run

Review Summary

The new commit changes the order of checks in doRoleRequest (pkg/linear/roles.go:131-136). The uhttp requestErr is now returned before the GraphQL-errors catch-all. Non-2xx responses keep uhttp's gRPC code: 5xx → Unavailable (retryable), 400 → InvalidArgument. Only a 2xx response with an errors body still maps to codes.Unknown. role_test.go adds 503-with-errors and 500-empty cases, both expecting Unavailable. It also updates the 400 expectation and limits the rate-limit-annotation check to non-5xx statuses. The no-request assertion now keys on role ("invalid"/"app") instead of on the code. It covers the same cases as before.

I scanned the full PR diff (README, capabilities, docs, role.go, role_test.go, user.go, roles.go) for security and correctness. The incremental artifact is complete: nothing was dropped or truncated. I applied the repo-local criteria:

  • E2: 5xx/429 now land on Unavailable, matching uhttp's GrpcCodeFromHTTPStatus.
  • E3/P4: provisioning errors carry explicit status codes.
  • PR1–PR3: WHO comes from the principal ID and WHAT from the entitlement resource ID. Nothing reads ParentResourceId.
  • S/R7: List/Entitlements/Grants are unchanged.
  • Section A: the change adds no new logging.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

Resolved prior findings

  • Fixed: "success=false and the catch-all GraphQL error have no gRPC code" (thread already handled by a person). pkg/linear/roles.go:78 returns codes.Internal and :135 returns codes.Unknown. Both have explicit statuses, and role_test.go asserts them.
  • Fixed: the prior summary-only finding that a 5xx response with a GraphQL errors body became codes.Unknown instead of Unavailable. pkg/linear/roles.go:131-133 now returns requestErr before the catch-all. The new role_test.go cases "server error remains retryable" (503) and "empty server error remains retryable" (500) cover this.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Connector PR Review: Add workspace role provisioning

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base a846afaefb30.
Review mode: incremental since 0ad6640
View review run

Review Summary

The new commit changes the order of checks in doRoleRequest (pkg/linear/roles.go:131-136). The uhttp requestErr is now returned before the GraphQL-errors catch-all. Non-2xx responses keep uhttp's gRPC code: 5xx → Unavailable (retryable), 400 → InvalidArgument. Only a 2xx response with an errors body still maps to codes.Unknown. role_test.go adds 503-with-errors and 500-empty cases, both expecting Unavailable. It also updates the 400 expectation and limits the rate-limit-annotation check to non-5xx statuses. The no-request assertion now keys on role ("invalid"/"app") instead of on the code. It covers the same cases as before.

I scanned the full PR diff (README, capabilities, docs, role.go, role_test.go, user.go, roles.go) for security and correctness. The incremental artifact is complete: nothing was dropped or truncated. I applied the repo-local criteria:

  • E2: 5xx/429 now land on Unavailable, matching uhttp's GrpcCodeFromHTTPStatus.
  • E3/P4: provisioning errors carry explicit status codes.
  • PR1–PR3: WHO comes from the principal ID and WHAT from the entitlement resource ID. Nothing reads ParentResourceId.
  • S/R7: List/Entitlements/Grants are unchanged.
  • Section A: the change adds no new logging.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

Resolved prior findings

  • Fixed: "success=false and the catch-all GraphQL error have no gRPC code" (thread already handled by a person). pkg/linear/roles.go:78 returns codes.Internal and :135 returns codes.Unknown. Both have explicit statuses, and role_test.go asserts them.
  • Fixed: the prior summary-only finding that a 5xx response with a GraphQL errors body became codes.Unknown instead of Unavailable. pkg/linear/roles.go:131-133 now returns requestErr before the catch-all. The new role_test.go cases "server error remains retryable" (503) and "empty server error remains retryable" (500) cover this.

Reviewed commit: 494f19b1a948

@github-actions github-actions 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.

No blocking issues found — see the full review report

@russellhaering
russellhaering merged commit ac56688 into main Nov 22, 2026
11 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