Repository navigation
fix: log evaluated commit in run-switch and warn when HEAD moves during build (#3817) - #7362
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 47 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d81a94e9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Capture the evaluated source state before the build starts. The flake | ||
| # is evaluated from src_dir at invocation time; that commit — not | ||
| # whatever HEAD is when the long build finishes — is what lands. | ||
| eval_commit=$(git -C "${src_dir}" rev-parse HEAD 2>/dev/null || printf 'unknown') |
There was a problem hiding this comment.
Bind the recorded commit to the source actually evaluated
If HEAD advances after this capture but before Nix reads the source—for example, while sudo waits for a password—the rebuild can evaluate the newer tree, but EVALUATED_COMMIT and the final warning incorrectly assert that the older commit was activated. Line 76 still passes the mutable flake path; the Nix manual specifies that without ref or rev, “files are fetched directly from the local path”. Snapshot/pin the source used by the rebuild, or obtain its actual evaluated revision rather than treating this pre-build observation as authoritative.
Useful? React with 👍 / 👎.
| lock_file=${RUN_SWITCH_LOCK_FILE:-"${home}/.run-switch.lock"} | ||
| log_dir=${RUN_SWITCH_LOG_DIR:-"${home}"} | ||
| flake=${RUN_SWITCH_FLAKE:-"${home}/code#amd"} | ||
| src_dir=${RUN_SWITCH_SRC:-"${home}/code"} |
There was a problem hiding this comment.
Monitor the repository selected by the flake override
When an existing caller sets RUN_SWITCH_FLAKE to another checkout without also setting the newly introduced RUN_SWITCH_SRC, the rebuild uses that checkout but the metadata and HEAD-movement guard inspect ${HOME}/code. Consequently, a successful switch can report an unrelated commit and miss changes to the actual source. The Nix manual defines direct path references as selecting the flake at that path. Derive the monitored source from the selected flake, or validate that the two settings agree instead of silently defaulting to a different repository.
Useful? React with 👍 / 👎.
Summary
lib/run-switch.shthat PR fix: serialize run-switch and give each invocation its own log #5146 (merged 2026-11-08T06:39Z, closing issue run-switch.sh: concurrent switches clobber the shared ~/switch-current.logpath pointer (wrong-log exit attribution) #3753) landed: the flock and per-invocation logs were already in; this PR adds the evaluated-commit half.EVALUATED_COMMIT(the flake source HEAD at eval time),TREE_STATE(clean/dirty), andSWITCH_STARTED_ATbefore the build starts.HEAD MOVED DURING BUILDwarning naming both commits, and the same warning goes to stderr.RUN_SWITCH_SRCenv override (default~/code, the flake source) makes the guard testable.Verification
bash lib/run-switch.test.shon the laptop — all scenarios pass, including the new ones:rev-parse HEAD)bash -n lib/run-switch.sh lib/run-switch.test.sh— pass.Closes #3817
Queue: task 12642 (repo-health-code-pilot, lane code-i). Deployment of the merged script to the laptop's
~/run-switch.shfollows the merge in the same shift.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.