Skip to content

Guard hub phase transitions against spurious session events#126

Closed
scion-gteam[bot] wants to merge 1 commit into
mainfrom
scion/dev-issue-124
Closed

Guard hub phase transitions against spurious session events#126
scion-gteam[bot] wants to merge 1 commit into
mainfrom
scion/dev-issue-124

Conversation

@scion-gteam
Copy link
Copy Markdown

@scion-gteam scion-gteam Bot commented Jun 2, 2026

Summary

Fixes #124 — Hub phase stuck at 'starting' after spurious session lifecycle events.

  • Adds a phase regression guard to the hub's updateAgentStatus handler and handleBrokerHeartbeat handler that rejects transitions backward in the forward-progress lifecycle (e.g. running → starting). This prevents a spurious session.start/session.end pair from corrupting the agent's phase.
  • Adds activity-driven phase auto-correction: when an activity that implies the agent is running (working, thinking, executing, etc.) arrives but the phase is pre-running (starting, provisioning, etc.), auto-promotes the phase to running. This allows the agent's real activity updates to correct a stuck phase.
  • Adds Phase.Ordinal(), Phase.IsActivePhase(), and Activity.ImpliesRunning() helpers to the state package to support the guards.

Test plan

  • New state package tests: TestPhaseOrdinal, TestPhaseIsActivePhase, TestActivityImpliesRunning
  • New hub handler tests: TestAgentStatusUpdate_RejectsPhaseRegression, TestAgentStatusUpdate_ActivityAutoCorrectsPhase, TestBrokerHeartbeat_RejectsPhaseRegression
  • Full pkg/agent/state test suite passes (no regressions)
  • Full pkg/hub test suite passes (no regressions — 141s, all existing tests pass)

…events

A rapid session.start → session.end sequence from a spurious sciontool
could permanently reset an agent's phase even while the agent works
normally. This adds two guards:

1. Phase regression guard: rejects transitions that would move an agent
   backward in its forward-progress lifecycle (e.g. running → starting)
   in both the status update handler and broker heartbeat handler.

2. Activity-driven phase auto-correction: when an activity that implies
   the agent is running (working, thinking, executing, etc.) arrives but
   the phase is pre-running, auto-promotes the phase to running.

Fixes #124
@ptone ptone closed this Jun 5, 2026
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.

Hub phase stuck at 'starting' after spurious session lifecycle events

1 participant