Skip to content

Commit 00a69d2

Browse files
committed
Correct model activity timing and cloud work summaries
1 parent 6e62905 commit 00a69d2

26 files changed

Lines changed: 480 additions & 173 deletions

‎cli/src/features/agent-status/activity-rail.test.tsx‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('activity rail', () => {
142142
vi.spyOn(Date, 'now').mockReturnValue(1_400)
143143
const html = renderToStaticMarkup(
144144
<ActivityRail
145-
work={work()}
145+
work={work({ phase: 'waiting_for_model', activeSince: null })}
146146
width={100}
147147
modelLoadActivity={null}
148148
modelRequestActivity={request()}
@@ -157,7 +157,7 @@ describe('activity rail', () => {
157157
vi.spyOn(Date, 'now').mockReturnValue(2_000)
158158
expect(text(
159159
<ActivityRail
160-
work={work()}
160+
work={work({ phase: 'waiting_for_model', activeSince: null })}
161161
width={100}
162162
modelLoadActivity={null}
163163
modelRequestActivity={request({
@@ -216,7 +216,7 @@ describe('activity rail', () => {
216216
vi.restoreAllMocks()
217217
})
218218

219-
it('keeps the timer paused during a model-only wait', () => {
219+
it('shows a generic model wait instead of a frozen Working timer', () => {
220220
vi.spyOn(Date, 'now').mockReturnValue(10_000)
221221
expect(text(
222222
<ActivityRail
@@ -229,7 +229,24 @@ describe('activity rail', () => {
229229
modelLoadActivity={null}
230230
modelRequestActivity={null}
231231
/>,
232-
)).toBe('● Working... 0:03')
232+
)).toBe('⠋ Waiting for model · 0:03 worked')
233+
vi.restoreAllMocks()
234+
})
235+
236+
it('shows a generic model wait without a zero duration before generation starts', () => {
237+
vi.spyOn(Date, 'now').mockReturnValue(10_000)
238+
expect(text(
239+
<ActivityRail
240+
work={work({
241+
phase: 'waiting_for_model',
242+
activeSince: null,
243+
accumulatedMs: 0,
244+
})}
245+
width={100}
246+
modelLoadActivity={null}
247+
modelRequestActivity={null}
248+
/>,
249+
)).toBe('⠋ Waiting for model')
233250
vi.restoreAllMocks()
234251
})
235252

‎cli/src/features/agent-status/activity-rail.tsx‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { useTheme } from '../../hooks/use-theme'
1111
import {
1212
slate,
1313
displayActorWorkElapsedMs,
14-
isDisplayActorWorkActive,
14+
displayActorWorkLiveState,
15+
modelRequestProgressSegments,
1516
type LocalModelLoadActivity,
1617
} from '@magnitudedev/client-common'
1718
import { red } from '../../utils/theme'
1819
import { spinnerFrameForTick } from '../../hooks/use-spinner-frame'
1920
import { useAnimationTick } from '../../hooks/use-animation-tick'
20-
import { modelRequestProgressSegments } from '../chat-timeline/model-request-progress'
2121
import { Button } from '../../components/button'
2222

2323
const WORKING_PULSE_COLORS = [
@@ -69,7 +69,8 @@ export const ActivityRail = memo(function ActivityRail({
6969
}: ActivityRailProps) {
7070
const theme = useTheme()
7171

72-
const active = work !== null && isDisplayActorWorkActive(work)
72+
const liveState = work === null ? 'inactive' : displayActorWorkLiveState(work)
73+
const active = liveState !== 'inactive'
7374
const activity = work?.activity ?? null
7475
const hasSpinner = activity?.kind === 'tool' && Option.getOrNull(activity.decorator) === 'spinner'
7576
const hasActivity = activity !== null
@@ -160,6 +161,22 @@ export const ActivityRail = memo(function ActivityRail({
160161
)
161162
}
162163

164+
if (liveState === 'waiting_for_model' && work !== null) {
165+
const worked = work.accumulatedMs > 0
166+
? ` · ${formatElapsed(Math.floor(work.accumulatedMs / 1000))} worked`
167+
: ''
168+
return (
169+
<box style={{ height: 1, flexShrink: 0 }}>
170+
<text>
171+
<span style={{ fg: theme.primary }}>{loadingSpinner}</span>
172+
{' '}
173+
<span style={{ fg: theme.foreground }}>Waiting for model</span>
174+
{worked && <span style={{ fg: theme.muted }}>{worked}</span>}
175+
</text>
176+
</box>
177+
)
178+
}
179+
163180
// Active: show running timer
164181
if (active && work !== null) {
165182
const responseElapsedMs = displayActorWorkElapsedMs(work, Date.now())

‎cli/src/features/chat-timeline/message-view.test.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,40 @@ describe('work summary message', () => {
4040
expect(html).toContain('Worked for 1:05')
4141
})
4242

43+
it('avoids showing zero seconds for sub-second work', () => {
44+
const html = renderToStaticMarkup(
45+
<MessageView message={summary(999)} isStreaming={false} />,
46+
)
47+
48+
expect(html).toContain('Worked for &lt;1 second')
49+
expect(html).not.toContain('Worked for 0 seconds')
50+
})
51+
4352
it('renders native model throughput with the standard separator', () => {
4453
const message: DisplayMessage = {
4554
...summary(6_000),
4655
performance: Option.some({
4756
modelDisplayName: 'Qwen3 Coder',
48-
decodeTokensPerSecond: 20.46,
57+
decodeTokensPerSecond: Option.some(20.46),
4958
}),
5059
}
5160
const html = renderToStaticMarkup(<MessageView message={message} isStreaming={false} />)
5261

5362
expect(html).toContain('Qwen3 Coder worked for 6 seconds · 20.5 tok/s')
5463
expect(html).not.toContain('ttft')
5564
})
65+
66+
it('renders the cloud model name without unavailable throughput', () => {
67+
const message: DisplayMessage = {
68+
...summary(1_000),
69+
performance: Option.some({
70+
modelDisplayName: 'DeepSeek V4 Flash',
71+
decodeTokensPerSecond: Option.none(),
72+
}),
73+
}
74+
const html = renderToStaticMarkup(<MessageView message={message} isStreaming={false} />)
75+
76+
expect(html).toContain('DeepSeek V4 Flash worked for 1 second')
77+
expect(html).not.toContain('tok/s')
78+
})
5679
})

‎cli/src/features/chat-timeline/message-view.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const StatusIndicatorRow = ({ message }: { message: Extract<DisplayMessage, { ty
4949
}
5050

5151
function formatWorkDuration(durationMs: number): string {
52+
if (durationMs < 1_000) return '<1 second'
5253
const totalSeconds = Math.floor(durationMs / 1000)
5354
if (totalSeconds < 60) return `${totalSeconds} second${totalSeconds === 1 ? '' : 's'}`
5455
const minutes = Math.floor(totalSeconds / 60)
@@ -63,7 +64,10 @@ const WorkSummaryRow = ({ message }: { message: Extract<DisplayMessage, { type:
6364
onNone: () => `Worked for ${formatWorkDuration(message.durationMs)}`,
6465
onSome: (performance) =>
6566
`${performance.modelDisplayName} worked for ${formatWorkDuration(message.durationMs)}`
66-
+ ` · ${performance.decodeTokensPerSecond.toFixed(1)} tok/s`,
67+
+ Option.match(performance.decodeTokensPerSecond, {
68+
onNone: () => '',
69+
onSome: (tokensPerSecond) => ` · ${tokensPerSecond.toFixed(1)} tok/s`,
70+
}),
6771
})
6872
return (
6973
<box style={{ height: 1, flexShrink: 0, marginBottom: 1 }}>

‎design/acn/activity-and-session-residency.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ applies_to:
3434
- packages/agent/src/process/detached-process-registry-live.ts
3535
- packages/agent/src/process/detached-process-registry.ts
3636
- packages/agent/src/projections/compaction.ts
37+
- packages/agent/src/projections/agent-lifecycle.ts
38+
- packages/agent/src/display-view/semantic.ts
39+
- packages/client-common/src/utils/actor-work.ts
40+
- packages/client-common/src/utils/model-request-progress.ts
3741
- packages/agent/tests/session-work-status.test.ts
3842
- cli/src/**
3943
- desktop/src/**
@@ -267,6 +271,26 @@ while that interval is open. Transient request progress controls loading and pre
267271
owns, reconstructs, or adjusts the work timer. This keeps live and replayed completed timing
268272
identical even when a chain crosses several model requests.
269273

274+
Completed root turns attribute the selected model display name independently from optional native
275+
decode telemetry. Work summaries therefore identify both local and cloud models. A summary includes
276+
decode tokens per second only when every contributing request in the chain supplied a valid native
277+
measurement; clients never estimate missing cloud throughput.
278+
279+
Clients distinguish an active root chain from an open productive interval. Authoritative model
280+
loading and request progress takes precedence when present. When a root is waiting for a provider
281+
that exposes no granular request progress and no worker keeps the productive interval open, clients
282+
show a generic model-wait state rather than presenting the paused accumulated duration as a running
283+
Working timer. Providers do not receive synthetic progress for presentation purposes.
284+
285+
Thinking activity follows the semantic response lifecycle. Thinking start opens the activity,
286+
thinking chunks refine its copy, and thinking end closes it immediately unless another
287+
independently active derived activity takes precedence. Assistant-message start and streamed answer
288+
text also close stale or interleaved thinking activity, so the live rail never claims the model is
289+
thinking while it is actively emitting its answer. The lifecycle projection stores only the
290+
authoritative response and tool lifecycle fields; display activity is derived from those fields at
291+
the display-view boundary rather than retained as a second synchronized copy. Clients never infer
292+
or retain thinking state from rendered text.
293+
270294
Closing the final subscription removes the display registration. There is no separate close RPC.
271295

272296
## Subscription protocol

‎packages/acn-protocol/src/schemas/display.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export type StatusIndicatorMessage = Schema.Schema.Type<typeof StatusIndicatorMe
9191

9292
export const WorkSummaryPerformance = Schema.Struct({
9393
modelDisplayName: Schema.String,
94-
decodeTokensPerSecond: Schema.Number.pipe(Schema.finite(), Schema.nonNegative()),
94+
decodeTokensPerSecond: Schema.optionalWith(
95+
Schema.Number.pipe(Schema.finite(), Schema.nonNegative()),
96+
{ as: 'Option', exact: true },
97+
),
9598
})
9699
export type WorkSummaryPerformance = Schema.Schema.Type<typeof WorkSummaryPerformance>
97100

‎packages/acn/src/agent-runtime.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const idleAgentStatus: AgentLifecycleState = {
5555
accumulatedWorkMs: 0,
5656
workingStartedAt: null,
5757
lastChainMs: 0,
58-
activity: null,
5958
activeChildCount: 0,
6059
_currentTurnId: null,
6160
_currentChainId: null,

‎packages/acn/src/display-view-streams.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const idleAgents: AgentLifecycleState = {
5353
accumulatedWorkMs: 0,
5454
workingStartedAt: null,
5555
lastChainMs: 0,
56-
activity: null,
5756
activeChildCount: 0,
5857
_currentTurnId: null,
5958
_currentChainId: null,

‎packages/acn/src/session-commands.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const idleAgentStatus: AgentLifecycleState = {
2828
accumulatedWorkMs: 0,
2929
workingStartedAt: null,
3030
lastChainMs: 0,
31-
activity: null,
3231
activeChildCount: 0,
3332
_currentTurnId: null,
3433
_currentChainId: null,

‎packages/agent/src/display-view/semantic.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type TaskDisplayRow,
1111
} from '@magnitudedev/acn-protocol'
1212
import { DEFAULT_CHAT_NAME } from '../constants'
13-
import type { AgentLifecycleState, AgentInfo } from '../projections/agent-lifecycle'
13+
import { rootWorkActivity, type AgentLifecycleState, type AgentInfo } from '../projections/agent-lifecycle'
1414
import type { TaskAssignmentRow, TaskAssignmentState, WorkerActivity } from '../projections/task-assignment'
1515

1616
function titleCase(value: string): string {
@@ -37,7 +37,7 @@ const materializeRootWork = (
3737
lastWorkMs: rootWork.lastChainMs,
3838
accumulatedMs: rootWork.accumulatedWorkMs,
3939
resumeCount: 0,
40-
activity: rootWork.activity,
40+
activity: rootWorkActivity(rootWork),
4141
activeChildCount: rootWork.activeChildCount,
4242
})
4343

0 commit comments

Comments
 (0)