Reverse 8081 only when the debug_http_host write fails - #145
Merged
Conversation
A healthy run now registers one adb reverse, `<port> -> <port>`, which is what the host written into `debug_http_host` resolves to. The `8081 -> <port>` mapping is registered only when the prefs write fails and the app is left asking for its compiled-in default. `tcp:8081` is the one device port every workspace competes for, and re-registering a device port silently replaces the previous entry. Only registering it when it is load-bearing keeps a healthy run out of that contention entirely, and keeps `adb reverse --list` honest about what serves the app. Behavior on a failed write is unchanged: the fallback is added and the existing warning still says Stim is relying on adb reverse. `reverseMetroPorts` takes the device ports to map instead of deriving them, and the `wired` line reports the reverses actually registered rather than a fixed string.
janicduplessis
force-pushed
the
fix/conditional-8081-reverse
branch
from
August 31, 2026 20:40
9e8f9ba to
0a91a19
Compare
janicduplessis
marked this pull request as ready for review
August 31, 2026 20:41
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.
Closes #142
Description
launchAndroidAppregistered twoadb reversepairs before writingdebug_http_host:Once the prefs write lands the app asks for
<host>:<metroPort>, which the second pair serves. The first is unused. I checked rather than assumed: deletingtcp:8081from under a running app on a physical device and triggering a full reload, the app re-bundled and came back with onlytcp:8082 -> tcp:8082present.That matters because
tcp:8081is the one device port every workspace competes for, and re-registering a device port silently replaces the previous entry -- no error, no warning. A run that does not need the mapping should not be entering that contention, and an unused cross-port entry inadb reverse --listis a misleading thing to find when debugging.Solution
Register
tcp:8081 -> tcp:<port>only when thedebug_http_hostwrite fails, which is exactly when the app is left asking for its compiled-in default.Removing it outright would have been wrong. The write goes through
run-as, which fails on a non-debuggable app and under a secondary Android user. Today that is a warning and the app still loads; with no fallback at all it would become "the app loads no JS", and the existingrelying on adb reversenote would be false. Ordering the fallback behind the failure keeps that degraded path working while taking it off the healthy one.reverseMetroPortsnow takes the device ports to map rather than deriving them frommetroPort, so the fallback is one explicit call instead of a flag that re-registers the same-port pair.The
wiredline printed a fixedtcp:8081 -> tcp:<port>string regardless of what was registered, so it would have started lying after this change. It now reports whatlaunchAndroidAppactually returned.Risk
The behavior change is that a healthy run no longer registers
tcp:8081. Anything outside Stim that assumed the app is reachable on device port 8081 -- a hand-runcurl, another tool's expectation -- loses that on a healthy run. Nothing in Stim depends on it: the app followsdebug_http_host, and the collector and launch verification go through the serial, not the port.Reverting is a one-file change.
Test plan
Verified on a physical Samsung SM-G996W with
stim android --device --variant previewDebug, after clearing every mapping withadb reverse --remove-all:One mapping, same port both sides, and the app still bundles. The failed-write path is covered by a unit test that makes
run-asthrow and asserts the8081fallback is then registered and the existing note is emitted.