Skip to content

acquire capture: report incomplete verification and lldb exit after rejection; test no-write on disk - #54

Merged
bojieli merged 6 commits into
mainfrom
fix/issue-48-capture-diagnostics
Nov 24, 2026
Merged

bojieli merged 6 commits into
mainfrom
fix/issue-48-capture-diagnostics

Conversation

@bojieli

@bojieli bojieli commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Closes #48

Follow-ups from the #31 review. These change diagnostics and test coverage only. A wrong key is still never accepted, and nothing is written when capture fails.

Incomplete verification is no longer reported as a mismatch

  • DatabaseSaltInventory.saltVerification(for:shouldStop:) returns a SaltVerification (verified, checked, and total distinct salts). verifiedSaltCount is now a thin wrapper around it.
  • The capture command's verify-then-write step moved from main.swift into VerifiedPassphraseCapture.captureAndWrite, so it can be tested. When the deadline cuts a candidate's check short, the capture ends at once with CaptureVerificationError.incomplete ("the timeout expired after checking k of N distinct database salts ... neither confirmed nor ruled out"). It is no longer counted as a rejection that later turns into "no match among N".
  • Candidates that were captured but never offered because the deadline had passed are reported as unchecked by the new CaptureError.timedOutWithUncheckedCandidates, which the CLI also reports as incomplete. This covers candidates queued in the same batch and complete reads that arrived while the last check was running.
  • The helper writes the candidate that passed verification, not whatever the capture closure returned.

The lldb exit stays the cause after a rejection

  • exitedWithoutCapture keeps its payload-free form. The new exitedAfterRejecting(rejectedCandidateCount:) is used when lldb exits before the deadline after earlier rejections. Its wording is neutral about why candidates were rejected, because capture(accept:) is a general API.
  • The exit time comes from Process.terminationHandler, so an exit during the last check, before the deadline, is still reported as the exit. An exit first seen after the deadline is reported as the timeout.

No-write guarantee tested on the filesystem

VerifiedPassphraseCaptureTests drives the real runSingleCapture loop against a stand-in lldb, a shell script that prints memory read hexdumps. It uses synthetic SQLCipher pages with a valid page-1 HMAC and a real temporary output:

  • For both endings, lldb timing out and lldb exiting, with the output absent and with it existing plus overwrite: true: the run fails with the expected error, an absent file and its folder stay absent, and an existing file keeps its bytes.
  • Control: with the same harness, an accepted key is written.
  • Further tests cover incomplete versus no-match classification, a candidate that arrives during the last check, and the exit after a rejection.

runSingleCapture changed from private to internal so that tests can call it.

Review

Five rounds of codex review --base origin/main, the cap. No round reported a P0 or P1. I fixed every P2 and P3 from rounds 1 to 4. Round 5 left two P2s about pipe-timing edge cases, both diagnostic-only:

  • If lldb prints a second candidate and then exits during the first check, and that check ends after the deadline, the result is exitedAfterRejecting and the buffered candidate is not counted as unchecked.
  • The final drain before a "no match" verdict waits a fixed 100 ms instead of using a synchronized cutoff. A read that arrives within that window can turn the verdict into "incomplete", and a very delayed reader could still be missed.

Testing

  • swift test (scratch copy without GreenBubblesHistoryApp): all suites pass; GreenBubblesAcquireTests: 142 tests.
  • swift format lint --strict, scripts/check-secret-hygiene.swift, and swift build --product greenbubbles-acquire pass.

Needs manual check

  • A live capture with WeChat. The write still goes through SecretOutputWriter as the invoking user, and the privileged path is unchanged, so scripts/sudo-smoke-test-acquire.sh was not extended. Running it once is still a reasonable check that the write site moved cleanly.

🤖 Generated with Claude Code

bojieli and others added 6 commits November 24, 2026 09:30
…jection

- Track whether each candidate was checked against every salt. A candidate
  the deadline cut short is reported as an incomplete check (salts checked
  of total) instead of "no match among" the full inventory.
- An unexpected lldb exit before the deadline stays the cause after an
  earlier rejection: exitedWithoutCapture now carries the rejected count
  as context instead of turning into noAcceptableCandidate.
- Move the capture command's verify-then-write step into
  VerifiedPassphraseCapture so it can be tested, and test the no-write
  guarantee on the filesystem with a stand-in lldb: an absent output stays
  absent and an existing one keeps its contents with --overwrite, both on
  timeout and on lldb exit.

Closes #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed key

- An incomplete check now throws from the verifier, so a following lldb
  exit cannot report it as a rejection.
- Write the candidate that passed verification, not whatever the capture
  closure returned.
- Scope the documented no-write guarantee to capture and verification
  failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dWithoutCapture

- A candidate the cursor skipped because the deadline passed now ends the
  capture with timedOutWithUncheckedCandidates, which the verified capture
  reports as an incomplete check rather than a mismatch.
- Keep the payload-free exitedWithoutCapture case and add
  exitedAfterRejecting for an exit after rejections, with wording that
  does not assume why the candidates were rejected.
- The no-write tests assert the specific error for each ending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…out over a late exit

- At the deadline, drain output that arrived while the last candidate was
  checked; complete reads there count as unchecked candidates.
- Report an lldb exit only when it was observed before the deadline.
- Changelog: mention unchecked candidates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…utput before no-match

- Record when lldb exits from Process.terminationHandler, so an exit during
  the last check before the deadline is still reported as the exit.
- Give in-flight output a moment to reach the accumulator before a
  definitive no-acceptable-candidate verdict.
- The late-read test has the stand-in lldb wait for the first check to
  start before printing the second read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bojieli
bojieli merged commit 54c3f3d into main Nov 24, 2026
4 checks passed
bojieli added a commit that referenced this pull request Nov 24, 2026
Keeps both sides of the CaptureError and runSingleCapture changes from #54.
An lldb exit during the attach phase is reported through #54's exitError.
VerifiedPassphraseCaptureTests' stand-in lldb now reports the process stopped
and waits for the post-check capture commands before printing reads, as
real lldb does under the two-phase attach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

acquire capture: follow-ups from the #31 review

1 participant