Skip to content

Extend the graph state machine with a recovery state - #1033

Draft
NicolasFussberger wants to merge 10 commits into
component_restart_taskfrom
graph_recovery_state
Draft

NicolasFussberger wants to merge 10 commits into
component_restart_taskfrom
graph_recovery_state

Conversation

@NicolasFussberger

@NicolasFussberger NicolasFussberger commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Introduces the new state kComponentRecovery in the Graph state machine which is entered while executing any component recovery actions.
The new state is highlighted in red in the following state machine.

Discussed alternative: Allow component restarts in state kSuccess
We can achieve the same behavior this way, but in a less explicit way.
The state machine edges would all depend on whether any jobs are in progress (i.e. restarts are happening) or not.
A dedicated state machine state was deemed easier to understand.

graph_states

Scenarios if Restart recovery action is configured for a component:

A component fails during a transition (Graph in kInTransition) -> No change to before, transition is aborted, Run Target recovery action
A component fails during active Run Target (Graph in kSuccess) -> Graph moves to kComponentRecovery, component is restarted
A second component fails while recovering a first component (Graph in kComponentRecovery) -> Graph stays in kComponentRecovery, second component is restarted as well
A (non-forced) transition request while recovering component (Graph in kComponentRecovery) -> request is queued

  • Recovery succeeds and graph moves back to kSuccess -> Queued request will be executed
  • Recovery fails and graph moves to kAborting/kUndefined -> Transition to fallback run target. Proceed with queued requests after recovery
    A forced transition request while recovering component (Graph in kComponentRecovery) -> graph moves to kAborting/kUndefined and initiates transition to the requested Run Target.

Why not just do a self-transition to the already active Run Target?

  • We want to support multiple concurrent component recovery actions
  • A single failure during a transition would fail the transition and lead to recovery escalation, even though also the second failure should just lead to a component restart (at least with the current recovery action concept)
  • We may end up restarting components for which actually no restart recovery action is configured

@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview for this pull request is available at:
pr-1033: https://eclipse-score.github.io/lifecycle/pr-1033/

@NicolasFussberger
NicolasFussberger force-pushed the graph_recovery_state branch 3 times, most recently from 7875c69 to cde6867 Compare November 20, 2026 09:20
@NicolasFussberger
NicolasFussberger force-pushed the graph_recovery_state branch 3 times, most recently from 4be4fc2 to 87daed8 Compare November 23, 2026 10:38
Graph -> Component ++: deactivate()
Component --> Graph --: clean up done
note over Graph
The clean up is done in place on the main loop thread, not on a worker.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should number the arrows and give longer notes in a table? Maybe the diagrams wouldn't have the sideways scroll then? Would be nice if this works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mmh I am not sure if this would be better then you need two screens to look at the diagram and the table at the same time

kInTransition : Run Target transition is in progress
kAborting : Wait for ongoing jobs to finish after\na failure or transition cancellation
kUndefinedState : No ongoing jobs, graph is in\nan undefined but consistent state
state kComponentRecovery #Red

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
state kComponentRecovery #Red
state kComponentRecovery #LightCoral

Bit hard to read with the saturated red 😆

kAborting --> kAborting : job finished\n[not the last job]
kAborting --> kUndefinedState : job finished\n[last job]
kAborting --> kAborting : cancel or new request
kAborting --> kAborting : cancel or\nnew request

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think if you merge all the loops going to itself into a single arrow and in the description concatenate the steps it would look a bit more readable.

}

if (new_state == GraphState::kSuccess)
if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition)
const bool transition_successful = target_state == GraphState::kSuccess && old_state == GraphState::kInTransition;
if (transition_successful )

Might be nice to name what is happening.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think new code is more strict and less resilient... I would go for something like this:

if (new_state == GraphState::kSuccess)
{
    if (old_state == GraphState::kComponentRecovery)
    {
        // Log recovery success
    }
    else
    {
        // Do successful graph state transition things
    }
}

LM_LOG_INFO() << "Completed the request for Run Target" << getRequestedRunTarget() << "in" << timeDiff.count()
<< "ms";
}
else if (target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
else if (target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery)
const bool recovery_successful = target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery;
else if (recovery_successful )


if (jobs_in_progress_ == 0)
const GraphState state = getState();
if ((state == GraphState::kSuccess || state == GraphState::kComponentRecovery) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ((state == GraphState::kSuccess || state == GraphState::kComponentRecovery) &&
const bool in_recoverable_state = state == GraphState::kSuccess || state == GraphState::kComponentRecovery;
if (in_recoverable_state &&

}
else
{
cancel();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might need a log here, unless it already does somewhere down the chain.

response = score::MakeUnexpected(ExecErrc::kInTransitionToSameState);
}
}
else if (GraphState::kComponentRecovery == graph_state)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
else if (GraphState::kComponentRecovery == graph_state)
else if (graph_state == GraphState::kComponentRecovery)

Comment on lines +87 to +88
A component can be configured with a restart recovery action. If it terminates unexpectedly while
its Run Target is active, the graph moves to kComponentRecovery and restarts only this component on the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
A component can be configured with a restart recovery action. If it terminates unexpectedly while
its Run Target is active, the graph moves to kComponentRecovery and restarts only this component on the
A component can be configured with a restart recovery action. If it terminates unexpectedly outside
Run Target activation, the graph moves to kComponentRecovery and restarts only this component on the

{

/// @brief States in which the graph has jobs that can be stopped through its stop source.
bool isActiveState(const GraphState state)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just cannot figure out what is the problem or a check that this function is solving.

We should either update name or description. What is special or what is the shared characteristic between kInTransition and kComponentRecovery?

// kInTransition and kComponentRecovery are never entered directly from each other, so one stop source
// is enough for both.
const bool becomes_active = !isActiveState(old_state) && isActiveState(target_state);
const bool leaves_active = isActiveState(old_state) && target_state != old_state;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old code is not very readable, but the new code is even less readable IMHO. Please note that introduction of the new function, is only making it harder to understand.

Now I'm not saying that become_transition and coming_from_transition are perfect variable names, but becomes_active and leaves_active are even more cryptic...

AFAIK this code is detecting if we are about to do one of two things:

  • Start new graph state transition.
  • Stop an active graph state transition.

Variables with names like starting_new_graph_state_transition / stopping_new_graph_state_transition or starting_new_run_target_activation / stopping_new_run_target_activation would make this code much more readable. Please note I'm not advocating to leak Run Target terminology into the graph here.

With descriptive variable names and a bit of comments, this code could become ease to maintain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The case that needs to be distinguished whether going to a state that dispatches jobs on the thread pool or leaving a state that dispatches jobs on the thread pool so that the stop source can be adapted accordingly.

Previously, this was a property of kInTransition but now its also a property of kComponentRecovery state.

I'll try to come up with a name for this

}

if (new_state == GraphState::kSuccess)
if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think new code is more strict and less resilient... I would go for something like this:

if (new_state == GraphState::kSuccess)
{
    if (old_state == GraphState::kComponentRecovery)
    {
        // Log recovery success
    }
    else
    {
        // Do successful graph state transition things
    }
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants