Skip to content

feat: sub agent use new supervisor [NR-497494]#2077

Merged
sigilioso merged 5 commits intomainfrom
refactor/sub-agent-use-new-supervisor
Jan 22, 2026
Merged

feat: sub agent use new supervisor [NR-497494]#2077
sigilioso merged 5 commits intomainfrom
refactor/sub-agent-use-new-supervisor

Conversation

@sigilioso
Copy link
Contributor

Summary

This PR introduces a refactored version of sub_agent.rs in a new temporary module sub_agent_new.rs. The refactoring adopts the new Supervisor trait that unifies SupervisorStopper functionality and adds support delegating to an existing supervisor the application of new configuration via the apply() method.

Changes

Supervisor apply() usage

Previous behavior:

  • When a new remote config arrived, the old supervisor was always stopped and a new one was always started
  • This means long interruptions of the agents while installing new agent on 'on-host' environments.

New behavior:

  • When a new remote config arrives and a supervisor is already running, the system attempts to apply the configuration without restarting using Supervisor::apply()
    • If there's no existing supervisor does the system fall back to the old "stop and start" approach
    • If apply() fails, the RemoteConfig is reported as failed and no supervisor keeps running (agents stop).
  • This enables zero-downtime updates if implemented in the supervisor.

Supervisor Lifecycle

Previous behavior:

// Old: Explicit stop before starting new supervisor
stop_supervisor(old_supervisor);
new_supervisor.start(...)

New behavior:

// New: Try to apply first, only rebuild if necessary
if let Some(existing) = old_supervisor {
    existing.apply(new_config) // Hot-reload attempt
} else {
    build_and_start_new_supervisor()
}

‼️ The Supervisor::apply() method is responsible for handling any necessary internal restarts.

Small refactors and improvements

  • Simplify error handling: SupervisorCreationError is kept on init_supervisor only.
  • Add new helpers for improving maintainability
  • Unit tests are extended to check the configuration updates behaviors when there was a previous supervisor ("aply") and there was no supervisor ("build + start").
  • Extend helpers documentation.

Notes for reviewers

  • Because the new behavior is introduced in a different module, this PR is best reviewed commit-by-commit.

  • The new module is not yet used and will replace sub_agent.rs once other dependent changes are ready.

    When the supervisors are ready we need to:

    1. Replace sub_agent.rs with sub_agent_new.rs
    2. Fix the imports
    3. Replace the supervisors as well

@sigilioso sigilioso requested a review from a team as a code owner January 19, 2026 16:54
@sigilioso sigilioso force-pushed the refactor/sub-agent-use-new-supervisor branch from f291c20 to f813eb4 Compare January 19, 2026 16:57
@DavSanchez
Copy link
Contributor

Needs conflict resolution (probably because we both added mocks to the supervisor module xD)

Refactors the code with no behavior changes in order to make the
following behavior change as easy as possible
@sigilioso sigilioso force-pushed the refactor/sub-agent-use-new-supervisor branch from f813eb4 to 39f75e8 Compare January 20, 2026 14:58
@sigilioso
Copy link
Contributor Author

That was it! Thanks for pointing out

@sigilioso sigilioso force-pushed the refactor/sub-agent-use-new-supervisor branch from 39f75e8 to a5b8454 Compare January 20, 2026 15:01
@sigilioso sigilioso force-pushed the refactor/sub-agent-use-new-supervisor branch from a5b8454 to a865d50 Compare January 20, 2026 15:02
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DavSanchez I opted for the incoming implementation for the mocks because sub_agent_new.rs is already using them. They were mostly the same! But I can switch names or whatever if you think we should to 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine by me! 👌

Copy link
Contributor

@gsanchezgavier gsanchezgavier left a comment

Choose a reason for hiding this comment

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

I ended up doing a diff between sub_agent and sub_agent_new files locally 😅 .

Haven't check the tests yet but changes look good . I left a doubt

@sigilioso sigilioso requested review from a team, DavSanchez and gsanchezgavier January 21, 2026 12:01
Copy link
Contributor

@DavSanchez DavSanchez left a comment

Choose a reason for hiding this comment

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

Looking good! Some nits now that I'm getting to look at this code again. Feel free to not address any at all xD

Let me have another shot at the tests before approving.

Comment on lines +79 to +81
type AgentSupervisorStarter<B> = <B as SupervisorBuilder>::Starter;

type AgentSupervisor<B> = <AgentSupervisorStarter<B> as SupervisorStarter>::Supervisor;
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@sigilioso sigilioso requested review from a team and DavSanchez January 22, 2026 07:29
Copy link
Contributor

@gsanchezgavier gsanchezgavier left a comment

Choose a reason for hiding this comment

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

great! i did a diff between the new and old sub-agents and foucus the review on trying to catch any behave issue but it looks all good to me! , i saw we could reuse most of the testing scenarios with some adaptation :) 🚀

@sigilioso sigilioso merged commit 90ce8dd into main Jan 22, 2026
52 of 58 checks passed
@sigilioso sigilioso deleted the refactor/sub-agent-use-new-supervisor branch January 22, 2026 11:41
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