Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
c867bd2
refactor(native-chat): remove the unused terminal handoff
brennanb2025 Sep 25, 2026
eab4ef1
fix(native-chat): never let the pre-stop snapshot hold a chat's stop
brennanb2025 Sep 25, 2026
abafbbc
refactor(native-chat): drop helpers only the terminal handoff called
brennanb2025 Sep 25, 2026
3cbf6b5
docs(native-chat): stop citing the removed handoff in lifecycle comments
brennanb2025 Sep 25, 2026
e048579
test(native-chat): type the stalled snapshot drain without a cast
brennanb2025 Sep 25, 2026
b50c574
test(native-chat): pin that a start dead before proving owes no settl…
brennanb2025 Sep 25, 2026
12efdef
fix(native-chat): keep the owner-status read behind an in-flight attach
brennanb2025 Sep 25, 2026
42d10ee
refactor(terminal): remove the agent-session PTY write gate
brennanb2025 Sep 25, 2026
0483915
refactor(native-chat): drop the transcript helpers only the handoff c…
brennanb2025 Sep 25, 2026
d0f4dae
fix(native-chat): stop calling a starting chat "mid-handoff"
brennanb2025 Sep 25, 2026
faecece
test(native-chat): type the stand-in roster decoder without a cast
brennanb2025 Sep 25, 2026
250250e
refactor(codex): name the pinned rollout lookup for what it does
brennanb2025 Sep 25, 2026
b588185
refactor(native-chat): type the owner-status reply as the host sends it
brennanb2025 Sep 25, 2026
35742fd
refactor(native-chat): normalize terminal-handoff lease values once a…
brennanb2025 Sep 25, 2026
54ce5fc
refactor(native-chat): stop threading the owner kind through a reserv…
brennanb2025 Sep 25, 2026
713b126
test(native-chat): pin the legacy-lease rewrite with a transaction th…
brennanb2025 Sep 25, 2026
44d7977
fix(native-chat): name a chat write by its target, not the owner gene…
brennanb2025 Sep 25, 2026
6dad39a
fix(native-chat): every journal append reaches the chats that are open
brennanb2025 Sep 25, 2026
97bf3bb
test(native-chat): an epoch replacement reaches the open chat
brennanb2025 Sep 25, 2026
427dc8d
test(native-chat): each row reaches an open chat once, and a live han…
brennanb2025 Sep 25, 2026
2bd44f5
test(native-chat): give the legacy-lease store test a tab id so the b…
brennanb2025 Sep 25, 2026
f79eb9b
test(worktree-activation): restore the OMP surfaced-agent resume test
brennanb2025 Sep 25, 2026
50d2e33
perf(native-chat): a publish behind a delivered commit reads nothing
brennanb2025 Sep 25, 2026
bd72b13
test(native-chat): state why the teardown test's fake journal is safe…
brennanb2025 Sep 25, 2026
fa9b76a
docs(native-chat): say mutation admission checks only the writer lease
brennanb2025 Sep 25, 2026
5435973
docs(native-chat): drop the send rebase from comments that still desc…
brennanb2025 Sep 25, 2026
8fd4558
Merge #22811 into the PR 1 base
brennanb2025 Sep 25, 2026
12dde37
Merge #22812 into the PR 1 base
brennanb2025 Sep 25, 2026
c753e8a
fix(native-chat): a message is accepted, then delivered
brennanb2025 Sep 25, 2026
82f9bfd
fix(native-chat): settle queued messages only for the child that ended
brennanb2025 Sep 25, 2026
f3e52d2
fix(native-chat): an adoption that fails to import keeps the conversa…
brennanb2025 Sep 25, 2026
29a340b
perf(native-chat): the recovering open reads the journal once
brennanb2025 Sep 25, 2026
c7a652f
fix(native-chat): an attach that fails after indexing its child leave…
brennanb2025 Sep 25, 2026
34d0bb0
fix(native-chat): a withdrawn message shows no error, and a rejection…
brennanb2025 Sep 25, 2026
46b6472
fix(orchestration): a structured worker whose agent outlasts the prea…
brennanb2025 Sep 25, 2026
283819d
fix(native-chat): a message rejected while its chat was closed reads …
brennanb2025 Sep 25, 2026
40dabe8
test(orchestration): name why the readiness settlement fakes are cast
brennanb2025 Sep 25, 2026
31444bf
fix(native-chat): keep each pane's own fence on frames so a failed re…
brennanb2025 Sep 25, 2026
494d8c7
docs(native-chat): drop the fence from the admission the send effects…
brennanb2025 Sep 25, 2026
0e74529
docs(native-chat): give the fence move on release the reason that sti…
brennanb2025 Sep 25, 2026
6c16f35
docs(native-chat): stop citing a write fence check in launch and mail…
brennanb2025 Sep 25, 2026
d2f646b
refactor(native-chat): the provider child is its own record
brennanb2025 Sep 25, 2026
25fa38a
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-wri…
brennanb2025 Sep 25, 2026
aa56b50
fix(native-chat): the delivery loop alone settles a message its start…
brennanb2025 Sep 25, 2026
d23cca4
Merge #22812 and main into PR 1
brennanb2025 Sep 25, 2026
4993696
refactor(native-chat): a stopped child ends on the one reading of its…
brennanb2025 Sep 25, 2026
a2ad8f2
feat(native-chat): the host says it accepts a send before any agent h…
brennanb2025 Sep 25, 2026
48def96
refactor(native-chat): an attach never opens a journal of its own
brennanb2025 Sep 25, 2026
da65d57
fix(native-chat): a moved fence resends nothing on a host that accept…
brennanb2025 Sep 25, 2026
0184a3d
refactor(native-chat): a child's end says whether the user or the hos…
brennanb2025 Sep 25, 2026
12577d8
fix(native-chat): a chat whose only work is a queued message is not o…
brennanb2025 Sep 25, 2026
a59eed9
test(native-chat): type the queued-message fixtures in the resume-off…
brennanb2025 Sep 25, 2026
ccaf412
fix(native-chat): a start that dies while a message waits on it is th…
brennanb2025 Sep 25, 2026
9123568
fix(native-chat): a request that failed reads as failed
brennanb2025 Sep 25, 2026
0efca93
docs(native-chat): say what an attach's open conversation and unconfi…
brennanb2025 Sep 25, 2026
36067f3
test(native-chat): a verdict change republishes the mobile status pro…
brennanb2025 Sep 25, 2026
a47a902
refactor(native-chat): the store's retention trigger keeps its flag c…
brennanb2025 Sep 25, 2026
69540f8
Merge remote-tracking branch 'origin/brennanb2025/chat-accept-then-de…
brennanb2025 Sep 25, 2026
918091d
test(native-chat): a user message the provider journaled keeps its se…
brennanb2025 Sep 25, 2026
74d6506
test(native-chat): pin what a failed start settles, and what a resume…
brennanb2025 Sep 25, 2026
9c671f1
test(native-chat): the failed-start pins fail on what the message bec…
brennanb2025 Sep 25, 2026
40f3d35
fix(native-chat): a late provider-session update keeps a failed recov…
brennanb2025 Sep 25, 2026
80ccb33
test(orchestration): the preamble's host stub is typed, not cast
brennanb2025 Sep 25, 2026
97a5321
test(native-chat): the terminal-bell check asserts the renamed verdic…
brennanb2025 Sep 25, 2026
4c67270
Merge remote-tracking branch 'origin/brennanb2025/chat-accept-then-de…
brennanb2025 Sep 25, 2026
dfe35eb
fix(native-chat): a failed turn ranks like a completion for attention
brennanb2025 Sep 25, 2026
a96f475
fix(native-chat): a failed main agent reads failed while its subagent…
brennanb2025 Sep 26, 2026
9d9a8ae
docs(native-chat): the worktree ps outcome comment no longer claims o…
brennanb2025 Sep 26, 2026
48cdb21
docs(native-chat): the status-store listing rule names provider-journ…
brennanb2025 Sep 26, 2026
bbec1b6
fix(native-chat): a refused send notifies failed through the completi…
brennanb2025 Sep 26, 2026
e6dadd1
Merge main into PR 1
brennanb2025 Sep 26, 2026
a6c7153
fix(native-chat): every copy of a row carries the main agent's own st…
brennanb2025 Sep 26, 2026
7b6eafb
test(native-chat): pin the worktree ps verdict across host and phone …
brennanb2025 Sep 26, 2026
a73c33a
test(mobile): name the parity table's row for its role
brennanb2025 Sep 26, 2026
159b971
fix(native-chat): a request that settles while the user is asked some…
brennanb2025 Sep 26, 2026
93ee58a
fix(native-chat): the completion says when the user is being asked
brennanb2025 Sep 26, 2026
d242e5e
Merge remote-tracking branch 'origin/brennanb2025/chat-accept-then-de…
brennanb2025 Sep 26, 2026
e17c80e
fix(worktree-status): a departed agent's failure yields to live work …
brennanb2025 Sep 26, 2026
6374f35
Merge main into PR 1
brennanb2025 Sep 27, 2026
0f89353
docs(agent-status): a departed agent's failure ranks below live work …
brennanb2025 Sep 27, 2026
724b961
Merge main into PR 1
brennanb2025 Sep 27, 2026
4d36cd3
Merge remote-tracking branch 'origin/brennanb2025/chat-accept-then-de…
brennanb2025 Sep 27, 2026
c39151d
fix(native-chat): a view never restarts a chat whose last start failed
brennanb2025 Sep 27, 2026
9613178
test(native-chat): start the child the loop waits on with an attach, …
brennanb2025 Sep 27, 2026
0224459
fix(native-chat): settle a gone generation's turn wherever a conversa…
brennanb2025 Sep 27, 2026
2276cef
test(native-chat): prove the next child's start settles the turn an e…
brennanb2025 Sep 27, 2026
9275869
test(native-chat): count a failed start's rows by row, not by text
brennanb2025 Sep 27, 2026
8fea3f0
test(cross-version): load the phone row readers without mobile's tool…
brennanb2025 Sep 27, 2026
8c966c7
test(cross-version): keep the checkout path-guard message and justify…
brennanb2025 Sep 27, 2026
158ca0a
test(native-chat): give the failed-start and stale-turn waits a loade…
brennanb2025 Sep 27, 2026
8f66a25
test(native-chat): pin the open's and the send's start and row counts…
brennanb2025 Sep 27, 2026
ad04c3b
fix(native-chat): settle a gone generation's turn at every open but a…
brennanb2025 Sep 27, 2026
05b8b93
test(native-chat): hold the create's start open until the views bind
brennanb2025 Sep 27, 2026
d5716f3
Merge main into PR 1
brennanb2025 Sep 27, 2026
3ea60f2
Merge remote-tracking branch 'origin/brennanb2025/chat-accept-then-de…
brennanb2025 Sep 27, 2026
740ed1f
Merge main into PR 1
brennanb2025 Sep 28, 2026
7002b1b
refactor(native-chat): drop the composer's second error formatter
brennanb2025 Sep 28, 2026
cb5ce82
test(native-chat): pin the reason on a message rejected while its cha…
brennanb2025 Sep 28, 2026
fcad779
Merge PR 1 into #22944
brennanb2025 Sep 28, 2026
5b9379d
fix(native-chat): a send the provider never received after a restart …
brennanb2025 Sep 28, 2026
1a894f5
Merge main into #22944 after PR 1 squash-merged
brennanb2025 Sep 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ jobs:
tests/e2e/cross-version-wire/cross-version-worktree-identity-downgrade.unit.test.ts
tests/e2e/cross-version-wire/cross-version-session-tabs-retirement-proof.unit.test.ts
tests/e2e/cross-version-wire/agent-session-unproven-release-downgrade.unit.test.ts
tests/e2e/cross-version-wire/cross-version-worktree-ps-verdict.unit.test.ts

managed_hook_node18:
name: managed hooks on Node 18
Expand Down
3 changes: 3 additions & 0 deletions config/scripts/pr-code-change-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ const CROSS_VERSION_WIRE_PREFIXES = [
'src/main/runtime/rpc/methods/session-tabs.ts',
'src/main/runtime/rpc/methods/structured-agent-session',
'src/main/runtime/rpc/methods/terminal',
'src/main/runtime/runtime-worktree-agent-',
'src/main/runtime/runtime-worktree-pty-agent-sources',
'src/shared/runtime-worktree-contracts',
'src/renderer/src/runtime/remote-runtime-terminal-multiplexer'
]

Expand Down
3 changes: 3 additions & 0 deletions config/scripts/pr-code-change-scope.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ describe('per-job path classification', () => {
'src/main/runtime/rpc/methods/structured-agent-session-hold.ts',
'src/main/runtime/rpc/methods/structured-agent-session-schemas.ts',
'src/main/runtime/rpc/methods/terminal.ts',
'src/main/runtime/runtime-worktree-agent-rows.ts',
'src/main/runtime/runtime-worktree-pty-agent-sources.ts',
'src/shared/runtime-worktree-contracts.ts',
'src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts'
]) {
expectClassification([file], {
Expand Down
37 changes: 35 additions & 2 deletions docs/reference/agent-status-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ ingests the summary into the hook server as a status row:
| `structuredHost` | `'owned'` while `summary.hostExecutionOwned` is set, otherwise `'held'`; `worktree ps` derives its row's `structuredHostOwned` from it |
| prompt, tool, last message, model, provider session | the summary's fields |

Sessions with no persisted turn (`status === null`) produce no row, matching
what the chat shows. When the host revokes live ownership the row is re-set
Sessions with no request (`status === null`) produce no row. A request is a
turn record, an assistant message, a user message the provider journaled itself
(history, an older host), an accepted or unanswered send, or a send the agent or
its start refused; a send that was withdrawn, or left undelivered by a
restart or a close, fails nobody and makes nothing listable.
`summary.turnOutcome` is the latest request's verdict: its turn's outcome, or
`failure` for a send the agent or its start refused (a send that joined a running
turn is answered by that turn). The row also publishes `interrupted` from
`mainAgent.outcome`, exactly as the hook lanes do. When the host revokes live ownership the row is re-set
without the flag; when the host closes or evicts the session the row is
dropped. Both already exist as feed events (`revokeLive` and the roster
filter in `liveSessionSummaries`); PR 1 turns them into store writes.
Expand Down Expand Up @@ -218,6 +225,32 @@ sends no hook at all on a cancel and no `is_interrupt` on Stop; that flag on a
turn boundary remains a secondary source for builds that send it, and
`StopFailure` maps to `failure`.

Readers decode the verdict through one accessor, `agentMainAgentVerdict`, which
reads the main agent's own state, not the combined row's: `mainAgent.outcome`
while `mainAgent.state` is `done`, then the legacy `interrupted` flag as a
cancellation, which alone needs the combined `done`. So a main agent that
failed while its subagents still run has a verdict on a `working` row. Every
copy of a row (state-history entries, sleep records, `worktree ps` rows) takes
the verdict through `agentVerdictFields`, which carries `interrupted` and the
whole `mainAgent` (state, outcome and its own clock) together, so a copy agrees
with the row and can date a failure by `mainAgent.stateStartedAt`.

Display reads the verdict through `agentVerdictDisplayMark`: a failure marks the
agent failed whatever the combined state, because it is news the user must see
even while subagents run; a stop marks it interrupted only on a `done` row, so
a stopped or finished main agent with live child work still reads working.
Each subagent keeps its own row and state. Container rollups (worktree card,
terminal tab, Cmd+J) rank a pending question first, then a failure, then live
work, then a stop, then done. On the worktree card, a failure retained after its
agent's pane went away has no expiry, so it ranks below live work and above a
stop. Lifecycle waiters keep reading the combined `state`.

Policy splits the verdict two ways. Clean-finish policy (hibernation, pane
ownership, the star-nag value moment) treats a failure like a cancellation
(`agentTurnEndedUncleanly`). Attention (completion time, Smart Sort, sticky
retention, Cmd+J Recent) demotes only a turn the user stopped
(`agentTurnStoppedByUser`); a failure ranks like a completion.

Admission is one function, `normalizeAgentStatusPayload`, on the relay wire,
IPC and disk. A malformed `mainAgent` drops the field and keeps the row. Old hosts
send none and readers fall back to `state`. Hook rows persist it inside the
Expand Down
3 changes: 2 additions & 1 deletion mobile/src/components/AgentStateDot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import type { AgentDotState } from '../worktree/agent-row-display'

// Per-agent state indicator, 1:1 with desktop AgentStateDot
// (src/renderer/src/components/AgentStateDot.tsx): yellow spinner for 'working',
// emerald for 'done', red for blocked/waiting/interrupted (attention), neutral
// emerald for 'done', red for blocked/waiting/interrupted/failed (attention), neutral
// for idle. Distinct from the worktree-level AgentSpinner, which collapses the
// agent vocabulary into the 5-state rollup the sidebar dot uses.
const DOT_COLORS: Record<Exclude<AgentDotState, 'working' | 'monitoring'>, string> = {
done: '#10b981',
blocked: '#ef4444',
waiting: '#ef4444',
interrupted: '#ef4444',
failed: '#ef4444',
idle: 'rgba(115,115,115,0.4)'
}
const WORKING_COLOR = '#eab308'
Expand Down
9 changes: 7 additions & 2 deletions mobile/src/components/WorktreeAgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { memo } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'
import { colors, spacing } from '../theme/mobile-theme'
import { agentDisplayLabel, agentDotState, formatTimeAgo } from '../worktree/agent-row-display'
import {
agentDisplayLabel,
agentDotState,
agentRowTimeAt,
formatTimeAgo
} from '../worktree/agent-row-display'
import { AgentStateDot } from './AgentStateDot'
import { MobileAgentIcon } from './MobileAgentIcon'

Expand All @@ -22,7 +27,7 @@ type Props = {
function WorktreeAgentRowComponent({ agent, depth, now, unvisited }: Props) {
const dotState = agentDotState(agent, now)
const label = agentDisplayLabel(agent, now)
const ts = formatTimeAgo(agent.stateStartedAt, now)
const ts = formatTimeAgo(agentRowTimeAt(agent), now)

return (
<View style={[styles.row, { paddingLeft: depth * INDENT_PER_DEPTH }]}>
Expand Down
87 changes: 84 additions & 3 deletions mobile/src/worktree/agent-row-display.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { describe, expect, it } from 'vitest'
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'
import {
agentMainAgentVerdict,
agentVerdictDisplayMark
} from '../../../src/shared/agent-main-agent-verdict'
import { AGENT_JOURNAL_TURN_OUTCOMES } from '../../../src/shared/agent-turn-outcome'
import {
AGENT_STATUS_STALE_AFTER_MS,
agentDisplayLabel,
agentDotState,
agentIdentityLabel,
agentRowTimeAt,
agentRowVerdict,
agentRowVerdictMark,
formatTimeAgo
} from './agent-row-display'

type Outcome = (typeof AGENT_JOURNAL_TURN_OUTCOMES)[number]
const mainAgentDone = (outcome: Outcome, stateStartedAt = 0) => ({
mainAgent: { state: 'done' as const, outcome, stateStartedAt }
})

function row(overrides: Partial<RuntimeWorktreeAgentRow> = {}): RuntimeWorktreeAgentRow {
return {
paneKey: 'p',
Expand Down Expand Up @@ -37,8 +50,54 @@ describe('agentDotState', () => {
expect(agentDotState(row({ state: 'unknown-state' as never }), 0)).toBe('idle')
})

it('reports interrupted regardless of state', () => {
it('reports the verdict of a done row: failed, interrupted, or an old host legacy flag', () => {
expect(agentDotState(row({ state: 'done', interrupted: true }), 0)).toBe('interrupted')
expect(agentDotState(row({ state: 'done', ...mainAgentDone('failure') }), 0)).toBe('failed')
expect(
agentDotState(row({ state: 'done', ...mainAgentDone('cancellation'), interrupted: true }), 0)
).toBe('interrupted')
expect(agentDotState(row({ state: 'done', ...mainAgentDone('success') }), 0)).toBe('done')
})

it('shows a main agent that failed while its subagents still run as failed', () => {
expect(agentDotState(row({ state: 'working', ...mainAgentDone('failure') }), 0)).toBe('failed')
expect(agentDotState(row({ state: 'waiting', ...mainAgentDone('failure') }), 0)).toBe('failed')
// Only a failure outranks live work; a success or a stop with live subagents reads working.
expect(agentDotState(row({ state: 'working', ...mainAgentDone('success') }), 0)).toBe('working')
expect(
agentDotState(
row({ state: 'working', ...mainAgentDone('cancellation'), interrupted: true }),
0
)
).toBe('working')
})

// The shared accessor cannot be imported by app code here, so this mirror must not drift from it.
it('agrees with the desktop verdict accessor on every row', () => {
const states = ['working', 'blocked', 'waiting', 'done'] as const
const mainAgents = [
undefined,
...states.flatMap((state) =>
[undefined, ...AGENT_JOURNAL_TURN_OUTCOMES].map((outcome) => ({
state,
...(outcome ? { outcome } : {}),
stateStartedAt: 0
}))
)
]
for (const state of states) {
for (const mainAgent of mainAgents) {
for (const interrupted of [false, true]) {
const agentRow = { state, interrupted, ...(mainAgent ? { mainAgent } : {}) }
expect(agentRowVerdict(agentRow), JSON.stringify(agentRow)).toBe(
agentMainAgentVerdict(agentRow)
)
expect(agentRowVerdictMark(agentRow), JSON.stringify(agentRow)).toBe(
agentVerdictDisplayMark(agentRow)
)
}
}
}
})

it('decays a stale active state to idle, matching desktop', () => {
Expand All @@ -51,14 +110,36 @@ describe('agentDotState', () => {
expect(
agentDotState(row({ state: 'working', updatedAt: 0 }), AGENT_STATUS_STALE_AFTER_MS)
).toBe('working')
// 'done' never decays; interrupted still wins.
// 'done' never decays, and neither does its verdict.
expect(agentDotState(row({ state: 'done', updatedAt: 0 }), stale)).toBe('done')
expect(agentDotState(row({ state: 'working', updatedAt: 0, interrupted: true }), stale)).toBe(
expect(agentDotState(row({ state: 'done', updatedAt: 0, interrupted: true }), stale)).toBe(
'interrupted'
)
})
})

describe('agentRowTimeAt', () => {
it('dates a main agent that failed while its subagents run by its own failure', () => {
expect(
agentRowTimeAt(
row({ state: 'working', stateStartedAt: 100, ...mainAgentDone('failure', 900) })
)
).toBe(900)
})

it('dates every other row by when its state began', () => {
expect(
agentRowTimeAt(
row({ state: 'working', stateStartedAt: 100, ...mainAgentDone('success', 900) })
)
).toBe(100)
expect(
agentRowTimeAt(row({ state: 'done', stateStartedAt: 100, ...mainAgentDone('failure', 900) }))
).toBe(100)
expect(agentRowTimeAt(row({ state: 'working', stateStartedAt: 100 }))).toBe(100)
})
})

describe('agentDisplayLabel', () => {
it('prefers last message, then prompt, then state label', () => {
expect(agentDisplayLabel(row({ lastAssistantMessage: 'hello there' }), 0)).toBe('hello there')
Expand Down
46 changes: 43 additions & 3 deletions mobile/src/worktree/agent-row-display.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'
import type { AgentJournalTurnOutcome } from '../../../src/shared/agent-turn-outcome'

// Mirrors the desktop AGENT_STATUS_STALE_AFTER_MS (src/shared/agent-status-types.ts:
// 30 min). Defined locally rather than imported because a runtime-value import
Expand All @@ -17,13 +18,39 @@ export type AgentDotState =
| 'done'
| 'idle'
| 'interrupted'
| 'failed'

type AgentRowVerdictSource = Pick<RuntimeWorktreeAgentRow, 'state' | 'interrupted' | 'mainAgent'>

// Mirrors desktop agentMainAgentVerdict and agentVerdictDisplayMark
// (src/shared/agent-main-agent-verdict.ts); a parity test runs both over one table. `mainAgent` is
// the main agent's own status, sent also while subagents hold the row working; an old host sends none.
export function agentRowVerdict(row: AgentRowVerdictSource): AgentJournalTurnOutcome | null {
if (row.mainAgent && row.mainAgent.state !== 'done') {
return null
}
return row.mainAgent?.outcome ?? (row.state === 'done' && row.interrupted ? 'cancellation' : null)
}

// A failure outranks every state; a stop marks only a row that is itself done.
export function agentRowVerdictMark(row: AgentRowVerdictSource): 'failed' | 'interrupted' | null {
const verdict = agentRowVerdict(row)
if (verdict === 'failure') {
return 'failed'
}
return verdict === 'cancellation' && row.state === 'done' ? 'interrupted' : null
}

export function agentDotState(
row: Pick<RuntimeWorktreeAgentRow, 'state' | 'workingMode' | 'interrupted' | 'updatedAt'>,
row: Pick<
RuntimeWorktreeAgentRow,
'state' | 'workingMode' | 'interrupted' | 'mainAgent' | 'updatedAt'
>,
now: number
): AgentDotState {
if (row.interrupted) {
return 'interrupted'
const mark = agentRowVerdictMark(row)
if (mark) {
return mark
}
switch (row.state) {
case 'blocked':
Expand Down Expand Up @@ -56,6 +83,8 @@ export function agentStateLabel(state: AgentDotState): string {
return 'Waiting for input'
case 'interrupted':
return 'Interrupted'
case 'failed':
return 'Failed'
case 'done':
return 'Done'
case 'idle':
Expand Down Expand Up @@ -99,6 +128,17 @@ export function agentIdentityLabel(agentType: string | null): string {
return known[normalized] ?? normalized.slice(0, 2).toUpperCase()
}

// When the row's state began, except that a main agent that failed while its subagents run is
// dated by its own failure. Mirrors desktop lastEnteredDoneAt (agent-finished-timestamp.ts).
export function agentRowTimeAt(
row: Pick<RuntimeWorktreeAgentRow, 'state' | 'interrupted' | 'mainAgent' | 'stateStartedAt'>
): number {
if (row.state !== 'done' && row.mainAgent && agentRowVerdictMark(row) === 'failed') {
return row.mainAgent.stateStartedAt
}
return row.stateStartedAt
}

// Relative time, matching desktop formatTimeAgo thresholds (just now / Xm / Xh / Xd).
export function formatTimeAgo(ts: number, now: number): string {
const delta = now - ts
Expand Down
32 changes: 32 additions & 0 deletions mobile/src/worktree/worktree-list-snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ function agent(overrides: Partial<RuntimeWorktreeAgentRow> = {}): RuntimeWorktre
}
}

function done(
outcome: 'success' | 'failure',
stateStartedAt = 1
): NonNullable<RuntimeWorktreeAgentRow['mainAgent']> {
return { state: 'done', outcome, stateStartedAt }
}

function worktree(overrides: Partial<Worktree> = {}): Worktree {
const worktreePath = join('/tmp', 'orca', 'worktrees', 'manta')
return {
Expand Down Expand Up @@ -160,6 +167,31 @@ describe('areWorktreeListsEqual', () => {
expect(areWorktreeListsEqual(first, second)).toBe(false)
})

it('detects a verdict change that leaves the interrupted flag as it was', () => {
const first = [worktree({ agents: [agent({ state: 'done', mainAgent: done('success') })] })]
const second = [worktree({ agents: [agent({ state: 'done', mainAgent: done('failure') })] })]

expect(areWorktreeListsEqual(first, second)).toBe(false)
})

it('detects a main agent failing while its subagents keep the row working', () => {
const first = [worktree({ agents: [agent({ state: 'working' })] })]
const second = [worktree({ agents: [agent({ state: 'working', mainAgent: done('failure') })] })]

expect(areWorktreeListsEqual(first, second)).toBe(false)
})

it('detects the main agent clock moving, which dates a failure', () => {
const at = (stateStartedAt: number) => [
worktree({
agents: [agent({ state: 'working', mainAgent: done('failure', stateStartedAt) })]
})
]

expect(areWorktreeListsEqual(at(1), at(2))).toBe(false)
expect(areWorktreeListsEqual(at(1), at(1))).toBe(true)
})

it('detects monitoring mode changes within working', () => {
const first = [worktree({ agents: [agent({ state: 'working' })] })]
const second = [worktree({ agents: [agent({ state: 'working', workingMode: 'monitoring' })] })]
Expand Down
18 changes: 18 additions & 0 deletions mobile/src/worktree/worktree-list-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function areAgentRowsEqual(
a.toolName !== b.toolName ||
a.toolInput !== b.toolInput ||
a.interrupted !== b.interrupted ||
!areMainAgentsEqual(a.mainAgent, b.mainAgent) ||
a.stateStartedAt !== b.stateStartedAt ||
a.updatedAt !== b.updatedAt
) {
Expand All @@ -118,3 +119,20 @@ function areAgentRowsEqual(
}
return true
}

function areMainAgentsEqual(
left: RuntimeWorktreeAgentRow['mainAgent'],
right: RuntimeWorktreeAgentRow['mainAgent']
): boolean {
if (left === right) {
return true
}
if (!left || !right) {
return false
}
return (
left.state === right.state &&
left.outcome === right.outcome &&
left.stateStartedAt === right.stateStartedAt
)
}
Loading
Loading