Skip to content

fix(component): roll back failed startup - #426

Open
RerankerGuo wants to merge 1 commit into
agentscope-ai:mainfrom
RerankerGuo:fix/component-start-rollback
Open

fix(component): roll back failed startup#426
RerankerGuo wants to merge 1 commit into
agentscope-ai:mainfrom
RerankerGuo:fix/component-start-rollback

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

Summary

Roll back partially started component lifecycles when BaseComponent.start() fails.

Problem

start() currently starts owned dependencies before invoking the parent's _start(). If the parent hook raises, the parent remains marked as not started, so a later close() returns immediately while the owned components remain running.

This can leak clients, tasks, or other resources created by default-factory dependencies.

Changes

  • Track owned components that successfully started during the current attempt.
  • If parent startup fails, invoke its cleanup hook and close started owned components in reverse order.
  • Preserve the original startup exception even if rollback cleanup also fails.
  • Add a regression test covering failed parent startup and defensive follow-up close.

Evidence

Before the fix:

FAILED test_start_failure_rolls_back_parent_and_owned_components
assert parent.close_count == 1
E assert 0 == 1

After the fix:

pytest tests/unit/test_base_component.py -q
25 passed

pytest tests/unit/test_job.py -q
21 passed

All relevant pre-commit hooks pass.

Scope

Successful startup and normal idempotent close behavior are unchanged.

@jinliyl

jinliyl commented Aug 6, 2026

Copy link
Copy Markdown
Member

LGTM

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