Skip to content

feat(assistant): add send preferences and preserve the CLI during steering - #1042

Merged
crispinhu27 merged 5 commits into
mainfrom
fix/steer-preserve-cli
Nov 18, 2026
Merged

crispinhu27 merged 5 commits into
mainfrom
fix/steer-preserve-cli

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Steering a running Codex or Cursor conversation could validate its model against CodeBuddy's catalog, replace it with the default, and fail the next turn's CLI consistency check. Resolve the CLI from the saved conversation and validate its model, credentials, runner login and reasoning effort before requesting cancellation. The follow-up retains the selected model, execution target and partial reply. Choosing Default uses the follow-up model's default reasoning effort. Repeating the same text with a new file or reference preserves the new message and its context even before the first reply produces output.

Add an AI assistant setting for messages sent during generation: Queue (the default) or Send immediately. The preference is saved per user and refreshes when settings are saved or the chat tab becomes visible. Immediate sends reuse steering. A validation or permission rejection pauses automatic sends and preserves the message. If the reply already ended, the message goes out on the next turn. A running reply can have one pending steer. A competing request gets a conflict and its message stays in that tab’s paused queue. Closing a turn and accepting a steer use the same generation row lock. The worker carries an accepted message into the transcript and starts its follow-up. A message that arrives after steering closes queues until the transcript has been saved.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

  • Applies to cloud and bound-runner conversations, including legacy unprefixed model IDs.
  • Adds assistant_preferences.steer_on_send, defaulting to false. Existing users keep queueing.
  • The normal additive AutoMigrate adds the column. Optional, idempotent manual DDL is in migrations/036_assistant_steer_on_send.sql; no data migration or seed.
  • No generated frontend bundles are committed, following design.md.

Validation

All 16 GitHub checks for b0cb4ac passed. Check results.

Passed locally:

  • npm --prefix chatbot test — 56 files, 395 tests.
  • npm --prefix chatbot run build.
  • Node 22: npm --prefix webtest run coverage — 87.53% line coverage (85% required).
  • go test ./internal/httpapi ./internal/repo ./web -run 'TestAssistant|TestSteer|TestGeneration|TestStoppedGeneration|TestAppBundleFilesAreEmbeddedAndListed|TestAppJSParses|Hui|NoNativeDialogs' -count=1 -timeout=180s.
  • Steering, generation, and SOP proposal regression tests passed with go test -race on a8d7a41, including equal-text messages with different attachments and references and replay of an accepted steer.
  • SQLite and disposable Docker MySQL 8.4 passed five consecutive -race runs of TestAssistantGenerationCoordinatesSteering. The test covers competing requests, handing an accepted steer to the worker, and closing the current turn before the request arrives.
  • The HTTP finalization regression reproduced an HTTP 200 without a follow-up on the previous commit. Both arrival orders now pass and preserve the partial reply. The focused HTTP race suite and all 27 frontend queue tests passed on b0cb4ac.
  • Disposable local Docker MySQL 8.4: preference persistence, generation reply guards, existing-row defaults and repeating the manual DDL.
  • Isolated Playwright check of the settings renderer: desktop/light, narrow/dark/reduced motion, saving both choices, reload persistence, no overflow or page errors.
  • go vet ./....
  • python3 scripts/check-public.py.
  • git diff --check.

The broader local Go run (with the CI real-browser test exclusion) encountered host-specific failures in unrelated tests: Linux /proc assumptions in deploy tests, the macOS Unix socket path limit, and the local Git safe.bareRepository=explicit setting. The deploy failures were also reproduced from an unchanged main export. The broad run also exceeded its local 180-second timeout; the focused regression and race tests above passed. See the PR checks for the full Linux CI result.

Not run locally: real cloud CLI end-to-end validation, the Linux-only secret-scan script, and the Classic validation/install/e2e scripts (no Classic changes).

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable (not applicable).
  • I documented third-party content and licensing changes when applicable (no new third-party content).

@newexploreor

Copy link
Copy Markdown
Collaborator

修复 bug:引导(steer)当前回复时,会话原来用的 CLI 和执行机器保不住。之前 Codex/Cursor 会话一引导,裸模型 ID 会被当成 CodeBuddy 处理,结果报「请先配置 CodeBuddy Key」。另外 followSteer 没把 Executor 和 ExecutionTarget 传下去,后续这一轮可能跑到云端,而不是原来绑定的执行机器。
新功能:新增一个按用户保存的设置项 steerOnSend,控制回复生成中发消息时是「排队」还是「立即发送」(立即发送就是直接引导)。

@newexploreor

Copy link
Copy Markdown
Collaborator

PR #1042 代码评审结论
建议修一处再合。 作者 crispinhu27,16 个文件,+450/−96。这个 PR 做了两件事:

修复 bug:引导(steer)当前回复时,会话原来用的 CLI 和执行机器保不住。之前 Codex/Cursor 会话一引导,裸模型 ID 会被当成 CodeBuddy 处理,结果报「请先配置 CodeBuddy Key」。另外 followSteer 没把 Executor 和 ExecutionTarget 传下去,后续这一轮可能跑到云端,而不是原来绑定的执行机器。
新功能:新增一个按用户保存的设置项 steerOnSend,控制回复生成中发消息时是「排队」还是「立即发送」(立即发送就是直接引导)。
测试情况
改动涉及的 Go 测试都通过了,包括新增的 TestSteerKeepsConversationCLI 16 个用例和 TestSteerContinuesFromPartialTranscript 7 个用例。repo 层新测试和 go vet 也通过。
chatbot 全部 vitest 通过(56 个文件 / 392 个用例),web/assistant_settings_test.js 通过。
跑整个 httpapi 包时,TestInstallStatusSurvivesAReload 失败,最后在 8 分钟超时处中断。这个测试在 main 上一样失败,原因是沙箱环境,和本 PR 无关;但因为超时,这次没有拿到整个包的完整结果。
必须修改

  1. 引导时 effort 的回退方式是一个回归

位置:internal/httpapi/assistant_generation.go:539

go

effort := firstNonEmpty(body.Effort, session.Effort)
前端在用户选「默认」,或者换模型后旧的 effort 不再适用时(modelEffort 返回 ""),会发送 effort: ""。服务端现在会退回到 session.Effort,再拿新模型去校验,于是请求被拒。

我写了一个临时测试复现(已删除):先用 claude-opus-5.5 + max 开一轮,生成中换成 gpt-6-sol 并选「默认」,然后引导:

本 PR:返回 400,模型 gpt-6-sol 不支持思考强度 "max"
main:返回 200
开了「立即发送」后,这种情况就是:用户换了模型再发消息,引导失败,消息退回队列,界面报错。另外用户选的「默认」在引导这条路上也不生效。普通发送(startGeneration)是直接用 req.Effort 的,所以两条路径的行为不一致。

建议:直接用 body.Effort 做校验并写进 steer;同时让 followSteer 能把空值当成「默认」,不要再用 firstNonEmpty 去恢复旧值。再补一个「换模型 + 默认 effort」的测试用例。

建议(不阻塞合并)
steer 接口没有 executor 字段。 裸模型 ID 现在一律当作会话已锁定的 CLI 的模型。正常 UI 下没问题,因为在已锁定的会话里换 CLI 会直接新开对话(chooseExecutor → open(null))。但这样一来,steer 和 /generations 的接口约定不一致:后者是用请求里的 executor 来判断。建议前端引导时也带上 executor,或者至少在注释里写清楚这个约定。
第二次 assistantEngineSwitchRefusal 检查基本不会触发(assistant_generation.go:531)。缺 key 和非法模型在前面已经被拦下了,assistantAllowedUserModel 不会再换成别的 CLI。可以删掉,或者注释说明它是防御性检查。
每次窗口获得焦点都会请求一次 /api/assistant/preferences。 已经有 postMessage 通知了,焦点刷新只是用来覆盖在其他标签页修改设置的情况。可以考虑节流,或者改用 visibilitychange。
引导失败会把消息退回队列且不暂停(restoreQueued(..., false))。如果失败原因是 409「不能切换 CLI」这类重试也没用的错误,当前回复结束后这条消息会自动再发一次,大概率还是失败,然后才被暂停。可以考虑对 4xx 错误直接暂停队列。
PR 粒度:标题写的是 fix,但里面还带了一个新功能、一个数据库迁移和设置页 UI 改动,建议拆成两个 PR,或者把标题改成 feat。CHANGELOG 可以在发版时补。
没发现问题的部分
迁移脚本 036 写法幂等,和 AGENTS.md 的约定一致(手动执行,启动时 AutoMigrate 也会补列)。repo 层和 handler 层的归属正确。
前端:引导进行中时再发的消息会排队,有停止请求时不会触发引导,偏好设置不会被较慢的旧请求覆盖。这几种情况都有测试,而且通过了。
设置页:「排队」仍是默认值;改了这一项保存按钮会变为可用,保存后会通知已打开的对话页刷新。
需要的话,我可以把这些意见作为 review comment 发到 PR 上(要你确认后才会发)。

@crispinhu27 crispinhu27 changed the title fix(assistant): preserve CLI during steering and add send preference feat(assistant): add send preferences and preserve the CLI during steering Nov 18, 2026

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 DeepSeek V4.1 Flash 实测生成中插话并按默认推理强度续跑通过。补充回归发现同文案插话会丢失新附件,已标在代码行。

Model: session.Model,
Effort: session.Effort,
ApprovalMode: steer.ApprovalMode,
Messages: session.Messages,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 连续发送相同文字时保留插话的新附件

开启「立即发送」后,若上一轮尚未产出可保存的回复,commitTurnTranscript 仅凭文字相同就会跳过新消息。本地用相同文字和两个不同文件复测,续跑用的对话记录只剩第一个文件。建议以插话请求的唯一标识去重,确保本次消息的附件和引用随续跑一起保存。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 DeepSeek V4.1 Flash 复测了相同文字、更换附件后立即发送,两条用户消息和各自的附件均正确保留。双标签页对同一轮连续插话时,已接受的消息仍可能丢失,见行内评论。

ActorName: user.LoginName,
TriggerID: rand.Text(),
}
if err := h.repo.SteerAssistantGeneration(ownerID, g.SessionID, g.ID, steer); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 保留已接受的插话,避免后续请求覆盖

我把同一轮生成留在运行中,模拟两个标签页先后发送不同插话。两个 POST 都返回 HTTP 200,续跑后的会话只保存了第二条。SteerAssistantGeneration 会直接覆盖待处理的 Steer,而发送成功的前端已经从队列移除了第一条。请在同一事务内检查是否已有待处理插话,并保留第二条待发送,或返回明确冲突让前端保留它。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上一轮的双标签页覆盖已修复。第二次插话返回 HTTP 409,第一条保留,SQLite 和独立 Docker MySQL 并发复测通过。DeepSeek V4.1 Flash 的正常插话续跑通过。补充复测发现回复收尾时接受的插话仍可能丢失,见行内评论。

Comment thread internal/repo/assistant_generations.go Outdated
return fmt.Errorf("生成已结束或不存在")
}
g := decodeGeneration(row)
if g.Steer != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 收尾时保留已经接受的插话

executeGeneration 最后一次读取 Steer 后,生成在数据库里仍是 running。这时第一条插话可返回 HTTP 200。最终 checkpoint 会把这条插话写进已完成的生成记录,worker 手里的 steer 仍为空,消息没有进会话记录,也没有启动续跑。我固定该时序连续复测三次,结果一致。建议用同一事务协调结束状态与待处理插话。收尾先完成时返回已有的结束冲突,让前端排到下一轮。插话先被接受时,把它交给当前 worker 或持久派发流程处理。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复测通过。插话先被接受时,原回复和新消息会保存,随后启动续跑。收尾先锁定时返回 409,前端按已结束转入下一轮队列。HTTP 收尾和 SQLite、Docker MySQL 并发回归加 -race 重复通过,DeepSeek V4.1 Flash 的真实插话续跑通过。

@crispinhu27
crispinhu27 merged commit 01ef8dd into main Nov 18, 2026
16 checks passed
@crispinhu27
crispinhu27 deleted the fix/steer-preserve-cli branch November 18, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants