Skip to content

Extract NodeState join outcome handlers - #8560

Merged
Amaury Chamayou (achamayou) merged 3 commits into
mainfrom
achamayou-join-outcome-extraction
Oct 16, 2026
Merged

Amaury Chamayou (achamayou) merged 3 commits into
mainfrom
achamayou-join-outcome-extraction

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Motivation

NodeState::initiate_join_unsafe scores 125 on readability-function-cognitive-complexity, against a threshold of 50, with its response callback and processing task at 89 and 61. All three carry baseline suppressions. This PR moves the response-handling branches into helpers so the suppressions can be removed without changing behaviour.

Related to #7358. The remaining suppressions are handled in #8561 and #8562.

Implementation summary

Move the interiors of the four outcome branches in the join response task into private _unsafe members, verbatim:

  • handle_join_transport_error_unsafe: retryable transport errors, oversize response body, and fatal TLS/protocol failures.
  • handle_join_client_error_unsafe: ODataErrorResponse parsing, the StartupSeqnoIsOld snapshot-fetch path, and the fatal 4xx path.
  • handle_join_unexpected_status_unsafe: redirect following and the generic non-200 log.
  • complete_join_unsafe: the TRUSTED completion, including snapshot installation, consensus and snapshotter setup, state transitions, and join-timer cancellation.

The callback and task lambdas, lock, readiness gate, outer catch, and TRUSTED/PENDING dispatch stay in place. Each call site keeps its original return, so early returns inside the helpers have the same effect as before. .clang-tidy is unchanged.

Measured with clang-tidy 21.1.8 and IgnoreMacros=true; the repository threshold stays at 50:

Function Before After
initiate_join_unsafe 125 35
Response callback 89 18
Processing task 61 9
complete_join_unsafe - 17
handle_join_client_error_unsafe - 8
handle_join_transport_error_unsafe - 4
handle_join_unexpected_status_unsafe - 4

Safety and compatibility

Internal refactor with no API, wire-format, ledger, or snapshot-format impact. A token comparison against main shows the only differences are the removed suppression comments, the four helper signatures, and their call sites. The ledger-secret move, lock scope, exception boundaries, log messages, and the order of all state transitions and side effects are unchanged. A failed snapshot install still cannot reach backup initialization or Ready.

Validation:

  • Built the ccf_launcher translation unit that includes node_state.h on the merged tree.
  • scripts/ci-checks.sh passed without auto-fix.
  • CI passed on the pre-merge head, including the Debug CLANG_TIDY=ON build, unit tests, and the bucket-b recovery and join e2e tests. Required CI must pass again on the current head.

Move the four join-task outcome branches into private NodeState helpers while retaining scheduling, locking, exception boundaries and terminal returns. Remove the join cognitive-complexity suppressions without changing the checker configuration.

Refs #7358

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou
Amaury Chamayou (achamayou) marked this pull request as ready for review October 16, 2026 07:17
@achamayou
Amaury Chamayou (achamayou) requested a review from a team as a code owner October 16, 2026 07:17
Copilot AI balanced review requested due to automatic review settings October 16, 2026 07:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The extraction preserves behavior, no blocking issues were identified, and CI succeeded at the stated PR head.

0 open findings

What changed in this PR

Refactors NodeState join-response handling to reduce cognitive complexity as part of #7358, without intended behavior changes.

Changes:

  • Extracts four private helpers for transport errors, client errors, redirects/unexpected statuses, and trusted completion.
  • Removes complexity suppressions while preserving locking, exception handling, and state-transition ordering.

Custom instructions used

Applied .github/copilot-instructions.md and .github/instructions/reviewing.instructions.md as supplied in the review context.

File Description
src/​node/​node_state.h Extracts join-outcome helpers and removes complexity suppressions.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou
Amaury Chamayou (achamayou) merged commit 4eea8b9 into main Oct 16, 2026
12 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-join-outcome-extraction branch October 16, 2026 10:46
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.

3 participants