* fix(agent-status): restore hydrated nonterminal statuses as unconfirmed A hook transition that fires while Electron is down has no receiver and is discarded, so last-status.json can restore a stale 'working' as confirmed truth for up to the 7-day hydrate TTL. Stamp hydrated nonterminal rows with restoredUnconfirmed, carry it through both IPC paths, and treat such rows as never-fresh in the shared and renderer freshness gates so the sidebar, worktree.ps, and the raw snapshot all present the same degraded semantics. Terminal states restore as-is; any accepted live event clears the flag; the flag itself is never persisted. Interrupt/question inference refuses to fabricate transitions onto unconfirmed rows. * fix(agent-status): shed unconfirmed marker when the liveness sweep verifies done The restored-subagent reaper's reconciled entry spread carried restoredUnconfirmed onto a process-probe-verified 'done', making freshness gates suppress a legitimate completion. Keep the marker only while the reconciled state stays nonterminal. * fix(agent-status): let live evidence replace hydrated rows * fix(agent-status): keep restored rows degraded Sort accepted live evidence after hydrated rows even across wall-clock rollback. Let unconfirmed rows own their preserved pane titles without asserting live state, while retaining independently live sibling evidence. * fix(agent-status): suppress unmapped restored titles Treat a single runtime title as covered by the single restored hook row while layout identity is unavailable. Preserve ordinary age-stale fallback and mapped sibling-pane evidence.
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import {
|
|
AGENT_STATUS_STALE_AFTER_MS,
|
|
isFreshNonDoneAgentStatus,
|
|
type AgentStatusState,
|
|
type AgentType
|
|
} from './agent-status-types'
|
|
|
|
type ExistingAgentIdentity = {
|
|
agentType?: AgentType
|
|
state: AgentStatusState
|
|
updatedAt: number
|
|
restoredUnconfirmed?: boolean
|
|
}
|
|
|
|
type AgentIdentityResolution = {
|
|
agentType: AgentType
|
|
inheritedFromActivePane: boolean
|
|
}
|
|
|
|
export function shouldSuppressInheritedTerminalStatus(args: {
|
|
inheritedFromActivePane: boolean
|
|
incomingState: AgentStatusState
|
|
}): boolean {
|
|
// Why: nested child hooks inherit the parent's ORCA_PANE_KEY. A child
|
|
// completion does not prove the active parent turn completed.
|
|
return args.inheritedFromActivePane && args.incomingState === 'done'
|
|
}
|
|
|
|
function normalizedKnownAgentType(agentType: AgentType | null | undefined): AgentType | null {
|
|
if (!agentType || agentType === 'unknown') {
|
|
return null
|
|
}
|
|
return agentType
|
|
}
|
|
|
|
function isActiveExistingIdentity(
|
|
existing: ExistingAgentIdentity,
|
|
now: number,
|
|
staleAfterMs: number
|
|
): boolean {
|
|
return isFreshNonDoneAgentStatus(existing, now, staleAfterMs)
|
|
}
|
|
|
|
export function resolveAgentStatusIdentity(args: {
|
|
existing?: ExistingAgentIdentity
|
|
incoming?: AgentType
|
|
now: number
|
|
staleAfterMs?: number
|
|
}): AgentIdentityResolution {
|
|
const staleAfterMs = args.staleAfterMs ?? AGENT_STATUS_STALE_AFTER_MS
|
|
const existingAgentType = normalizedKnownAgentType(args.existing?.agentType)
|
|
const incomingAgentType = normalizedKnownAgentType(args.incoming)
|
|
|
|
if (!incomingAgentType) {
|
|
return {
|
|
agentType: existingAgentType ?? 'unknown',
|
|
inheritedFromActivePane: false
|
|
}
|
|
}
|
|
if (!args.existing || !existingAgentType || existingAgentType === incomingAgentType) {
|
|
return {
|
|
agentType: incomingAgentType,
|
|
inheritedFromActivePane: false
|
|
}
|
|
}
|
|
if (isActiveExistingIdentity(args.existing, args.now, staleAfterMs)) {
|
|
return {
|
|
// Why: child agent CLIs inherit ORCA_PANE_KEY from their parent terminal.
|
|
// While the parent turn is active, do not let a nested hook steal the
|
|
// pane's visible identity.
|
|
agentType: existingAgentType,
|
|
inheritedFromActivePane: true
|
|
}
|
|
}
|
|
|
|
return {
|
|
agentType: incomingAgentType,
|
|
inheritedFromActivePane: false
|
|
}
|
|
}
|