Skip to content

csv_output silently overwrites distinct fields when flattened keys collide #3865

Backlog

Description

@sre-agent-mcp-poc

Summary

When csv_output is enabled, list-tool results are converted to CSV by flattening nested objects with .-joined column names. A literal field name containing . can produce the same column name as a nested field. One value is silently overwritten; Go map iteration makes the surviving value unpredictable.

Reproduction (from the current implementation)

Convert a list response containing this JSON row through jsonTextToCSV:

[{"user.login":"literal","user":{"login":"nested"}}]

appendFlattenedCSVFields maps both the top-level user.login and the nested user → login to the same row["user.login"]. The resulting CSV has only one user.login column, containing either literal or nested, depending on map iteration order. The other value is lost.

The conversion is used by withCSVOutput for default list_* tools whenever the csv_output feature flag is enabled (including insiders mode). This is a code-path demonstration, not a claim of a live GitHub API response with these exact fields.

Expected behavior

Distinct JSON fields remain distinguishable in CSV, or the conversion explicitly reports that it cannot represent this row without loss. The chosen output should be deterministic.

Suggested fix

Escape/encode path components when building flattened column names, or detect collisions and use unambiguous names/fail clearly. Add a regression test with both a literal dotted key and an equivalent nested path (and verify neither value is silently dropped).

Source

  • pkg/github/csv_output.go: appendFlattenedCSVFields, csvColumnName, csvRowsFromArray, and withCSVOutput.
  • pkg/github/csv_output_test.go: existing flattening tests cover nested objects, but not colliding flattened names.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions