Skip to content

Conversation

@lia-viam
Copy link
Collaborator

No description provided.

@lia-viam lia-viam requested a review from a team as a code owner June 27, 2025 18:07
@lia-viam lia-viam requested review from gabegottlob and njooma and removed request for a team June 27, 2025 18:07
stoppable->stop();
}

manager->remove(cfg.resource_name());
Copy link
Member

Choose a reason for hiding this comment

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

Below, this calls manager->replace_one. The documentation for replace_one indicates that it will only work right if resource is present, and will fail otherwise. So, by removing the resource here, I think it prevents replace_one below from working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ugh good catch...i will look into what's happening in replace_one because i think from @hexbabe earlier testing the destructor on the original instance was not getting called during this always-rebuild control flow

@lia-viam lia-viam changed the title remove resource on alwaysrebuild RSDK-11067: remove resource on alwaysrebuild Jul 1, 2025

const std::shared_ptr<const ModelRegistration> reg =
Registry::get().lookup_model(cfg.name());
Registry::get().lookup_model(cfg.api(), cfg.model());
Copy link
Member

Choose a reason for hiding this comment

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

If you fail to look up the model registration here, I think you should return an error. It's a pretty strange state of affairs because the model was registered once, apparently, such that the object could be brought into existence (otherwise, what is being reconfigured?) but now that it is time to reconfigure by rebuilding, the registration is gone. That also would have made the error here obvious, rather than a silent misbehavior.

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 you're right, it was really confusing to debug

Comment on lines 137 to 138
std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg);
manager->replace_one(cfg.resource_name(), std::move(resource));
Copy link
Member

Choose a reason for hiding this comment

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

  • Arguably, this is part of RSDK-11067, but the behavior here means that if construct_resource fails, the old one sticks around. Is that OK?
  • Maybe add some warn logging here after the call to replace_one that if res.use_count != 1 that the old Resource has been held alive somewhere? I know it isn't perfect due to multithreading, but at least it gives some indication that things haven't gone according to plan.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, I just saw the commit that removed the TODO RSDK-11067, but this review doesn't fix that fully. The call to construct_resource here happens before the call to replace_one which will (in theory) remove the old one. If the intention is to actually resolve RSDK-11067, the ordering here needs to be changed, and I don't think replace_one can be used.

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 this does resolve RSDK-11067 at least in terms of the observed behavior. Maybe the issue title was described incorrectly, because it would be more accurate to say that in the absence of Reconfigurable the reconfiguration was not happening whatsoever, the old one was not getting deleted, etc.

If we do it without replace_one would you suggest a manual call to remove followed by add ? Because it occurred to me that in the absence of Reconfigurable that a call to ReconfigureResource should be equivalent to RemoveResource followed by AddResource, so maybe we can reuse the code from each of those

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, but please file a new ticket about investigating reconfiguration behavior and CC me on it. I'll write up my observations there.

@lia-viam lia-viam merged commit 56542bc into main Jul 1, 2025
5 checks passed
@lia-viam lia-viam deleted the remove-rebuild branch July 1, 2025 21:25
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