mirror of
https://github.com/moghtech/komodo.git
synced 2026-07-16 01:59:56 -05:00
[PR #1522] [MERGED] fix: prevent terminal execute echo from colliding with output sentinels #28689
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/moghtech/komodo/pull/1522
Author: @mvanhorn
Created: 7/13/2026
Status: ✅ Merged
Merged: 7/14/2026
Merged by: @mbecker20
Base:
2.3.0← Head:fix/terminal-echo-sentinel-collision📝 Commits (1)
e306f34fix terminal execute echo colliding with output sentinels📊 Changes
1 file changed (+8 additions, -1 deletions)
View changed files
📝
bin/periphery/src/api/terminal.rs(+8 -1)📄 Description
Summary
Fixes the intermittent wrong-output / wrong-exit-code failures of the terminal
executemethods (execute_container_terminal,execute_server_terminal,execute_stack_exec) reported in #1289, where a run returnsinstead of the real command output, even though the command ran correctly on the
server. As agreed in the issue thread ("a parsing issue of the terminal output,
and the command is executed correctly"), the command itself is fine and this is a
parsing collision, not an execution bug.
The
executecommand is written to a PTY-backed shell whose stdout is also thestream the parser reads for its sentinel markers, and local echo is on (needed for
interactive terminals). In
bin/periphery/src/api/terminal.rsthe built commandused real newline bytes inside the single-quoted
printfformat strings, so thecommand spanned multiple physical lines:
The PTY echoes that multi-line input back before the real output, putting bare
lines equal to
__KOMODO_START_OF_OUTPUT__,__KOMODO_EXIT_CODE:%d, and__KOMODO_END_OF_OUTPUT__on the stream. The setup loop(
line == START_OF_OUTPUT) breaks on the echoed start marker, then forwards theechoed
'; date; rc=$?; printf 'as output and reads the echoed__KOMODO_EXIT_CODE:%d(hence exit code"%d") and echoedEND_OF_OUTPUTas theterminator - exactly the reported symptom. This also matches why
shfailsdeterministically (verbatim line-discipline echo of the bare marker lines) while
interactive
bash/readline usually re-renders continuation lines and only failsintermittently under arm64/load timing.
The fix makes the command a single physical line by using literal
\nescapes(Rust
\\n) inside theprintfformat strings instead of embedded newline bytes.printfexpands those escapes, so the emitted output is byte-identical, but theechoed command can no longer contain a bare sentinel line.
Why this matters
These terminal
executemethods back Actions and Stack exec, and the failure issilent and non-deterministic: the command really runs, but the caller sees garbage
output and a
%d(or otherwise wrong) exit code. Onshit fails every time; onbashunder arm64/load it fails an unpredictable fraction of runs, which makes ithard to trust or automate around.
Change
bin/periphery/src/api/terminal.rs, insetup_execute_command_on_terminal:The inner newlines (inside the single-quoted
printfformats) become\\n; thefinal trailing
\nthat submits the command to the shell is left as a realnewline.
Byte-identity proof
Reconstructing the OLD and NEW command strings and running both under
sh(
{command}=echo hi):OLD source (7 physical lines, as above) vs NEW source (1 physical line):
cmpof the two stdouts reports byte-identical output:So the change only affects how the command echoes, not what it emits. Only the
START sentinel needs de-colliding for correctness (once the real START marker is
matched, the whole echo has already been consumed), but all three markers are
de-collided together since it is free.
cargo check -p komodo_peripherycompiles.Verification note
This was verified by the byte-identity proof above and
cargo check, but notreproduced end-to-end (that needs core + periphery + Docker with a real PTY). The
change is tiny and output-preserving, so regression risk is low - but it would be
great if you could confirm it under your own repro, especially the arm64/load
bashcase, in case you would prefer a different approach.Closes #1289
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #1522] fix: prevent terminal execute echo from colliding with output sentinelsto [PR #1522] [MERGED] fix: prevent terminal execute echo from colliding with output sentinels