Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4cf4e38
fix(native-chat): a usage limit reads as a pause with its reset time …
brennanb2025 Oct 18, 2026
16dc2c1
fix(native-chat): keep the failure words and chat session files withi…
brennanb2025 Oct 18, 2026
71e91e3
fix(native-chat): drop a check the shown branch already rules out
brennanb2025 Oct 18, 2026
3d4e2b7
fix(i18n): ship the usage-limit failure words in the runtime catalog
brennanb2025 Oct 18, 2026
adb3b92
fix(native-chat): reconcile usage failures by owning turn and typed c…
brennanb2025 Oct 18, 2026
22af333
fix(codex): keep snapshot import type-only
brennanb2025 Oct 18, 2026
31b4d34
fix(claude): open refusal turns without opening empty placeholders
brennanb2025 Oct 18, 2026
a6fef63
fix(native-chat): bind usage Continue to the latest idle failed turn
brennanb2025 Oct 18, 2026
9ec8a6b
test(native-chat): isolate stale Continue from ordinary delivery prog…
brennanb2025 Oct 18, 2026
b9fd04f
test(native-chat): use a braced journal assertion
brennanb2025 Oct 18, 2026
d94f5af
test(native-chat): build failure rows through their word factory
brennanb2025 Oct 18, 2026
b3a760d
fix(claude): retain terminal failure evidence through result reconcil…
brennanb2025 Oct 18, 2026
1262d01
fix(native-chat): complete usage Continue through the composer sender
brennanb2025 Oct 18, 2026
c975f76
test(native-chat): provide the composer options surface in Continue c…
brennanb2025 Oct 18, 2026
78d44f4
test(native-chat): use typed failure words in renderer fixtures
brennanb2025 Oct 18, 2026
ef15a0c
test(native-chat): match the remote send payload apart from transport…
brennanb2025 Oct 18, 2026
d02e69a
fix(native-chat): replace the previous sender notice on Continue
brennanb2025 Oct 18, 2026
9f01f02
fix(native-chat): clear superseded Continue notices before rendering
brennanb2025 Oct 18, 2026
1598940
fix(native-chat): preserve ordinary composer send arguments
brennanb2025 Oct 18, 2026
502950e
fix(claude): resolve terminal ownership and preserve resultless quota…
brennanb2025 Oct 18, 2026
1a35fa1
fix(claude): keep repeated terminal detail unchanged and complete tes…
brennanb2025 Oct 18, 2026
b6a0073
fix(claude): resolve deferred terminal replays after owning journal w…
brennanb2025 Oct 18, 2026
5dd0972
refactor(native-chat): share tombstone append within the sink line bu…
brennanb2025 Oct 18, 2026
aab312e
fix(claude): retain both input and echo correlation on the live turn
brennanb2025 Oct 18, 2026
aebb7ec
fix(claude): preserve unowned result completion after terminal resolu…
brennanb2025 Oct 18, 2026
8f69aa7
fix(claude): allow unassociated successful goal completion
brennanb2025 Oct 18, 2026
edda625
fix(claude): keep terminal completion on the live turn
brennanb2025 Oct 19, 2026
ab64f1e
fix(claude): keep typed notices separate from quota failures
brennanb2025 Oct 19, 2026
08d519d
fix(claude): preserve context-limit failures as ordinary errors
brennanb2025 Oct 19, 2026
a2b8396
fix(native-chat): keep quota failures visible in collapsed turns
brennanb2025 Oct 19, 2026
3a38c84
fix(native-chat): return keyboard Continue focus to the composer
brennanb2025 Oct 19, 2026
887ec1e
test(native-chat): keep quota fixture context stable
brennanb2025 Oct 19, 2026
f7ab34c
test(native-chat): hoist quota context to module scope
brennanb2025 Oct 19, 2026
f986e0d
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-usa…
brennanb2025 Oct 19, 2026
ee0da4c
fix(i18n): use one Chinese word for the agent in both Continue tooltips
brennanb2025 Oct 19, 2026
5e33b1f
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-usa…
brennanb2025 Oct 19, 2026
7c2e1be
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-usa…
brennanb2025 Oct 19, 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
6 changes: 4 additions & 2 deletions mobile/src/session/MobileNativeChatNoticeRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type NativeChatNoticeTone
} from '../../../src/shared/native-chat-notice'
import { isTextBlock, type NativeChatBlock } from '../../../src/shared/native-chat-types'
import { usageLimitLineText } from '../../../src/shared/agent-session-usage-limit-words'
import { MobileMarkdown } from '../components/MobileMarkdown'
import { INLINE_TEXT_SELECTION } from '../components/inline-text-selection'
import { colors, radii, spacing, typography } from '../theme/mobile-theme'
Expand Down Expand Up @@ -97,6 +98,7 @@ export function MobileNativeChatNoticeRow({
</Text>
)
case 'line': {
const lineText = usageLimitLineText(notice)
const textStyle = [
styles.line,
scaledType(TEXT_SIZE, fontScale),
Expand All @@ -105,7 +107,7 @@ export function MobileNativeChatNoticeRow({
if (!look.tone) {
return (
<Text selectable={INLINE_TEXT_SELECTION} style={textStyle}>
{notice.text}
{lineText}
</Text>
)
}
Expand All @@ -120,7 +122,7 @@ export function MobileNativeChatNoticeRow({
style={styles.toneIcon}
/>
<Text selectable={INLINE_TEXT_SELECTION} style={[...textStyle, styles.toneText]}>
{notice.text}
{lineText}
</Text>
</View>
)
Expand Down
5 changes: 1 addition & 4 deletions src/main/acp/acp-dialects/grok-dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,5 @@ export const GROK_ACP_DIALECT: AcpDialect = {
contextWindow,
modelEfforts: grokModelEfforts,
promptErrorDetail: (error) => promptErrorDataSchema.safeParse(error.data).data?.message,
failedTurnText: (stopReason) =>
stopReason === 'rate_limit'
? 'Grok usage limit reached.'
: 'Grok ended this turn with an error.'
failedTurnText: () => 'Grok ended this turn with an error.'
}
15 changes: 10 additions & 5 deletions src/main/acp/acp-timeline-turn-failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,29 @@ describe('a failed ACP turn says why', () => {
expect(failures.map((failure) => failure.body.text)).toEqual([REASON])
})

it('names a rate-limited turn the provider gave no words for, without inventing a reason', async () => {
it('upgrades an early diagnostic to a usage failure without a later downgrade', async () => {
const f = await openAcpFixtureRig()
const lane = f.lane()
const prompt = lane.openPrompt('c1', 1000)
f.apply(lane.notification('_x.ai/queue/changed', queued(prompt.promptId), 1001))
f.apply(
lane.notification('_x.ai/session_notification', ended(prompt.promptId, 'rate_limit'), 1002)
)
f.apply(lane.notification('_x.ai/session_notification', retryFailed, 1002))
f.apply(lane.notification('_x.ai/session_notification', ended(prompt.promptId, 'rate_limit'), 1003))
f.apply(
lane.notification(
'_x.ai/session/prompt_complete',
promptComplete(prompt.promptId, 'rate_limit', null),
1003
)
)
f.apply(lane.promptFailed('c1', rpcError, 1004))
const failures = statusRows(await f.rig.rows())
expect(failures.map((failure) => failure.body)).toEqual([
{ kind: 'status', tone: 'error', text: 'Grok usage limit reached.' }
{
kind: 'status',
tone: 'warning',
text: 'The agent hit its usage limit. Send a message once it resets to continue.',
failure: { kind: 'usageLimitReached', detail: { text: REASON, audience: 'person' } }
}
])
expect((await f.rig.turns())[0]?.outcome).toBe('failure')
})
Expand Down
38 changes: 22 additions & 16 deletions src/main/acp/acp-turn-failures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export function acpSignInRequiredRefusal(
* reason the row still lacks. */
export class AcpTurnFailures {
/** The reason each failed turn's row holds; '' for none yet. */
private readonly rows = new BoundedMap<string, { text: string; notSignedIn: boolean }>({
private readonly rows = new BoundedMap<
string,
{ text: string; notSignedIn: boolean; usageLimited: boolean }
>({
maxEntries: 128
})

Expand Down Expand Up @@ -93,32 +96,35 @@ export class AcpTurnFailures {
): ProviderTimelineEvent[] {
const written = this.rows.peek(turn)
const detail = text === undefined ? undefined : providerDiagnostic(text, 'person')
if (
written !== undefined &&
(written.text !== '' || !detail) &&
(!notSignedIn || written.notSignedIn)
) {
return []
}
const diagnostic =
detail ?? (written?.text ? providerDiagnostic(written.text, 'person') : undefined)
(written?.text ? providerDiagnostic(written.text, 'person') : undefined) ?? detail
const authenticationRequired = notSignedIn || written?.notSignedIn === true
// A later copy of the reason (the prompt's error answer) names no stop reason of its own.
const usageLimited =
!authenticationRequired && (stopReason === 'rate_limit' || written?.usageLimited === true)
if (written && written.text === (diagnostic?.text ?? '') &&
written.notSignedIn === authenticationRequired && written.usageLimited === usageLimited) {
return []
}
this.rows.set(turn, {
text: diagnostic?.text ?? '',
notSignedIn: authenticationRequired
notSignedIn: authenticationRequired,
usageLimited
})
const failure = authenticationRequired
? agentSessionFailureFact('notSignedIn', { detail: diagnostic })
: usageLimited
? agentSessionFailureFact('usageLimitReached', { detail: diagnostic })
: null
return [
{
type: 'item.update',
item: `turn-failure:${turn}`,
body: {
kind: 'status',
tone: 'error',
...(authenticationRequired
? agentSessionFailureWords(
agentSessionFailureFact('notSignedIn', { detail: diagnostic }),
{ agentName: this.agentName, surface: 'row' }
)
tone: usageLimited ? 'warning' : 'error',
...(failure
? agentSessionFailureWords(failure, { agentName: this.agentName, surface: 'row' })
: {
text:
diagnostic?.text ??
Expand Down
1 change: 1 addition & 0 deletions src/main/claude/claude-command-turn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function harness() {
writes.push(row)
}
const journal: StructuredAgentSessionRevisionJournal = {
item: () => null,
epoch: 'epoch-1',
itemBody: (itemId) => rows.get(itemId)?.body ?? null,
visitItems: (visit) => {
Expand Down
35 changes: 24 additions & 11 deletions src/main/claude/claude-context-usage-test-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import type {
StructuredAgentSessionEventSink,
StructuredAgentSessionRevisionJournal
} from '../native-chat/agent-session-wire/structured-agent-session-event-sink'
import { createJournalReducerState } from '../native-chat/agent-session-journal/journal-reducer'
import { personStopDecidesTurn } from '../native-chat/agent-session-journal/journal-stop-turn-end'
import type { ClaudeContextReportTarget } from './claude-context-facts'
import { createClaudeJournalTranslator } from './claude-structured-journal-translation'
import { claudeTurnLifecycleIdentity } from './claude-turn-lifecycle-item'

/** A journal in miniature: the latest revision per row, its creation clock
* pinned, and revisions resolved against it as a bound sink would. */
export function journal() {
export function journal({ deferred = false } = {}) {
const queued: (() => void)[] = []
const run = (write: () => void): void => {
if (deferred) { queued.push(write) } else { write() }
}
const flush = (): void => { while (queued.length) { queued.shift()!() } }
const clock = { now: 0 }
const appends: { identity: AgentJournalItemIdentity; body: AgentJournalItemBody }[] = []
const rows = new Map<string, AgentJournalRenderItem>()
Expand All @@ -30,11 +37,12 @@ export function journal() {
revision: (existing?.revision ?? 0) + 1,
sequence: existing?.sequence ?? rows.size + 1,
observedAt: existing?.observedAt ?? options?.observedAt ?? clock.now,
body
...options, turnScope: existing?.turnScope ?? options.turnScope, body
})
}
const scans = { count: 0 }
const bound: StructuredAgentSessionRevisionJournal = {
item: (itemId) => rows.get(itemId) ?? null,
epoch: 'test',
visitItems: (visit) => {
scans.count += 1
Expand All @@ -44,19 +52,24 @@ export function journal() {
},
itemBody: (itemId) => rows.get(itemId)?.body ?? null
}
const revise: NonNullable<StructuredAgentSessionEventSink['tryReviseResolvedItem']> = (
const revise: NonNullable<StructuredAgentSessionEventSink['tryReviseResolvedItemAndPublish']> = (
_reservedBytes,
resolve,
options
) => {
const resolved = resolve(bound)
if (resolved) {
appendItem(resolved.identity, resolved.body, options)
}
run(() => {
const resolved = resolve(bound)
if (resolved) { appendItem(resolved.identity, resolved.body, options) }
})
return { accepted: true }
}
const stopState = createJournalReducerState('orca-session', 'test')
const queueStop = (turnId: string, at: number): void => run(() => {
stopState.queuePauseMarks.latestStop = { sequence: rows.size + 1, event: { reason: 'user-stop', turnId, at } }
})
const sink: StructuredAgentSessionEventSink = {
appendItem,
journalStopDecidesTurn: (turnId, at) => personStopDecidesTurn(stopState, turnId, at),
appendItem: (...args) => run(() => appendItem(...args)),
tryReviseResolvedItem: revise,
tryReviseResolvedItemAndPublish: revise,
appendTombstone: () => {},
Expand All @@ -65,7 +78,7 @@ export function journal() {
const turnRow = (turnId: string) =>
rows.get(agentJournalItemKey(claudeTurnLifecycleIdentity('claude-session', turnId)))
const items = () => [...rows.values()].sort((left, right) => left.sequence - right.sequence)
return { sink, clock, appends, rows, turnRow, items, scans }
return { sink, clock, appends, rows, turnRow, items, scans, flush, queueStop }
}

export function frame(message: Record<string, unknown>, observedAt: number, startsTurn = false) {
Expand Down Expand Up @@ -146,8 +159,8 @@ export const turnIdentity = (turnId: string) =>
claudeTurnLifecycleIdentity('claude-session', turnId)

/** Every turn the CLI runs opens with an init naming the main model as `modelUsage` keys it. */
export function setup({ init = 'claude-fable-5-1[1m]' }: { init?: string | null } = {}) {
const state = journal()
export function setup({ init = 'claude-fable-5-1[1m]', deferred = false }: { init?: string | null; deferred?: boolean } = {}) {
const state = journal({ deferred })
const translator = createClaudeJournalTranslator({ sink: state.sink, coalesceMs: 0 })
const requests: ClaudeContextReportTarget[] = []
translator.subscribeContextUsageRequests((target) => requests.push(target))
Expand Down
37 changes: 29 additions & 8 deletions src/main/claude/claude-message-journaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// read off an explicit context, so the open turn and the collaborators it
// writes through stay owned by the translator.

import { writeClaudeTerminalFailure } from './claude-terminal-failure'
import { agentSessionFailureWords } from '../../shared/agent-session-failure-words'
import { agentJournalItemKey } from '../../shared/agent-session-journal-item-key'
import type { StructuredAgentSessionEventSink } from '../native-chat/agent-session-wire/structured-agent-session-event-sink'
import type { ClaudeBackgroundTaskRows } from './claude-background-task-rows'
Expand Down Expand Up @@ -34,6 +36,7 @@ import type { ClaudeSubagentIdentities } from './claude-subagent-identities'
import { claudeTurnOpenedBySendEcho, type ClaudeTurnSource } from './claude-turn-opening'
import type { ClaudeOpenTurn } from './claude-open-turn'
import type { ClaudeAuthenticationFailures } from './claude-authentication-failures'
import type { ClaudeUsageLimits } from './claude-usage-limits'
import type { ClaudeThreadGoal } from './claude-thread-goal'

export type ClaudeMessageJournalContext = {
Expand All @@ -53,6 +56,7 @@ export type ClaudeMessageJournalContext = {
* latch; this module asks it rather than tracking a copy. */
turn: ClaudeOpenTurn
authenticationFailures: ClaudeAuthenticationFailures
usageLimits: ClaudeUsageLimits
threadGoal: ClaudeThreadGoal
}

Expand Down Expand Up @@ -92,28 +96,45 @@ export function journalClaudeMessage(
const stamp = ctx.corrections.stampFor(producerRef)
const outputEnvelope = claudeOutputEnvelope(envelope)
ctx.threadGoal.observe(message)
const source: ClaudeTurnSource = {
sessionId: envelope.sessionId,
uuid: envelope.uuid,
assistant: envelope.role === 'assistant'
}
const openOutputTurn = (): void => ctx.turn.ensureOpen(message, source, observedAt)
const messageBody = claudeMessageBody(outputEnvelope)
const ordinaryFailure = typeof message.api_error === 'string' && message.api_error !== 'usage_limit_reached'
? { kind: 'status' as const, tone: 'error' as const, ...agentSessionFailureWords({ kind: 'providerRejected' }, { agentName: 'Claude', provider: 'claude', surface: 'row' }) } : null
const terminal = envelope.role === 'assistant' && producerRef === null &&
(typeof message.api_error === 'string' || message.error === 'rate_limit')
if (envelope.role === 'assistant' &&
(messageBody || typeof message.api_error === 'string' || message.error === 'rate_limit')) {
openOutputTurn()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const usageLimit = ctx.usageLimits.assistant(message, ctx.turn)
const body =
ctx.authenticationFailures.assistant(message) ??
usageLimit ??
ctx.threadGoal.report(message, claudeMessageIdentity(envelope), observedAt) ??
claudeMessageBody(outputEnvelope)
messageBody ?? ordinaryFailure
const terminalIdentity = terminal && ctx.turn.identity && usageLimit
? ctx.turn.identity : null
const identity =
(body && envelope.role === 'assistant'
? ctx.streamedBlocks.reconcile(envelope)?.identity
: null) ?? claudeMessageIdentity(envelope)
ctx.streamedText.forget(agentJournalItemKey(identity))
const thinking = ctx.streamedThinking.finalize(outputEnvelope, observedAt)
const source: ClaudeTurnSource = {
sessionId: envelope.sessionId,
uuid: envelope.uuid,
assistant: envelope.role === 'assistant'
}
const openOutputTurn = (): void => ctx.turn.ensureOpen(message, source, observedAt)
if (body) {
// Opening before the append is what brackets a turn around its own first
// output; a reader that scans back to the turn record and stops would
// otherwise look straight past the row that opened it.
ctx.turn.ensureOpen(message, source, observedAt)
ctx.sink.appendItem(identity, body, stamp(identity, body))
if (terminalIdentity) {
writeClaudeTerminalFailure(ctx.sink, terminalIdentity, body)
} else {
ctx.sink.appendItem(identity, body, stamp(identity, body))
}
changed = true
}
for (const tool of claudeToolUses(outputEnvelope)) {
Expand Down
21 changes: 18 additions & 3 deletions src/main/claude/claude-open-turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
import { writeAgentJournalTurnRow } from '../native-chat/agent-session-timeline/agent-journal-turn-row-revision'
import type { ClaudeCommandTurn } from './claude-command-turn'
import { createClaudeTurnOpener, type ClaudeTurnSource } from './claude-turn-opening'
import { refineClaudeQuotaTurnEnd } from './claude-terminal-failure'
import type { ClaudeUsageLimitEvidence } from './claude-usage-limits'
import type { ClaudeStartedSend } from './claude-structured-session-state'

export type ClaudeOpenTurnDeps = {
Expand All @@ -35,6 +37,7 @@ export type ClaudeOpenTurnDeps = {

export class ClaudeOpenTurn {
private current: ClaudeCurrentTurn | null = null
usageLimitEvidence: ClaudeUsageLimitEvidence | null = null
/** Provider output may not reopen a turn after the session ended or a turn
* failed: nothing would ever close the turn it opened, and the row would read
* working for the life of the session. Only an accepted send lifts it. */
Expand Down Expand Up @@ -125,6 +128,7 @@ export class ClaudeOpenTurn {
* later would sweep THIS turn. The replaced turn is recorded superseded: a newer
* request ended it, whoever sent that request. */
open(turn: ClaudeCurrentTurn, observedAt: number): void {
this.usageLimitEvidence = null
this.deps.onOpen?.()
if (this.current) {
this.deps.turnSuperseded()
Expand All @@ -143,6 +147,7 @@ export class ClaudeOpenTurn {
/** A conversation command the host opened a turn for. Its row is the host's, already written,
* so only an end is published; the command's result is what ends it. */
beginCommand(turn: ClaudeCurrentTurn): void {
this.usageLimitEvidence = null
this.deps.onOpen?.()
if (this.current) {
this.deps.turnSuperseded()
Expand All @@ -167,6 +172,7 @@ export class ClaudeOpenTurn {
/** The command was never sent; its turn is the host's to settle. */
forgetCommand(turnId: string): void {
if (this.current?.command && this.current.turnId === turnId) {
this.usageLimitEvidence = null
this.current = null
}
}
Expand All @@ -185,12 +191,16 @@ export class ClaudeOpenTurn {
/** End the open turn, if one is open, and clear the live activity line. The
* context facts the end brings ride the same revision. */
settle(end: ClaudeTurnEnd, contextUsage?: AgentSessionContextUsage): void {
const quotaEnd = this.current !== null && end.outcome === undefined &&
this.usageLimitEvidence?.cause === 'quota'
this.suppressReopenOnFailure(quotaEnd)
// Every settle is a provider cycle ending (result, idle, child exit).
this.cycleWorkObserved = false
this.usageLimitEvidence = null
// Even with no turn open: work a suppressed turn produced still ends here.
this.deps.endOpenWork(end.completedAt)
if (this.current) {
this.publish(this.current, end, contextUsage)
this.publish(this.current, end, contextUsage, quotaEnd)
this.current = null
}
this.deps.sink.setActivity?.(null)
Expand All @@ -216,13 +226,18 @@ export class ClaudeOpenTurn {
private publish(
turn: ClaudeCurrentTurn,
end?: ClaudeTurnEnd,
contextUsage?: AgentSessionContextUsage
contextUsage?: AgentSessionContextUsage,
quotaEnd = false
): void {
const item = claudeTurnLifecycleItem(turn, end)
const write = { lifecycle: item.body, ...(contextUsage ? { contextUsage } : {}) }
if (quotaEnd && refineClaudeQuotaTurnEnd(this.deps.sink, item.identity, write)) {
return
}
writeAgentJournalTurnRow(
this.deps.sink,
{ identity: item.identity },
{ lifecycle: item.body, ...(contextUsage ? { contextUsage } : {}) },
write,
{ publish: false, options: item.options }
)
// Keyed apart, so this never replaces the start's publication while it still waits to run.
Expand Down
Loading
Loading