TW-5383: support detaching a workspace policy via --policy-id ""#103
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CLI cannot detach a policy from a workspace. The Nylas v3 API requires
PATCH /v3/workspaces/{id}to carrypolicy_idas a valid UUID or JSONnull— empty string is rejected withpolicy_id must be a valid UUID or null (api.bad_request).UpdateWorkspaceRequest.PolicyID *stringwithomitemptyserialized&""as"policy_id":"", sonylas workspace update <id> --policy-id ""always failed and the only workaround was a raw curl call.This also shows up in
nylas agent overviewas⚠ Policy <id> no longer exists — plan maximums applywhen a policy is deleted while still attached: the dangling reference could not be cleared from the CLI.Fix
MarshalJSONondomain.UpdateWorkspaceRequest: aPolicyIDpointing at""serializes as JSONnull(detach);nilstill omits the field so rule-only updates don't touch the policy;rule_idsbehavior is unchanged — including&[]string{}→"rule_ids":[], which matches the previousomitemptysemantics and is required to clear the last rule.policy_idthrough as*string).nylas workspace updatehelp 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 literalnull.--policy-id "", confirmedpolicy_idgone, deleted the policy.make cigreen.Related docs
Jira: TW-5383