Repository navigation
Check that a woken agent came back #15312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
teamleaderleo
merged 13 commits into
manaflow-ai:main
from
teamleaderleo:hibernation/wake-verify
Sep 30, 2026
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e3033ff
Add failing tests for agent wake verification
teamleaderleo fca2217
Check that a woken agent came back
teamleaderleo a87c6c0
Only fail quick resume exits and never retype into a running program
teamleaderleo 96d592a
Merge main (0c753fe28dfd) into hibernation/wake-verify
teamleaderleo 214528e
Confirm wakes only from the woken agent's own evidence
teamleaderleo e5cbda7
Merge remote-tracking branch 'upstream/main' into HEAD
teamleaderleo 7a0ed42
Merge remote-tracking branch 'upstream/main' into HEAD
teamleaderleo 3582235
Merge main (478e3232b099) into hibernation/wake-verify
teamleaderleo c72fe03
Merge main (5cfc6a669255) into hibernation/wake-verify
teamleaderleo e08c109
Merge main (8599250a7cd6) into hibernation/wake-verify
teamleaderleo 1933f51
Merge main (1b06f84cbd93) into hibernation/wake-verify
teamleaderleo 269c94f
Merge main (4d9bec3bc1d8) into hibernation/wake-verify
teamleaderleo 5ada757
Merge main (34caf6723814) into hibernation/wake-verify
teamleaderleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import Foundation | ||
|
|
||
| /// Why a woken agent was judged not to have come back. | ||
| enum AgentWakeFailureReason: Equatable, Sendable { | ||
| /// The resume command ran and returned to the shell prompt before the | ||
| /// agent reported in. | ||
| case exitedBeforeStart | ||
| /// Nothing reported in before the verification deadline, and no live | ||
| /// agent process was found for the pane. | ||
| case didNotStart | ||
|
|
||
| /// The second line of the failure banner and the feed entry body. | ||
| var detail: String { | ||
| switch self { | ||
| case .exitedBeforeStart: | ||
| String( | ||
| localized: "agentWake.reason.exitedBeforeStart", | ||
| defaultValue: "Its resume command exited." | ||
| ) | ||
| case .didNotStart: | ||
| String( | ||
| localized: "agentWake.reason.didNotStart", | ||
| defaultValue: "It did not start within 90 seconds." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A failed wake shown on the terminal pane until retried, dismissed, or | ||
| /// superseded by a later success signal. | ||
| struct AgentWakeFailure { | ||
| let reason: AgentWakeFailureReason | ||
| /// The agent name shown to the user, for example "Claude Code". | ||
| let agentDisplayName: String | ||
| /// The command shown by "Show command". This is the agent's resume | ||
| /// command when one exists, otherwise the typed startup input. | ||
| let commandText: String | ||
| let agent: SessionRestorableAgentSnapshot | ||
| /// False while something still runs in the pane, where typing the resume | ||
| /// command again would feed it to that program instead of the shell. | ||
| var canRetry: Bool = true | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import Foundation | ||
|
|
||
| /// One pane's wake check, owned by its `Workspace`. | ||
| struct AgentWakeVerification { | ||
| /// Identifies this check so a deadline scheduled for an older check does | ||
| /// not act on a newer one. | ||
| let token: UUID | ||
| let agent: SessionRestorableAgentSnapshot | ||
| let startedAt: Date | ||
| /// The command shown to the user if the wake fails. | ||
| let commandText: String | ||
| var state: AgentWakeVerificationState | ||
| var deadlineTask: Task<Void, Never>? | ||
|
|
||
| /// Whether a hook report under `statusKey` comes from the woken agent. | ||
| /// Hook status keys name the agent kind (Claude reports as | ||
| /// `claude_code`); a Feed attention overlay for that agent counts too. | ||
| /// Reports from another agent in the same pane leave the check pending. | ||
| func acceptsReport(statusKey: String) -> Bool { | ||
| let source = agent.kind.rawValue | ||
| return statusKey == FeedCoordinator.lifecycleStatusKey(forSource: source) | ||
| || statusKey == FeedCoordinator.attentionStatusKey(forSource: source) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import Foundation | ||
|
|
||
| /// Pure state for checking that an agent woken from hibernation came back. | ||
| /// | ||
| /// The owner feeds it the signals it sees for one pane: the wake itself, an | ||
| /// agent hook reporting for the pane, the resume command returning to the | ||
| /// shell prompt, and the verification deadline. | ||
| enum AgentWakeVerificationState: Equatable, Sendable { | ||
| case pending | ||
| case succeeded | ||
| case failed(AgentWakeFailureReason) | ||
|
|
||
| enum Event: Equatable, Sendable { | ||
| /// A wake (or a retry) typed the resume command into the pane. | ||
| case started | ||
| /// An agent hook reported a PID or a lifecycle state for the pane. | ||
| case agentReported | ||
| /// A live process of the woken agent was found in the pane, which | ||
| /// confirms agents without hooks. | ||
| case liveProcessFound | ||
| /// The resume command ended and the shell prompt came back. | ||
| case commandEnded | ||
| /// The verification deadline passed. `hasLiveProcess` says whether a | ||
| /// live agent process was found for the pane at that moment. | ||
| case deadline(hasLiveProcess: Bool) | ||
| } | ||
|
|
||
| func applying(_ event: Event) -> AgentWakeVerificationState { | ||
| switch (self, event) { | ||
| case (_, .started): | ||
| return .pending | ||
| case (_, .agentReported): | ||
| // A report after a failure means the agent did come back. | ||
| return .succeeded | ||
| case (.pending, .liveProcessFound): | ||
| return .succeeded | ||
| case (.pending, .commandEnded): | ||
| return .failed(.exitedBeforeStart) | ||
| case (.pending, .deadline(let hasLiveProcess)): | ||
| // Some agents have no hooks; a live process is enough. | ||
| return hasLiveProcess ? .succeeded : .failed(.didNotStart) | ||
| case (.succeeded, _), (.failed, _): | ||
| return self | ||
| } | ||
| } | ||
|
|
||
| var failureReason: AgentWakeFailureReason? { | ||
| if case .failed(let reason) = self { return reason } | ||
| return nil | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import AppKit | ||
| import SwiftUI | ||
|
|
||
| /// Shown above the terminal when an agent woken from hibernation did not come back. | ||
| struct AgentWakeFailureBanner: View { | ||
| let failure: AgentWakeFailure | ||
| let onRetry: () -> Void | ||
| let onDismiss: () -> Void | ||
|
|
||
| @State private var showsCommand = false | ||
|
|
||
| var body: some View { | ||
| VStack(alignment: .leading, spacing: 6) { | ||
| HStack(alignment: .top, spacing: 8) { | ||
| Image(systemName: "exclamationmark.triangle.fill") | ||
| .foregroundStyle(.orange) | ||
| .accessibilityHidden(true) | ||
| VStack(alignment: .leading, spacing: 2) { | ||
| Text(message) | ||
| .font(.callout) | ||
| .accessibilityIdentifier("agent-wake-failure-message") | ||
| Text(failure.reason.detail) | ||
| .font(.callout) | ||
| .foregroundStyle(.secondary) | ||
| .accessibilityIdentifier("agent-wake-failure-detail") | ||
| } | ||
| .textSelection(.enabled) | ||
| Spacer(minLength: 0) | ||
| if failure.canRetry { | ||
| Button(retryTitle, action: onRetry) | ||
| .controlSize(.small) | ||
| .accessibilityIdentifier("agent-wake-failure-retry") | ||
| } | ||
| Button(showsCommand ? hideCommandTitle : showCommandTitle) { | ||
| showsCommand.toggle() | ||
| } | ||
| .controlSize(.small) | ||
| .accessibilityIdentifier("agent-wake-failure-show-command") | ||
| Button(action: onDismiss) { | ||
| Image(systemName: "xmark") | ||
| } | ||
| .buttonStyle(.borderless) | ||
| .help(closeTitle) | ||
| .accessibilityLabel(closeTitle) | ||
| .accessibilityIdentifier("agent-wake-failure-close") | ||
| } | ||
| if showsCommand { | ||
| HStack(alignment: .top, spacing: 8) { | ||
| Text(verbatim: failure.commandText) | ||
| .font(.system(.callout, design: .monospaced)) | ||
| .textSelection(.enabled) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .accessibilityIdentifier("agent-wake-failure-command") | ||
| Button(copyTitle) { | ||
| let pasteboard = NSPasteboard.general | ||
| pasteboard.clearContents() | ||
| pasteboard.setString(failure.commandText, forType: .string) | ||
| } | ||
| .controlSize(.small) | ||
| .accessibilityIdentifier("agent-wake-failure-copy") | ||
| } | ||
| } | ||
| } | ||
| .padding(10) | ||
| .accessibilityElement(children: .contain) | ||
| .accessibilityIdentifier("agent-wake-failure-banner") | ||
| } | ||
|
|
||
| private var message: String { | ||
| String( | ||
| format: String( | ||
| localized: "agentWake.banner.message", | ||
| defaultValue: "%@ didn't resume after waking." | ||
| ), | ||
| failure.agentDisplayName | ||
| ) | ||
| } | ||
|
|
||
| private var retryTitle: String { | ||
| String(localized: "agentWake.banner.retry", defaultValue: "Retry") | ||
| } | ||
|
|
||
| private var showCommandTitle: String { | ||
| String(localized: "agentWake.banner.showCommand", defaultValue: "Show command") | ||
| } | ||
|
|
||
| private var hideCommandTitle: String { | ||
| String(localized: "agentWake.banner.hideCommand", defaultValue: "Hide command") | ||
| } | ||
|
|
||
| private var copyTitle: String { | ||
| String(localized: "agentWake.banner.copy", defaultValue: "Copy") | ||
| } | ||
|
|
||
| private var closeTitle: String { | ||
| String(localized: "agentWake.banner.close", defaultValue: "Close") | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.