Skip to content

fix: preserve job data when serialization fails - #1365

Merged
speller26 merged 2 commits into
amazon-braket:mainfrom
rioyu123:codex/preserve-braket-job-files
Nov 22, 2026
Merged

speller26 merged 2 commits into
amazon-braket:mainfrom
rioyu123:codex/preserve-braket-job-files

Conversation

@rioyu123

Copy link
Copy Markdown
Contributor

Issue #, if available: None.

Description of changes:

save_job_checkpoint and save_job_result opened the output file with "w" before serializing the data. If serialization failed, the existing file was already truncated. If no file existed, an empty one was left behind.

For results.json this also blocked recovery: every later save tried to load the empty file and failed, even with valid data.

This change builds the complete JSON string before opening the file. Serialization failures leave existing data untouched and do not create a new file. The file format and public API are unchanged. This does not make writes atomic or protect against errors during the write itself.

Testing done:

  • Eight regression cases cover both save functions, plaintext and pickled formats, and existing or missing files. They check file preservation and a successful retry. All eight fail on the original code and pass with the fix.
  • Windows, CPython 3.12: persistence tests pass (24 passed, 4 existing xfails).
  • Linux, CPython 3.12: tox -e unit-tests -- -n 4 passes (3,504 passed, 131 xfailed).
  • tox -e linters_check,type-check,docs passes. The documentation build completes with warnings.
  • tox -e coverage-check passes at 100%.
  • Live AWS integration tests were not run; the new tests make no AWS calls.

Merge Checklist

General

  • I have read the CONTRIBUTING doc
  • I used the PR title format described in CONTRIBUTING
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate) — N/A; no documentation changes are needed.

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
@rioyu123
rioyu123 requested a review from a team as a code owner October 10, 2026 07:36
@github-actions github-actions Bot added the aws label Oct 10, 2026
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4a299f4) to head (02c89a5).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          171       171           
  Lines        11765     11767    +2     
  Branches      1557      1557           
=========================================
+ Hits         11765     11767    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@speller26
speller26 merged commit 39f8299 into amazon-braket:main Nov 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants