Add const reference service callback signatures #3269
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 354 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3269"
general
weight: 0.35
KR-Ravindra
Problem
AnySubscriptionCallbackacceptsconst MessageT &callbacks, butAnyServiceCallbackonly acceptsstd::shared_ptrsignatures. Every service callback therefore has to takeshared_ptrs (the response one is copied per call) even when the handler answers immediately and never needs to extend the request/response lifetime. This is inconsistent with subscriptions.Design
Follows the approach suggested in the issue: the request and response keep arriving as
shared_ptrinternally;dispatch()dereferences them for the user callback, exactly likeAnySubscriptionCallbackdoes forconst MessageT &. The existingshared_ptroverloads are unchanged.Fix
rclcpp/include/rclcpp/any_service_callback.hppConstRefCallback=void (const Request &, Response &)andConstRefWithRequestHeaderCallback=void (const rmw_request_id_t &, const Request &, Response &), appended after the existing alternatives.set()overloads get matchingfunction_traits::same_argumentsbranches sostd::bindresults resolve like theshared_ptrshapes do.dispatch()callscb(request, response)/cb(request_header, request, *response)and returns the response as before.The new alternatives cannot be ambiguous with the existing ones in the
std::variantconverting assignment: a callable takingconst Request &is not invocable with ashared_ptr<Request>and vice versa, so at most onestd::functionalternative is viable for any callback.How tested
rclcpp/test/rclcpp/test_any_service_callback.cpp: four new cases (const-ref without/with request header, response mutation propagated to the returnedshared_ptr,std::bindfor both shapes).rclcpp/test/rclcpp/test_service.cpp:create_service<>with a const-ref callback, exercised end to end through a client.Before the change, the new callback shapes fail to compile:
After the change the header compiles and all cases pass. I could not run
colcon testlocally (no ROS 2 workspace), so the new gtest cases were mirrored in a standalone gtest harness that compiles the unmodifiedany_service_callback.hpp/function_traits.hppagainst stubrmw/tracetoolsheaders: 10/10 pass with-Wall -Wextraon GCC 13, including the pre-existing callback shapes.cpplintwith the ament filters reports no issues. Please rely on CI for the full build and forament_uncrustify.Links
This change was prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it.