Skip to content

fix(examples): consistent CSV schema in survey_agent#5689

Merged
tinalenguyen merged 1 commit into
mainfrom
fix/survey-agent-csv-schema
May 12, 2026
Merged

fix(examples): consistent CSV schema in survey_agent#5689
tinalenguyen merged 1 commit into
mainfrom
fix/survey-agent-csv-schema

Conversation

@u9g
Copy link
Copy Markdown
Contributor

@u9g u9g commented May 8, 2026

Description

Fix three bugs in examples/survey/survey_agent.py's write_to_csv: the header was never written (os.path.exists ran after aiofiles.open(..., "a") had already created the file), AsyncWriter has no writeheader() and was being mis-constructed (its second positional arg is dialect, not fieldnames), and the disqualify and success paths used disjoint column sets.

Changes

  • Switch to AsyncDictWriter with a fixed CSV_COLUMNS tuple (extrasaction="ignore").
  • Decide on the header by checking await csvfile.tell() == 0 after opening in append mode.
  • Normalize the disqualify key to disqualification_reason (was "disqualification reason").
  • Populate name on the success path from userdata.candidate_name.

Testing

  • make lint (ruff) passes locally.
  • Manual reasoning only — example writes a local CSV.

write_to_csv had three issues: writeheader() was dead code (the
os.path.exists() check ran after aiofiles.open(filename, "a")
already created the file), AsyncWriter has no writeheader() and was
being mis-constructed (its second positional arg is dialect, not
fieldnames), and the disqualify and success paths wrote disjoint
column sets so rows would be misaligned even if a header existed.

Use AsyncDictWriter with a fixed CSV_COLUMNS tuple, decide on the
header by checking the file pointer position after opening in append
mode, and normalize the disqualify key to disqualification_reason.
Populate name on the success path from userdata so both paths fill
the name column.
@chenghao-mou chenghao-mou requested a review from a team May 8, 2026 16:42
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@longcw longcw requested a review from tinalenguyen May 11, 2026 01:29
@tinalenguyen tinalenguyen merged commit e260ac8 into main May 12, 2026
26 checks passed
@tinalenguyen tinalenguyen deleted the fix/survey-agent-csv-schema branch May 12, 2026 05:28
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.

2 participants