Skip to content

script: report parallel signing progress in order - #432

Merged
kiwidream merged 1 commit into
1.x.xfrom
kiwidream/flaky-sign-progress
Nov 16, 2026
Merged

kiwidream merged 1 commit into
1.x.xfrom
kiwidream/flaky-sign-progress

Conversation

@kiwidream

@kiwidream kiwidream commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The parallel P2MR signer could report signing progress out of order (3, then 2). That is the one-off Windows failure in wallet_p2mr_parallel_signing_tests/MixedManagersKeepForeignInputErrors:

check progress.completed >= completed has failed [2 < 3]

Fixes #394.

Cause

notify_completed_input in TrySignTransactionPQCParallel (src/script/sign.cpp) incremented the completed-input counter before taking progress_mutex and called the progress callback after taking it. Two workers finishing close together could take counts 2 and 3, and the worker holding 3 could win the mutex.

Fix

Take the mutex first, so counting and reporting are one critical section. One statement moves inside an existing lock; no new locks. Signing, PQC counter reservation and commit, cancellation and error handling are unchanged.

The ordering guarantee covers the SIGNING_INPUTS reports of one parallel signing call. Not changed, and found by reading rather than tested: a wallet operation can still report a lower count after a higher one when

  • the serial signing path restarts its count at 0 for each script-pubkey manager (src/script/sign.cpp around line 1755, reached from CWallet::SignTransaction), or
  • a later manager recounts from the inputs that are complete in the transaction after a worker failure or a failed finalize in an earlier manager.

Tests

  • New regression case P2MRWalletParallelProgressNeverDecreases. It runs three workers and uses the existing test-only PQC signing observer to hold one worker after it signs. The progress callback keeps the lock until another worker has signed and is waiting, then releases the held worker. With counting under the lock the order is correct whatever the timing, so the case cannot fail on correct code; its waits give up after 10 s, so it cannot hang. Whether it catches the old code depends on which waiter gets the mutex, so detection is likely, not guaranteed (measured below).
  • P2MRWalletParallelDefaultArgsUseAutoWorkers now also checks that SIGNING_INPUTS progress never decreases.

Evidence

Local runs on Linux, Release build, -DBUILD_GUI=OFF:

Check Old code This change
New case (only the lambda reverted for "old") failed 10 of 10 runs, 3 of 3 repetitions each, [2 < 3] passed 20 of 20, about 2.2 s per run
MixedManagersKeepForeignInputErrors with a temporary 50 ms sleep between the increment and the lock failed 10 of 10 passed 10 of 10 with the same sleep inside the lock
  • wallet_p2mr_parallel_signing_tests: 5 consecutive passes with the new case, 20 consecutive before it was added.
  • Full test_qbit passed (462 s).
  • A callback-only version of the regression case (sleeping 50 ms or 800 ms in the first worker report) did not catch the old code on Linux, 0 of 30 repetitions: the waiting workers queue on the mutex in count order and glibc hands it over in that order. That is why the case uses the signing observer.
  • Clang 20 -Wthread-safety -Werror=thread-safety on src/script/sign.cpp: no diagnostics. std::mutex is not annotated, so this does not verify the lock itself.

Not run: Windows, where the original failure was seen, and sanitizer builds. CI covers those here.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T15:27:18.223824Z ecdc0c5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The parallel P2MR signer counted a completed input before taking the
progress mutex and reported it after. Two workers finishing close
together could take counts 2 and 3, and the one holding 3 could win the
mutex, so the callback saw 3 followed by 2. The signing progress shown
to the caller then went backwards, which is what made
MixedManagersKeepForeignInputErrors fail once on Windows with
"progress.completed >= completed has failed [2 < 3]".

Take the mutex before counting, so counting and reporting happen in one
critical section and the reported count never decreases. Signing,
counter reservation, cancellation and error handling are unchanged.

Add P2MRWalletParallelProgressNeverDecreases as a regression case. With
three workers it uses the existing test-only PQC signing observer to
hold one worker after it signs, keeps the progress lock in the callback
until another worker has signed and is waiting for that lock, and then
lets the held worker go as the lock is released. With the old code the
released worker took the higher count and reported first; with counting
under the lock the reported order is correct whatever the timing.

Also check that SIGNING_INPUTS progress never decreases in
P2MRWalletParallelDefaultArgsUseAutoWorkers, which already records the
events.

Fixes #394

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kiwidream
kiwidream force-pushed the kiwidream/flaky-sign-progress branch from d4e4bd7 to ecdc0c5 Compare November 16, 2026 15:25
@kiwidream

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: ecdc0c5a14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kiwidream
kiwidream merged commit 3271b63 into 1.x.x Nov 16, 2026
37 checks passed
kiwidream added a commit that referenced this pull request Nov 17, 2026
…Policy Gate to main (#423, #372, #440)

## Summary

This brings two changes that landed on `1.x.x` to `main`, unchanged, and one that is open against `1.x.x`:

- **#423:** Full Validation and Core Checks skip their expensive jobs for a pull request whose tree already passed.
- **#372:** the signed-commit and `signed-landing` ruleset templates, the `signed-landing` workflow, first-parent release checks, and secret scans that cover merges.
- **#440 (open against `1.x.x`, rebased onto it on 17 November):** the Key Policy Gate asks signed approvals only for its own three files, and the mainnet posture test pins the Core Checks gate as whole blocks. Its two commits are here as they are on #440's branch.

GitHub runs `signed-landing` (`pull_request_target`) only from `main`'s copy of the workflow. Until `main` holds it, the check reports nothing on any qbit pull request, and `required-checks.json` cannot be applied to `1.x.x`, `1.0.0` and `0.1.x`. This is the step #372 named: bringing the workflow to `main` before the next release.

#423 comes first because #372's posture test and documents rely on it.

After this, everything under `.github/`, `ci/`, `contrib/` and `doc/` equals `1.x.x` with #440 on top; before #440's two commits, each of the 33 files #423 and #372 touch equals `1.x.x`'s copy. Nothing is left out, and nothing else from `1.x.x` comes over: the three other changes `main` lacks (#431, #432, #434: two test fixes and one in `src/script/sign.cpp`) stay off it. Every pick applied without a conflict.

Merging changes no ruleset: an admin applies the templates afterwards, by `doc/development/public-branch-and-rulesets.md`.

## Testing

- [ ] Built locally.
- [x] Ran focused unit or functional tests for the changed area.
- [x] Ran lint or formatting checks relevant to this change.
- [ ] Not run. Reason:

- Every Python test file under `ci/` (`ci/checks`, `ci/release`, `ci/scanners`), each run as `python3 <file>`: 20 files and 602 tests pass on `main` before; 21 files and 774 tests pass with #423 and #372; with #440's commits on top, 21 files pass again (781 tests). No test that passed before fails.
- `.github/workflows/signed-landing.yml` is byte for byte the file the other Qbit-Org repositories run, apart from its two configuration lines (`AS_IS_HEADS: "sync-* subtree-*"`, `AS_IS_LINES: ""`).
- The documentation, metadata and lint checks that could run without building the node pass. Not run: the subtree lint, which could not fetch its sources from the machine these checks ran on. One more actionlint finding of a class `main` already has (a YAML alias).
- The node was not built and no functional test was run here: neither commit changes anything under `src/` or `test/`. CI runs them.

## Target Branch

- [x] This PR targets `main` or a maintainer-requested release branch such as `0.1.x`.

## Risk / Review Notes

- [x] Consensus, script, crypto, wallet, P2P, release, CI, or security-sensitive behavior changed.
- [ ] No consensus, script, crypto, wallet, P2P, release, CI, or security-sensitive behavior changed.

Notes:
- **CI and release behaviour change on `main`**, as they did on `1.x.x` with #423 and #372: the same-tree skip in Full Validation and Core Checks; a release needs protected, first-parent trusted refs; staging refuses a tag on a pull request's head; the secret scans cover merges.
- **The Key Policy Gate's own code changes** (#440): gate code becomes three files, and two of its checks run without approvals. See #440 for the review notes; it should land on `1.x.x` too, so the two branches do not drift.
- **Key Policy Gate:** the check is red on this pull request, and that is expected. The gate refuses a change to workflows and files under `ci/` without approvals signed by three mainnet signers. No ruleset requires the gate yet, and the operator decided on 13 November to land the signed-landing workflow before one does, without collecting signatures.
- **`signed-landing` starts reporting** on qbit pull requests once this lands. Nothing requires it until `required-checks.json` is applied.
- **One sentence goes stale:** `doc/development/public-branch-and-rulesets.md` says the check reports nothing until `main` holds the workflow, "which is after the next release moves `main`". This pull request makes that happen earlier. The sentence is left as it is so that the file stays equal to `1.x.x`'s; it can be reworded on `1.x.x`.

## Docs / Process Impact

Choose exactly one:

- [x] I updated public docs because this PR changes user-visible behavior, integration guidance, release/process guidance, or expected validation.
- [ ] No public docs update needed. Reason:

The documents come over with the two changes: `CONTRIBUTING.md`, `doc/development/public-branch-and-rulesets.md`, `doc/development/ci-same-tree-skip.md`, `doc/development/developer-notes.md`, the release process documents and `doc/subtrees/libbitcoinpqc.md`.

## libbitcoinpqc Subtree Checklist (if `src/libbitcoinpqc` changed)

Not applicable: `src/libbitcoinpqc` is not changed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
1422396 ci: bring the same-tree CI skip and signed landing to main (#423, #372)
2bee83d ci: ask signatures only for the Key Policy Gate's own three files
c130f87 test: pin the Core Checks gate's posture check as whole blocks

Co-authored-by: Claude Opus 5.5 <[email protected]>
Squashed-from: c130f87
kiwidream added a commit that referenced this pull request Nov 17, 2026
…Policy Gate to main (#423, #372, #440) (#441)

## Summary

This brings two changes that landed on `1.x.x` to `main`, unchanged, and one that is open against `1.x.x`:

- **#423:** Full Validation and Core Checks skip their expensive jobs for a pull request whose tree already passed.
- **#372:** the signed-commit and `signed-landing` ruleset templates, the `signed-landing` workflow, first-parent release checks, and secret scans that cover merges.
- **#440 (open against `1.x.x`, rebased onto it on 17 November):** the Key Policy Gate asks signed approvals only for its own three files, and the mainnet posture test pins the Core Checks gate as whole blocks. Its two commits are here as they are on #440's branch.

GitHub runs `signed-landing` (`pull_request_target`) only from `main`'s copy of the workflow. Until `main` holds it, the check reports nothing on any qbit pull request, and `required-checks.json` cannot be applied to `1.x.x`, `1.0.0` and `0.1.x`. This is the step #372 named: bringing the workflow to `main` before the next release.

#423 comes first because #372's posture test and documents rely on it.

After this, everything under `.github/`, `ci/`, `contrib/` and `doc/` equals `1.x.x` with #440 on top; before #440's two commits, each of the 33 files #423 and #372 touch equals `1.x.x`'s copy. Nothing is left out, and nothing else from `1.x.x` comes over: the three other changes `main` lacks (#431, #432, #434: two test fixes and one in `src/script/sign.cpp`) stay off it. Every pick applied without a conflict.

Merging changes no ruleset: an admin applies the templates afterwards, by `doc/development/public-branch-and-rulesets.md`.

## Testing

- [ ] Built locally.
- [x] Ran focused unit or functional tests for the changed area.
- [x] Ran lint or formatting checks relevant to this change.
- [ ] Not run. Reason:

- Every Python test file under `ci/` (`ci/checks`, `ci/release`, `ci/scanners`), each run as `python3 <file>`: 20 files and 602 tests pass on `main` before; 21 files and 774 tests pass with #423 and #372; with #440's commits on top, 21 files pass again (781 tests). No test that passed before fails.
- `.github/workflows/signed-landing.yml` is byte for byte the file the other Qbit-Org repositories run, apart from its two configuration lines (`AS_IS_HEADS: "sync-* subtree-*"`, `AS_IS_LINES: ""`).
- The documentation, metadata and lint checks that could run without building the node pass. Not run: the subtree lint, which could not fetch its sources from the machine these checks ran on. One more actionlint finding of a class `main` already has (a YAML alias).
- The node was not built and no functional test was run here: neither commit changes anything under `src/` or `test/`. CI runs them.

## Target Branch

- [x] This PR targets `main` or a maintainer-requested release branch such as `0.1.x`.

## Risk / Review Notes

- [x] Consensus, script, crypto, wallet, P2P, release, CI, or security-sensitive behavior changed.
- [ ] No consensus, script, crypto, wallet, P2P, release, CI, or security-sensitive behavior changed.

Notes:
- **CI and release behaviour change on `main`**, as they did on `1.x.x` with #423 and #372: the same-tree skip in Full Validation and Core Checks; a release needs protected, first-parent trusted refs; staging refuses a tag on a pull request's head; the secret scans cover merges.
- **The Key Policy Gate's own code changes** (#440): gate code becomes three files, and two of its checks run without approvals. See #440 for the review notes; it should land on `1.x.x` too, so the two branches do not drift.
- **Key Policy Gate:** the check is red on this pull request, and that is expected. The gate refuses a change to workflows and files under `ci/` without approvals signed by three mainnet signers. No ruleset requires the gate yet, and the operator decided on 13 November to land the signed-landing workflow before one does, without collecting signatures.
- **`signed-landing` starts reporting** on qbit pull requests once this lands. Nothing requires it until `required-checks.json` is applied.
- **One sentence goes stale:** `doc/development/public-branch-and-rulesets.md` says the check reports nothing until `main` holds the workflow, "which is after the next release moves `main`". This pull request makes that happen earlier. The sentence is left as it is so that the file stays equal to `1.x.x`'s; it can be reworded on `1.x.x`.

## Docs / Process Impact

Choose exactly one:

- [x] I updated public docs because this PR changes user-visible behavior, integration guidance, release/process guidance, or expected validation.
- [ ] No public docs update needed. Reason:

The documents come over with the two changes: `CONTRIBUTING.md`, `doc/development/public-branch-and-rulesets.md`, `doc/development/ci-same-tree-skip.md`, `doc/development/developer-notes.md`, the release process documents and `doc/subtrees/libbitcoinpqc.md`.

## libbitcoinpqc Subtree Checklist (if `src/libbitcoinpqc` changed)

Not applicable: `src/libbitcoinpqc` is not changed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
1422396 ci: bring the same-tree CI skip and signed landing to main (#423, #372)
2bee83d ci: ask signatures only for the Key Policy Gate's own three files
c130f87 test: pin the Core Checks gate's posture check as whole blocks


Squashed-from: c130f87

Co-authored-by: Claude Opus 5.5 <[email protected]>
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