Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All notable changes to DreamCoder will be documented in this file.
- **Providers in OpenAI format reuse their prompt cache.** Later turns of a session now hit the cache for about 99% of the input (measured on OpenRouter with GPT-4.1 mini and GLM-4.6), and cache hits that DeepSeek and Moonshot report are counted as cache reads (#262).
- Providers in OpenAI format can run several tool calls in one step and get tool definitions without schema fields they do not use, and replies show the model you chose instead of the dated version the provider reports (#262).
- Every request the app itself sends to a provider (through the local proxy, for session titles and for connection tests) is recorded in the diagnostics log with the provider, model, status, timings, the provider's request id and how it ended, including errors in the middle of a stream and clients that disconnect; never the key or the request body (#262).
- **A stalled reply ends after the AI request timeout.** When a provider stops sending anything for longer than the timeout in the network settings, the agent gives up on that reply and asks again without streaming, instead of waiting until you stop it. This now applies to every provider, whether it is reached directly or through the local proxy; keep-alive signals alone do not count as progress (#262).
- **A stalled reply ends after the AI request timeout.** When a provider stops sending anything for longer than the timeout in the network settings, the agent gives up on that reply and starts it again, instead of waiting until you stop it. This now applies to every provider, whether it is reached directly or through the local proxy; keep-alive signals alone do not count as progress (#262).
- Providers in OpenAI format can carry extra request headers and query parameters, such as Azure's `api-version`. The settings form does not offer them yet; for now they are set by editing the provider in `providers.json`. Authentication and the content type still come from the provider settings and override a header of the same name (#262).

### Fixed
Expand All @@ -24,6 +24,14 @@ All notable changes to DreamCoder will be documented in this file.
- With a manual HTTP proxy set in the network settings, the agent reaches the app's local proxy directly instead of sending those requests to the HTTP proxy (#262).
- Replies from some providers no longer come back empty; the provider's error message is shown instead (#262).
- `/context` in the terminal no longer sends a request to the model for each part of the context when the provider is reached through the local proxy; it uses the local estimate (#262).
- **A session that outgrows a third-party model's context can be compacted again.** Context overflow errors from OpenAI, OpenRouter, DashScope, Moonshot, Zhipu and Gemini are recognized as "Prompt is too long", so `/compact` drops the oldest turns and succeeds instead of failing the same way (#263).
- Auto-compaction also triggers for providers that do not report token usage; the agent estimates the context itself instead of counting it as empty (#263).
- Errors from providers in OpenAI format show the provider's own message, such as the reason for a 429, instead of a cut-off JSON fragment, and the agent waits as long as the provider's `retry-after` asks before trying again (#263).
- A reply that the provider stops with its content filter or because of an error on its side, a stream that closes before the reply is complete, and a reply with no content now show an error instead of looking finished (#263).
- Replies from providers in OpenAI format no longer lose text when one chunk carries reasoning, text and a tool call together, and Responses-format replies keep text and tool arguments that only arrive in completed events (#263).
- **A wrong API key or an empty balance is reported at once.** For providers that use an API key, the agent no longer retries authentication failures and quota or balance errors for minutes before showing them; it shows the provider's message right away (#263).
- When the output limit cuts off a tool call in the middle of its arguments, the agent no longer runs the tool with missing arguments; the model is told the call was cut off and retries with smaller pieces (#263).
- **A reply that breaks off in the middle is retried as a stream.** When a provider's stream fails partway, the agent removes the half-finished reply from the conversation, the app and the session history, and asks again with streaming, instead of switching to a slower request without streaming that long answers could not finish within the timeout. Retries before and during a stream share one limit (#263).

## [0.9.0] — 2026-11-17

Expand Down
56 changes: 56 additions & 0 deletions desktop/src/stores/chatStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,62 @@ describe('chatStore history mapping', () => {
vi.useRealTimers()
})

it('drops what a retried reply already streamed and keeps the earlier turn', () => {
vi.useFakeTimers()
const earlier: UIMessage[] = [
{ id: 'u1', type: 'user_text', content: 'do it', timestamp: 1 },
{ id: 'a1', type: 'assistant_text', content: 'Reading the file.', transcriptMessageId: 'cli-a1', timestamp: 2 },
{ id: 't1', type: 'tool_use', toolName: 'Read', toolUseId: 'toolu_read', input: {}, timestamp: 3 },
{ id: 'r1', type: 'tool_result', toolUseId: 'toolu_read', content: 'file', isError: false, timestamp: 4 },
]
useChatStore.setState({ sessions: { [TEST_SESSION_ID]: makeSession({ messages: earlier, chatState: 'streaming' }) } })
const send = (msg: Parameters<ReturnType<typeof useChatStore.getState>['handleServerMessage']>[1]) =>
useChatStore.getState().handleServerMessage(TEST_SESSION_ID, msg)

send({ type: 'thinking', text: 'planning' })
send({ type: 'content_start', blockType: 'text' })
send({ type: 'content_delta', text: 'Now I write' })
send({ type: 'message_id', id: 'cli-a2' })
send({ type: 'content_start', blockType: 'tool_use', toolName: 'Write', toolUseId: 'toolu_write' })
send({ type: 'content_delta', toolInput: '{"file_pa' })
send({ type: 'content_start', blockType: 'tool_use', toolName: 'Grep', toolUseId: 'toolu_sub', parentToolUseId: 'toolu_agent' })
send({ type: 'tool_use_complete', toolName: 'Grep', toolUseId: 'toolu_sub', input: { pattern: 'x' }, parentToolUseId: 'toolu_agent' })
send({ type: 'content_start', blockType: 'text' })
send({ type: 'content_delta', text: 'half a sen' })
send({ type: 'content_start', blockType: 'tool_use', toolName: 'Edit', toolUseId: 'toolu_edit' })
send({ type: 'content_delta', toolInput: '{"old_str' })
vi.runOnlyPendingTimers()
send({ type: 'thinking', text: 'checking again' })
vi.runOnlyPendingTimers()
send({ type: 'content_delta', text: 'and then' })
vi.runOnlyPendingTimers()
expect(useChatStore.getState().sessions[TEST_SESSION_ID]).toMatchObject({
activeToolUseId: 'toolu_edit',
activeToolName: 'Edit',
activeThinkingId: expect.any(String),
streamingText: 'and then',
streamingToolInput: '{"old_str',
})

send({ type: 'reply_retracted' })
vi.runOnlyPendingTimers()

const session = useChatStore.getState().sessions[TEST_SESSION_ID]!
expect(session.messages).toEqual([
...earlier,
expect.objectContaining({ type: 'tool_use', toolUseId: 'toolu_sub', parentToolUseId: 'toolu_agent' }),
])
expect(session).toMatchObject({
chatState: 'thinking',
streamingText: '',
streamingToolInput: '',
activeToolUseId: null,
activeToolName: null,
activeThinkingId: null,
})
vi.useRealTimers()
})

it('builds on history and keeps only live messages history does not have yet', async () => {
vi.mocked(sessionsApi.getTranscript).mockResolvedValueOnce(transcriptOf([
{ id: 'u1', type: 'user_text', content: 'prompt', transcriptMessageId: 'u1', timestamp: 1 },
Expand Down
27 changes: 27 additions & 0 deletions desktop/src/stores/chatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,18 @@ function mergeHistoryWithLiveMessages(history: UIMessage[], live: UIMessage[]):

const liveStartBySession = new Map<string, number>()

const STREAMED_REPLY_TYPES = new Set<UIMessage['type']>(['assistant_text', 'thinking', 'tool_use'])

function dropRetractedReply(messages: UIMessage[]): UIMessage[] {
const replyStart = messages.findLastIndex((message) => message.type === 'user_text' || message.type === 'tool_result') + 1
const kept = messages.filter((message, index) =>
index < replyStart ||
!STREAMED_REPLY_TYPES.has(message.type) ||
(message.type === 'tool_use' && !!message.parentToolUseId),
)
return kept.length === messages.length ? messages : kept
}

function tagLatestAssistantText(messages: UIMessage[], pendingText: string, id: string, timestamp: number): UIMessage[] {
for (let index = messages.length - 1; index >= 0; index--) {
const message = messages[index]!
Expand Down Expand Up @@ -1347,6 +1359,21 @@ export const useChatStore = create<ChatStore>((set, get) => ({
break
}

case 'reply_retracted':
textDeltaBuffer.clear(sessionId)
thinkingDeltaBuffer.clear(sessionId)
toolInputDeltaBuffer.clear(sessionId)
update((s) => ({
messages: dropRetractedReply(s.messages),
streamingText: '',
streamingToolInput: '',
activeThinkingId: null,
activeToolUseId: null,
activeToolName: null,
chatState: 'thinking',
}))
break

case 'api_retry': {
const attempt = Math.max(1, Math.trunc(msg.attempt))
const maxRetries = Math.max(attempt, Math.trunc(msg.maxRetries))
Expand Down
5 changes: 3 additions & 2 deletions docs/features/harness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ DreamCoder 的 CLI 派生自 Claude Code 2.1.92(`src/constants/claudeCodeCompa

- 推理强度:CLI 对自定义提供方发 `thinking:{type:'adaptive'}`,代理只在带预算或类型为 `enabled` 时写 `reasoning_effort`(`src/server/proxy/transform/anthropicToOpenaiChat.ts:64-72`),桌面上选的 Effort 不起作用。
- 输出上限:`max_tokens` 不转发,实际用上游默认值。
- 错误:上游错误统一包成 `api_error`,`retry-after` 丢失;CLI 针对 Anthropic 的错误识别(上下文过长、过载)对翻译后的错误不命中。
- 错误:上游错误统一包成 `api_error`,`retry-after` 丢失;CLI 针对 Anthropic 的错误识别(上下文过长、过载)对翻译后的错误不命中。已在 #263 修复:代理解析上游错误并透传 `retry-after`,代理和 CLI 按同一张表分类(见 proxy/transport.md 的 P-NET-03、P-NET-04)。
- 推理内容:只对 DeepSeek 一类上游写回历史里的 `reasoning_content`,Kimi、GLM 的会丢。
- 图片:工具结果里的图片被换成 `[image omitted]`(`src/server/proxy/transform/toolArguments.ts:38`)。
- 图片:工具结果里的图片被换成 `[image omitted]`(`src/server/proxy/transform/toolArguments.ts:31`)。
- 工具调用:chat 流里没有 id 的工具调用整个被丢掉。

详见 [model-adaptation.md](comparison/model-adaptation.md)。
Expand Down Expand Up @@ -100,6 +100,7 @@ DreamCoder 的 CLI 派生自 Claude Code 2.1.92(`src/constants/claudeCodeCompa
- 外部构建里没有「完成前先验证」的条文。
- 没有空响应重试和重复调用提醒(ZCode 有)。
- 不在内置表里的模型(如 GLM-5.3、Kimi-K3),上下文窗口按 200K 计。
- 工具在一次模型回复读完之后才执行:`tengu_streaming_tool_execution2` 在 DreamCoder 里打不开(见 loop-execution.md)。

详见 [loop-execution.md](comparison/loop-execution.md)。

Expand Down
2 changes: 1 addition & 1 deletion docs/features/harness/comparison/loop-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

- Codex:`handle_output_item_done` 构造 future,`tokio::spawn` 执行(`codex:core/src/stream_events_utils.rs:~345-372`;`codex:core/src/tools/parallel.rs:201`);读写锁分配(`parallel.rs:213-217`);`exec_command` 声明可并行(`codex:core/src/tools/handlers/unified_exec/exec_command.rs:135`),apply_patch handler 默认不可并行(`codex:tools/src/tool_executor.rs:122`)。错误输出(`parallel.rs:338-384`;`codex:core/src/tools/registry.rs:963-966`)。exec 审批策略固定 Never(`codex:exec/src/lib.rs:591`),`request_user_input` 与文件变更审批被拒(`exec/src/lib.rs:2122-2143`);需要提权时返回「approval policy is Never; reject command — you cannot ask for escalated permissions ...」(`exec_command.rs:~330`)。
- ZCode:`ToolScheduler` 并发 10,判定规则(`zcode:core/src/tool/scheduler.ts:45, 90-185`);流中执行条件 `modelStreaming === "on"`(headless 为 on,`zcode:cli/src/prompt-command.ts:270`)且 `streamingToolExecution` 默认 `readOnly`(`runtime/methods/streaming-tool-coordinator.ts:383-406`);排序(`runtime/methods/turn-tools.ts:47-57`)。错误措辞与 DreamCoder 同一套(`tool/input-validation-model-content.ts:12-68`;`tool/executor/errors.ts:44-58`)。`zcode -p` 默认 yolo(`zcode:cli/src/run.ts:52`),但判为 ask 的调用经 deny broker 拒绝(`permission/broker.ts:22-37`;`permission/service.ts:121-150`;`prompt-command.ts:250-253`;`tool/executor/errors.ts:136-160`)。
- DreamCoder:流式执行门 `tengu_streaming_tool_execution2`(`src/query/config.ts:33`),GrowthBook 无 clientKey 时关闭(`src/services/analytics/growthbook.ts:173, 422-427, 819-821`),所以由 `runTools` 在响应结束后执行(`src/query.ts:1368-1370`)。并发上限 `CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY` 默认 10(`src/services/tools/toolOrchestration.ts:8-112`)。错误类型(`src/services/tools/toolExecution.ts:402, 474-482, 671, 724`)。权限拒绝返回 is_error 的 tool_result(`toolExecution.ts:1030-1040`),文案见 `src/utils/messages.ts:217-241`。应用用 `--sdk-url` 强制 stdio 权限提示并转发服务器(`src/cli/print.ts:851-853, 4315-4317`);无人响应时是等待而不是自动拒绝(推断)。
- DreamCoder:流式执行门 `tengu_streaming_tool_execution2`(`src/query/config.ts:33`),GrowthBook 无 clientKey 时关闭(`src/services/analytics/growthbook.ts:173, 422-427, 819-821`),所以由 `runTools` 在响应结束后执行(`src/query.ts:1369-1371`)。#263 的流式重试依赖这一点:读流中途出错时,失败那次的工具调用还没有执行,撤回后重来不会重复执行;以后要打开这个开关,必须先补上保护,已有工具开始执行时不再重试这次流。并发上限 `CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY` 默认 10(`src/services/tools/toolOrchestration.ts:8-112`)。错误类型(`src/services/tools/toolExecution.ts:402, 474-482, 671, 724`)。权限拒绝返回 is_error 的 tool_result(`toolExecution.ts:1030-1040`),文案见 `src/utils/messages.ts:217-241`。应用用 `--sdk-url` 强制 stdio 权限提示并转发服务器(`src/cli/print.ts:851-853, 4315-4317`);无人响应时是等待而不是自动拒绝(推断)。

### 2.3 编辑文件

Expand Down
Loading
Loading