Commit 35c9ddb
committed
fix(runs): saveCurrentRun persists the RESERVED run number (no 4-store split)
CRITICAL from the bug hunt: saveCurrentRun re-derived the run number via
getNextRunNumber() (= max(index.runs)+1) instead of using the number startFreshRun
already reserved as state.activeRunNumber. A concurrent delete/save that shifted
max(index.runs) made the snapshot dir, index entry, SQLite row, and
state.activeRunNumber split across two numbers (one run → two identities).
Root-cause fix:
- Persist into state.activeRunNumber (fall back to getNextRunNumber only when no
run is reserved, e.g. the first-boot "Initial Audit" save).
- Index write is now find-or-update on that number: re-saving the same run updates
its entry in place instead of pushing a duplicate. One run = one number = one
dir = one entry.
- Add a busy guard to POST /api/runs/save (block only status==='running' — saving
during a pause stays allowed, matching the SAVE button which hides only while
running) so a manual save can't race the live results array.
Adversarially reviewed: the two high-risk paths (re-saving a loaded run, spend
regression in the dbRunId-mismatch case) are non-reachable — C-1(b) fires first
when dbRunId matches, and after a load live spend equals stored spend. Strictly
safer than the prior duplicate-push. Test suite green (188/31/45/35).1 parent be64d79 commit 35c9ddb
1 file changed
Lines changed: 24 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
624 | | - | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
625 | 632 | | |
626 | 633 | | |
627 | 634 | | |
| |||
658 | 665 | | |
659 | 666 | | |
660 | 667 | | |
661 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
662 | 673 | | |
663 | | - | |
| 674 | + | |
664 | 675 | | |
665 | 676 | | |
666 | 677 | | |
| |||
669 | 680 | | |
670 | 681 | | |
671 | 682 | | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | 683 | | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | 684 | | |
680 | | - | |
681 | 685 | | |
682 | | - | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
683 | 690 | | |
684 | 691 | | |
685 | 692 | | |
| |||
2894 | 2901 | | |
2895 | 2902 | | |
2896 | 2903 | | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
2897 | 2910 | | |
2898 | 2911 | | |
2899 | 2912 | | |
| |||
0 commit comments