You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(live-activity): end a finished run's activity when the app returns to the foreground - #1802
If the app sat suspended overnight with the chat closed and the relay's final push was lost, the run's Live Activity kept running after the run ended. #1800 fixed this only for a cold launch.
When the app returns to the foreground, AgentLiveActivityManager.endFinishedRuns now makes the same per-Profile session.active_list check, but it only ends runs the host says are over. It never adopts, retires or ends anything else, because in a running process the manager may be driving another activity. The pass covers the activity the manager holds when no stream is live for it. That one ends through end(status:) only if nothing wrote to it during the read: same lifecycle and update generation, no reattached stream. A leftover the manager doesn't hold is checked again after its relay route is retired.
Review also found a bug in the existing endActivity path. It compared the manager's state against the relay-enriched final state, so the manager didn't reset after ending an activity that had relay tool counts. It now compares against the manager's own state.
Full local suite before the review fixes: 4218 passed, 1 failed. The failure was BotChatPresentationTests.testThreadSearchOpensChronologicalDetailAndItsOwnComposer, which this diff doesn't touch; it passed when re-run on the final code.
The new testForegroundEndsOnlyFinishedHermesRunsIncludingTheHeldOne fails if the pass applies anything besides ending a finished run (for example, a bot leftover's .end), or ends the held activity by the wrong path.
The guards on the held activity need a real ActivityKit Activity and can't be unit-tested. Live Activities don't run on the simulator, so they still need a check on a phone.
Proved with a focused test that fails without the change, plus a full local suite run.
Reviewed with sol-review: 1 round with gpt-6.2-sol. Fixed S1 (the reset comparison), S2 (the recheck after retiring the route) and S3 (the update-generation guard). Declined S4: a foreground end reads "Response complete" whatever the outcome, the same as cold launch, because session.active_list doesn't carry the outcome and the open chat shows it. Declined S5, a server switch between Profile reads, as a nit.
Checklist
Local validation passes using scripts/test-sim <assigned-simulator-udid> with the tests required by AGENTS.md § Verifying; the selection and results are recorded above
New/changed Codable models decode tolerantly (optionals for fields the server might add or rename)
No new third-party dependencies (the list in AGENTS.md is locked)
No invented API endpoints or JSON shapes (verified against upstream source or a running server)
Created with Claude Opus 5.5 in Claude Code (T3 Code), with gpt-6.2-sol (review).
When the app returns to the foreground, live activities for Hermes runs confirmed as finished are now cleared, including an activity still held by the app.
Activities for runs that are still in progress remain active, and unrelated bot activities are unaffected.
Activities ended by this check display “Response complete.”
…s to the foreground
A Live Activity whose run ended while the app sat suspended stayed running
until the next cold launch when its last push was lost, because only cold
launch checked the host. Foreground now runs the same per-Profile
session.active_list check but only ends runs the host says are over,
including the activity the manager holds when no stream is live for it.
Fixes#1801
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
When the scene becomes active, the app checks Hermes run state and ends eligible finished Live Activities. The manager rechecks that held activities remain unchanged and disconnected before ending them.
Changes: Foreground Live Activity settlement
Layer / File(s)
Summary
Foreground check and completion HermesMobile/ContentView.swift, HermesMobile/LiveActivities/AgentLiveActivityManager.swift, HermesMobileTests/LiveActivityTests.swift, docs/adr/0070-live-activity-orphan-reconciliation.md
The active-scene task invokes endFinishedRuns. The manager ends activities marked .endComplete and checks ownership and generation conditions before completion. The final activity state preserves the relay count. The test covers held, finished, running, and bot activities. The ADR documents the foreground check and safeguards.
sequenceDiagram
participant ContentView
participant AgentLiveActivityManager
participant HermesSession
participant LiveActivity
ContentView->>AgentLiveActivityManager: Call endFinishedRuns(checking:)
AgentLiveActivityManager->>HermesSession: Check session.active_list per Profile
HermesSession-->>AgentLiveActivityManager: Return active run keys
AgentLiveActivityManager->>LiveActivity: End eligible activity
Loading
Possibly related issues
uzairansaruzi/hermex#1723 — Describes finished runs that remain active when a terminal push is lost; this change checks for finished runs when the app returns to the foreground.
Possibly related PRs
uzairansaruzi/hermex#1800 — Adds cold-launch reconciliation using session.active_list; this PR adds foreground reconciliation, including the manager-held activity.
Merge Risk: Minimal · up to c0e33
The change ends finished Live Activities when the app returns to the foreground, and it only ends runs the host reports as over. The earlier concern about ending a held activity whose push key changed is fixed. No known merge-blocking risk remains, but the author's planned on-device check is still worth completing.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: a finished run's Live Activity is ended when the app returns to the foreground. It also uses the fix(live-activity) scope, which fits the changeset. The summary and ob…
Linked Issues check
Issue #1801 requires a foreground, end-only pass that applies only .endComplete. In AgentLiveActivityManager.endFinishedRuns(checking:), the held activity is selected only when `activeConnectedStr…
Out of Scope Changes check
The changes connect to #1801. The endFinishedRuns and endFinished functions implement the foreground pass. The endActivity rename from finalState to shownState in the update and end calls fi…
Full details: Title check
Explanation
The title names the main change: a finished run's Live Activity is ended when the app returns to the foreground. It also uses the fix(live-activity) scope, which fits the changeset. The summary and objectives both describe a foreground, end-only pass through endFinishedRuns, and the title matches that.
Full details: Linked Issues check
Explanation
Issue #1801 requires a foreground, end-only pass that applies only .endComplete. In AgentLiveActivityManager.endFinishedRuns(checking:), the held activity is selected only when activeConnectedStreamID == nil and currentState?.isFinal == false. endFinished applies only actions equal to .endComplete. The held path ends through end(status:), which resets the manager. Before ending, endHeld rechecks activity?.id, lifecycleGeneration, updateGeneration, drivenPushSessionID, and activeConnectedStreamID. This covers the reattach check after the session.active_list read. Unheld leftovers are checked again after retirePush (guard unowned() != nil) before finishPersisted. The ContentView change wires the pass into the scene-active task, and the endActivity change compares against the manager's own state (resetIfStillCurrent still uses finalState). The no-progress watchdog is not implemented. The new test testForegroundEndsOnlyFinishedHermesRunsIncludingTheHeldOne covers the held path and the running and bot exclusions. The on-device behavior of the held-activity guards needs a phone check. The simulator cannot run Live Activities, so this part stays unverified in automation.
Full details: Out of Scope Changes check
Explanation
The changes connect to #1801. The endFinishedRuns and endFinished functions implement the foreground pass. The endActivity rename from finalState to shownState in the update and end calls fixes the reset comparison that the issue needs for end(status:) to reset the manager. The ContentView change wires the pass into the scene-active task. The unit test verifies the required behavior. The ADR section documents the same behavior. The retirement of a leftover's push route before ending it is part of ending that leftover, not a separate change. No unrelated change was found in the reviewed diff.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
[Medium impact] The PR appears safe to merge; no new actionable issues were found.
Summary
The PR ends finished Hermes Live Activities when the app returns to the foreground. The latest change also skips an old result if the held activity’s push key changed during the check.
Foreground checks end Hermes runs the host no longer lists.
Finished runs clear the manager even when relay counts are shown.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Fixes #1801
What changed
If the app sat suspended overnight with the chat closed and the relay's final push was lost, the run's Live Activity kept running after the run ended. #1800 fixed this only for a cold launch.
When the app returns to the foreground,
AgentLiveActivityManager.endFinishedRunsnow makes the same per-Profilesession.active_listcheck, but it only ends runs the host says are over. It never adopts, retires or ends anything else, because in a running process the manager may be driving another activity. The pass covers the activity the manager holds when no stream is live for it. That one ends throughend(status:)only if nothing wrote to it during the read: same lifecycle and update generation, no reattached stream. A leftover the manager doesn't hold is checked again after its relay route is retired.Review also found a bug in the existing
endActivitypath. It compared the manager's state against the relay-enriched final state, so the manager didn't reset after ending an activity that had relay tool counts. It now compares against the manager's own state.How it was tested
scripts/test-sim <udid> --onlyLiveActivityTests, PushRegistrationTests, HermesChatTurnTests, ChatStreamCoordinatorTests, BotChatPresentationTests: 304 passed.BotChatPresentationTests.testThreadSearchOpensChronologicalDetailAndItsOwnComposer, which this diff doesn't touch; it passed when re-run on the final code.testForegroundEndsOnlyFinishedHermesRunsIncludingTheHeldOnefails if the pass applies anything besides ending a finished run (for example, a bot leftover's.end), or ends the held activity by the wrong path.Activityand can't be unit-tested. Live Activities don't run on the simulator, so they still need a check on a phone.Proved with a focused test that fails without the change, plus a full local suite run.
Reviewed with sol-review: 1 round with gpt-6.2-sol. Fixed S1 (the reset comparison), S2 (the recheck after retiring the route) and S3 (the update-generation guard). Declined S4: a foreground end reads "Response complete" whatever the outcome, the same as cold launch, because
session.active_listdoesn't carry the outcome and the open chat shows it. Declined S5, a server switch between Profile reads, as a nit.Checklist
scripts/test-sim <assigned-simulator-udid>with the tests required byAGENTS.md§ Verifying; the selection and results are recorded aboveCodablemodels decode tolerantly (optionals for fields the server might add or rename)AGENTS.mdis locked)Created with Claude Opus 5.5 in Claude Code (T3 Code), with gpt-6.2-sol (review).
🤖 Generated with Claude Code
Summary by CodeRabbit