Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions docs/users/features/goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Each turn the session takes on its own reports what the Goal has spent so far, h

A long Goal periodically compresses the evidence it has recorded into checkpoint claims with a side model check, so later turns and the verifier still have it to cite. The check is bounded by [`model.goalCheckpointTimeoutSeconds`](../configuration/settings.md), 180 seconds by default. If its claims overrun the aggregate byte budget, or include a claim over the per-claim character limit, it makes one corrective model call and both calls share that ceiling. A check that does not finish in time is abandoned as inconclusive; it counts toward the checkpoint stall limit only when the evidence window has overflowed, while a non-overflowing check preserves the streak and retries on a later turn. The calls are streamed, so the per-request transport timeout bounds only connect and first response, and the ceiling itself stops at the stream guards' 15-minute lifetime cap because past that the guard, not the setting, ends the check. That 15-minute limit on the setting is fixed, and raising the stream guard's own cap does not lift it.

A failing checkpoint shows up before it stops the Goal. While a stall streak runs, the footer pill switches to `checkpoint N/3 stalled` on its own, and the web shell's Goal status strip shows the same count. Whenever a Goal status card is rendered, for example by `/goal` or by a pause, resume or verifier card, it shows how many consecutive checks have stalled out of the three the Goal allows together with the last failure; the web shell's Goals dialog shows the same line, and the model sees both fields when it reads the Goal. A check that fails while the window still has room is shown too, without spending a stall, but only while the Goal is active, and a completed Goal shows no checkpoint line. The failure is kept as a single line with control characters removed. A Goal stopped by three stalled checkpoints names what the last one ran into. A check that could not fit the window within the checkpoint claim bounds, whether a full claim list that still left evidence behind or claims over the size budget, means the objective produces more evidence than one window holds, so narrow it. An answer that could not be folded into claims means the checkpoint model is not returning the structured output it is asked for, and narrowing the objective does not fix that. A check that never answered can mean an unreachable or rate-limited provider, a check that did not finish within `model.goalCheckpointTimeoutSeconds`, or an error in the check itself; the recorded failure says which. Resuming after any of the three starts a fresh evidence window.

## Interrupting a Goal

Cancelling a Goal turn pauses the Goal. Press Esc while the model is answering or while its tools are still running, and the turn stops, the Goal moves to `paused`, and the card and `/goal` both say why it stopped. Nothing continues until you run `/goal resume`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { describe, expect, it } from 'vitest';
import { GOAL_CHECKPOINT_STALL_LIMIT } from '@qwen-code/qwen-code-core';
import { GOAL_CHECKPOINT_STALL_LIMIT as SDK_GOAL_CHECKPOINT_STALL_LIMIT } from '@qwen-code/sdk/daemon';

// The Web Shell renders the checkpoint stall streak against the SDK's
// hand-duplicated copy of this limit, while the runtime stops a Goal at
// Core's. The SDK has no dependency path to Core, so pin the two copies here,
// where both packages are importable: a drift would show users the wrong N/3
// rather than fail a build.
describe('goal checkpoint stall limit wire contract', () => {
it('is identical across core and the SDK', () => {
expect(SDK_GOAL_CHECKPOINT_STALL_LIMIT).toBe(GOAL_CHECKPOINT_STALL_LIMIT);
});
});
34 changes: 34 additions & 0 deletions packages/cli/src/ui/components/GoalPill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,40 @@ describe('GoalPill', () => {
unmount();
});

it('warns about stalled checkpoints before the stall breaker stops the Goal', () => {
vi.setSystemTime(NOW);
const { lastFrame, unmount } = renderPill({
snapshot: snapshot('active', 'running', {
checkpointStalls: 2,
lastCheckpointFailure: 'Error: provider failed',
}),
});

expect(lastFrame()).toContain('! /goal checkpoint 2/3 stalled');
// The footer has no room for the failure itself; the status card has it.
expect(lastFrame()).not.toContain('provider failed');
unmount();
});

it('keeps the plain labels when no checkpoint has stalled', () => {
vi.setSystemTime(NOW);
// A failure on a window with room spends no stall and is the card's to
// show; the footer stays quiet until the streak starts.
const quiet = renderPill({
snapshot: snapshot('active', 'running', {
lastCheckpointFailure: 'Error: provider failed',
}),
});
expect(quiet.lastFrame()).toContain('/goal active');
quiet.unmount();

const checking = renderPill({
snapshot: snapshot('active', 'verifying', { checkpointStalls: 1 }),
});
expect(checking.lastFrame()).toContain('/goal checking');
checking.unmount();
});

it('adds the current active span to persisted active time', () => {
vi.setSystemTime(NOW);
const { lastFrame, unmount } = renderPill({
Expand Down
30 changes: 22 additions & 8 deletions packages/cli/src/ui/components/GoalPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { useEffect, useState } from 'react';
import { Text } from 'ink';
import { elapsedActiveTime } from '@qwen-code/qwen-code-core/goals/goal-reducer.js';
import type { Config } from '@qwen-code/qwen-code-core/config/config.js';
import type { GoalSnapshotV2 } from '@qwen-code/qwen-code-core/goals/goal-protocol.js';
import {
GOAL_CHECKPOINT_STALL_LIMIT,
type GoalSnapshotV2,
} from '@qwen-code/qwen-code-core/goals/goal-protocol.js';
import type { GoalRuntime } from '@qwen-code/qwen-code-core/goals/goal-runtime.js';
import { useConfig } from '../contexts/ConfigContext.js';
import { theme } from '../semantic-colors.js';
Expand Down Expand Up @@ -98,13 +101,24 @@ function presentation(snapshot: GoalSnapshotV2): {
if (!goal || goal.status === 'complete') return null;

if (goal.status === 'active') {
return snapshot.activity === 'verifying'
? {
icon: ICON.CIRCLE_EMPTY,
label: 'checking',
color: theme.text.secondary,
}
: { icon: ICON.BULLSEYE, label: 'active', color: theme.text.accent };
if (snapshot.activity === 'verifying') {
return {
icon: ICON.CIRCLE_EMPTY,
label: 'checking',
color: theme.text.secondary,
};
}
// A Goal paying a failed checkpoint every turn otherwise looks exactly
// like one that is working, until the stall breaker stops it.
const stalls = goal.checkpointStalls ?? 0;
if (stalls > 0) {
return {
icon: '!',
label: `checkpoint ${stalls}/${GOAL_CHECKPOINT_STALL_LIMIT} stalled`,
color: theme.status.warning,
};
}
return { icon: ICON.BULLSEYE, label: 'active', color: theme.text.accent };
}
switch (goal.status) {
case 'paused':
Expand Down
108 changes: 108 additions & 0 deletions packages/cli/src/ui/components/messages/GoalStatusMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,114 @@ describe('<GoalStatusMessage />', () => {
expect(lastFrame()).not.toContain('tokens');
});

it('shows stalled checkpoints and the last failure on an active card', () => {
const { lastFrame } = render(
<GoalStatusMessage
snapshot={snapshot('active', 'running', undefined, {
checkpointStalls: 2,
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);

expect(lastFrame()).toContain(
'Checkpoint: 2/3 stalled · Error: provider failed',
);
});

it('shows a checkpoint failure that spent no stall', () => {
const { lastFrame } = render(
<GoalStatusMessage
snapshot={snapshot('active', 'running', undefined, {
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);

expect(lastFrame()).toContain(
'Checkpoint: last check failed · Error: provider failed',
);
});

it('keeps the failure on the card of a Goal the stall breaker stopped', () => {
// The stop reason names the kind of failure; only this line says which.
const { lastFrame } = render(
<GoalStatusMessage
snapshot={snapshot('usage_limited', 'idle', 'checkpoints stalled', {
checkpointStalls: 3,
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);

expect(lastFrame()).toContain('Reason: checkpoints stalled');
expect(lastFrame()).toContain(
'Checkpoint: 3/3 stalled · Error: provider failed',
);
});

it('hides checkpoint health on a completed Goal that still carries it', () => {
// The terminal snapshot spreads the record and overrides only `status`,
// so a Goal that completed after a failed check journals both fields.
const { lastFrame } = render(
<GoalStatusMessage
snapshot={snapshot('complete', 'idle', 'all acceptance checks passed', {
checkpointStalls: 1,
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);

expect(lastFrame()).toContain('Goal complete');
expect(lastFrame()).not.toContain('Checkpoint');
});

it('hides a stall-free failure once the Goal stops for another reason', () => {
const paused = render(
<GoalStatusMessage
snapshot={snapshot('paused', 'idle', 'no progress in three turns', {
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);
expect(paused.lastFrame()).not.toContain('Checkpoint');

// A running streak is still the truth about the window a resume re-enters.
const streak = render(
<GoalStatusMessage
snapshot={snapshot('paused', 'idle', 'paused by the user', {
checkpointStalls: 2,
lastCheckpointFailure: 'Error: provider failed',
})}
/>,
);
expect(streak.lastFrame()).toContain('Checkpoint: 2/3 stalled');
});

it('never writes control or bidi characters from the diagnostic to the terminal', () => {
const { lastFrame } = render(
<GoalStatusMessage
snapshot={snapshot('active', 'running', undefined, {
checkpointStalls: 1,
lastCheckpointFailure: 'stalled\rGoal complete \u202efailed',
})}
/>,
);

const frame = lastFrame() ?? '';
expect(frame).toContain('Checkpoint: 1/3 stalled');
expect(frame).not.toContain('\r');
expect(frame).not.toContain('\u202e');
});

it('says nothing about checkpoints on a healthy card', () => {
const { lastFrame } = render(
<GoalStatusMessage snapshot={snapshot('active', 'running')} />,
);

expect(lastFrame()).not.toContain('Checkpoint');
});

it('leaves the legacy card without spend it cannot know', () => {
// The legacy props carry an iteration count and nothing else; there is no
// record behind them to read a spend off.
Expand Down
34 changes: 33 additions & 1 deletion packages/cli/src/ui/components/messages/GoalStatusMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

import React from 'react';
import { Box, Text } from 'ink';
import type { GoalSnapshotV2, GoalStateCause } from '@qwen-code/qwen-code-core';
import {
GOAL_CHECKPOINT_STALL_LIMIT,
goalCheckpointHealthVisible,
type GoalSnapshotV2,
type GoalStateCause,
} from '@qwen-code/qwen-code-core';
import { theme } from '../../semantic-colors.js';
import { sanitizeTerminalText } from '../../utils/textUtils.js';
import { ICON } from '../../constants.js';
import { formatDuration } from '../../utils/formatters.js';
import { formatTokenCount } from '../../statusLinePresets.js';
Expand Down Expand Up @@ -127,6 +133,27 @@ const GoalStateCard: React.FC<GoalStateMessageProps> = ({
goal.status !== 'active' || snapshot.activity === 'verifying'
? goal.lastReason?.trim()
: undefined;
// Checkpoint health, shown before the stall breaker has to stop the Goal:
// a Goal paying a failed checkpoint every turn otherwise looks like one
// that is working. A Goal the breaker stopped keeps the line, since its stop
// reason names the kind of failure but not the failure itself; which
// records show it at all is decided once, in goalCheckpointHealthVisible.
// The diagnostic is cleaned where it is written and again here, because
// this renderer writes straight to the terminal.
const stalls = goal.checkpointStalls ?? 0;
const checkpointFailure = sanitizeTerminalText(
goal.lastCheckpointFailure ?? '',
).trim();
const checkpoint = goalCheckpointHealthVisible(goal)
? [
stalls > 0
? `${stalls}/${GOAL_CHECKPOINT_STALL_LIMIT} stalled`
: 'last check failed',
checkpointFailure,
]
.filter(Boolean)
.join(' · ')
Comment thread
qqqys marked this conversation as resolved.
Resolved
: undefined;

return (
<Box flexDirection="row">
Expand All @@ -153,6 +180,11 @@ const GoalStateCard: React.FC<GoalStateMessageProps> = ({
Reason: {reason}
</Text>
) : null}
{checkpoint ? (
<Text color={theme.status.warning} wrap="wrap">
Checkpoint: {checkpoint}
Comment thread
qqqys marked this conversation as resolved.
Resolved
</Text>
) : null}
</Box>
</Box>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/ui/opentui/event-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ export type GoalSnapshotLike = {
activeTimeMs?: number;
tokensUsed?: number;
tokenBudget?: number;
checkpointStalls?: number;
lastCheckpointFailure?: string;
lastReason?: string;
} | null;
activity?: string;
Expand Down
53 changes: 53 additions & 0 deletions packages/cli/src/ui/opentui/live-session-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,59 @@ describe('describeGoalCard (ink GoalStateCard)', () => {
});
});

it('shows checkpoint health, matching the ink card', () => {
expect(
describeGoalCard(
snap({
objective: 'o',
status: 'active',
checkpointStalls: 2,
lastCheckpointFailure: 'Error: provider failed',
}),
),
).toMatchObject({
checkpoint: 'Checkpoint: 2/3 stalled · Error: provider failed',
});
expect(
describeGoalCard(
snap({
objective: 'o',
status: 'active',
lastCheckpointFailure: 'Error: provider failed',
}),
),
).toMatchObject({
checkpoint: 'Checkpoint: last check failed · Error: provider failed',
});
const healthy = describeGoalCard(
snap({ objective: 'o', status: 'active' }),
);
expect(healthy).toMatchObject({ state: 'card' });
expect(healthy).not.toHaveProperty('checkpoint');

// Same visibility rule as the ink card: never on a completed Goal, and a
// stall-free failure only while the Goal is active.
expect(
describeGoalCard(
snap({
objective: 'o',
status: 'complete',
checkpointStalls: 1,
lastCheckpointFailure: 'Error: provider failed',
}),
),
).not.toHaveProperty('checkpoint');
expect(
describeGoalCard(
snap({
objective: 'o',
status: 'paused',
lastCheckpointFailure: 'Error: provider failed',
}),
),
).not.toHaveProperty('checkpoint');
});

it('builds the subtitle from turns and active time', () => {
expect(
describeGoalCard(
Expand Down
Loading
Loading