Skip to content

Refuse a second apply while a change waits for confirmation; pending banner (#10) - #53

Merged
Cd1s merged 1 commit into
mainfrom
fix/refuse-apply-while-pending
Sep 25, 2026
Merged

Cd1s merged 1 commit into
mainfrom
fix/refuse-apply-while-pending

Conversation

@Cd1s

@Cd1s Cd1s commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What

  • Refusal: while /etc/mini-router/confirm-pending exists (state applying, pending or reverting), every other change is refused — mr apply (not --dry-run), the web UI's apply (HTTP 409 with the pending state) and mr sys restore (checked before any list file is touched) — with "keep it (mr confirm) or roll it back (mr rollback) first". The apply claims the marker with O_EXCL, so two applies started at the same moment cannot both proceed.
  • mr rollback with no argument now undoes the pending change (its own snapshot, not simply the newest file in the history); it is refused while an apply runs, and a restore that fails leaves the change pending instead of stuck in "reverting".
  • API: confirm / revert are POST-only and return errors (409); mr confirm no longer prints into the CGI response; job includes the pending state; every answer to a logged-in client carries X-MR-Pending: {"state","via","left"}.
  • Web UI: a banner under the header on every page — 有待确认的更改(来源)N 秒后自动回滚 [回滚][保留] (also shows 正在应用 / 正在回滚). It updates from the header of any API call; quiet pages ask every 10 s. 保存并应用 is blocked while it shows. The mock API emulates the header and the 409.

Why

Before, apply A --confirm followed by apply B --confirm overwrote the marker: A's timer saw it replaced and exited, and B's rollback only went back to the state after A — A stayed without anyone confirming it. The web UI and an agent working at the same time made that easy. (VyOS: "Another confirm is pending".)

Verification

  • tools/ci.sh passes (private and public trees). New tests: a second apply refused in every state through the CLI, the API and restore (no snapshot taken, marker untouched); dry run allowed; mr confirm lifts the block; unreadable marker; exactly one of 8 concurrent applies claims the marker; failed rollback keeps the change pending.
  • Banner checked in the mock UI (desktop light, phone dark): countdown ticks, buttons wrap on narrow screens.

Closes #10

https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr

…UI banner on every page

`apply A --confirm` then `apply B --confirm` before confirming A overwrote the marker: A's timer
exited, and B's rollback only went back to "after A" — A was kept without being confirmed.

- While the marker exists (applying, pending, reverting) `mr apply`, the web UI's apply (409 with
  the pending state) and `mr sys restore` are refused: keep it (`mr confirm`) or roll it back
  (`mr rollback`) first. `--dry-run` still works. The marker is claimed with O_EXCL.
- `mr rollback` without an argument undoes the pending change; a failed restore leaves it pending.
- API: confirm / revert POST-only with errors; `job` returns the pending state; every answer to a
  logged-in client carries X-MR-Pending {state, via, left}.
- Web UI: banner under the header on every page with 回滚 / 保留 and the countdown; 保存并应用 is
  blocked while it shows. Mock API emulates it.
- Tests: refusal in every state and path, dry run, confirm lifts it, exclusive claim, failed rollback.

Closes #10
@Cd1s
Cd1s merged commit e43662f into main Sep 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the fix/refuse-apply-while-pending branch September 25, 2026 16:15
@Cd1s Cd1s mentioned this pull request Sep 25, 2026
52 tasks done
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.

待确认期间再次 apply 会让上一次改动被隐式确认

1 participant