From 7f0b3764e4a116dac2208a4a8142fcbeaa2dde37 Mon Sep 17 00:00:00 2001 From: dhivadhiva Date: Mon, 16 Nov 2026 23:11:32 +0530 Subject: [PATCH 1/2] Give the channel-opening deadline test a margin a slow runner can meet The test let the channel take 300 ms to open, gave the call 100 ms and required the answer within 280 ms of wall-clock time. A slow Windows runner took 853 ms and failed it. The channel now takes 3 s and the bound is 2 s: still far below what a call that waited for the channel would take, and far above a slow runner's overhead. --- test/bridge_stop_test.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/bridge_stop_test.dart b/test/bridge_stop_test.dart index 97a78e7..9c26161 100644 --- a/test/bridge_stop_test.dart +++ b/test/bridge_stop_test.dart @@ -156,13 +156,18 @@ void main() { final web = rig.serve( 'web1', (_) => FakeExecSession(stdout: _probeOutput), - delay: const Duration(milliseconds: 300), + delay: const Duration(seconds: 3), ); + // The channel takes 3 s to open and the call has 100 ms. The bound is + // well clear of both, so a slow runner cannot fail it, while a call + // that waited for the channel still would. final watch = Stopwatch()..start(); final r = await rig.call('server_stats', {'host': 'web'}); - expect(watch.elapsedMilliseconds, lessThan(280)); + expect(watch.elapsedMilliseconds, lessThan(2000)); expect(r.isError, true); - await Future.delayed(const Duration(milliseconds: 400)); + await Future.delayed( + Duration(milliseconds: 3400 - watch.elapsedMilliseconds), + ); expect(web.sessions.single.stdinClosed, true); expect(web.sessions.single.wasClosed, true); }); From d745f04b1c78497c094928e8be7286f70533cb20 Mon Sep 17 00:00:00 2001 From: dhivadhiva Date: Mon, 16 Nov 2026 23:24:30 +0530 Subject: [PATCH 2/2] Report a stopped command's status as the stop's, on every shell When the watcher's signal cut the wrapper's wait short, some shells had already collected the command, so the wrapper found no process to wait for again and reported the signal's own number (138) instead of the stop's (143). Ask the shell once more for the status it kept, and when it kept none and a stop had begun, report the stop's TERM. --- docs/changes/README.md | 1 + docs/changes/bridge-stop-status.md | 2 ++ lib/services/bridge/bridge_tools.dart | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 docs/changes/bridge-stop-status.md diff --git a/docs/changes/README.md b/docs/changes/README.md index ae26726..cab8465 100644 --- a/docs/changes/README.md +++ b/docs/changes/README.md @@ -28,6 +28,7 @@ One file per piece of work, named for it: | `remote-ops.md` | Commands on many servers, archive and search actions | | `mosh.md` | Mosh | | `localization.md` | Translations | +| `bridge-stop-status.md` | AI Bridge: a stopped command's exit status | Write for the people using the app, in the sections `CHANGELOG.md` uses: `### Added`, `### Changed`, `### Fixed`, `### Security`. One line per change, diff --git a/docs/changes/bridge-stop-status.md b/docs/changes/bridge-stop-status.md new file mode 100644 index 0000000..de7f086 --- /dev/null +++ b/docs/changes/bridge-stop-status.md @@ -0,0 +1,2 @@ +### Fixed +- A command the AI Bridge stopped is now always reported with the stop's own exit status. Before, it was sometimes reported with a different number. diff --git a/lib/services/bridge/bridge_tools.dart b/lib/services/bridge/bridge_tools.dart index c2b77fb..5dc61fb 100644 --- a/lib/services/bridge/bridge_tools.dart +++ b/lib/services/bridge/bridge_tools.dart @@ -82,7 +82,12 @@ class BridgeCommands { /// when a trapped signal arrives) is repeated while the command's process /// is still there. A command that died of a signal has been reaped by /// then, so its status is kept; a zombie `kill -0` still sees is reaped - /// by the next `wait`, so the loop cannot spin. A stopped command's + /// by the next `wait`, so the loop cannot spin. Some shells have already + /// collected the command by the time the cut-short `wait` returns, so + /// `kill -0` finds nothing; one more `wait` then gives the status the + /// shell kept. When the shell kept none (127), the first status stands + /// for a command that ended by itself, and a stop that had begun counts + /// as the stop's TERM. A stopped command's /// status is the stop's (143 for the TERM, 137 for the KILL). /// /// The app holds the channel's stdin open for the whole run and closes it @@ -117,6 +122,7 @@ exec 3<&- wait $p r=$? while [ "$r" -gt 128 ] && kill -0 $p 2>/dev/null; do wait $p; r=$?; done +if [ "$r" -gt 128 ]; then wait $p 2>/dev/null; q=$?; if [ "$q" -ne 127 ]; then r=$q; elif [ -n "$s" ]; then r=143; fi; fi if [ -z "$s" ]; then kill -s KILL $w 2>/dev/null; fi exit $r'''; return 'sh -c ${posixSingleQuote(wrapper)} ssg-bridge '