Skip to content

Conversation

@lia-viam
Copy link
Collaborator

Fixes logic in ReconfigureResource which would have prevented any action on non-Reconfigurable resources

@lia-viam lia-viam requested a review from a team as a code owner June 25, 2025 13:40
@lia-viam lia-viam requested review from gabegottlob and njooma and removed request for a team June 25, 2025 13:40
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

LGTM with some small suggestions and questions, but nothing that should block merge or require another round of review.

}
try {
Reconfigurable::reconfigure_if_reconfigurable(res, deps, cfg);
res->set_log_level(cfg.get_log_level());
Copy link
Member

Choose a reason for hiding this comment

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

Why do we no longer need the call to set_log_level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch!

Reconfigurable::reconfigure_if_reconfigurable(res, deps, cfg);
res->set_log_level(cfg.get_log_level());

if (auto reconfigurable = std::dynamic_pointer_cast<Reconfigurable>(res)) {
Copy link
Member

Choose a reason for hiding this comment

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

If reconfigure_if_reconfigurable is going away, I think stop_if_stoppable should too. I don't think they are clearer than just using dynamic_pointer_cast.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed

return resources_.at(short_name);
auto name_it = short_names_.find(name);
if (name_it != short_names_.end()) {
res_it = resources_.find(name_it->second);
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, this was a latent bug, in that the old code tried to look up the resource by short name a second time, rather than by using the "long name" it dug out of the short names map. Is that basically it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think the original logic was correct, the issue was just that it was discarding the result of find and then calling at instead of keeping the iterator and dereferencing it

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see I missed the at. OK, well, I agree this is better than the double lookups.

res->set_log_level(cfg.get_log_level());

if (auto reconfigurable = std::dynamic_pointer_cast<Reconfigurable>(res)) {
reconfigurable->reconfigure(deps, cfg);
Copy link
Member

Choose a reason for hiding this comment

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

⬇️

  • If we aren't going to address the issue where we construct a new resource before we have destroyed the old in this PR, let's ticket that work and add a TODO down around line 132 now. I think it is something of a priority.
  • Do we have any idea why the compiler wasn't able to flag everything after the block dealing with reconfigure as dead code? Actually, nevermind. I see it. If the code managed to throw something other than a std::exception, then it wasn't dead. Oops.

@lia-viam lia-viam merged commit f5ce69a into viamrobotics:main Jun 26, 2025
5 checks passed
@lia-viam lia-viam deleted the reconfigure-fix branch June 26, 2025 20:06
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.

2 participants