Skip to content

TW-5383: support detaching a workspace policy via --policy-id ""#103

Merged
qasim-nylas merged 1 commit into
mainfrom
feature/TW-5383-workspace-policy-detach
Jun 12, 2026
Merged

TW-5383: support detaching a workspace policy via --policy-id ""#103
qasim-nylas merged 1 commit into
mainfrom
feature/TW-5383-workspace-policy-detach

Conversation

@qasim-nylas

@qasim-nylas qasim-nylas commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

The CLI cannot detach a policy from a workspace. The Nylas v3 API requires PATCH /v3/workspaces/{id} to carry policy_id as a valid UUID or JSON null — empty string is rejected with policy_id must be a valid UUID or null (api.bad_request). UpdateWorkspaceRequest.PolicyID *string with omitempty serialized &"" as "policy_id":"", so nylas workspace update <id> --policy-id "" always failed and the only workaround was a raw curl call.

This also shows up in nylas agent overview as ⚠ Policy <id> no longer exists — plan maximums apply when a policy is deleted while still attached: the dangling reference could not be cleared from the CLI.

Fix

  • Custom MarshalJSON on domain.UpdateWorkspaceRequest: a PolicyID pointing at "" serializes as JSON null (detach); nil still omits the field so rule-only updates don't touch the policy; rule_ids behavior is unchanged — including &[]string{}"rule_ids":[], which matches the previous omitempty semantics and is required to clear the last rule.
  • Agent Studio's workspace PATCH handler gains detach support through the same marshaler (it passes policy_id through as *string).
  • nylas workspace update help text and flag description document the empty-string detach.
  • docs/commands/agent-policy.md: detach example added; the troubleshooting section no longer suggests swapping in another policy as the only way out.

Tests

  • TestUpdateWorkspaceRequest_PolicyIDWireFormat — table test pinning nil → omitted, ""null, value → string.
  • TestUpdateWorkspaceRequest_RulesAndPolicyTogether — pins "rule_ids":[] semantics (clears the last rule) and that both fields serialize together.
  • TestHTTPClient_UpdateWorkspace_DetachPolicy — adapter test asserting the PATCH body carries literal null.
  • Verified end-to-end against the live API: created a policy, attached it, detached with --policy-id "", confirmed policy_id gone, deleted the policy.
  • make ci green.

Related docs

Jira: TW-5383

The API requires policy_id to be a valid UUID or JSON null in
PATCH /v3/workspaces/{id} - empty string is rejected. A custom
MarshalJSON on UpdateWorkspaceRequest serializes a PolicyID pointing
at "" as null (detach), keeps nil omitting the field, and leaves
rule_ids behavior unchanged. Agent Studio workspace PATCH gains
detach support through the same marshaler. Docs and help text updated.
@qasim-nylas qasim-nylas requested a review from AaronDDM June 12, 2026 20:57

@AaronDDM AaronDDM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@qasim-nylas qasim-nylas merged commit adc4013 into main Jun 12, 2026
7 checks passed
@qasim-nylas qasim-nylas deleted the feature/TW-5383-workspace-policy-detach branch June 12, 2026 21:03
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.

2 participants