Skip to content

fix(bin): guard unbound $raw variable in fm_pending_reply_new_id on openssl-less hosts - #5184

Open
RyzeNGrind wants to merge 4 commits into
kunchenguid:mainfrom
RyzeNGrind:fm/fm-send-openssl-fix
Open

RyzeNGrind wants to merge 4 commits into
kunchenguid:mainfrom
RyzeNGrind:fm/fm-send-openssl-fix

Conversation

@RyzeNGrind

Copy link
Copy Markdown

Summary

  • Fixes crash in bin/fm-pending-reply-lib.sh: fm_pending_reply_new_id evaluated [ -z "$raw" ] under set -u on the openssl-absent fallback path, causing every reply-bearing secondmate steer to crash with raw: unbound variable
  • Fix: guard with ${raw:-} instead
  • Adds regression test in tests/fm-pending-reply.test.sh that simulates openssl absence via PATH isolation (symlink directory containing only non-openssl tools) and confirms the function returns a well-formed 16-character lowercase hex ID without crashing

Test plan

  • tests/fm-pending-reply.test.sh passes on hosts with and without openssl
  • Fallback path produces a 16-char lowercase hex ID when openssl is absent
  • No crash on --resolve-key sends on openssl-less hosts

RyzeNGrind and others added 4 commits September 21, 2026 19:34
…penssl-less hosts

In fm_pending_reply_new_id, when openssl is unavailable or fails, the $raw
variable remains unbound. The check [ -z "$raw" ] crashes under set -u with
"unbound variable" error on hosts without openssl, breaking all reply-bearing
secondmate steers including --resolve-key sends.

Fix: use "${raw:-}" to safely access the variable, which expands to empty
if unbound, preventing the crash. Add regression test to verify the fallback
path generates valid IDs without openssl.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
…gression

The previous test didn't trigger the fallback path because it put a
fake openssl first on PATH, but command -v still found the real openssl
in /usr/local/bin. Use minimal PATH="/usr/bin:/bin:/usr/sbin:/sbin"
which excludes /usr/local/bin to ensure command -v openssl returns
non-zero and triggers the true fallback path under set -u.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
On NixOS systems, standard tools (awk, date, shasum, etc.) are in
/run/current-system/sw/bin, not /usr/bin. Update the test PATH to
include this directory so the fallback path has access to all needed
tools while still excluding /usr/local/bin where openssl is located.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 21, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Watts-Blake

Copy link
Copy Markdown

Physical device wake-lock lifecycle validation (partial)

Device: Launcher R5CY62JEFXX, DEV account, DEV test room (pushback-384207cd...).

Leave: the channel audio session partial lock (frontier:comms_audio_session) released promptly on leave. A separate system AudioMix lock (held by the system audioserver, attributed to this app's audio session) did not clear - it was still held and growing more than 17 minutes after leave at the time of this check. This lock is not one of the three locks this PR's scope names (comms_audio_session, WearMonitor's screen-off lock, assistant locks), so it may be outside this PR's scope or a pre-existing platform behavior, but flagging it since it is the kind of leftover-lock symptom this PR is meant to prevent.

Logout: clean - returned to a "Not in a channel" state with no new stray locks beyond the pre-existing AudioMix lock above.

Quick leave+rejoin: inconclusive. Firing the room-join action twice within a few seconds right after the logout/re-login cycle produced no visible connect/health-transition progression in the logs the second time - the request was received but didn't appear to proceed to a live connection. No crash and no new stray lock resulted, but I could not confirm a successful rapid rejoin in the time available, so this is reported as unverified rather than pass or fail.

Not covered: the 60-second screen-off-while-in-room test (listed as a gap per guidance, not reattempted this round).

Install and launch were clean on all three Group B devices with no crashes throughout.

@Watts-Blake

Copy link
Copy Markdown

5184 lock-lifecycle A/B re-check (main vs 5184)

Device: Launcher R5CY62JEV9J, DEV account, DEV test channel.

AudioMix lock - confirmed pre-existing, NOT introduced by 5184.
Ran the identical leave sequence on main (commit f918593a4d, current post-5183 main) and on PR 5184's latest head (b994722605), checking dumpsys power and dumpsys audio at t=10s and t=60s on each (main was also checked at t=5min). Result on BOTH builds, identically:

  • The system AudioMix partial wake lock (held by uid 1041, the system audioserver, attributed to this app's audio session) stays held indefinitely after leave - still present at 5 minutes on main.
  • A genuinely active AudioPlaybackConfiguration (type AAudio, state:started, on the USB device) remains running after leave on both builds - this is not just a stale wake-lock artifact, there is a real active audio player object still open.
  • Notably, the exact same system wake-lock object never actually released between the end of the main-build test and the start of the 5184-build test (a fresh app install/relaunch in between), indicating this is a system/hardware audio-routing-level condition tied to the USB device route itself, not something either app build's code individually controls.

Conclusion: this is a pre-existing battery/audio-routing issue that predates PR 5184, not a regression it introduces. Recommend filing it as its own item for the audio/platform layer rather than blocking this PR on it.

Quick rejoin: Leave then immediately rejoin on the 5184 build succeeded cleanly - result=success, ptt_ready in 792ms, no crash.

Screen-off 60s in room: Connection stayed HEALTHY continuously throughout. Locks held during screen-off were exactly the expected ones for an active session: frontier:comms_audio_session, MmapCapture (active mic), WearMonitor:WakeLock (its documented screen-off purpose), plus the already-flagged pre-existing AudioMix lock. No new or unexpected locks appeared.

All three required checks are clean or explained per the above.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @RyzeNGrind, and sorry this one waited so long for a first look. It's a real bug, and the fix is right.

  • Still broken on main: on 8eb9be51, fm_pending_reply_new_id in bin/fm-pending-reply-lib.sh still declares local raw hex and then tests [ -z "$raw" ]. On a host without openssl, that's an unbound-variable crash under set -u. ${raw:-} is the minimal correct guard. Building the test's PATH from symlinks, so openssl is truly unreachable, is a nice touch.
  • Contract class (my own read): restore. Reply-bearing sends are an existing default path that should work on openssl-less hosts and currently crashes there. The fix adds no new surface or behavior.
  • VISION.md: aligns on every rule. It closes a silent failure on a default path, keeps the mechanics in a script, and stays vendor-neutral and in scope.
  • What's needed from you, whenever convenient: the branch is 277 commits behind main and now conflicts, and the PR body has no no-mistakes attestation. Could you rebase onto current main and re-raise through git push no-mistakes? That records the attestation and a live-validation verdict, and CI will run on the fresh head. I haven't approved the old fork CI runs, because they'd test a stale, conflicting merge.

Once that's in and CI is green, this can land as a restore.

@kesslerio

Copy link
Copy Markdown
Contributor

Cross-reference from #7610: we independently hit this defect while running live remote-steer validation on an openssl-less host and fixed it a slightly different way at f55007f9 — local raw="" hex="" at declaration, which covers the unset hex on the openssl path as well as raw, rather than guarding only the [ -z ] check. The maintainer asked us not to carry ours since this PR targets the same fix; noting it here in case the initialize-at-declaration form is preferable (it also survives any future reads of hex outside the fallback branch).

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @RyzeNGrind, and thanks @kesslerio for the cross-reference from #7610.

A quick correction to my 10-21 note first. I asked you to rebase, and I shouldn't have. The merge conflict is ours to resolve when this is ready to merge, so please ignore that part.

I re-checked main bb3e6906. fm_pending_reply_new_id in bin/fm-pending-reply-lib.sh still declares local raw hex and then tests [ -z "$raw" ] when openssl is missing, so the crash is still real and this fix is still needed. The contract-class is still restore, and VISION still aligns on every rule. #7610 deliberately doesn't carry its own copy of the fix, so this PR is where it lands.

Where it stands: waiting on you. One thing is needed:

  • Re-raise through no-mistakes (git push no-mistakes). The PR body has no attestation yet, and we need one that binds the head with no skipped steps, plus a live verdict (an --resolve-key send on an openssl-less host or PATH, for example). The no-mistakes run handles the rebase itself.

Optional, your call: @kesslerio's form, local raw="" hex="" at the declaration, also covers hex and any future read outside the fallback branch. Either form is fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants