Repository navigation
fix(chat): handle long prompts across Agent CLIs - #1267
Conversation
crispinhu27
left a comment
There was a problem hiding this comment.
Reviewed at head 04e8eef0 (base main 4ff0e73, merge-base 88255b7). This is the first review.
Scope: the dsh branch of AgentCLICommand, plus the code that consumes CommandSpec.Stdin:
AgentCLITaskPrompt,positionalPromptandPromptOnStdin- chat execution through
assistant_engine_agentcli→ConversationCommandFor(...).Interactive→ theassistant_processwrite/EOF pump, including the runner path remap - local
sandbox_localand Dockerexec -i - the dsh native-approval
--patchinsertion andapplyDeepSeekCredentialargv splicing, which still operate onargv[:3]
Verification: run in an isolated user, with no repository credentials and synthetic data only.
go build ./...andgo vet ./internal/runtime ./internal/httpapipass.- The new tests
TestDeepSeekOversizedPromptReachesCLIOnStdin(fresh and resume) andTestDeepSeekShortPromptUsesPositionalArgumentpass. With the same test file on the merge-base, both subtests fail withfork/exec …/dsh: argument list too long, so the regression is real and this PR fixes it. - End-to-end with the real
@deepseek-ai/dsh@0.2.2-rc.5. The probe builds the chat command withAgentCLICommand(dsh, Chat:true, …)and a 162,019-byte prompt, then runs it withExecuteLocalCommandandBindAgentCLIagainst a local mock OpenAI-compatible endpoint.- Head: dsh starts, and the mock receives the complete prompt (one 186,540-byte request containing the tail marker). The run then finishes with
final … "text":"MOCK_REPLY_OK". - Merge-base: the same probe fails before start with
argument list too long.
- Head: dsh starts, and the mock receives the complete prompt (one 186,540-byte request containing the tail marker). The run then finishes with
go test ./internal/httpapi -run 'AgentCLI|DeepSeek|DSH|Stdin|OversizedPrompt|ConversationProcess|AssistantEngine'passes.go test ./internal/runtime(full package): the remaining failures are environment-related and appear identically on the merge-base. They are the Chromium browser tests,TestEnvironmentIdentityGitAndMCPHeadersandTestBwrapMountsManagedInstallationUnderPrivateTmp. The Docker-helper tests that failed under the full parallel run pass when run alone on both head and base.- All CI checks on this head are green, including
core.
Not separately verified:
- A real-dsh resume turn. Resume is covered by the PR's fake-CLI test, and it uses the same headless stdin path.
- A real remote runner or Docker run. Both use the existing stdin transport, which Claude Code and CodeBuddy already rely on.
No blocking issues found.
crispinhu27
left a comment
There was a problem hiding this comment.
Re-review at head 41b0df7a (base main 4ff0e73, merge-base 88255b7). The earlier APPROVE on 04e8eef0 (review 6023140337) was dismissed by the new push. This review covers the whole PR, with a focus on the new commit 41b0df7a, which extends long-prompt handling to all Agent CLIs.
Scope:
agentCLIPromptInputandStageAgentCLIConversationCommand: stdin for dsh, OpenCode and Pi; NDJSON for Antigravity; staged prompt files for Kimi (UserPromptSubmithook) and ZCode (16 KiB attachments).- The ACP client in
assistant_engine_acp.goand the Antigravity keep-open input. - The local
runAssistantCLIpath and theconversationExecutorpath, includingprompt-inputasset sync/rewrite, runner remap/cleanup, thePromptInputFilesupgrade gate andConversationTextChunkLen. - Antigravity
--settingsinsertion when-pis absent.
Verification: isolated workspace, synthetic data only, local mock OpenAI-compatible endpoint, no repository credentials.
go build ./...andgo vet ./...pass.- Focused runtime/httpapi tests pass, including the new
TestAgentCLIConversationLongPrompt,TestAgentCLIConversationShortPromptUsesArgvandTestAssistantACPConversationInput. - Full
go test ./internal/httpapi ./internal/runtime: the failing tests are identical on head and merge-base. They are the Chromium/browser, Docker, bwrap and git-identity tests, which are environment-related. - Real CLIs, 170,016-byte chat prompt with a tail marker:
- On head, the mock receives the complete prompt (tail marker present) and the CLI replies for dsh 0.2.2-rc.5, OpenCode 1.19.6, Pi (
@earendil-works/pi-coding-agent) and Kimi Code 2.7.2 (through theUserPromptSubmithook file). - On merge-base, all of these fail with
argument list too long.
- On head, the mock receives the complete prompt (tail marker present) and the CLI replies for dsh 0.2.2-rc.5, OpenCode 1.19.6, Pi (
- Antigravity, through the real chat invocation: the NDJSON frame is delivered, the result is translated, and the process exits after
closeWriter, both new and resumed. This holds with long-context model aliases. With short-context aliases, Antigravity itself rejects the prompt (no messages fit within the context token budget), as the PR description notes. prompt-inputstaging is removed after each turn.- CI on this head is green, including
coreand the re-runbrowserjob. The firstbrowserfailure wasdesktop settings navigation reopens on the current page(a focus assertion); the PR touches no web code, and the same test also failed on unrelated commit ca11d64.
Blocking issue: one P2, inline. A long-prompt Cursor (ACP) turn does not finish, because cursor-agent acp ignores stdin EOF.
Not verified:
- A successful Cursor ACP prompt (needs a Cursor account).
- ZCode with a real CLI (not installable here).
- A real remote runner or Docker run.
- Resume turns with real dsh/OpenCode/Pi/Kimi; these are covered by the PR's unit tests.
crispinhu27
left a comment
There was a problem hiding this comment.
Re-review of head 7e62c3d3 (base main 4ff0e73c, merge-base 88255b7e). The increment since my last review (41b0df7a) is f7cf3407 and 7e62c3d3.
Previous finding
- [P2] Long-prompt Cursor ACP turns never finish because
cursor-agent acpignores stdin EOF: FIXED. I re-tested it with the real Cursor CLI and with a fake ACP peer that lingers after EOF, on both the local executor and the local conversation-process executor. Turns now end about 2.5 s after the terminal ACP result. Before this change they ran until the 90 s probe deadline. Details are in the thread.
Reviewed in this increment
assistantACP.execute: drain-then-cancel after the result. A user cancellation is still reported as an error, andresult()runs only once becausetranslatereturns early whenstream.Finished().- Cursor ACP transport pinning: the
cursor-acp:entry inagent-cli-sessions.json,CursorACPinagentCLIPromptInput, andACPPrompt *string. CursorRouteFilterapplied to ACP answer chunks, and the model ID taken fromsession/new.
Validation
go build ./...andgo vet ./internal/httpapi ./internal/runtimepass.- Focused tests pass: httpapi
ACP|Cursor|AgentCLI|LongPromptand runtimeAgentCLI|Cursor|Conversation|Prompt. - Full
internal/httpapiandinternal/runtimeruns: the only failures are browser, Docker, bwrap and git-identity tests. The same tests fail on merge-base in this sandbox, so they are environmental. - Multi-turn probe with a fake Cursor CLI: short print turn → long ACP turn (
session/loadof the print session) → two short follow-ups. The follow-ups stay on ACP with the same native session, and each turn completes. - CI: everything is green except the
browserjob. Its one failure isui/03-workbench-settings.spec.mjs:103(desktop settings navigation focus). This PR does not touchweb/,e2e/orchatbot/. The same test passed on41b0df7a, whose frontend is identical, and it failed on its own in unrelated PR runs 45165195194 and 45168175968. It looks like an existing flake. A re-run of that job should clearplatform-required.
Not verified: a successful real Cursor ACP turn (no Cursor account), the remote runner and Docker execution paths, and real ZCode/Kimi CLIs for this increment.
|
结论:需要修改 GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号对 LoopForge 只有 pull 权限,无法提交正式 Approve / Request changes。以下改为普通评论。 长提示词主线与 #434、#1081 是对得上的:超过 96 KiB 时 DeepSeek / OpenCode / Pi 走 stdin,Cursor 走 ACP,Antigravity 走 NDJSON,Kimi 与 ZCode 走暂存文件,并有回归测试。CI 16 项成功,也没有和 main 冲突。但最新提交把与这两条 issue 无关、描述里也没说明的设置导航改动夹进来了,需要先拆出去。
请把提交 |
crispinhu27
left a comment
There was a problem hiding this comment.
复审(增量 7e62c3d..917b176):APPROVE
本轮审查范围:7e62c3d3 上的 APPROVE 之后新增的提交 917b176「fix(web): keep focus when reopening settings navigation」(web/app.js、web/app/navigation.css、e2e/ui/03-workbench-settings.spec.mjs)。我读了 setSettingsSidebarExpanded 的全部调用方、路由切换过渡逻辑和设置导航的 CSS,确认这次增量和 PR 其余部分(CLI / 对话改动)没有交叉。
验证(隔离环境,head 917b176,对照 7e62c3d):
webtest下npm test:230/230 通过;go test ./web/...:147 个通过,唯一失败的 TestNativeChatLazyImportsAreEmbedded 是因为本地没有构建 chatbot 产物,和本 PR 无关(CI core 为绿)。- 用本地静态服务加 Chromium(Playwright)跑新的 03-workbench-settings 用例(重复 31 次):head 全部通过。旧 head 上,原来那条“焦点最终落到收起按钮”的断言 31 次里失败 3 次,复现了上一轮 browser 任务的偶发失败;新代码在所有重复运行中都没有再出现。
- 补测:鼠标点击、空格键重开导航,以及焦点在 body 上时重开,焦点都会落到收起按钮;焦点在主内容区时重开不会抢焦点;收起后侧栏是 inert、点不到,Tab 键进不去;900px 抽屉模式正常;1440/900 两种宽度下开、合状态的截图和旧 head 逐像素一致。
- 当前 head 的 16 项 CI 全部 success。
非阻塞备注:收起后侧栏改用 clip 隐藏,不再设 visibility: hidden,所以 e2e 里 expect(collapse).toBeVisible() 已经不能证明侧栏重新打开了,不过 aria-hidden 和焦点断言仍然覆盖了这个行为。未验证:真实 Safari 和读屏软件,以及在完整后端上跑真实 e2e(本地缺 MySQL/Docker;CI 的 browser 和 e2e-browser 已在该 head 上通过)。
此前的阻塞问题(ACP 长 prompt 进程挂住)已在 7e62c3d 上复测为 FIXED,线程已解决;本次增量没有动相关代码。
This reverts commit 917b176. The settings navigation focus fix is unrelated to long prompt handling and moves to its own pull request. Co-Authored-By: Claude Code <noreply@anthropic.com>
Keep main's workspace-aware stdin chunk boundaries and route them through the shared runtime.ConversationTextChunkLen used for staged prompt files. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
|
已按 cocofhu00 的意见拆分,并合入最新 main,head 现为
验证
|
crispinhu27
left a comment
There was a problem hiding this comment.
Re-review of head 34529d06 (base main 177d881). My earlier APPROVE on 917b176c was dismissed by the new push. New since then: 0fced5fb reverts the settings-nav focus change (moved to #1311), and 309ece75 / 34529d06 merge main.
Scope
- The PR now changes 14 Go files against main and no web files, so the revert is clean.
- I compared this PR's own changes in those 14 files at the approved head and at the current head. The only difference is that
runtime.ConversationTextChunkLen(data string, limit int, paths ...string)now takes several paths (main's multi-path logic moved in unchanged), and its two callers were updated to match. - Codex stdin still calls
conversationInputChunkLen(data, workspacePath, rootPath)and goes throughruntime.ConversationStdinPath, so main's handling of both the encoded root and<root>/wsis kept. - Kimi/ZCode staged files (
provider_agentcli.gostageText) split aroundi.root. The runner'ssyncforprompt-input/only maps the session root, so this is enough.
Verification (offline sandbox, no real Agent CLI or model credentials):
go build ./...andgo vetpass.go test ./...: the head and the base each have 27 packages passing. The 127 failing tests are the same set on both (commfinds no difference). They need bwrap, Chromium or Docker.- The long-prompt and chunking tests pass, including:
TestAgentCLIConversationLongPromptandTestAgentCLIConversationShortPromptUsesArgv- the DeepSeek stdin tests,
TestAssistantACP*andTestAssistantCursorShortResumeKeepsItsTransport TestConversationImageInputChunkPreservesRemotePathAndUTF8andTestConversationInputChunkPreservesEncodedWorkspacePath
- A temporary harness (not committed) checks the staged files end to end.
- Setup: for ZCode and Kimi, it builds a ~300 KB prompt with session-root,
ws/andattachments/paths placed across 16 KiB chunk boundaries at 29 offsets, stages it withStageAgentCLIConversationCommand, and moves it to a new root throughConversationProcessPool.Handle(sync). - Result: the reassembled text exactly equals the prompt with every path remapped, so it passes.
- Negative control: with the path argument removed from
stageText, the harness fails (residual src refs=15).
- Setup: for ZCode and Kimi, it builds a ~300 KB prompt with session-root,
- CI: all 16 checks pass at this head.
Not covered: real CLI runs and macOS seatbelt runners. Non-blocking note, not from this merge and not reproduced: Antigravity and Cursor ACP stdin frames are JSON but don't go through ConversationStdinPath, so a session root containing ", \, <, > or & would not be remapped. Ordinary paths are unaffected.
I found no blocking issues, so I'm approving.
|
结论:建议合入 GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。 对照了 #434 和 #1081。 |
Robert0622
left a comment
There was a problem hiding this comment.
CR + 部署实测(head 34529d06):LGTM
说明:这次评审的 token 是 PR 作者本人的账号,GitHub 不允许作者 approve 自己的 PR,所以只发评论、不点 Approve。
部署实测(本机原生部署 PR 和 main 两个实例,MySQL 8.4.7 全新库,真实 CLI 和模型)
提示词约 195KB(单个参数超过内核 128KiB 上限),开头和结尾各放一个暗号,要求模型把两个暗号都复述出来;然后追问一轮「开头的暗号数字是多少」,验证会话能续上。
| CLI / 模型 | PR 长提示词 | PR 追问一轮 | main 长提示词 |
|---|---|---|---|
DeepSeek dsh / deepseek-flash |
✅ ALPHA-7319 OMEGA-4826(10s) |
✅ 7319 |
❌ 4s 失败:argument list too long (a single argument exceeds the ~128KiB kernel limit…) |
Cursor cursor-agent / grok-4.7 high(走 ACP) |
✅ 两个暗号都对(30s) | ✅ 7319,长提示词之后的会话继续走 ACP |
❌ 4s 失败,原因同上 |
CodeBuddy / deepseek-v4.1-flash |
✅(12s) | ✅ | ✅(main 上本来就走 stdin) |
另外单独验证了 ACP 下的权限请求:用 cursor-agent --trust --force --approve-mcps acp 让模型执行 shell 命令,Cursor 没有发 session/request_permission,命令照常执行、stopReason=end_turn。所以 assistant_engine_acp.go:175 对权限请求一律回 cancelled,在 --force 下目前碰不到。不过按 ACP 规范,cancelled 的意思是「整轮被取消」;如果以后去掉 --force,建议改成回 reject_once。
代码审查
- stdin、stdout、stderr 并发处理,大段 stdin 不会把管道写死;取消时 Close 能唤醒阻塞的 Write,不会泄漏进程或协程。
- 临时提示词文件写在
root/prompt-input/turn-*(目录 0700、文件 0600),不在工作区里,不会被提交,本地和远端都会清理。 - 96KiB 以内的提示词仍走 argv,行为不变。
- 与 main
f3d4f41a合并无冲突;设置导航那个提交已经 revert,移到了 #1311,净 diff 里没有 web 改动。
建议(P3,不阻塞):internal/runtime/conversation_process.go:996 ConversationStdinPath 只对 codex 按 JSON 转义路径。现在 Cursor ACP 帧和 agy 的 stream-json 帧也是 JSON;如果远端执行机是 Windows(路径里有 \),替换进去的路径会变成非法转义。目前没有 Windows 执行机的话可以先不管。
回归:go test ./internal/httpapi/ ./internal/runtime/ -run 'ACP|Prompt|DeepSeek|Cursor|LongPrompt' 通过;httpapi/runtime/repo/runeval 四个包,失败项与 main 完全相同(26 项,本机缺 Docker、bwrap、Chromium 等),没有新增失败;chatbot vitest 487/487。工具调用类的端到端场景本机跑不了(会话工作区要 Docker),main 上也一样。
结论:没有发现阻塞问题,可以合入。
|
关于上次评审里那条 P3(Windows 执行机上的路径进入 stdin JSON 帧会变成非法转义):核对后不成立,不需要改。
等真的要支持 Windows 执行机时再一起处理。 |
Resolve the ConversationProcessResult conflict by keeping both the WorkingDir/PromptInputFiles fields from this branch and ErrorCode from #1318. Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
left a comment
There was a problem hiding this comment.
Re-review of head 571ab388 (base main 848793b). My APPROVE on 34529d06 was dismissed by this push. The only new commit is 571ab388, which merges main (7 commits since 177d8815, including #1318's workspace-CLI fallback).
Scope
- I compared this PR's own changes against main at the previously approved head (
177d8815...34529d06) and at the current head (848793b3...571ab388). The same 14 Go files change, with no web files. The only difference is the merge resolution ininternal/runtime/conversation_process.go:ConversationProcessResultkeeps main's newErrorCodefield next to this PR'sWorkingDirandPromptInputFiles, and the column alignment changes. The PR doesn't drop or revert anything from main. - Main and this PR both touch
assistant.go,assistant_process.goandconversation_process.go. I read the merged code. #1318's mode switching andworkspaceStartFailedprompt live inchat'sgenerate. This PR's ACP execution wrapper lives inrunAssistantCLI, and itsPromptInputFiles/WorkingDirhandling lives inconversationExecutor. They change different code paths, andErrorCodestill reaches the runner control response.
Verification (isolated sandbox, synthetic data, no real Agent CLI or model credentials)
go build ./...andgo vet ./internal/httpapi/ ./internal/runtime/pass.go test ./internal/runtime/... ./internal/httpapi/... ./internal/runner/...on head and on main: every test that failed on head without also failing on main falls into one of two groups:- Missing
bwrap: 8 cases, includingTestWorkspacePreparationAPISeparatesReadersAndWritersandTestGenericTemplatesAndCopiesRunWithoutRepository. They fail withbwrap sandbox unavailableon both. I reran them 3 times on each side and they failed every time. TestChatClarificationEdgePaths: panics intermittently withindex out of rangeon both main and head. That's existing flakiness.
- Missing
- Focused runs pass: long and short prompts, DeepSeek stdin,
TestAssistantACP*, Cursor short resume, conversation input/image chunking,ConversationProcess*, and main's newWorkspaceFallback*/ResumeRecovery*tests on this head. - CI: all 16 checks pass at this head.
- Previous issues: the only thread from my reviews (the [P2] where long-prompt Cursor turns never finish after the ACP exchange ends) was already verified FIXED and resolved in an earlier round. The ACP code didn't change in this merge.
Not covered: real CLI runs and macOS seatbelt runners, same as the previous review. The end-to-end staging harness from the previous round wasn't rerun because the staging code is unchanged.
I found no blocking issues, so I'm approving.
|
main 前进到
验证
|
|
Re-review of Code
Deployment test
I also ran a ~194 KB prompt in a session that was switched to workspace mode and fell back to platform mode: 200, both codewords correct. Not covered
Conclusion: no blocking issues, OK to merge. This token is the PR author's account, so this is a comment, not a formal approval. |
What changed
Fixes #434 and #1081. Related to #429.
Compatibility
Short prompts use each CLI's original launch mode until a Cursor conversation enters ACP. Subsequent turns in that Cursor conversation reuse ACP and its native history. When Cursor cannot open a print-mode journal in ACP, LoopForge uses its existing transcript replay to start the ACP session. The tested Cursor version reports token usage in print mode and omits it over ACP.
Older remote runners report an upgrade requirement for long Kimi Code and ZCode turns because these modes synchronize temporary prompt files.
Validation
go vet ./..., the public-content check, and the secret scanner passed.Safety