Skip to content

refactor(codec): typed CodecConsensusError replaces substring matching - #342

Merged
nh13 merged 1 commit into
mainfrom
nh/issue-338-typed-consensus-errors
May 21, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/issue-338-typed-consensus-errors

Conversation

@nh13

@nh13 nh13 commented May 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Audited the workspace per Audit substring-based error-discrimination patterns across consensus and pipeline code #338: the only production substring-based error discrimination was e.to_string().contains("duplex disagreement") at src/lib/commands/codec.rs:392, 622, silently coupling reject-vs-error behavior to wording in crates/fgumi-consensus/src/codec_caller.rs:1161, 1164. Simplex, duplex, overlapping, and the rest of the pipeline have no equivalent patterns.
  • Introduce CodecConsensusError (thiserror) with DuplexDisagreementCount, DuplexDisagreementRate, and Other(#[from] anyhow::Error) variants plus an is_duplex_disagreement() helper.
  • Expose CodecConsensusCaller::try_consensus_reads as the typed inherent entry point; keep the ConsensusCaller::consensus_reads trait surface unchanged by wrapping the typed result via anyhow::Error::from.
  • Both codec.rs reject paths now match on the typed variant instead of the message string. Reword-resistance: changing the #[error(...)] text in CodecConsensusError no longer affects recovery behavior.

Closes #338

Test plan

  • cargo build clean
  • cargo ci-fmt clean
  • cargo ci-lint clean
  • cargo ci-test — 2067 passed, 23 skipped
  • New test test_try_consensus_reads_typed_disagreement_error asserts the typed variant on the strict-disagreement path
  • Existing test_not_emit_consensus_high_disagreement still passes (covers the wrapped anyhow::Result surface via consensus_reads_from_sam_records)

@nh13
nh13 temporarily deployed to github-actions May 16, 2026 03:09 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented May 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5348a93-2214-4eac-8f06-891708639e08

📥 Commits

Reviewing files that changed from the base of the PR and between 0fa1659 and 3bd1b02.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • crates/fgumi-consensus/Cargo.toml
  • crates/fgumi-consensus/src/codec_caller.rs
  • crates/fgumi-consensus/src/lib.rs
  • src/lib/commands/codec.rs
  • src/lib/consensus/mod.rs
  • tests/integration/test_codec_command.rs

📝 Walkthrough

Walkthrough

This PR replaces fragile substring matching of codec consensus errors with a typed CodecConsensusError enum. It adds thiserror, defines duplex-disagreement and fatal variants, refactors internal consensus functions and the public consensus_reads_typed() API to return typed errors, updates the codec command to handle recoverable disagreements via recover_or_propagate_codec_error(), and adds unit and integration tests for single-threaded and multi-threaded recovery.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main refactoring: replacing substring-based error discrimination with a typed CodecConsensusError.
Description check ✅ Passed The description clearly relates to the changeset, detailing the audit findings, typed error introduction, and migration from string-based to variant-based error handling.
Linked Issues check ✅ Passed The PR fully addresses #338 objectives: audits and fixes the substring-based error discrimination in codec.rs by introducing CodecConsensusError with DuplexDisagreement variants and pattern matching, removing fragile string-based checks.
Out of Scope Changes check ✅ Passed All changes are scoped to codec consensus error handling; dependency additions (thiserror), type definitions, test additions, and call-site migrations are directly related to the #338 objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nh/issue-338-typed-consensus-errors

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.90%. Comparing base (00c1e48) to head (3bd1b02).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #342      +/-   ##
==========================================
+ Coverage   90.87%   90.90%   +0.02%     
==========================================
  Files          78       78              
  Lines       50775    50799      +24     
==========================================
+ Hits        46143    46178      +35     
+ Misses       4632     4621      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nh13
nh13 force-pushed the nh/issue-338-typed-consensus-errors branch from 982856e to 57e053a Compare May 16, 2026 03:22
@nh13
nh13 temporarily deployed to github-actions May 16, 2026 03:22 — with GitHub Actions Inactive
@nh13
nh13 force-pushed the nh/issue-338-typed-consensus-errors branch from 57e053a to 3878064 Compare May 16, 2026 04:20
@nh13
nh13 temporarily deployed to github-actions May 16, 2026 04:20 — with GitHub Actions Inactive
@nh13
nh13 force-pushed the nh/issue-338-typed-consensus-errors branch from 3878064 to 6e76e4e Compare May 16, 2026 04:34
@nh13
nh13 temporarily deployed to github-actions May 16, 2026 04:34 — with GitHub Actions Inactive
@nh13

nh13 commented May 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/fgumi-consensus/src/codec_caller.rs`:
- Around line 98-106: The doc comment links the wrong method name: update the
reference from CodecConsensusCaller::try_consensus_reads to the actual exposed
method CodecConsensusCaller::consensus_reads_typed (or add an alias if
appropriate) so the documentation link points to the correct symbol and remains
accurate; modify the doc comment above the error enum to mention
CodecConsensusCaller::consensus_reads_typed instead of try_consensus_reads.

In `@src/lib/commands/codec.rs`:
- Around line 399-401: Update the outdated comment references to the old API
name `try_consensus_reads` to the current name `consensus_reads_typed`; locate
the explanatory comments near the `consensus_reads_typed` call in the file (the
blocks around the existing comment that mention distinguishing recoverable
duplex disagreements from failures) and replace the old identifier in both
occurrences so the comment matches the actual function being called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d7ba61a-857e-43f3-931c-ef176bb7454b

📥 Commits

Reviewing files that changed from the base of the PR and between c221274 and 6e76e4e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • crates/fgumi-consensus/Cargo.toml
  • crates/fgumi-consensus/src/codec_caller.rs
  • crates/fgumi-consensus/src/lib.rs
  • src/lib/commands/codec.rs
  • src/lib/consensus/mod.rs
  • tests/integration/test_codec_command.rs

Comment thread crates/fgumi-consensus/src/codec_caller.rs Outdated
Comment thread src/lib/commands/codec.rs Outdated
@nh13
nh13 force-pushed the nh/issue-338-typed-consensus-errors branch from 6e76e4e to 0fa1659 Compare May 16, 2026 16:01
@nh13
nh13 temporarily deployed to github-actions May 16, 2026 16:01 — with GitHub Actions Inactive
@nh13

nh13 commented May 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

The two duplex-disagreement reject paths in `src/lib/commands/codec.rs`
discriminated recoverable failures from genuine errors via
`e.to_string().contains("duplex disagreement")`, which silently coupled
recovery behavior to error-message wording in `codec_caller.rs`.

Introduce `CodecConsensusError` with `DuplexDisagreementCount`,
`DuplexDisagreementRate`, and `Other(anyhow::Error)` variants plus an
`is_duplex_disagreement()` helper. Expose `try_consensus_reads` as a
typed inherent method on `CodecConsensusCaller`; keep the
`ConsensusCaller::consensus_reads` trait surface unchanged by wrapping
the typed result via `anyhow::Error::from`. Both codec.rs call sites now
pattern-match on the variant. Reword-resistance is covered by a new test
that asserts the typed variant for the strict-disagreement path.

The single-thread err arm is also extracted to a small
`recover_or_propagate_codec_error` helper so its `Other`-variant
propagation branch is unit-testable — that branch is unreachable from
valid CLI input today (`consensus_reads_raw` only returns `Other` if
`ss_caller.consensus_call` propagates, and the public API gates against
the conditions that trigger it).

Two end-to-end integration tests drive the typed recovery path through
`Codec::run` (single-threaded) and `Codec::execute_threads_mode`
(--threads N) using an offset-position FR fixture whose single-strand
positions register as duplex disagreements; together they cover the
single-thread and parallel-mode lines that the existing test suite did
not exercise.

Audit (issue #338) confirmed these were the only production substring-
based error matches in the workspace; simplex, duplex, overlapping, and
the rest of the pipeline have no equivalent patterns to migrate.

Closes #338
@nh13
nh13 force-pushed the nh/issue-338-typed-consensus-errors branch from 0fa1659 to 3bd1b02 Compare May 17, 2026 20:53
@nh13
nh13 temporarily deployed to github-actions May 17, 2026 20:53 — with GitHub Actions Inactive
@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit 7ce653f into main May 21, 2026
10 checks passed
@nh13
nh13 deleted the nh/issue-338-typed-consensus-errors branch May 21, 2026 19:38
@nh13 nh13 mentioned this pull request May 20, 2026

This branch was previously deployed

1 inactive deployment
github-actions — 3bd1b02c Deployed May 17, 2026 by nh13 via coverage #1441
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.

Audit substring-based error-discrimination patterns across consensus and pipeline code

1 participant