Add stage checkpoints and resume to SourceHuntRunner - #129
Draft
jorge-garcia-le wants to merge 1 commit into
Draft
Add stage checkpoints and resume to SourceHuntRunner#129jorge-garcia-le wants to merge 1 commit into
jorge-garcia-le wants to merge 1 commit into
Conversation
Write a lossless findings snapshot at each natural pipeline phase boundary (end of hunt, verify, exploit) under <session>/checkpoints/<stage>.json. Each file is a json.load-simple superset of findings.json, so it doubles as an eval artifact showing how findings evolve across phases. These checkpoints back a new resume_session parameter: a crashed or errored run resumes from the last completed phase instead of re-hunting from scratch. Resume re-runs preprocess (rebuilds repo/callgraph/sandbox) but skips rank (its priority fields are only consumed by the hunt phase), seeds the finding lists from the checkpoint, and guards each completed phase and its enrichment/side-effect sub-stages so only work after the last checkpoint executes. Report always re-runs. Budget carries forward: the prior run's settled spend is summed from the existing spend-ledger.jsonl and seeded into a new SpendLedger via a new initial_spent_usd kwarg, so a resumed run honors the original dollar cap. Resume is deliberate — a session dir with no checkpoint raises rather than silently starting over. Existing artifacts are untouched; only new checkpoint files are added. Adds tests for the checkpoint module, budget carry-forward, deliberate exit, and end-to-end resume (hunt+verify skipped, report re-runs, budget carried).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-stage checkpoints and a resume capability to a single
SourceHuntRunnerrun. Today, if a run crashes partway through, everything is lost — the hunt runs entirely in memory andfindings.json/SARIF/report.mdare written only once at the end. This change writes a lossless findings snapshot at each natural pipeline phase boundary so a crashed run can resume from the last completed phase.Two goals:
json.load-simple artifact per phase showing how findings evolve across hunt → verify → exploit.Scope is deliberately coarse (three phase-level checkpoints, not the ~10 internal sub-stages). Mid-hunt/per-file resume, the proof flow, and changes to existing artifacts are out of scope.
What it does
Three checkpoints under
<output_dir>/<session_id>/checkpoints/:hunt.jsonfindingsverify.jsonfindings+verified+rejectedexploit.jsonfindings+verified+rejected+exploitedEach file is a superset of
findings.json. Serialization is lossless (dataclasses.asdict, not the pool's lossy discovery-time subset); reload uses the tolerant__dataclass_fields__filter.Resume via a new
resume_sessionparameter (accepts a baresh-<uuid>name or a path to a session dir):findings.json/SARIF/report.md).Budget carries forward: the prior run's settled spend is summed from the existing
spend-ledger.jsonland seeded into a newSpendLedgervia a newinitial_spent_usdkwarg, so a resumed run honors the original dollar cap.Existing artifacts (
findings.json,findings_pool.jsonl, etc.) are untouched — only new checkpoint files are added.Changes
clearwing/sourcehunt/checkpoints.py— standalone checkpoint read/write (atomicmkstemp+os.replace),latest_checkpoint,sum_prior_spend,resolve_session_dir.clearwing/llm/budget.py— newinitial_spent_usdkwarg onSpendLedger(validated finite/≥0), recorded ascarried_forward_usdin therun_startedevent.clearwing/sourcehunt/runner.py—resume_sessionparam; adopts the resumed session id before instrumentation; seeds the ledger on resume; preflight skips models for skipped phases;arunwrites the three checkpoints and guards completed phases on resume.tests/test_sourcehunt_checkpoints.py— 27 tests covering lossless round-trip, priority ordering, spend reconstruction, budget seeding, deliberate exit, and end-to-end resume (hunt+verify skipped, report re-runs, budget carried).Eval passthrough
No call-site change needed in
agent_eval.py—resume_sessionflows through the existing**extra/--runner-arg resume_session=<name>passthrough.Verification
ruff checkclean on all touched files.