You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(conductor): decode bridge child output with errors=replace again - #3397
The conductor bridge crashes again when agent-deck prints a byte that is not valid UTF-8 (ANSI art, a multibyte character cut in half, locale-encoded output). run_cli raises UnicodeDecodeError and the bridge dies. This was fixed in #920 (via #926), and the fix was lost when #1406 moved bridge.py to a single go:embed source. Refs #920.
Why this change
run_cli uses subprocess.Popen(..., text=True) with strict decoding. It now decodes as UTF-8 with errors="replace", so bad bytes become U+FFFD. The encoding and error policy live in one pair of module constants (_CHILD_TEXT_ENCODING, _CHILD_TEXT_ERRORS) that each text-mode child call passes.
Sibling: run_hook had the same strict decode. A hook that printed a non-UTF-8 byte and exited 0 was reported as Hook crashed (exit 1). It now uses the same constants.
Left strict on purpose: the macOS keychain lookup (/usr/bin/security ... -w). Its output is a secret, so it must not be silently altered; a decode error there is already caught and returns "".
So the fix cannot be lost silently again, TestBridgeChildOutputSurvivesNonUTF8Bytes runs the embedded bridge.py against a fake agent-deck and a fake hook that print invalid UTF-8 on stdout and stderr. It covers run_cli (with and without stdin), get_session_status, get_session_output and run_hook, under both C.UTF-8 and C locales. Each row checks that the call succeeds and the bad bytes became U+FFFD.
User impact
The Telegram/Slack/Discord conductor bridge no longer crashes, and hooks are no longer reported as failed, when CLI or hook output contains a non-UTF-8 byte. Bad bytes show as U+FFFD.
Evidence
Fail first, on main 0b4bc1d2 with only the new test added (deck-test -count=1 -run TestBridgeChildOutputSurvivesNonUTF8Bytes -v ./internal/session/):
--- FAIL: TestBridgeChildOutputSurvivesNonUTF8Bytes (0.99s)
--- FAIL: .../C.UTF-8/run_cli_stdout_and_stderr File "/usr/lib/python3.14/subprocess.py", line 2194, in _communicate ... UnicodeDecodeError
--- FAIL: .../C.UTF-8/run_hook AssertionError: (1, '', "'utf-8' codec can't decode byte 0xff in position 5: invalid start byte")
(all 10 rows FAIL)
Mutation: with only the run_hook decode reverted, the run_hook rows fail and the others pass (see the lane log).
Full suite on 93b2596 in the sandbox container (deck-test -count=1 ./...): 113 packages ok. internal/session and cmd/agent-deck hit go test's default 10m timeout under host load (CI uses 20m). Rerun with -timeout 30m: internal/session ok. In cmd/agent-deck the only failure is TestPerf_ColdStart_Version (40.5 ms against a 40 ms budget); the same perf tests fail on unmodified main in the same container at the same time (TestPerf_ColdStart_Help and _Version). tools/visualcheck passed in the full run and once showed a 12-attach-shell golden diff in the rerun; this change does not touch the TUI.
Review notes
Two independent reviews (Claude, Codex) both passed. Nits, left as is:
the C locale rows repeat the C.UTF-8 ones: Python already decodes as UTF-8 under the C locale
errors="replace" also applies when run_cli encodes stdin text (a lone surrogate becomes ?)
the keychain call has no comment saying it is deliberately strict
the get_session_status row only checks that a string comes back
one #nosec G306 is redundant
Not verified: a live Telegram round trip with a real conductor; the test drives the real bridge.py code paths with a fake CLI.
AI disclosure
Human-written
AI-assisted (I directed and reviewed it)
AI-authored (a model wrote most of it)
Model(s), if AI helped: unsure
Prompt / session log (optional): —
What actually bothered you
A new regression-test sweep found that the #920 crash fix was gone. My human asked: "conductor bridge run_cli crashes on non-UTF-8 output again: the #920 fix (decode with errors=replace) was lost in #1406. Restore it so it can't be lost again (a test that feeds invalid UTF-8 through run_cli)."
Checklist
Targeted diff: one problem, no unrelated changes
Tests added or updated for new behavior
Test suite passes sandboxed, inside a container: run skills/agent-deck/scripts/contributing/self-check.sh, which prints the Docker command (never go test on your host)
If this touches a hot path (list, status, session output, startup, tmux layer): before/after timing evidence included (not a hot path: the decode options of two subprocess calls in the bridge)
CHANGELOG.md untouched (entries are added at landing)
AI-assisted? Disclosed above, with validation evidence, and I can answer questions about the code
The #920 fix (decode CLI output with errors="replace") was lost when #1406
moved bridge.py to a single go:embed source: run_cli went back to strict
text-mode decoding, so one non-UTF-8 byte in agent-deck output (ANSI art, a
multibyte char cut in half) raised UnicodeDecodeError and crashed the bridge.
run_cli and run_hook now decode child output as UTF-8 with errors="replace"
from one pair of module constants. run_hook had the same strict decode: a
hook that printed a non-UTF-8 byte was reported as failed even when it
exited 0.
TestBridgeChildOutputSurvivesNonUTF8Bytes feeds invalid UTF-8 through
run_cli, get_session_status, get_session_output and run_hook under both
C.UTF-8 and C locales, so the decode cannot be lost silently again.
Committed by Ashesh Goplani
CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.
Parsing warnings: 5
Validation error: Unrecognized key: "requirements" at "reviews.pre_merge_checks.description"; Unrecognized key: "threshold" at "reviews.pre_merge_checks.issue_assessment"; Unrecognized key: "gosec" at "reviews.tools"; Unrecognized keys: "estimated_code_review_effort", "ignore_users" at "reviews"; Unrecognized key: "language" at "code_generation.unit_tests"
If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
No actionable comments were generated in the recent review.
Walkthrough
The bridge now decodes CLI and hook subprocess output as UTF-8, replacing invalid byte sequences. Regression tests cover CLI and hook output under C.UTF-8 and C locales.
Changes: Child-process output handling
Layer / File(s)
Summary
UTF-8 decoding and regression coverage internal/session/conductor_bridge.py, internal/session/conductor_bridge_non_utf8_test.go
run_cli and run_hook use UTF-8 decoding with replacement for invalid bytes. Regression tests cover CLI and hook output across two locales.
The bridge now tolerates invalid bytes in CLI and hook output instead of crashing or reporting successful hooks as failed. A regression test covers the change, and no merge-blocking risk was found.
Pre-merge checks: 6
Check name
Status
Explanation
Title check
The title uses the Conventional Commits format with the fix(conductor) prefix, which matches the configured title requirement. It also describes the main change: the bridge child output now decodes wi…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Remote_parity
The remote_parity check applies only when a pull request changes TUI behavior in internal/ui/ or cmd/agent-deck/. The reviewed diff (refs/coderabbit/pre-merge-check/base..head) changes two files, both…
Test_coverage_per_surface
The check applies to new features. It requires tests for each applicable surface (TUI / Web / CLI / remote) and forbids Web UI stubs. This pull request is a bug fix, not a new feature. The PR title, d…
Full details: Title check
Explanation
The title uses the Conventional Commits format with the fix(conductor) prefix, which matches the configured title requirement. It also describes the main change: the bridge child output now decodes with errors=replace again, which matches the summary of the bridge.py UTF-8 handling change and the regression test.
Full details: Remote_parity
Explanation
The remote_parity check applies only when a pull request changes TUI behavior in internal/ui/ or cmd/agent-deck/. The reviewed diff (refs/coderabbit/pre-merge-check/base..head) changes two files, both under internal/session/: conductor_bridge.py (M) and conductor_bridge_non_utf8_test.go (A). It touches no file under internal/ui/ or cmd/agent-deck/. The check is therefore inapplicable, and the PR passes. The PR changes decoding in the conductor bridge subprocess calls (run_cli, run_hook), not TUI behavior, so no RemoteSession handling is required for this change.
Full details: Test_coverage_per_surface
Explanation
The check applies to new features. It requires tests for each applicable surface (TUI / Web / CLI / remote) and forbids Web UI stubs. This pull request is a bug fix, not a new feature. The PR title, description, and objectives all describe restoring the #920 fix: run_cli and run_hook now decode child output with errors="replace". The diff (confirmed with git diff against the review base) changes two files: - internal/session/conductor_bridge.py (+12/-0): adds _CHILD_TEXT_ENCODING and _CHILD_TEXT_ERRORS constants and passes them to the run_cli and run_hook subprocess calls. It adds no new user-facing feature and no new surface. - internal/session/conductor_bridge_non_utf8_test.go (new): a regression test that runs the embedded bridge.py with a fake CLI and hook. It covers run_cli, get_session_status, get_session_output, and run_hook. No new TUI, Web, CLI, or remote feature is introduced, so the per-surface coverage requirement is not triggered. The new test also covers the bridge paths that the fix touches. The primary PR author is asheshgoplani (verified).
Resolution
None required.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this solve?
The conductor bridge crashes again when
agent-deckprints a byte that is not valid UTF-8 (ANSI art, a multibyte character cut in half, locale-encoded output).run_cliraisesUnicodeDecodeErrorand the bridge dies. This was fixed in #920 (via #926), and the fix was lost when #1406 movedbridge.pyto a single go:embed source. Refs #920.Why this change
run_cliusessubprocess.Popen(..., text=True)with strict decoding. It now decodes as UTF-8 witherrors="replace", so bad bytes become U+FFFD. The encoding and error policy live in one pair of module constants (_CHILD_TEXT_ENCODING,_CHILD_TEXT_ERRORS) that each text-mode child call passes.Sibling:
run_hookhad the same strict decode. A hook that printed a non-UTF-8 byte and exited 0 was reported asHook crashed(exit 1). It now uses the same constants.Left strict on purpose: the macOS keychain lookup (
/usr/bin/security ... -w). Its output is a secret, so it must not be silently altered; a decode error there is already caught and returns"".So the fix cannot be lost silently again,
TestBridgeChildOutputSurvivesNonUTF8Bytesruns the embeddedbridge.pyagainst a fakeagent-deckand a fake hook that print invalid UTF-8 on stdout and stderr. It coversrun_cli(with and without stdin),get_session_status,get_session_outputandrun_hook, under bothC.UTF-8andClocales. Each row checks that the call succeeds and the bad bytes became U+FFFD.User impact
The Telegram/Slack/Discord conductor bridge no longer crashes, and hooks are no longer reported as failed, when CLI or hook output contains a non-UTF-8 byte. Bad bytes show as U+FFFD.
Evidence
Fail first, on main
0b4bc1d2with only the new test added (deck-test -count=1 -run TestBridgeChildOutputSurvivesNonUTF8Bytes -v ./internal/session/):With the fix:
Mutation: with only the
run_hookdecode reverted, therun_hookrows fail and the others pass (see the lane log).Full suite on 93b2596 in the sandbox container (
deck-test -count=1 ./...): 113 packages ok.internal/sessionandcmd/agent-deckhit go test's default 10m timeout under host load (CI uses 20m). Rerun with-timeout 30m:internal/sessionok. Incmd/agent-deckthe only failure isTestPerf_ColdStart_Version(40.5 ms against a 40 ms budget); the same perf tests fail on unmodified main in the same container at the same time (TestPerf_ColdStart_Helpand_Version).tools/visualcheckpassed in the full run and once showed a12-attach-shellgolden diff in the rerun; this change does not touch the TUI.Review notes
Two independent reviews (Claude, Codex) both passed. Nits, left as is:
Clocale rows repeat theC.UTF-8ones: Python already decodes as UTF-8 under the C localeerrors="replace"also applies when run_cli encodes stdin text (a lone surrogate becomes?)get_session_statusrow only checks that a string comes back#nosec G306is redundantNot verified: a live Telegram round trip with a real conductor; the test drives the real
bridge.pycode paths with a fake CLI.AI disclosure
Model(s), if AI helped: unsure
Prompt / session log (optional): —
What actually bothered you
A new regression-test sweep found that the #920 crash fix was gone. My human asked: "conductor bridge run_cli crashes on non-UTF-8 output again: the #920 fix (decode with errors=replace) was lost in #1406. Restore it so it can't be lost again (a test that feeds invalid UTF-8 through run_cli)."
Checklist
skills/agent-deck/scripts/contributing/self-check.sh, which prints the Docker command (nevergo teston your host)