Skip to content

Add GitHub-anchored attachment variants to Attachment enum#1823

Merged
SteveSandersonMS merged 2 commits into
github:mainfrom
pallaviraiturkar0:add-github-attachment-variants
Jun 29, 2026
Merged

Add GitHub-anchored attachment variants to Attachment enum#1823
SteveSandersonMS merged 2 commits into
github:mainfrom
pallaviraiturkar0:add-github-attachment-variants

Conversation

@pallaviraiturkar0

@pallaviraiturkar0 pallaviraiturkar0 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What & why

The hand-written Rust Attachment enum in rust/src/types.rs (the type copilotd (de)serializes user-message attachments through) only knew about 5 variants: File, Directory, Selection, Blob, and GitHubReference. The CLI already renders 9 additional GitHub-anchored reference types, and the corresponding codegen structs already exist in rust/src/generated/api_types.rs, but because the hand-written enum was missing the variants they were silently dropped at the SDK boundary.

These reference types were added to support Dotcom Chat via:

  • github/copilot-agent-runtime#11244 — types contract
  • github/copilot-agent-runtime#11401 — prompt rendering

Both are merged. This PR closes the SDK-side gap.

What's in this PR

Adds the 9 variants to the Attachment enum (serde type → variant):

JSON type Variant
github_commit GitHubCommit
github_release GitHubRelease
github_actions_job GitHubActionsJob
github_repository GitHubRepository
github_file_diff GitHubFileDiff
github_tree_comparison GitHubTreeComparison
github_url GitHubUrl
github_file GitHubFile
github_snippet GitHubSnippet

Each variant inlines its fields (using the generated AttachmentGitHub* structs as the authoritative field spec), exactly mirroring the existing github_reference variant.

Nested object fields (repo pointer, file-diff sides, tree-comparison sides, snippet line range) use small local sub-structs that derive PartialEq, Eq and match the generated JSON shapes.

The three small helper match arms in display_name(), ensure_display_name(), and derived_display_name() were relaxed from an explicit Self::GitHubReference { .. } arm to a wildcard _, which is future-proof since the enum is #[non_exhaustive].

Testing

  • cargo check, cargo fmt, cargo clippy all clean.
  • Added a focused unit test (github_anchored_attachment_variants_round_trip) that, for each of the 9 variants, deserializes a representative JSON blob into Attachment, re-serializes it, and asserts the output has exactly one type key with the correct discriminator and round-trips with no data loss.

Scope

Touches only rust/src/types.rs (variants + sub-structs + test). No codegen was run; nothing under generated/ was modified.

Add the nine GitHub-anchored attachment variants (github_commit,
github_release, github_actions_job, github_repository, github_file_diff,
github_tree_comparison, github_url, github_file, github_snippet) to the
hand-written `Attachment` enum so copilotd no longer drops them when
(de)serializing at the SDK boundary.

The fields are inlined directly into each variant, mirroring the existing
github_reference variant, rather than wrapping the generated
`AttachmentGitHub*` structs. Wrapping would emit a duplicate `type` JSON
key (the generated structs embed their own discriminator) and break the
enum's `Eq` derive (the generated structs do not derive Eq). Nested
object fields use local sub-structs that derive Eq.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pallaviraiturkar0 pallaviraiturkar0 requested a review from a team as a code owner June 29, 2026 12:38
Copilot AI review requested due to automatic review settings June 29, 2026 12:38

Copilot AI 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.

Pull request overview

This PR updates the Rust SDK’s hand-written Attachment enum (the type used for (de)serializing user-message attachments) to include additional GitHub-anchored attachment variants that the CLI already emits, preventing those attachment payloads from being dropped at the SDK boundary.

Changes:

  • Added 9 GitHub-anchored Attachment variants (github_commit, github_release, github_actions_job, github_repository, github_file_diff, github_tree_comparison, github_url, github_file, github_snippet).
  • Introduced small local helper structs (e.g., repo pointer, diff sides, snippet line range) to mirror generated shapes while preserving Eq on Attachment.
  • Added a unit test intended to validate round-trip serialization/deserialization for the new variants.
Show a summary per file
File Description
rust/src/types.rs Adds missing GitHub-anchored attachment variants + supporting structs + a round-trip unit test.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread rust/src/types.rs Outdated
List github_reference + the 9 GitHub-anchored variants explicitly in the
display-name match arms instead of a wildcard, so future Attachment variants
trigger a compile error and force an explicit display-behavior decision.

Count raw "type": occurrences in the serialized string rather than keys on a
parsed Value (which silently dedupes), so the test can actually catch a
duplicate-type regression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub

Copy link
Copy Markdown
Collaborator

It's not clear to me why these were hand written in the first place. @tclem, is there a reason these can't be auto-generated?

@SteveSandersonMS

SteveSandersonMS commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

It's not clear to me why these were hand written in the first place. @tclem, is there a reason these can't be auto-generated?

All the server->client calls in the Rust SDK are not codegenerated. As far as I can tell it's simply debt.

I've added a couple of lines to an "infra/debt" section of our July planning though don't know if we'll reach them without reprioritization, as they are beyond the cutline.

@pallaviraiturkar0

Copy link
Copy Markdown
Contributor Author

The generated types for these 9 attachment kinds already landed across all languages in the routine schema-bump PR #1819 (Update @github/copilot to 1.0.66-1). I re-ran the code generator for all six languages (scripts/codegen + java/scripts/codegen) against the pinned 1.0.66-1 schema and git diff is empty, confirming they're already in sync. The only representation codegen doesn't own is Rust's hand-written Attachment enum (rust/src/types.rs), which is what this PR fixes.

@SteveSandersonMS SteveSandersonMS added this pull request to the merge queue Jun 29, 2026
Merged via the queue into github:main with commit 40ae242 Jun 29, 2026
16 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.

4 participants