Skip to content

fix: persistence starttime unset/defaults - #4251

Merged
johanneskoester merged 4 commits into
mainfrom
fix/db-metadata-starttime
Jul 30, 2026
Merged

johanneskoester merged 4 commits into
mainfrom
fix/db-metadata-starttime

Conversation

@tedil

@tedil tedil commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

This PR addresses #517 (comment) a regression introduced in #4012 by a) recording the current time as the starttime in the DB backend, b) re-instating the double-finish check for the file backend.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).
  • I, as a human being, have checked each line of code in this pull request

AI-assistance disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Summary by CodeRabbit

  • Bug Fixes
    • Improved job metadata timestamp handling across file-based and database-backed persistence.
    • Preserved the original start time when jobs complete, including repeated completion updates.
    • Ensured completed records include a start time even when no prior start event was recorded.
    • Recorded start times for incomplete job metadata and maintained correct start/end time ordering.

@tedil
tedil requested a review from johanneskoester as a code owner July 22, 2026 07:23
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Persistence metadata now records job start times when incomplete markers are created and reuses them when jobs finish. File and database backends implement starttime retrieval, with parametrized tests covering both implementations.

Changes

Starttime recording

Layer / File(s) Summary
Backend starttime contract and completion flow
src/snakemake/persistence/__init__.py, src/snakemake/persistence/db.py, src/snakemake/persistence/file.py
PersistenceBase retrieves recorded start times during completion; file and database persistence implementations record and retrieve them.
Cross-backend starttime tests
tests/test_persistence.py
Parameterized tests cover starttime creation, stale-value replacement, completion ordering, repeated completion, and fallback behavior for both backends.

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

Sequence Diagram(s)

sequenceDiagram
  participant PersistenceBase
  participant FilePersistence
  participant DbPersistence
  participant MetadataRecord
  PersistenceBase->>FilePersistence: _get_recorded_starttime(key)
  FilePersistence->>MetadataRecord: read incomplete marker or metadata record
  PersistenceBase->>DbPersistence: _get_recorded_starttime(key)
  DbPersistence->>MetadataRecord: read recorded starttime
  PersistenceBase->>MetadataRecord: write completed metadata with preserved starttime
Loading

Suggested reviewers: johanneskoester

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the persistence starttime fix.
Description check ✅ Passed The description covers the bug, QC checklist, and AI-assistance disclosure required by the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/db-metadata-starttime

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/snakemake/persistence/__init__.py`:
- Line 506: Update the start-time assignment around _get_recorded_starttime to
use fallback_time only when the recorded value is None, preserving valid
timestamps such as 0.0.

In `@tests/test_persistence.py`:
- Around line 184-196: Strengthen test_normal_completion by capturing the
timestamp returned by persistence._get_recorded_starttime() immediately after
started(...), then assert rec.starttime equals that captured value exactly.
Retain the existing completion and record-state assertions while replacing the
broad before/after timestamp validation that permits a fallback timestamp.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbde688a-f9c6-4ce1-af4e-ddaccb018488

📥 Commits

Reviewing files that changed from the base of the PR and between 1a27746 and 8a1336a.

📒 Files selected for processing (4)
  • src/snakemake/persistence/__init__.py
  • src/snakemake/persistence/db.py
  • src/snakemake/persistence/file.py
  • tests/test_persistence.py


if record.starttime is None:
record.starttime = fallback_time
record.starttime = self._get_recorded_starttime(key) or fallback_time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Preserve valid epoch timestamps.

Line 506 treats 0.0 as missing and overwrites it with fallback_time. Check explicitly for None.

Proposed fix
-                record.starttime = self._get_recorded_starttime(key) or fallback_time
+                recorded_starttime = self._get_recorded_starttime(key)
+                record.starttime = (
+                    recorded_starttime
+                    if recorded_starttime is not None
+                    else fallback_time
+                )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
record.starttime = self._get_recorded_starttime(key) or fallback_time
recorded_starttime = self._get_recorded_starttime(key)
record.starttime = (
recorded_starttime
if recorded_starttime is not None
else fallback_time
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/snakemake/persistence/__init__.py` at line 506, Update the start-time
assignment around _get_recorded_starttime to use fallback_time only when the
recorded value is None, preserving valid timestamps such as 0.0.

Comment thread tests/test_persistence.py Resolved
@johanneskoester
johanneskoester merged commit 56395c0 into main Jul 30, 2026
87 checks passed
@johanneskoester
johanneskoester deleted the fix/db-metadata-starttime branch July 30, 2026 10:36
@johanneskoester

Copy link
Copy Markdown
Contributor

Thanks a lot!

johanneskoester pushed a commit that referenced this pull request Jul 30, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.24.0](v9.23.1...v9.24.0)
(2026-07-30)


### Features

* allow to combine cases with otherwise in branch function
([#4262](#4262))
([000ff52](000ff52))


### Bug Fixes

* avoid config hash crash for non-serializable values
([#4241](#4241))
([1a27746](1a27746))
* compilation error when final line contains an f-string
([#4234](#4234))
([9c5e7fe](9c5e7fe))
* Group error log formatting
([#4256](#4256))
([bb6dcde](bb6dcde))
* leak of benchmark monitor threads
([#4259](#4259))
([d37852e](d37852e))
* no benchmark warning when a process exits before it can be sampled
([#4260](#4260))
([6738359](6738359))
* persistence starttime unset/defaults
([#4251](#4251))
([56395c0](56395c0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants