Skip to content

fix(mission): honor compare-and-swap loss on recovery failure and cancellation writes - #230

Open
jimmyallinai wants to merge 1 commit into
elder-plinius:mainfrom
jimmyallinai:recovery-cas-outcomes
Open

jimmyallinai wants to merge 1 commit into
elder-plinius:mainfrom
jimmyallinai:recovery-cas-outcomes

Conversation

@jimmyallinai

Copy link
Copy Markdown

Issue for this PR

Fixes #229

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

MissionRecoveryCoordinator.recover() checked the compare-and-swap result on the claim, crash-block, and completion writes, but ignored it on two later writes:

  • Execution-failure write: when the CAS lost a concurrent race, recover() still returned recovered/blocked with a snapshot showing the action as failed/blocked — a transition that was never persisted. The store still held the action as in_progress from the claim, so the next recovery would report it as ambiguous-after-crash, contradicting the outcome just returned.
  • Post-claim cancellation write: same shape — a lost CAS still produced outcome: 'cancelled' with a cancelled-state snapshot the store never accepted.

Both paths now honor a lost CAS exactly like the completion path already does: return { outcome: 'concurrent' } with no fabricated snapshot. executed carries the action id on the failure path (the executor did run, and its side effect may have happened) and stays empty on the cancellation path (it never ran). This restores the invariant in docs/MISSION_RECOVERY.md that a writer which loses the revision comparison reports concurrent instead of asserting state it does not hold.

The change is two one-line guards in src/mission/recovery.ts; no outcome values, schemas, or store semantics change.

How did you verify your code works?

  • Reproduced first with an in-memory store whose CAS succeeds for the claim and fails for the second write: on the base commit, an executor that throws produced outcome: 'recovered' with the action reported failed while the store still showed in_progress; an abort landing after the claim produced outcome: 'cancelled' while the store still showed in_progress. After the fix both return outcome: 'concurrent' and the stored state is untouched by the losing write.
  • New regression tests in src/__tests__/mission-recovery.test.ts cover both paths: on the base commit they fail (2 failed / 8 passed in that file), with the fix the full suite passes — vitest run src: 990 passed, 0 failed.
  • tsc --noEmit clean; eslint on the changed files reports no problems.

@jimmyallinai

Copy link
Copy Markdown
Author

Hi — checking in on this PR, it has been open for a week. I re-verified just now: it is still mergeable with no conflicts, and this repo has no CI configured so there are no failing checks on my side. Happy to adjust the CAS-guard approach or the test coverage if you would like anything changed.

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.

Mission recovery reports failed/cancelled transitions that were never persisted when a later compare-and-swap loses

1 participant