Skip to content

fix(update): write .channel BEFORE install.sh (closes #264 regression) - #266

Merged
joelteply merged 1 commit into
canaryfrom
fix/cmd-update-write-channel-before-install
Apr 29, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/cmd-update-write-channel-before-install

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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.

…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]>
Copilot AI review requested due to automatic review settings April 29, 2026 00:53
@joelteply
joelteply merged commit 84524d3 into canary Apr 29, 2026
@joelteply
joelteply deleted the fix/cmd-update-write-channel-before-install branch April 29, 2026 00:53

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.

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_update to persist $AIRC_DIR/.channel before invoking install.sh, so install.sh sees 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"

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
echo "$channel" > "$channel_file"
printf '%s\n' "$channel" > "$channel_file"

Copilot uses AI. Check for mistakes.
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.

2 participants