Repository navigation
fix(update): write .channel BEFORE install.sh (closes #264 regression) - #266
Conversation
…ession in #264) continuum-b741 caught during #264 regression sweep: 'airc version' reports 'on canary' but 'airc channel' reports 'main' after running 'airc update --main'. Disagreement between branch and saved-channel preference. ## Root cause cmd_update.sh sequence on 'airc update --main': 1. requested_channel='main'; channel='main' 2. checkout main branch (success) 3. ★ run install.sh 4. write .channel='main' install.sh has an auto-recovery block (install.sh:797-809) for users on a non-channel branch. It reads .channel + current branch and 'fixes' disagreement by reverting branch to the saved channel. Step 3 sees: branch='main' (just switched), .channel='canary' (stale, not yet updated). The 'fix' switches branch BACK to canary. Step 4 then writes .channel='main' to the now-canary install dir. Net: branch=canary, .channel=main. Reported version disagrees with saved channel — looks broken even though the underlying state is just inconsistent. ## Fix Reorder: write .channel BEFORE running install.sh. install.sh now sees .channel='main' + branch='main' = consistent, leaves branch alone, ff-pulls cleanly. Result: branch=main, .channel=main, version correctly reports 'on main'. Trade-off: if install.sh fails after the .channel write, the file records the intended channel but the install dir might be partially on the new branch. That's strictly better than the prior bug — the prior order had the same partial-state risk plus the disagreement above on the success path. Either way, the dirty-tree check (#247) catches most pre-failure conditions. ## Verification test/integration.sh tabs: 19/0 ✓ Manual repro on Mac: Before: branch=canary, .channel=main, version='on canary' (wrong) After: branch=main, .channel=main, version='on main' (correct) Closes the regression in #264. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in airc update where install.sh’s auto-recovery logic could switch the install directory back to the previous channel because .channel was being written after install.sh ran.
Changes:
- Reorders
cmd_updateto persist$AIRC_DIR/.channelbefore invokinginstall.sh, soinstall.shsees consistent “current branch ↔ saved channel” state. - Adds inline documentation explaining the #264 failure mode and why the new order prevents branch flip-flopping.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # already done — but the branch was successfully switched too, so | ||
| # the state is at least consistent (just on the new branch's tip | ||
| # instead of a fresh-pulled tip). | ||
| echo "$channel" > "$channel_file" |
There was a problem hiding this comment.
Now that install.sh reads .channel during the same airc update run, writing it via echo can misbehave for channel names that start with - (e.g. -n, -e): many echo implementations treat those as options, producing an empty/modified file. Use printf '%s\n' "$channel" (and/or reuse the same “reject -*” validation used by cmd_channel) so .channel is written reliably before install.sh consumes it.
| echo "$channel" > "$channel_file" | |
| printf '%s\n' "$channel" > "$channel_file" |
Reorder: write .channel before install.sh runs so install.sh's auto-recovery block sees consistent state instead of fighting the just-completed branch switch. Real-user regression caught by continuum-b741 in #264.