Skip to content

fix: preserve job data when serialization fails - #1365

Open
rioyu123 wants to merge 1 commit into
amazon-braket:mainfrom
rioyu123:codex/preserve-braket-job-files
Open

rioyu123 wants to merge 1 commit into
amazon-braket:mainfrom
rioyu123:codex/preserve-braket-job-files

Conversation

@rioyu123

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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.

1 participant