fix: decode Drata session listings with numeric ids - #4745
Merged
Conversation
The stranded-session sweep declared sessionRef.ID as a string, but the production session-list endpoint returns numeric ids, so the envelope decode failed and the bare-array fallback masked it with a misleading error — breaking every evidence push. Session ids now share the tolerant flexID decoding resource ids already had, a null or absent data field counts as an empty sweep, and the decode branch is picked by payload shape so the real error surfaces. The test fake now serves the observed production shape. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…iddanialy/fix-drata-session-list-decode
🦋 Changeset detectedLatest commit: 1350844 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Verified against the live API: completing a session with no records is refused with 422, so an empty fleet now clears stale evidence by enumerating and deleting the resource's records directly — the only truthful path when every device departs. Uploads also return 2xx while rejecting individual records via per-record error results; those now fail the push with the schema-validation message instead of publishing a session missing part of the fleet. The fake mirrors all three behaviors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
… safety invariants Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cubic P2: ids become URL path segments, so an object/bool/array id must fail the decode loudly instead of quote-trimming into a bogus cancel request; string ids now decode JSON escapes correctly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Auto-approved: review:bypass label applied by @daviddanialy. Required status checks still gate this merge.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Live Drata evidence pushes fail with
push coverage: clear stranded drata session: decode session list: json: cannot unmarshal object into Go value of type []drata.sessionRef.The stranded-session sweep declared
sessionRef.IDas a string, but Drata's (undocumented) session-list endpoint returns numeric ids:{"data":[{"id":2,"sessionId":"gram-...","status":"CANCELED",...}],"pagination":{"cursor":null}}The envelope decode failed on the number→string mismatch, and the bare-array fallback then masked the real error with the misleading one above. Every push hit this, because the sweep runs first.
Fix
flexID) that resource ids already had — the identical trap, anticipated once but not extended.null/absentdatafield counts as an empty sweep.id, extra fields, pagination envelope), plus a table test pinning all tolerated shapes — including the numeric-id-only fallback that names the cancel URL.Also verified live: the endpoint ignores the
?status=IN_PROGRESSfilter (it returned aCANCELEDsession), so the sweep's in-loop status re-check is load-bearing; the comment now records that.🤖 Generated with Claude Code
Summary by cubic
Fixes Drata evidence pushes by decoding session listings with numeric IDs, clearing empty fleets by deleting records, and failing pushes when uploads reject records. Also tightens ID decoding to accept only scalar JSON values to avoid bogus API calls.
flexID; choose envelope vs array by payload shape; treat null/missingdataas empty and surface real decode errors.flexIDto scalar JSON IDs (string/number/null); reject object/array/bool values and decode string escapes correctly to prevent malformed path segments./recordsviaclearEvidenceRecords(sessions cannot complete with no records).error, fail the push with the schema message instead of publishing a partial dataset.Written for commit 1350844. Summary will update on new commits.