Repository navigation
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
refreshRelayDemandBestEfforthelper — a new best-effort wrapper (try/catch→console.warn) for demand refreshes, placed inrelay-demand-ledger.tsto avoid growingdesktop-relay-service.tspast itsmax-linesceiling.withTransientDemandcontainment — bothrefreshDemand()calls (pre-acquire andfinallyteardown) now route through the helper, so a failing wake signal can no longer strand the transient ref or replace the operation's result.causepreservation — the mid-operation policy-flip rethrow now carries the original error ascauseinstead of discarding it.- Tests — a new spec with four exact assertions covering teardown failure, pre-op throw (no stranded ref), success preservation, and cause propagation.
The change is well-scoped and correctly reasoned: the pre-op refreshDemand failure leaked a no-expiry transient ref, and the teardown failure overwrote the operation result in both directions. The containment helper is idiomatic — console.warn('[relay] …') matches the module's existing log style, and new Error(msg, { cause }) is already used in RPC error-code paths (browser-network-tunnel.ts). The tests assert exact outcomes (message equality, call counts) rather than truthiness, and would fail if the fix were reverted. One deliberate scoping note: other bare refreshDemand() wake-signal call sites (start, authMutated, demandStateChanged, etc.) are left unwrapped, but none of them strand a ref or overwrite a result, so limiting the fix to withTransientDemand is the right call.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
9ce1902 to
13eee7e
Compare
`withTransientDemand` called `refreshDemand()` bare on both sides of the operation. It reaches the device registry (`nextPendingExpiry` -> `listDevices`) and the settings store (`hasDemand` -> `isRelayAllowedForDevice`), so it can fail on its own — and measured, each call site failed the operation instead: - the pre-call threw with the transient ref already acquired, so the ref was never released and the operation never ran. Transient refs have no expiry, so that ref holds relay demand for the rest of the process. - the teardown call replaced the operation's own result in both directions: a named mint failure arrived as `listDevices exploded`, and a SUCCESSFUL mint arrived as a rejection. Both are wake signals; the liveness tick and the next refresh re-ask, so a lost signal is recoverable where a stranded ref is not. The containment lives beside the ledger that owns the ref, because desktop-relay-service.ts is at its max-lines ceiling and this must not cost it a line. Also carries the original error as the `cause` of the mid-operation policy flip rewrite, which was discarding it — the one place in a commit about naming causes that destroyed one.
417707e to
4450e1d
Compare
One conflict, in the desktop-relay-service import block: keep this branch's refreshRelayDemandBestEffort import alongside the base's move to relay-region-preference-reader (main renamed the module).
Four of the eleven findings were removable rather than suppressible: annotate the variable instead of asserting the literal. The rest carry a line-specific SAFETY rationale on the line that opens the cast expression, which is where the diagnostic points -- not the `} as Foo` that closes it. Measured: gate exit 0, tc exit 0, relay 32 files / 251 tests passed.

What breaks
withTransientDemandcalledrefreshDemand()bare on both sides of the operation it wraps. That call is not pure — it reaches the device registry (nextPendingExpiry→listDevices) and the settings store (hasDemand→isRelayAllowedForDevice), so it can fail on its own.Measured, each call site failed the operation instead:
The pre-call threw with the transient ref already acquired. The ref was never released and the operation never ran. Transient refs have no expiry, so that ref holds relay demand for the rest of the process — the relay stays online forever because a wake signal failed.
The teardown call replaced the operation's own result, in both directions:
listDevices explodedWhy containment is the right shape
Both calls are wake signals. The liveness tick and the next refresh re-ask, so a lost signal is recoverable — where a stranded transient ref is not, and a successful mint reported as a failure is not. Containing the signal trades a recoverable loss for two unrecoverable ones.
The containment lives beside the ledger that owns the ref, not in
desktop-relay-service.ts— that file is at itsmax-linesceiling and this must not cost it a line. (Amax-linesdisable is not an option in this repo.)Also in here
The mid-operation policy-flip rewrite was discarding the original error. It now carries it as
cause— the one place in a commit about naming causes that was destroying one.Base
maindoes not work — this touchesdesktop-relay-service.tsandrelay-demand-ledger.tsas they stand after #19870's stack. Merge order: #19870 → this.Verification
tsc --noEmit -p config/tsconfig.node.jsonclean ·src/main/runtime/relay— 25 files / 204 tests passed, 0 failures ·oxlintclean ·oxfmt --checkclean.Cherry-picked from
nwparker/adv3-failure-fixes, which has no PR.Correction to the analysis above (2026-09-16)
The claim that
hasDemand→isRelayAllowedForDevicecan fail the caller is wrong, and the fix is narrower than the description implies.coordinator.reconcile()→beginReconcile→reconcileEpochis anasyncfunction whose whole body — includingreadContext()andhasDemand?.(context)— runs inside its owntry/catch, so a throw there becomes a caught rejection logged as[relay] broker reconcile failed:. It cannot escaperefreshDemand.The only synchronous throw surface that can is
nextPendingExpiry()→listDevices(), and it runs after the coordinator has already been woken. So what a contained throw actually costs is thedemandExpiryTimerre-arm, not the wake.That also narrows the "recoverable" argument:
ensureLive()returns early when ownership is valid and live and never touches the expiry timer, so an unscanned invite's expiry cannot drop standing demand until some laterrefreshDemand. The containment is still correct and worth having — this note only corrects why.Pre-existing, not introduced by this PR: the same throw point behaved this way before.
Rebase record (2026-09-11)
Stack preserved: base stays
fix/18211-lan-mode-applies-to-paired-devices(#19870), rebased ontomainat5fa62feda7c264c6eda99ba4788ffebab9aae26cfirst. Replayed withgit rebase --onto 13eee7eacf8a6fcd4bb77ff680d18f727fca1171 9ce190247edbdb508b452e8c62a63c4c2cdd0089.417707ea34733fbed01b72cd4819cd23e0d851dd4450e1ddae6a3ea1c103a189988447fac882973713eee7eacf8a6fcd4bb77ff680d18f727fca1171No conflicts.