Wait for the shell command before sending the next one - #604
Merged
Conversation
`shell` closed the pipe without reading it, on the reasoning that "the command runs whether or not anything reads its output". It does not: the pipe is what carries the command's end, and closing it unread returns in a handful of milliseconds whatever the command was still doing. Measured on an emulator, three rounds: a `sleep 2` came back in 5, 12 and 16ms closed, and in 2004, 2035 and 2015ms read. Which is why the first full set off CI has a status bar reading 6:54 with a charging bolt in the battery, in all fifteen locales of both devices. `demo enter` landed - the clock is frozen at the same minute from the first locale to the last, half an hour apart - and the six commands behind it did not. The clock, the battery, the notifications and the radios were all fired into a device already busy with the one before. On this machine they arrive anyway, which is why it was 9:41 here and never there. Reading to the end waits, and it also puts the demo commands in order: `am broadcast` answers `Broadcast completed: result=0` once its receiver has run, so there is something to wait for. The same helper writes `user_rotation`, `accelerometer_rotation`, the night mode and the navigation bar overlay, none of which were being waited on either. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UBGYtacAAsAiA19UJGvdXb
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The first full set of store screenshots off CI came back with this status bar, in
all fifteen locales of both devices:
Not
9:41, and not the batterydressTheDeviceasks for - "plugged false, orthe battery is drawn with a charging bolt in it, which says the picture was taken
on a desk rather than that the app was being used".
What happened
Demo mode did enter: the clock is frozen at the same minute in the first
locale captured and the last, half an hour apart. It is the six commands behind
enterthat never landed - the clock, the battery, the notifications, the radios.shellclosed the pipe without reading it:.executeShellCommand(command) .use { /* the command runs whether or not anything reads its output */ }It does not. The pipe is what carries the command's end, so closing it unread
returns immediately and the next command is sent into a device still busy with
the one before. Measured on an emulator, three rounds of
sleep 2:On this laptop they arrive anyway, which is why it has always been 9:41 here and
never there.
The fix
Read the descriptor to its end. That waits, and for the demo commands it also
puts them in order:
am broadcastanswersBroadcast completed: result=0onceits receiver has run, so there is something to wait for.
The same helper writes
user_rotation,accelerometer_rotation, the night modeand the navigation bar overlay. None of those were being waited on either, so the
rotation loop and the theme change were racing the same way - the rotation just
had a 2.5s sleep behind it that covered for it.
Checked
The mechanism is measured above rather than argued. Locally the set still comes
out
9:41with a clean battery, so nothing regressed. The symptom itself onlyshows on a slow emulator, so a dry run is going to confirm it on CI - I will note
the result here.
🤖 Generated with Claude Code