Repository navigation
Fix pairing with dark desktop codes and with a QR's own address - #34
Merged
Merged
Conversation
OpenCode Desktop draws its pairing QR light-on-dark in the dark theme
(#63150). ZXing's ALSO_INVERTED flips the binarized frame, so the dark
page's quiet zone, which HybridBinarizer reads as white, turns black and
small codes are missed. A frame with no code found is now read again with
its luminance inverted before binarizing (a plain QR reader on
luminance.invert()); the first pass is unchanged, so nothing that read
before stops reading.
Verified with a throwaway ZXing 3.5.4 harness (not committed): QRs made by
OpenCode's own encoder (Desktop light/dark, `opencode pair` multi-URL and
--url in dark/light terminals with and without line gaps, TUI link),
rendered into Y-plane frames at 8 sizes x 6 conditions (blur, noise, low
contrast, 0-12 degree tilt). Smallest size, as a share of the 1080-pixel
frame side, that reads in at least 5 of 6 conditions, at 1440x1080:
Desktop dark: 0.35 -> 0.30 (Desktop light: 0.30)
decodes 20 -> 26 of 48 (light: 27)
pair --url, dark page: 0.50 -> 0.30 (light: 0.25)
pair multi-URL, dark: never -> 0.50 (light: 0.50)
light terminal, TUI: 0.35 -> 0.21; pair --url 0.50 -> 0.30
every other case: unchanged; no case decodes fewer frames
For an 8 cm code and a ~50 degree field across the short side, 0.35 is
about 25 cm away and 0.30 about 29 cm. All frames: 343 -> 370 of 720 at
1440x1080, 160 -> 179 at 640x480; no false positives on blank frames.
Inverting the source alone (dropping ALSO_INVERTED) lost light-terminal
frames, so both passes stay. Cost on the laptop JVM at 1440x1080: 18 ->
32 ms for a frame with no code, 11 -> 17 ms with one; analysis keeps only
the latest frame, so a slower frame drops frames rather than queueing.
scripts/check.sh :feature:settings passes on the VM.
…ports A code from `opencode pair --url https://x.tailnet.ts.net` kept connecting over the server's OpenTunnel address (#62901). Redemption added every address `/api/info` reports to the saved server, and the address race starts every address at once, so whichever answered first won, often the tunnel. Deleting the server didn't help: pairing again reported the tunnel again. Now redemption also saves the code's own addresses (the redeemed origin first) as `OpenCodeServer.preferredURLs`; reported addresses stay in `alternateURLs` as fallbacks, since the desktop's QR carries only the tunnel. `ServerLinkStore.race` starts `firstAttemptURLs` at once and the rest after `preferredHeadStart` (1.5 s) or as soon as every first address has failed. A code that names only relayed addresses (the desktop's and `pair --remote`'s tunnel) doesn't hold the server's LAN and tailnet addresses back, so those still win at home as before. `preferredURLs` defaults to empty and isn't part of `persistenceID`, so servers saved before this decode unchanged, keep their identity and race every address at once as before. Editing a server's address clears it. This differs from iOS until iOS makes the same change (parity rows say so). Verified: scripts/check.sh :server :app (VM) passes, with new ServerLinkTests (paired address wins over a faster reported one; others join after the head start; others start at once when every paired one fails; tunnel-only code still lets LAN win; stale or all-preferred lists race as before; the preference persists and old saved JSON still loads) and an AppFeatureTests wire test of the redemption's saved addresses.
A code with an address the app can't use (for example `opencode pair --url https://box.example/opencode` behind a reverse proxy at a path) was reported as "That isn’t an OpenCode pairing code", which sent people looking for the wrong problem. Now it reads “Couldn’t use “<address>” from this pairing code: it has a path, and the server must be at the root of its address.” (also: not http(s), no host, a user name or password, a query or fragment, a port outside 1–65535). The shown address drops any user name, password, query or fragment and is capped at 80 characters. One bad address still rejects the whole code, as on iOS: skipping it would pair over a different address than the one the person asked for, the same surprise as #62901, and the server never lists a bad address itself, so a bad one means the `--url` needs fixing. Verified: scripts/check.sh :server :app (VM) passes, with new tests for the decoder (`anUnusableAddressInAPairingCodeIsNamedWithoutItsSecrets`) and the scan error (`aPairingCodeWithAnUnusableAddressSaysWhichAndWhy`).
The scanner's caption and its no-camera, camera-off and nothing-to-paste messages only named `opencode pair --remote`. The desktop's Settings › Pairing page and plain `opencode pair` (with or without --url) show codes the scanner reads just as well, so people pairing over the LAN or a tailnet were steered to the tunnel. The caption now reads “On your computer, open OpenCode’s Settings → Pairing, or run opencode pair in a terminal.”, close to the connection screen's existing hint, and the fallbacks say `opencode pair`. This differs from iOS's PairingScanner.swift copy until iOS changes; noted in docs/parity/settings.md. Verified: vm.sh check :feature:settings (assemble, lint, unit tests) passed.
This was referenced Nov 11, 2026
Tarquinen
added a commit
that referenced
this pull request
Nov 11, 2026
Conflicts: MainActivity imports (kept both sides) and the FloatingCallStageContent parity row (took dev's, which already describes the reveal-loop fix this branch also carried, so that fix drops out of this PR's diff).
Tarquinen
added a commit
that referenced
this pull request
Nov 12, 2026
refactor(server): simplify the preferred-address race from #34
This was referenced Nov 12, 2026
Merged
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.
Fixes two pairing bugs reported on anomalyco/opencode, and tidies the pairing error and scanner copy.
#63150: dark desktop pairing codes don't scan
In the dark theme the desktop draws its pairing QR as light modules on a dark page (
renderSVGwithblackColor: currentColor,whiteColor: transparent), and the quiet zone is dark too. Android 0.3.0 couldn't read inverted codes at all, and it analysed 640x480 frames, so even light codes had to fill about a third of the frame. v0.3.8 fixed most of this (77358feALSO_INVERTED, c6d391a 1440x1080 frames). That explains the "scanner simply does not trigger" comment on 0.3.0, and I found no other way for the scanner to fail silently.ALSO_INVERTEDonly flips the binarized matrix, though. HybridBinarizer has already made the dark quiet zone white, so after the flip it turns black and the finder patterns lose their margin. Dark codes therefore still needed to be about twice as large in the frame as light ones.QRDecodernow tries a second pass on the inverted luminance when the first pass finds nothing.renderSVG/renderUnicodeCompact, 1440 blurred, noisy and rotated frames.--urldark at 0.3 (was 0.5).#62901: a QR's own address loses to the OpenTunnel address
requestRedeemPairingadds the addresses the server reports in/api/info, including OpenTunnel, as alternates.ServerLinkStore.racethen tries every address at once, and the first to answer wins. So a code fromopencode pair --url https://x.tailnet.ts.netcould end up on the tunnel. Deleting the old entry didn't help, because the new pairing learned the tunnel again. iOS behaves the same way today.Now the addresses in the code (or a typed pairing link) are saved as
OpenCodeServer.preferredURLs, a new JSON field that defaults to empty, so existing saved servers decode unchanged.pair --remotecarry only the tunnel), direct LAN and tailnet addresses aren't held back.iOS needs the same change for #62901. The parity rows in
docs/parity/server.mddescribe the difference.Also
opencode pair, not onlypair --remote. This differs from iOS, as noted indocs/parity/settings.md.Verified
vm.sh check :feature:settings,vm.sh check :server :app(assemble, lint, unit tests). There are new tests for the preferred-first race, for falling back when the preferred address is unreachable or refuses, for relayed-only preferences, for persistence and decoding old JSON, for redemption saving the preference, and for the per-address error./auth/connecton two ports and reports both in/api/info. A, the code's address, answers 400 ms late; B, the reported one, answers at once.https://opencode.ai/pair#…naming only A: every request went to A, and B was never contacted.origin/devbuild on the same saved server: “Local Network answered first”, and traffic moved to B. That reproduces #62901.