Repository navigation
Commit 65a160e
authored
fix(exec): roll back the model write when mxbuild crashes (#424)
Independent review: APPROVE.
# Review: PR #424, exec.sh rolls the write back when mxbuild crashes (crash-rollback split from #311)
- Head: `aade99b7` (`fix/exec-crash-rollback`), one commit on master `2def0679`. 3 files: `project-bin/exec.sh` (+24/-3, one hunk), new `tests/wave2/test-exec-crash-rollback.sh` (118), one CHANGELOG line.
- Read-only detached worktrees under /tmp, removed afterwards. Synthetic fixtures only. macOS 26.6, bash 3.2 via `bash`.
- Verdict: **APPROVE** (items below are small; 1 and 2 are worth doing before merge, 3 to 5 are notes).
## Claims checked
| Claim | Result |
|---|---|
| New test 13/0 on the branch | **Reproduced**: 13 passed, 0 failed |
| 9/4 on master's exec.sh | **Reproduced**: 9 passed, 4 failed, all four in case B (write kept, model differs, no message, no row) |
| Extracted from #311 only, no guard | **Yes.** The hunk is the `elif [ "$MXBUILD_EXIT" -ne 0 ]` branch only. No refusal path, no new script, no routed text, no `applied.tsv`, no baseline words. |
## Behaviour against the T3 intent
| Question | Finding |
|---|---|
| Restores exactly the pre-exec model? | Yes. `restore_snapshot` -> `restore-mpr.sh` replaces `mprcontents/` wholesale (copy to temp, `rm -rf`, `mv`), so units the write ADDED are removed too, then copies the `.mpr`, then checks the unit count. Case B asserts a byte-identical checksum of `.mpr` + unit. |
| Only on a crash, not on a normal build error? | Yes. A written errors file goes down the existing CE branch (case D: ordinary `gate failed` row, crash branch not taken). The new code sits only in "non-zero exit and no/empty errors file". Matches T3-S2. |
| Only when the baseline is known? | Yes. `BASE_KNOWN=1` comes from a measured baseline (clean or with errors) or the clean verification stamp. Case C (baseline crash too) keeps the old "kept, flagged" behaviour. I also ran T3-S4 by hand (baseline with a CE error list, then crash): restored, model identical, rc 1, one honest row. |
| `--patch` | Unchanged: `PATCH_MODE=1` takes the old `else`, and the later `--patch` block restores once (`RESTORE_TRIED=0`). No double restore. Read only, not run (no test case, see item 1). |
| Backup step fails | No data loss. `./bin/snapshot-mpr.sh` runs bare under `set -e` (exec.sh:79), and the snapshot script is `set -euo pipefail`, so a failed snapshot aborts the exec **before** the write. If the restore itself fails, the branch prints the STOP line and logs "NOT rolled back (restore did not run)". `restore-mpr.sh` leaves the working tree untouched when its copy fails. |
| Exit code and stamp | `GATE_STATE=fail`, so the stamp is cleared and exec exits 1 (verified: rc 1 in B and S4). The next exec re-measures the baseline. |
| `--on-copy` | Not on master (#384 is open), so no interaction yet. Whoever lands second has to look at this branch again: under `--on-copy`, rollback means "discard the copy", not "restore the snapshot". T3 order (this first, #384 rebases over one hunk) still holds. |
| Ctrl-C | **Unchanged from master, not made worse.** I tested it: SIGINT to the process group while the post-write mxbuild runs. exec.sh dies (rc 130) in its `kill -0` / `sleep 1` poll, so the crash branch never runs. The write is kept, there is no BUILD-LOG row, and the background mxbuild keeps running (async children ignore SIGINT in a non-interactive shell). A Ctrl-C does not trigger a rollback. The only INT exposure is a Ctrl-C during `restore-mpr.sh`, between its `rm -rf mprcontents` and `mv`. That window already exists on the failed-gate path. This belongs to T3-S5 / E5, not to this PR. |
## Items
1. **Test gaps (small).** (a) Case B does not assert the exit code. Add `[ "$RC" -eq 1 ]`. (b) There is no case for a baseline that is known from the **verification stamp** rather than measured. That is the second source of `BASE_KNOWN=1`, and the one in item 2. (c) There is no `--patch` crash case (T3-S3), which would guard against a double restore. (d) The new file is mode 100644, while the other exec tests are 755. `run-all.sh` runs it with `bash`, so this is consistency only.
2. **The stamp case: wording and a possible false rollback.** The new message says "mxbuild ran on this model before the write". When the baseline was skipped because of the stamp, mxbuild did not run in this exec. The stamp fingerprint covers the model only (`model-stamp.sh`: `.mpr` + units), not the mxbuild or JDK version. So a Studio Pro or mxbuild change between the stamp and this exec can make mxbuild die from a machine problem, and that gets read as a write problem. The write is then rolled back. This is recoverable (re-run the script, snapshot kept), but the row then says something untrue. Either reword the message and row to "baseline known (measured, or verification stamp)", or keep the rollback only when the baseline was measured in this run, and treat a stamp-only baseline like case C. My recommendation is the rewording: T3 explicitly counts the stamp as known.
3. **CHANGELOG: two consequences after a pull.** (a) With `MXTK_GATE_TIMEOUT` set, a timed-out gate (exit 124, no errors file) now **rolls back** a write that may be fine. `_common.sh:608-611` already warns about exactly this. The default is unbounded, so only opt-in users see it. (b) T3 asked for the run output to say where the crash output is kept. The output prints the first 20 mxbuild lines and the snapshot path, which is enough, but one clause in the CHANGELOG line would help a project that relied on "kept, open Studio Pro".
4. Note, not this PR: `restore_snapshot` picks the newest snapshot by mtime (`ls -dt`), not `$SNAP_NOW`. This is pre-existing and shared with the failed-gate path. Under the exec lock it is the right directory, but passing `$SNAP_NOW` would make it exact.
5. Note: the V1-to-V2 repack case (the snapshot has no `mprcontents/` but the live model does) makes `restore-mpr.sh` refuse. The branch then logs "NOT rolled back" honestly. The failed-gate path behaves the same way. Fine.
## Verdict
**APPROVE.** Before merge, preferably: 1 (exit-code assert, stamp case, patch case) and 2 (honest wording for a stamp-only baseline). 3 is one CHANGELOG clause. 4 and 5 are notes.1 parent 9655978 commit 65a160e
3 files changed
Lines changed: 140 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1769 | 1769 | | |
1770 | 1770 | | |
1771 | 1771 | | |
1772 | | - | |
1773 | | - | |
1774 | | - | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
1775 | 1793 | | |
1776 | 1794 | | |
1777 | 1795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
0 commit comments