fix(grok): preserve ACP text deltas (#1860)

Grok ACP emits true agent_message_chunk deltas. Default overlap
dedupe treats a later "0" after "300" as an already-buffered suffix
and drops it, so the hub stores 300 instead of 3000.

Set textChunkMode: 'delta' on createGrokBackend, matching OpenCode.

Co-authored-by: Aqi77su <304702613+Aqi77su@users.noreply.github.com>
This commit is contained in:
Aqi77su
2026-09-15 13:07:46 +08:00
committed by GitHub
co-authored by Aqi77su
parent facb66ee03
commit 08dfce67c3
3 changed files with 77 additions and 2 deletions
@@ -397,6 +397,43 @@ describe('AcpMessageHandler', () => {
expect(messages).toEqual([{ type: 'text', text: '|-----|-----|-----|\n' }]);
});
it('drops extra zeros after 300 under default dedupe', () => {
// Grok streams "3000" as "300" then "0". Default overlap-dedupe sees
// bufferedText.endsWith("0") after "300" and skips the extra zero.
const messages: AgentMessage[] = [];
const handler = new AcpMessageHandler((message) => messages.push(message));
for (const text of ['3 \n', '30 \n', '300', '0 \n', '300', '00']) {
handler.handleUpdate({
sessionUpdate: ACP_SESSION_UPDATE_TYPES.agentMessageChunk,
content: { type: 'text', text }
});
}
handler.flushText();
expect(messages).toEqual([{ type: 'text', text: '3 \n30 \n300 \n300' }]);
});
it('preserves extra zeros after 300 in delta mode', () => {
const messages: AgentMessage[] = [];
const handler = new AcpMessageHandler(
(message) => messages.push(message),
{ textChunkMode: 'delta' }
);
for (const text of ['3 \n', '30 \n', '300', '0 \n', '300', '00']) {
handler.handleUpdate({
sessionUpdate: ACP_SESSION_UPDATE_TYPES.agentMessageChunk,
content: { type: 'text', text }
});
}
handler.flushText();
expect(messages).toEqual([{ type: 'text', text: '3 \n30 \n3000 \n30000' }]);
});
it('keeps existing tool name when update only has kind fallback', () => {
const messages: AgentMessage[] = [];
const handler = new AcpMessageHandler((message) => messages.push(message));
+34 -1
View File
@@ -1,6 +1,20 @@
import { afterEach, describe, expect, it } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const constructorCalls: Array<Record<string, unknown>> = []
vi.mock('@/agent/backends/acp', () => ({
AcpSdkBackend: vi.fn().mockImplementation(function (
this: unknown,
opts: Record<string, unknown>
) {
constructorCalls.push(opts)
return { __opts: opts }
})
}))
import {
buildGrokAgentArgs,
createGrokBackend,
formatGrokError,
isGrokBuildAuxiliaryQuotaError
} from './grokBackend'
@@ -53,6 +67,25 @@ describe('buildGrokAgentArgs', () => {
})
})
describe('createGrokBackend', () => {
beforeEach(() => {
constructorCalls.length = 0
})
it('concatenates ACP text chunks as deltas instead of overlap-deduping them', () => {
createGrokBackend({ cwd: '/tmp/project', model: 'grok-4.6' })
expect(constructorCalls).toHaveLength(1)
expect(constructorCalls[0]?.textChunkMode).toBe('delta')
expect(constructorCalls[0]?.flavor).toBe('grok')
expect(constructorCalls[0]?.args).toEqual([
'--cwd', '/tmp/project',
'agent',
'--model', 'grok-4.6',
'stdio'
])
})
})
describe('formatGrokError', () => {
it('turns ACP auth failures into an actionable login hint', () => {
expect(formatGrokError(new Error('Authentication required: no auth method id provided')))
+6 -1
View File
@@ -45,7 +45,12 @@ export function createGrokBackend(opts: {
return new AcpSdkBackend({
command: getAgentLaunchCommand('grok'),
args: buildGrokAgentArgs(opts),
env: filterEnv(process.env)
env: filterEnv(process.env),
// Grok ACP emits true agent_message_chunk deltas. Default overlap
// dedupe treats a later "0" after "300" as an already-buffered suffix
// and drops it, so the hub stores 300 instead of 3000.
textChunkMode: 'delta',
flavor: 'grok'
})
}