fix: pin UTF-8 stdout in resolvers so Windows cp1252 doesn't crash - #2578
fix: pin UTF-8 stdout in resolvers so Windows cp1252 doesn't crash#2578aranellaeth wants to merge 1 commit into
Conversation
Windows defaults stdout to cp1252, so resolve_config, resolve_party, resolve_personas, and brain crash (UnicodeEncodeError) or corrupt output on emoji agent icons and em-dashes. resolve_customization.py already guards this; apply the same UTF-8 pinning to its siblings. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe changes make CLI and resolver output handling explicitly UTF-8-aware. Console streams are reconfigured when supported, JSON output preserves non-ASCII characters, and subprocess stdout decoding uses UTF-8 with replacement errors. ChangesUTF-8 Output Handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/core-skills/bmad-forge-idea/scripts/resolve_personas.py (1)
49-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting the duplicated
_run_jsonhelper.
_run_jsonis byte-for-byte identical inresolve_personas.py(lines 48-67) andresolve_party.py(lines 46-65). If these scripts share a common package or utility module, extracting this function would prevent the implementations from diverging over time. If they're intentionally standalone per-skill scripts, the duplication is acceptable.The UTF-8 encoding change itself is correct —
encoding="utf-8", errors="replace"withtext=Trueproperly decodes child process output, and the 60s timeout and failure checks are preserved.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core-skills/bmad-forge-idea/scripts/resolve_personas.py` around lines 49 - 65, Extract the identical _run_json helper shared by resolve_personas.py and resolve_party.py into their common utility or package module, then update both scripts to import and reuse it. Preserve the existing UTF-8 decoding, timeout, failure handling, and JSON parsing behavior; if no shared module is appropriate, leave the standalone implementations unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/core-skills/bmad-forge-idea/scripts/resolve_personas.py`:
- Around line 49-65: Extract the identical _run_json helper shared by
resolve_personas.py and resolve_party.py into their common utility or package
module, then update both scripts to import and reuse it. Preserve the existing
UTF-8 decoding, timeout, failure handling, and JSON parsing behavior; if no
shared module is appropriate, leave the standalone implementations unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a7664864-bac5-4a60-949b-9915a6acacfa
📒 Files selected for processing (4)
src/core-skills/bmad-brainstorming/scripts/brain.pysrc/core-skills/bmad-forge-idea/scripts/resolve_personas.pysrc/core-skills/bmad-party-mode/scripts/resolve_party.pysrc/scripts/resolve_config.py
|
Thanks! _run_json is intentionally duplicated—these are standalone, stdlib-only per-skill scripts with no shared package to import from, and the duplication predates this PR (I only applied the encoding fix to the existing copies). Extracting a shared module would be a larger packaging change, out of scope for this targeted fix. Happy to follow up separately if a shared script utility is ever introduced. |
sanmaxdev
left a comment
There was a problem hiding this comment.
Checked the UTF-8 stream changes against the existing resolver pattern. The focused suite passes with 59 tests, and a cp1252 reproduction now exits cleanly with the emoji preserved. The base branch fails with UnicodeEncodeError. The diff is focused and looks correct.
What
Pin UTF-8 on stdout / subprocess output in
resolve_config,resolve_party,resolve_personas, andbrainso emoji agent icons and em-dashes stop crashing on Windows cp1252.Why
On Windows, Python's default stdout encoding is cp1252. These scripts emit
ensure_ascii=FalseJSON with emoji agent icons (or read a child's UTF-8 stdout as cp1252), so party-mode, forge-idea, and brainstorming crash withUnicodeEncodeError.resolve_customization.pyalready guards this withwrite_json_stdout; these siblings were missed.Repro (Windows, Python 3.11+):
PYTHONIOENCODING=cp1252 python _bmad/scripts/resolve_config.py --project-root . --key agents→UnicodeEncodeErroron\U0001f4ca(📊).How
resolve_config.py: addwrite_json_stdout()that reconfigures stdout to UTF-8 (the same helperresolve_customization.pyalready uses)resolve_party.py/resolve_personas.py: decode subprocess output as UTF-8 (errors="replace") in_run_jsonbrain.py: reconfigure stdout/stderr to UTF-8 atmain()entryTesting
Existing pytest suites pass (59). Reproduced the crash with
PYTHONIOENCODING=cp1252and confirmed exit 0 with emoji preserved after the fix.