Skip to content

fix(go): use *Part for GenerateActionResume.Respond and Restart#5226

Open
apascal07 wants to merge 1 commit intomainfrom
ap/go-resume-fix
Open

fix(go): use *Part for GenerateActionResume.Respond and Restart#5226
apascal07 wants to merge 1 commit intomainfrom
ap/go-resume-fix

Conversation

@apascal07
Copy link
Copy Markdown
Collaborator

The Respond and Restart fields on GenerateActionResume used the unexported toolResponsePart and toolRequestPart types, which are intended only for JSON marshaling. The rest of the codebase uses *Part with the appropriate Kind set, and the unexported types made these fields impossible for external callers to construct.

This change:

  • Adds type overrides in schemas.config so codegen produces []*Part for both fields, and regenerates gen.go.
  • Drops the conversion loops in Generate() that copied *Part into the private types — genOpts.RespondParts / RestartParts now flow through directly.
  • Moves part-kind validation into handleResumeOption, the single consumer, so all entry points (including direct GenerateWithRequest calls with hand-built GenerateActionOptions) are covered.

The private toolRequestPart / toolResponsePart types remain in gen.go and are still used by Part.MarshalJSON for the wire format, so JSON output is unchanged.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./... passes

The Respond and Restart fields used the unexported `toolResponsePart` and
`toolRequestPart` types, which are intended only for JSON marshaling. The
rest of the codebase uses `*Part` with the appropriate `Kind` set, and the
unexported types made the fields impossible for external callers to
construct. Validation now lives in `handleResumeOption` so all entry
points (including direct `GenerateWithRequest` calls) are covered.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the GenerateActionResume struct to use the generic Part type for its Respond and Restart fields, replacing the specialized tool part types. This change simplifies the Generate function by removing manual conversion logic and moves the validation of these parts to handleResumeOption. Review feedback identifies potential nil pointer dereferences in the new validation loops within handleResumeOption and suggests adding nil checks before calling IsToolResponse() and IsToolRequest().

Comment thread go/ai/generate.go
Comment thread go/ai/generate.go
@apascal07 apascal07 marked this pull request as ready for review May 1, 2026 22:47
@apascal07 apascal07 enabled auto-merge (squash) May 1, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant