Skip to content

refactor(dispatch): F-CONC audit batch (5 concurrency findings)#623

Merged
SDS-Mode merged 3 commits into
mainfrom
refactor/f-conc-batch
May 27, 2026
Merged

refactor(dispatch): F-CONC audit batch (5 concurrency findings)#623
SDS-Mode merged 3 commits into
mainfrom
refactor/f-conc-batch

Conversation

@SDS-Mode

Copy link
Copy Markdown
Owner

Summary

Bundles the five open F-CONC-* concurrency-audit findings into a single PR. Each finding was independently re-validated by a multi-agent review team against current code (post the F-ARCH batch merge) before any edits landed.

Issue Finding Verdict Action
#494 F-CONC-4: triple-lock in cancel_and_find_parent CONFIRMED, no deadlock today Document the lock-acquisition order as a project invariant
#497 F-CONC-7: Ctrl-C watcher loops indefinitely in drain CONFIRMED Add opt-in PITBOSS_CTRLC_DRAIN_ESCALATE_SECS env var
#498 F-CONC-8: race window in register_sublead CONFIRMED ordering — proposed reorder would CAUSE a bug Document why the current step order is load-bearing
#490 F-CONC-11: op-reply broadcast visible to all clients CONFIRMED, intentional Annotate the broadcast site (complements existing PR-Q routing block)
#491 F-CONC-12: done_tx Lagged triggers nested-lock rescan CONFIRMED, low severity Bump broadcast capacity 64 → 1024

Three commits routed by cliff.toml:

Notable findings from validation

F-CONC-8 turned out to be the most valuable validation. The audit's "no action needed" verdict was right, but the audit also flirted with a reorder (cascade → insert → install_watcher). Tracing install_cascade_cancel_watcher showed that reorder would actually introduce a bug: that watcher is fire-once on root cancel, so the eager cascade_to at step 3 is what closes the post-watcher-fired window for late-registered subleads. The doc-comment now spells out why the current order is load-bearing so a future refactorer doesn't try the "obvious" cleanup.

F-CONC-7 is opt-in for back-compat safety. Default behaviour is unchanged (loop forever in drain mode). Operators who want auto-cleanup set PITBOSS_CTRLC_DRAIN_ESCALATE_SECS=<n>. A unit test pins the env-parsing contract.

F-CONC-11 is documentation-only. Validation confirmed OpUnknownState.current_state only carries the coarse string enum already published via WorkerStatus — there is no leak. The existing PR-Q routing block at server.rs:619-635 is the design rationale; the new inline comment marks the broadcast site so a reader at that line knows the visibility is intentional, not a bug.

F-CONC-12 capacity bump from 64 → 1024. Pre-depth-2 the channel served a single layer; post depth-2 the root subscriber sees completions across the whole tree. ~8 KiB additional memory per WorkerRegistry, well within budget. The Laggedrefresh_in_flight_from_maps recovery path remains in place as belt-and-braces.

Test plan

What's NOT in this PR

The register_sublead "race window" (#498) is not closed by code change because closing it would require introducing the bug the audit reviewer flagged. The window is benign (sublead subprocess hasn't launched yet); the documentation makes that explicit so future maintainers don't trade it for the worse failure mode.

Closes #490
Closes #491
Closes #494
Closes #497
Closes #498

🤖 Generated with Claude Code

Dan and others added 3 commits May 26, 2026 21:25
…udit

Three audit findings (#494 F-CONC-4, #498 F-CONC-8, #490 F-CONC-11)
were re-validated against current code and confirmed as correct-by-
construction; what was missing was an in-source explanation of why.
This commit captures those invariants where a future refactor would
otherwise reintroduce the patterns the audit flagged.

- `cancel_and_find_parent` (signals.rs): document the
  `subleads` → `worker_layer_index` → `workers.cancels` lock-acquisition
  order as a project invariant, naming every site that currently respects
  it (#494).
- `register_sublead` (state.rs): explain why insert → install_watcher →
  cascade_to is load-bearing — the proposed reorder from the audit would
  have CAUSED a real bug because `install_cascade_cancel_watcher` is
  fire-once on root cancel. The eager cascade at step 3 is what closes
  the post-watcher-fired window for late-registered subleads (#498).
- `control/server.rs` broadcast site: annotate the op-reply broadcast
  as intentional, complementing the existing PR-Q routing block. The
  audit re-validation confirmed `OpUnknownState.current_state` carries
  only the coarse enum already published via `WorkerStatus`, so the
  "subscriber visibility" surface is not a leak (#490).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Closes the F-CONC-7 (#497) operator-surprise gap: after a single
Ctrl-C the watcher would drain and then loop forever waiting for a
second Ctrl-C. If an operator walked away and a worker hung with no
timeout, the run would never wind down.

Adds `PITBOSS_CTRLC_DRAIN_ESCALATE_SECS=<n>` as an opt-in env var.
When set to a positive integer, the watcher races a sleep timer against
a follow-up Ctrl-C after the 5-second second-SIGINT window expires;
whichever fires first escalates to terminate via
`TerminateReason::OperatorCtrlC` (matching the existing
double-Ctrl-C path).

Default behaviour is preserved: with the env var unset, empty, zero, or
unparseable, the watcher continues to drain forever (the pre-fix
contract). Operators who want auto-cleanup can opt in.

A `#[serial(env)]` unit test pins the env-parsing contract (none for
unset/empty/zero/unparseable, Some(Duration) for positive integers
with surrounding whitespace tolerated).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
F-CONC-12 #491: the per-`WorkerRegistry` broadcast channel that fans
worker-completion events out to `wait_for_*` subscribers was sized at
64 — fine for the historical single-layer flat mode, but post depth-2
every root subscriber sees every worker's completion across the whole
tree. In a mass-cancel scenario across a saturated tree, the slowest
subscriber can lag the channel and fall back to
`refresh_in_flight_from_maps`, which holds nested read locks on
`subleads` + per-sublead `workers.states` across the recovery scan.

Bumping to 1024 absorbs the storm without changing the fallback's
correctness guarantee — the `Lagged` → `refresh_in_flight_from_maps`
path remains in place as belt-and-braces, not the expected fast path.
The capacity change is ~8 KiB additional memory per `WorkerRegistry`
(tokio broadcast allocates the ring eagerly).

Doc-comment updated to explain the sizing rationale so a future
refactor that questions the value has the context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@SDS-Mode
SDS-Mode enabled auto-merge (rebase) May 27, 2026 01:30
@SDS-Mode
SDS-Mode merged commit 6e20c0e into main May 27, 2026
15 checks passed
@SDS-Mode
SDS-Mode deleted the refactor/f-conc-batch branch May 27, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment