Skip to content

fix(flow): two rechecks that held correct writes UNCERTAIN - #2377

Open
abrichr wants to merge 1 commit into
mainfrom
fix/recheck-false-stops
Open

abrichr wants to merge 1 commit into
mainfrom
fix/recheck-false-stops

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Summary

Two causes made a recheck hold a correct write UNCERTAIN. Both showed up when a replay of a first-contact study's graded cases started confirming writes. Before that, every write was refuted earlier, so no recheck ran.

  1. A write begun with no ledger. begin_write(..., ledger=None) records no attempt. recheck(contract, result) with the default ledger argument then resolved the default ledger, found no attempt there, and returned UNCERTAIN with "the ledger no longer has this attempt as its current write". A recheck now uses the ledger the write was begun under, so a ledger-less write is rechecked with no ledger. begin_write always stores the ledger it resolved: default_ledger() never returns None. So WriteResult.ledger is None means only an explicit ledger=None, and a write made under any ledger still binds its recheck to that ledger's attempt.
  2. A wake just before the due second. recheck(..., wait=True) slept seconds_until(due_at) once. The read time is the wall clock truncated to the second. A sleep that ended a few milliseconds before the wall clock reached due_at read as "not yet due", and the write was held UNCERTAIN. In the replay this hit 3 of 66 rechecks. The wait now loops until the wall clock has reached the due time.

Neither change lets a recheck confirm anything it refused before. A refuting recheck is unchanged, and a recheck without a ledger still holds late collateral; the new test checks this.

Tests

  • test_a_write_begun_without_a_ledger_rechecks_without_one: the first part fails on main (it gives UNCERTAIN) and passes here. Late collateral is still a stop.
  • test_a_sleep_that_wakes_early_still_reads_when_due: a sleep that ends 0.3 s early still reads when due.
  • tests/test_verifier_recheck.py: 85 passed. The existing assertions are unchanged.

Evidence: openadapt-internal evidence/false-stops-2026-11 (the replay harness and results).

A write begun with ledger=None was rechecked against the default ledger,
found no attempt there, and was held UNCERTAIN. A recheck that slept until
its due time could wake a few milliseconds before the wall clock reached
it, read the time as not yet due, and hold the write UNCERTAIN.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 9a0e1a5

Author is GitHub abrichr, not Grok. I reviewed verifier.py and tests/test_verifier_recheck.py in a fresh worktree at this head. I will not merge.

Both changes keep the recheck judgment itself fail-closed. They only stop a correct write from being held UNCERTAIN for a bookkeeping reason.

  1. Ledger-less writes. begin_write(ledger=None) leaves WriteResult.ledger is None (I checked _capture / pending.ledger = led — default_ledger() is never None, so ledger is None is only the explicit opt-out). _recheck_attempt now binds the recheck to write.ledger even when that value is None, instead of resolving the default ledger and failing with "the ledger no longer has this attempt as its current write". A ledger-less recheck still holds late collateral: the new test writes a second row and asserts the outcome is not CONFIRMED.

  2. Early wake. recheck(..., wait=True) now loops sleep(wait_s + 0.05) until seconds_until(due_at) is no longer positive, so a wake a few milliseconds before the truncated-to-the-second due time does not read as "not yet due". This does not shorten the owed wait or change what a due recheck will accept.

I did not find a path that confirms a write the previous code would have refused.

P3 (non-blocking)

_hold_after_recheck still has the old guard (if ledger is _NO_LEDGER and write.ledger is not None). For an explicit ledger=None write, a default recheck() can still resolve the default ledger when recording the hold. That path does not confirm the write (it adds a "hold this write by hand" reason if no attempt is there). It is inconsistent with _recheck_attempt and would be cleaner if it also used write.ledger unconditionally, including None.

What I ran

  • Confirmed the PR is OPEN, not draft, head still 9a0e1a54343bee8fa92e08d842969b90a0204ede. No STOP/HOLD in Scrubbing and Fix Atomacos #211 that withdraws this review. No prior Grok verdict on this PR.
  • tests/test_verifier_recheck.py: 85 passed (Python 3.12, hypothesis + pytest-timeout).
  • Mutant: restoring if ledger is _NO_LEDGER and write.ledger is not None in _recheck_attempt makes test_a_write_begun_without_a_ledger_rechecks_without_one fail with UNCERTAIN / "the ledger no longer has this attempt as its current write". Restored the file afterward.
  • Protected-path evidence is red for process metadata only (branch has no vendor prefix; expected exactly one current exact-head author declaration and expected exactly one current exact-head independent review). Secondary to the code review.

Review only; I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 9a0e1a5

Author declaration for protected-path check (false-stop recheck PR authored by Claude, approved by Grok at this exact head).

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Author: Claude (independent review by Grok at 9a0e1a5).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant