Skip to content

fix(storage): restore the last saved snapshot when timestamps tie 🤖🤖🤖 - #276

Open
Sampoornnagpal wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
Sampoornnagpal:fix/snapshot-timestamp-ties
Open

fix(storage): restore the last saved snapshot when timestamps tie 🤖🤖🤖#276
Sampoornnagpal wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
Sampoornnagpal:fix/snapshot-timestamp-ties

Conversation

@Sampoornnagpal

@Sampoornnagpal Sampoornnagpal commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Two snapshots can receive identical created_at timestamps. restore_latest_snapshot() then selects the earlier save, restoring stale agent state. Break timestamp ties by descending SQLite row insertion order while retaining timestamp ordering for distinct saves; no schema migration is required.

Add a fixed-clock regression that saves values 1 and 99 and checks that 99 is restored, including after reopening the database. It fails before the fix.

Related issues

No matching open issue found. This does not change the context serialization or durable operation work in #235/#174.

Validation

uv run pytest -q tests/test_sqlite_storage_latest.py tests/storage — 102 passed.

Windows/Python 3.12; external import-only helpers bypass the existing fcntl/SIGUSR2 blockers (#84/#85). This verifies snapshot ordering and persistence, not POSIX locking or signal behavior. Helpers are not included.

Checklist

  • Ruff lint and formatting pass.
  • Regression and storage tests pass.
  • No public API or documentation change required.
  • Existing SPDX headers retained.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed snapshot retrieval so the most recently saved snapshot is consistently selected when multiple snapshots share the same creation time, including after reopening storage.
    • Snapshot ordering is now deterministic in these tie cases.
  • Tests

    • Added regression coverage for snapshot ordering when timestamps are identical and storage is reopened.

Signed-off-by: Sampoorn Nagpal <nagpalsampoorn@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 23fa6ea2-3b67-4a1d-955a-74a3ba8739d9

📥 Commits

Reviewing files that changed from the base of the PR and between 3bef54f and 9daf259.

📒 Files selected for processing (1)
  • tests/test_sqlite_storage_latest.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_sqlite_storage_latest.py

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


📝 Walkthrough

Walkthrough

SQLite snapshot retrieval now uses rowid as a tie-breaker for equal timestamps. A regression test verifies that the most recently saved snapshot remains selected after database reopening.

Changes

Snapshot latest selection

Layer / File(s) Summary
Timestamp tie-breaking and regression coverage
src/nooa/storage/sqlite.py, tests/test_sqlite_storage_latest.py
Snapshot queries order by descending created_at and rowid. The regression test saves equal-timestamp snapshots and verifies the second snapshot remains latest after reopening.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 9daf2

Snapshot restoration now consistently returns the most recently saved snapshot when timestamps match, including after reopening the database. The covered behavior is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the storage fix for restoring the last saved snapshot when timestamps tie. The emojis add minor noise but do not reduce clarity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Sampoorn Nagpal <nagpalsampoorn@gmail.com>
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.

1 participant