Skip to content

fix(restart): refuse to clobber an armed reboot snapshot - #416

Merged
KooshaPari merged 5 commits into
masterfrom
fix/restart-save-armed-rebased
Nov 28, 2026
Merged

KooshaPari merged 5 commits into
masterfrom
fix/restart-save-armed-rebased

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Rebased replacement for #409. Same change set, rebased onto current master (a3c41a9ce); the original branch was
still based on 1d42e7822, so the size ratchet diff no longer applied and a rebase could not be pushed without
rewriting that branch.

What this does

jcode restart save used to overwrite an already-armed reboot snapshot. This guards the write:

  • restart save --replace-armed is required to clobber an existing armed snapshot; without it the command bails with
    the snapshot's own fields quoted back (the previous code reached for .expect("armed snapshot present")).
  • The guarded path propagates write errors instead of discarding them.
  • CloudSessionViewFormat moved out of src/cli/args.rs into src/cli/args/cloud_view.rs, which is what brings
    args.rs from 1247 to 1233 LOC.
  • The restart subcommand match moved from the top-level dispatcher into src/cli/commands/restart.rs, where the four
    handlers already live. src/cli/dispatch.rs drops 1528 -> 1520 LOC, so the size ratchet and cargo fmt agree on a
    durable shape instead of fighting over a squeezed line.
  • scripts/panic_budget.json re-keyed from lifecycle_driver.rs to lifecycle_contracts.rs, which is the file that
    actually holds the 2 recorded usages (renamed upstream). Count unchanged: this is a path fix, not a loosened budget.

Local evidence

[mac] No Linux node reachable (nixos, desk and cachyos are all Tailscale-offline), so this is a justified Mac
fallback run.

cargo +stable fmt --all -- --check        rc 0
cargo +stable clippy --bin kcode --all-targets   rc 0  (only the pre-existing jcode-storage CStr warning)
cargo +stable check --bin kcode --all-targets    rc 0
scripts/check_code_size_budget.py         rc 0
  - oversized file shrank: src/cli/args.rs (1247 -> 1233 LOC)
  - oversized file shrank: src/cli/dispatch.rs (1528 -> 1520 LOC)
scripts/check_panic_budget.py             rc 0  (139 -> 137)
scripts/check_swallowed_error_budget.py   rc 0

CI is the authority for the test suite.

Supersedes #409.

Closes #394.

Validation run:
- cargo +stable fmt --all -- --check: exit 0, no diffs
- python3 scripts/check_swallowed_error_budget.py: exit 0, total 3847 -> 3814
- NBUILD_REMOTE_ROOT=/home/kooshapari/builds/restart-save ~/bin/nbuild <wtree> test -p kcode --lib restart_: twice exit 2, nbuild cannot reach nixos, direct ssh timed out. ENV-BLOCKED.

tx-agent: jcode
tx-validated: lint
tx-task: G1-restart-save-safety
tx-scope: src/cli
tx-intent: restart save must never silently clobber an armed snapshot
tx-lane: jcode:session_koala_1795837517661_8c5572f0003a474a
…errors

Two defects in the previous commit, both found by actually building it:

- `restart_tests.rs:215` bound `let crashed = Session::create_with_id(...)` and
  then called `mark_active_with_pid(&mut self)`, so the test target failed to
  compile with E0596. The binding needs `mut`.
- Two `writeln!(output, ...)` calls in `run_restart_save_command` discarded their
  `io::Result`, which trips `unused_must_use` under `-D warnings`. They now
  propagate with `?`, matching the four sibling calls in the same function.

tx-agent: jcode
tx-validated: test
tx-task: PR-save-armed
tx-scope: src/cli/commands/restart.rs,src/cli/commands/restart_tests.rs
tx-intent: Make the branch build and pass its own restart tests.
tx-lane: jcode:session_daisy_1795074744352_88932230960f4f43
…ages

The two panic-prone usages in the provider doctor moved from
lifecycle_driver.rs into lifecycle_contracts.rs; the baseline still keyed the
old path, so the gate reported the new path as an addition and masked any
genuine growth there. Count is unchanged at 2.

tx-task: 409
tx-scope: scripts/panic_budget.json
tx-intent: keep the panic ratchet honest after a file move
tx-agent: jcode
tx-validated: manual
tx-lane: jcode:session_daisy_1795074744352_88932230960f4f43
args.rs had grown past its size ratchet. The cloud session view enum is a
self-contained argument type, so it moves to src/cli/args/cloud_view.rs
(1247 -> 1234 LOC) rather than being squeezed in place. Its re-export stays
for the call sites that name it.

The armed-snapshot guard in restart save no longer asserts the snapshot is
present after checking it is present: the check now binds the filtered
snapshot directly, so the refusal message reads its fields from the same
value it tested.

tx-task: 409
tx-scope: src/cli/args.rs, src/cli/args/cloud_view.rs, src/cli/args/tests.rs, src/cli/commands/restart.rs
tx-intent: clear the size and panic ratchets for the restore-save path
tx-agent: jcode
tx-validated: build
tx-lane: jcode:session_daisy_1795074744352_88932230960f4f43
Moves the four-arm restart match out of the top-level CLI dispatcher and
into src/cli/commands/restart.rs, where the handlers already live. The
dispatcher keeps one line per top-level command, so src/cli/dispatch.rs
drops from 1528 to 1520 LOC while fmt and the size ratchet agree.

tx-agent: jcode
tx-validated: build
tx-task: 409
tx-scope: src/cli/dispatch.rs, src/cli/commands.rs, src/cli/commands/restart.rs
tx-intent: give the size ratchet a durable shape instead of a squeezed line
tx-lane: jcode:session_daisy_1795074744352_88932230960f4f43
Copilot AI balanced review requested due to automatic review settings November 28, 2026 06:02
@codeant-ai

codeant-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt Review Status

✅  Review completed

Status Commit Started (UTC) Finished (UTC)
✅  #26577 Reviewed your PR 483c8ce Nov 28, 2026 · 06:02 06:08

@codeant-ai

codeant-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 95a76297-aa23-44d3-a161-78886c798813
Commits

Reviewing files that changed from the base of the PR and between a3c41a9 and 483c8ce.

Files selected for processing: 8

  • scripts/panic_budget.json
  • src/cli/args.rs
  • src/cli/args/cloud_view.rs
  • src/cli/args/tests.rs
  • src/cli/commands.rs
  • src/cli/commands/restart.rs
  • src/cli/commands/restart_tests.rs
  • src/cli/dispatch.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Nov 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codeant-ai

codeant-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

CodeAnt  CodeAnt Nitpicks

3 code suggestions

1. During startup auto-restore, the flag is cleared before restore reloads the file; a concurrent save sees this as unarmed and replaces the pending snapshot, so restore launches the new sessions.

Race condition · src/cli/commands/restart.rs:35-39


2. When --replace-armed overwrites an armed snapshot and captures sessions, this status text still says the replaced snapshot was unarmed.

Incorrect condition logic · src/cli/commands/restart.rs:75-83


3. If the snapshot file exists but load_snapshot() fails to parse it, try_exists() is true, so this treats corruption as absence and overwrites the unreadable snapshot.

Incorrect condition logic · src/cli/commands/restart.rs:117-124

@codeant-ai

codeant-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 483c8ce96ef2

@KooshaPari
KooshaPari merged commit 55897fd into master Nov 28, 2026
21 of 24 checks passed
@KooshaPari
KooshaPari deleted the fix/restart-save-armed-rebased branch November 29, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restart save silently overwrites an armed snapshot (clobbers pending restore, disarms it)

2 participants