Skip to content

fix(composer): skip predictions for occupied drafts - #6722

Merged
M4n5ter merged 4 commits into
rust-previewfrom
fix/prediction-composer-draft
Nov 10, 2026
Merged

M4n5ter merged 4 commits into
rust-previewfrom
fix/prediction-composer-draft

Conversation

@me2seeks

@me2seeks me2seeks commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Skip an unstarted next-message prediction when the composer contains a draft or attachment, including uploads. Clearing it later does not dispatch that turn's skipped prediction. While a saved draft or attachments are restoring, wait for their state before deciding whether to predict or skip.

An already-admitted prediction can finish and its result can be reused; typing or adding an attachment hides the suggestion without cancelling that request. A new turn or changed model context can predict normally. This preserves the source/configuration invalidation and prefix reuse introduced in #6568 without adding a setting or legacy behavior path.

Verification

  • node --test products/maka/workbench/tests/*.test.mjs: 173 passed at the review-fix commit.
  • The regression cases for occupied and restoring composers and a replacement source during cleanup failed against the preceding PR version and pass with this change.
  • TypeScript checks for packages/plugin-sdk/tsconfig.acceptance.json and products/maka/bundle/tsconfig.json: passed. The full contracts / workbench UI type check passed at the original PR commit, but was not rerun for the review-fix commit.
  • Biome check on changed TypeScript/JavaScript files and git diff --check: passed. The staged Biome, license and whitespace checks were run manually before committing because the pre-commit hook could not spawn biome.cmd under Node 26 on Windows.
  • Earlier node scripts/ci.mjs check tooling-tests had 283 passes, 2 failures, and 3 skips: release signing could not generate a GPG key, and the archive/cache test could not find usable Python on PATH.
  • Earlier node scripts/ci.mjs check format was blocked by a pre-existing ignored third-party/nsh/crates/gpui/target directory without a Cargo.toml. Native renderer integration tests were not run locally.

Remaining verification

  • Run the full tooling, format and workbench UI type checks in a correctly provisioned environment.
  • Exercise draft/attachment behavior in the native renderer.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka (GPT-6.1) investigated the original implementation, implemented the change and review follow-up, and authored tests and documentation. The commits include Generated-by trailers.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@me2seeks
me2seeks marked this pull request as ready for review November 9, 2026 14:35

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed the six-file change at bbbb16f4236d37d9345361e978c6ab28121cf523 against Rust baseline 09ca38c23ae9d46214c2743e182fe018c6544429. I found no demonstrated P0–P2 issue in this scope.

The controller now separates continued ownership of an admitted prediction from permission to start a new one. Conversation.tsx:2414 admits a new request only after draft restoration completes and text, staged files and attachment rows are empty. messagePrediction.ts:271 applies that admission check after handling the existing request; typing therefore does not cancel an already admitted operation. The existing source, settings-revision, cancellation and receipt checks remain in place. Composer.tsx:82 also suppresses presentation during attachment restoration or while attachment rows remain.

I ran all 170 workbench JavaScript tests successfully with Node 24.18.1 and the locked, patched Pele dependency, including the eight prediction tests. Running the same eight tests with only the controller restored from the baseline gives seven passes and one failure: the occupied draft incorrectly starts a request while preferences finish loading. I also checked the production caller and the draft/attachment restoration gates. These are controller and component-source checks; I did not execute the complete native composer or a live remote prediction service.

The actual merge into 09ca38c2 succeeds. There is no database-schema or wire-contract change. CI run 42633305895, attempt 1 has since completed successfully at this same head, including its final aggregate. Current Rust has subsequently advanced to 12971e440e93af1501872ec8eaf6bd781360ba92 through #6726; an actual merge of this PR into that baseline also succeeds. The new baseline has its own pending CI; the previous run does not validate an arbitrary later integration.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@M4n5ter

M4n5ter commented Nov 10, 2026

Copy link
Copy Markdown
Member

@me2seeks

English

Thanks for working on this! Avoiding new prediction requests when the composer already has a draft/attachment, hiding suggestions while attachments are restoring or uploading (Composer.tsx), and keeping an already-admitted in-flight prediction alive when the user starts typing all make sense.

One design adjustment requested before merging: when the composer is occupied, please skip/retire an unstarted prediction for that turn instead of deferring it until the composer is cleared.

Deferring an unsettled source and firing predictNextMessage later when draft becomes empty introduces two undesirable billing behaviors:

  1. Rewording a draft (Select All → Backspace → retype): When a turn finishes while the user already has a draft, clearing the box to rephrase momentarily flips mayStart to true and immediately dispatches predictNextMessage. Because an admitted request is not cancelled when typing resumes ~200ms later, that request runs to completion and bills tokens even though its output will never be shown.
  2. Cold prompt-cache rebuilds after idle time: live predictions are normally cheap right at turn completion because read_frozen_model_request hits the provider's warm prompt cache. Cache TTL and pricing vary by provider (for example, a ~5-minute ephemeral cache TTL with roughly a ~10x gap between cached reads and cold input / cache writes). If a prediction is deferred because a draft was present and the user comes back after the provider's cache has expired and clears that old draft, the controller still dispatches predictNextMessage with trigger: 'live' (100% default sample rate) against a cold prefix—paying full uncached input / cache-rebuild cost across the entire conversation history just for pressing Backspace.

Suggested state behavior

Distinguish three composer states in Conversation.tsx / messagePrediction.ts:

  1. Restoring (!draftReady() || attachments.restoring()): Wait without starting or retiring source yet, so opening a session neither fires before saved draft/attachments load nor prematurely retires an empty composer.
  2. Occupied (restoration complete, and draft() !== '' || attachments.files().length > 0 || attachments.rows().length > 0 / Boolean(attachments.blocked())):
    • If a request for source is already in flight, let it finish and keep its settled result reusable if the user clears their typo (same as your current PR).
    • If no request has been admitted yet (!request && source.state.kind === 'unsettled'), retire/skip source for this turn so later clearing the draft/attachments does not dispatch a delayed prediction.
  3. Empty (restoration complete, draft and attachments empty): Admit new predictions normally.

Please also update the README.md / README.zh-CN.md wording and the test in message-prediction.test.mjs to assert that clearing a previously occupied draft does not dispatch a late prediction for that same turn (until a new turn/context replaces source).

简体中文

感谢处理这个问题!在输入框已有草稿或附件时不发起新的预测请求、在附件恢复或上传期间隐藏建议(Composer.tsx),以及在用户开始输入时不取消已在途的预测请求,这几项改动方向都是合理的。

合并前希望调整一个设计点:当输入框处于非空占用状态时,如果当前轮次的预测尚未发起,请直接跳过/退役本轮预测,而不要挂起等待输入框清空后再补发。

把未发起的 source 挂起并在后续 draft 变空时补发 predictNextMessage,会带来两种不合理的计费行为:

  1. 重写草稿(全选 → 删除 → 重新输入)时白白扣费:当模型回复结束时用户框里已有草稿,若用户想换个说法、全选删空准备重打,删空瞬间 mayStart 变为 true 会立刻发出 predictNextMessage;又因为已准入的请求在 200ms 后继续打字时不会被取消,这次请求会跑完全程并扣费,但结果永远不会展示。
  2. 闲置后清空旧草稿触发冷缓存重算:正常情况下,live 预测紧跟在回复完成瞬间发起,read_frozen_model_request 能直接命中服务商刚热好的前缀缓存。不同服务商的缓存策略与定价不同(例如常见的约 5 分钟缓存 TTL、缓存命中与冷输入/重建缓存之间约 10 倍的价差):如果因为当时有草稿而把预测挂起,等用户过了缓存有效期再回来随手删掉旧草稿,控制器仍会按 trigger: 'live'(默认 100% 采样率)对已经失效的冷前缀发起预测——仅仅按了一下退格键,就会为整段历史上下文支付全额冷输入/重建缓存费用。

建议的状态行为

在 Conversation.tsx / messagePrediction.ts 中区分三种输入框状态:

  1. 恢复中(!draftReady() || attachments.restoring()):仅等待,既不发起请求也不提前退役 source,避免打开会话时抢在本地草稿/附件加载前误发请求,或把本就空白的输入框提前跳过。
  2. 已占用(恢复完成,且 draft() !== '' || attachments.files().length > 0 || attachments.rows().length > 0 / Boolean(attachments.blocked())):
    • 若当前 source 已有在途请求,保持现有逻辑让其完成,以便用户删掉误输入时直接复用结果;
    • 若当前 source 尚未发起请求(!request && source.state.kind === 'unsettled'),直接跳过/退役本轮 source,后续清空草稿或附件时不再补发延迟预测。
  3. 空白(恢复完成,且草稿与附件均为空):正常准入新的预测请求。

同时请同步更新 README.md / README.zh-CN.md 的描述,以及 message-prediction.test.mjs 中的对应测试(断言草稿占用跳过后,再清空草稿不会对同一轮补发预测,直到新轮次或新上下文替换 source)。

@me2seeks me2seeks changed the title fix(composer): defer predictions while the draft is occupied fix(composer): skip predictions for occupied drafts Nov 10, 2026
@me2seeks

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 9238ef6: an occupied composer now retires an unstarted source, so clearing it does not dispatch a delayed prediction; restoration waits without retiring, and admitted predictions still finish. The tests also cover replacement while an older request drains and settings changes while occupied. All 173 workbench tests pass locally; the PR description records the remaining environment and native-renderer verification limits.

— Maka (AI agent)

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed the six-file change at 9238ef6c186022ebcc21a509466eadf4d5f5c683, including the follow-up to bbbb16f4. I found no demonstrated P0–P2 issue in this scope. The documented behavior now skips an unstarted prediction for an occupied composer rather than merely delaying it until the draft is cleared. A restoring composer waits for its contents before deciding. An already admitted prediction can finish, while source, context, preference-revision, cancellation and original-receipt ownership checks remain in place.

I checked the caller's restoring/occupied/empty classification, draft and attachment gates, the controller's skipped state and request-draining paths, and both README descriptions. All 173 workbench JavaScript tests pass with Node 24.18.1 and the locked, patched dependencies, including all 11 message-prediction tests. Running those same 11 tests with only the controller restored from bbbb16f4 produces seven passes and four failures: occupation while settings load, restoration waiting, a replacement source while an older request drains, and stale-result regeneration after a settings change. Biome accepts all four changed TypeScript/JavaScript files. The temporary controller replacement was restored and the worktree is clean.

The actual merge into current Rust c20025e904a94c2b68020c9705a6a1bb19fe9a7f succeeds. No database-schema or wire-contract change is introduced. Current-head CI 42741683570 has not completed, so the old commit's successful CI does not establish the current commit's result. I did not run native composer/IME integration, a live prediction service, full UI typechecking, or packaged-app and populated-session acceptance. The author's results remain attributed to the author.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@me2seeks

Copy link
Copy Markdown
Contributor Author

I compared the failed CI jobs against upstream before updating the branch:

  • PR macOS native job and upstream macOS job fail the same desktop_file_gestures_preserve_drafts_and_stage_an_image test with the same missing-draft/Null assertion.
  • PR CLI slice and upstream CLI slice fail the same editor_copy_and_undo_precede_interrupt_and_ctrl_c_requires_confirming_the_current_run test waiting for the UI state. Its fixture disables message predictions.

Merged current rust-preview at 853052b in c7e1d62. After the merge, all 154 workbench JS tests and the changed-file Biome check pass locally. The new CI run must still complete; these upstream failures are not being bypassed.

— Maka (AI agent)

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed integration commit c7e1d625fcc804a9dd5a8383cb050dd863b78fc6 and the six-file author patch against 853052bec2f7c31aaefcf0beceeb0c7ad504fbb5. Its tree is exactly the actual merge of previously reviewed 9238ef6c with that base, and the author patch has the same stable patch identity. There is no new author logic in this integration, and I found no new demonstrated P0–P2 issue in that scope.

The reviewed behavior remains: a restoring composer waits for its contents, an occupied composer skips an unstarted prediction, clearing it does not resurrect that same skipped source/context, and an already admitted prediction can finish under the original source/configuration/receipt fences. I checked the incoming Composer changes separately from those admission and presentation gates. The 173-test workbench result and the 11-test controller comparison (seven passes/four failures with the old controller) were executed at 9238ef6c; I did not rerun them locally at this integration commit or claim native-composer acceptance.

Current-head CI 42749835323 is still running but already has failures: CLI slice 2 times out in the copy/undo test at 69.721s (18 passes, one failure, 94 skipped), and Mac times out in desktop_file_gestures_preserve_drafts_and_stage_an_image at 65.552s (four passes, one failure, 17 not run). I read the original logs, verified checkout 61e0787c989358c2e4b868ca30f8a9cf6fb4a93a and matched its parents/tree to the actual merge. The unmodified base also fails the CLI test, and the earlier base has the same Mac test failure; I have not isolated a PR-specific cause. Windows also fails desktop_side_pane_keeps_its_draft_separate_when_closed_and_reopened at 72.801s (18 passes, one failure, three not run), with the same verified checkout; its cause is not isolated here. The old 9238ef6c run finished cancelled and does not establish this commit's result.

An actual merge into the newer Rust baseline a75113d8b7d0cccf181a4d4214dab962e9124ac2 now conflicts because that baseline deletes products/maka/workbench/tests/message-prediction.test.mjs while this PR modifies it. There are no schema or wire changes in this PR. Integration of the changed baseline contracts, full UI typechecking, native composer/IME behavior, live prediction-service checks, and packaged/populated-session acceptance remain unverified here. The author's results remain attributed to the author.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@me2seeks

Copy link
Copy Markdown
Contributor Author

The CI run after merging upstream, 42749835323, completed with failures:

  • Linux CLI slice 2/6: editor_copy_and_undo_precede_interrupt_and_ctrl_c_requires_confirming_the_current_run timed out with its draft still visible. The upstream 853052bec run fails the same test in the same way.
  • macOS native: desktop_file_gestures_preserve_drafts_and_stage_an_image timed out waiting for the restored draft, observing Null. The same test and assertion fail on upstream c20025e90.
  • Windows native: desktop_side_pane_keeps_its_draft_separate_when_closed_and_reopened timed out waiting for SIDE_DRAFT, observing Null. Upstream Windows also failed on a missing-draft/Null assertion in a different test before reaching this one, so this particular failure is not yet conclusively attributed.
  • The aggregate test check failed because the planned jobs failed; no failing or skipped suite was overridden.

I did not merge the PR. Local post-merge workbench tests passed (154/154). The native failures require further investigation or an upstream fix before a green aggregate.

— Maka (AI agent)

@M4n5ter
M4n5ter merged commit 014e2c6 into rust-preview Nov 10, 2026
1 check passed
@M4n5ter
M4n5ter deleted the fix/prediction-composer-draft branch November 10, 2026 04:32
@me2seeks

Copy link
Copy Markdown
Contributor Author

Windows side-pane follow-up (Maka, AI agent):

I ran the real Windows native-desktop side-pane test in a separate local worktree, with LC_ALL=en_US.UTF-8 to match CI. With PR merge c7e1d62, 5 of 10 runs passed and 5 timed out (three at SIDE_DRAFT, two at MAIN_DRAFT).

For the control, I restored all six PR-modified files to upstream 853052b, verified git diff --quiet 853052bec -- for the entire tracked tree, and rebuilt maka-cli and its product bundle. Of three actual direct test runs, two reproduced the same SIDE_DRAFT/Null failure and one passed. A prior control run via cargo test also failed at MAIN_DRAFT. Seven subsequent attempted iterations could not start because the locally managed target binary disappeared; they are not counted as test results.

This demonstrates the CI symptom exists without this PR, although the small sample does not establish whether timing affects its frequency. The test checks text by issuing Select All and Copy back-to-back. Upstream #6731 specifically addresses that keymap race; its Windows CI currently fails earlier at an unrelated maka_event_log::root::windows::account_home unresolved import, so I have not verified the upstream fix with this Windows test.

No PR code change was made for this existing failure.

— Maka (AI agent)

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