Skip to content

Close the US post-export scorer when certification fails #1787

Backlog

Description

@MaxGhenis

Certification leaves the shared post-export scorer open when one of its stages fails. _certify_us_build in tools/build_us_fiscal_refresh_release.py opens the scorer before the reform-coverage smoke (line 19915). It closes it through _close_post_export_scorer after the Medicare IRMAA holdout (line 20077). No try in _certify_us_build covers the stages between, and the caller's handler doesn't close the scorer, so an exception that escapes any of them skips close().

Since #1772, a refused batch file in the merged baseline pass takes that path too. Before it, that pass fell back to each stage's own pass, so a file that failed one read there got a second read, and certification could still finish and close the scorer. A refused batch file in any other pass already took that path.

Effect today

  • tools/certify_us_national_build.py runs certification, and no other command does. On a failure, _certify_main_with_close_out calls telemetry.fail (line 15384) and raises the error again, and the process exits.
  • At exit, the scorer's weakref.finalize (line 5979) removes its batch directory, since a finalizer runs at exit by default. A first SIGTERM goes through raise_on_sigterm and exits 143, with the same cleanup.
  • A SIGKILL or an out-of-memory kill during scoring leaves the post-export-batches-* directory behind, and a fix on the failure path can't change that. Certifying the same --out again removes it in _place_build_for_certification (lines 15210 to 15216).
  • docs/us-release-build-rule.md puts the batch files at about as much disk as the exported H5. Today they hold that disk from the failure until the process exits, and a kill in that window, such as a second SIGTERM, leaves them behind.
  • The fix removes them at the failure, so a kill after it leaves nothing. The scorer's constructor already cleans up this way when writing the batch files fails (lines 5986 to 5988).

Fix

  • On the failure path, close the scorer in an except BaseException: block, suppress an Exception from close() itself, and raise the original error again.
  • close() removes the batch files last, after _finish_open_reform(), so the block also calls the scorer's _remove_batch_files() after it. After a close() that succeeded, that call does nothing.
  • A try/finally would raise an error from close() in place of the original, which would survive only as its __context__. telemetry.fail would then record the close error, and a SIGTERM whose cleanup failed would exit 1 where it now exits 143.
  • A test makes a stage fail with an error that propagates, and checks that the scorer closed while it still holds the exception. The smoke, reform validation and demographics propagate any error. The holdouts record an ordinary scoring error as unavailable and propagate a refused batch file.
  • The certification tests' stub scorer records close(), and a test with a real scorer can check that its batch directory has gone.
  • Report held-out SNAP caseload composition and take-up at certification (#647) #1714 adds a stage inside this span on its own branch, and another open PR changes the scorer's open call. I'll make the fix once both changes reach main, so that it rebases once.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions