Skip to content

fix: decode Drata session listings with numeric ids - #4745

Merged
daviddanialy merged 5 commits into
mainfrom
daviddanialy/fix-drata-session-list-decode
Jul 30, 2026
Merged

fix: decode Drata session listings with numeric ids#4745
daviddanialy merged 5 commits into
mainfrom
daviddanialy/fix-drata-session-list-decode

Conversation

@daviddanialy

@daviddanialy daviddanialy commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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.ID as 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

  • Session ids now use the same tolerant number-or-string decoding (flexID) that resource ids already had — the identical trap, anticipated once but not extended.
  • The decode branch (envelope vs bare array) is picked by payload shape instead of try-and-fall-back, so a decode failure reports the envelope's real error; a null/absent data field counts as an empty sweep.
  • The test fake now serves the observed production shape (numeric 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_PROGRESS filter (it returned a CANCELED session), 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.

  • Bug Fixes
    • Decode session lists with numeric or string IDs via flexID; choose envelope vs array by payload shape; treat null/missing data as empty and surface real decode errors.
    • Restrict flexID to scalar JSON IDs (string/number/null); reject object/array/bool values and decode string escapes correctly to prevent malformed path segments.
    • Clear empty fleets by listing and deleting /records via clearEvidenceRecords (sessions cannot complete with no records).
    • Parse per-record upload results; if any record has an error, fail the push with the schema message instead of publishing a partial dataset.

Written for commit 1350844. Summary will update on new commits.

Review in cubic

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>
@daviddanialy daviddanialy added the bug Something isn't working label Jul 30, 2026
@daviddanialy
daviddanialy requested a review from a team as a code owner July 30, 2026 17:02
@daviddanialy daviddanialy added the bug Something isn't working label Jul 30, 2026
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1350844

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
server Patch

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

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/deviceintegrations/providers/drata/drata.go
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>
@blacksmith-sh

This comment has been minimized.

daviddanialy and others added 2 commits July 30, 2026 10:28
… 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>
@daviddanialy daviddanialy added the review:bypass Merge without human review approval. Required status checks still apply. label Jul 30, 2026

@gram-bot gram-bot 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.

Auto-approved: review:bypass label applied by @daviddanialy. Required status checks still gate this merge.

@daviddanialy
daviddanialy added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit d5e1ea6 Jul 30, 2026
46 checks passed
@daviddanialy
daviddanialy deleted the daviddanialy/fix-drata-session-list-decode branch July 30, 2026 18:15
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working review:bypass Merge without human review approval. Required status checks still apply.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant