Skip to content

refactor(broker): one documented encoder per message kind; encodeRequest/encodeResponse visit them (#3043) - #3051

Merged
mgradwohl merged 1 commit into
mainfrom
refactor/broker-encoders-3043
Oct 26, 2026
Merged

mgradwohl merged 1 commit into
mainfrom
refactor/broker-encoders-3043

Conversation

@mgradwohl

Copy link
Copy Markdown
Owner

Description

CodeQL alert #3900 (cpp/poorly-documented-function) flags Broker::encodeRequest. It was one 103-line if/else if chain over every request kind, and passed 100 lines with protocol v6 and v7 (#2972, #3002). encodeResponse was 248 lines of the same shape, kept under the alert only by its comments.

As #2526 did for the decoders, each message kind now has its own short, documented Detail::encodePayload(Writer&, const T&) overload. It writes that kind's payload and returns its MessageKind. encodeRequest/encodeResponse are now a std::visit over those overloads.

  • The bytes written are unchanged. Each overload is the old branch, moved as is, and the protocol version is unchanged.
  • A new message kind without an encoder no longer compiles. The old chain silently fell through to MessageKind::Hello/HelloReply with an empty payload.

Fixes #3043

PR Size

Medium in lines (+403/−342, one header), but each block is a branch moved into its own function.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Build/CI improvement

Refactor, with no behaviour change.

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's coding standards
  • I have run clang-tidy and addressed any warnings
  • I have run clang-format on my changes
  • I have run pre-commit run --all-files or installed pre-commit hooks
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass
  • I have updated documentation as needed

No new tests: the decoders are unchanged, and test_BrokerProtocol.cpp's round trips cover every message kind, so the encoders are checked against them. The helper tests run each request end to end.

Testing

cmake --build --preset debug -j 4
build/debug/tests/TaskSmackTests --gtest_filter='Broker*:PkexecBroker*:*Helper*'   # 335 passed
TASKSMACK_REQUIRE_DISPLAY=1 TASKSMACK_REQUIRE_SDBUS=1 xvfb-run -a env -u WAYLAND_DISPLAY ctest --preset debug -j 4   # 689/689
clang-tidy-22 -p build/debug --header-filter="^$PWD/src/" src/Platform/BrokerRequestMapping.cpp   # clean in BrokerProtocol.h

Additional Notes

Main only, no backport: no wire change, and v0.9.x's protocol code stays as it shipped.

🤖 Generated with Claude Code

…est/encodeResponse visit them (#3043)

CodeQL flagged encodeRequest (cpp/poorly-documented-function, alert #3900):
one 103-line if/else chain over every request kind, past 100 lines since
protocol v6/v7. encodeResponse (248 lines) had the same shape. As #2526 did
for the decoders, each kind now has a Detail::encodePayload() overload that
writes its payload and returns its MessageKind, and both entry points are a
std::visit over them, so a message kind without an encoder no longer compiles.
The bytes on the wire are the same; no protocol version change.

Fixes #3043

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mgradwohl mgradwohl added this to the v0.10.0 milestone Oct 26, 2026
@mgradwohl mgradwohl added refactoring agent:WSL Owned by the Linux/WSL Claude session (bug-fix conveyor) labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@mgradwohl
mgradwohl marked this pull request as ready for review October 26, 2026 16:36
@mgradwohl
mgradwohl enabled auto-merge (squash) October 26, 2026 16:36
@mgradwohl
mgradwohl merged commit 7386192 into main Oct 26, 2026
28 checks passed
@mgradwohl
mgradwohl deleted the refactor/broker-encoders-3043 branch October 26, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:WSL Owned by the Linux/WSL Claude session (bug-fix conveyor) Platform refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Split Broker::encodeRequest (and encodeResponse) into one documented encoder per message kind (CodeQL #3900)

1 participant