-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(kimi-code): queue submissions until the slash-command catalog is ready #3480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
7Sageer
wants to merge
1
commit into
main
Choose a base branch
from
fix/tui-dynamic-commands-ready
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Fix slash commands typed right after startup being sent to the model as plain text instead of activating the skill. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Readiness gate for the dynamic (skill/plugin) slash-command catalog. While | ||
| * the gate promise is pending, `dispatchInput` defers every submission so a | ||
| * slash command typed right after startup still resolves against the loaded | ||
| * catalog instead of falling through to the model as plain text. | ||
| * | ||
| * The gate resolves when the catalog load settles — success or failure, the | ||
| * gate is infallible by construction so queued drains can never be dropped by | ||
| * a rejection — or when the fallback timeout fires, whichever comes first. On | ||
| * timeout `onTimeout` receives the user-facing warning and the gate clears | ||
| * anyway: a wedged load (e.g. stuck IPC) must not queue input forever. A load | ||
| * that settles after the timeout still applies its results; the gate only | ||
| * bounds how long input dispatch waits. | ||
| */ | ||
|
|
||
| import { DYNAMIC_COMMANDS_READY_TIMEOUT_MS } from '#/tui/constant/kimi-tui'; | ||
|
|
||
| export function createDynamicCommandsGate( | ||
| load: Promise<unknown>, | ||
| onTimeout: (warning: string) => void, | ||
| ): Promise<void> { | ||
| return new Promise<void>((resolve) => { | ||
| let settled = false; | ||
| const timer = setTimeout(() => { | ||
| settle(); | ||
| onTimeout( | ||
| 'Skill and plugin catalogs are still loading — slash commands may be incomplete for a moment.', | ||
| ); | ||
| }, DYNAMIC_COMMANDS_READY_TIMEOUT_MS); | ||
| // Never hold the process open for the fallback: quitting while a catalog | ||
| // load is wedged must not wait out the timer. | ||
| timer.unref(); | ||
| function settle(): void { | ||
| if (settled) return; | ||
| settled = true; | ||
| clearTimeout(timer); | ||
| // oxlint-disable-next-line promise/no-multiple-resolved -- `settled` guards the single resolve; the rule cannot see it | ||
| resolve(); | ||
| } | ||
| void load.then(settle, settle); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
apps/kimi-code/test/tui/utils/dynamic-commands-gate.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { DYNAMIC_COMMANDS_READY_TIMEOUT_MS } from '#/tui/constant/kimi-tui'; | ||
| import { createDynamicCommandsGate } from '#/tui/utils/dynamic-commands-gate'; | ||
|
|
||
| describe('createDynamicCommandsGate', () => { | ||
| it('clears the gate with a warning when the catalog load does not settle in time', async () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| const onTimeout = vi.fn(); | ||
| let resolveLoad!: () => void; | ||
| const load = new Promise<void>((resolve) => { | ||
| resolveLoad = resolve; | ||
| }); | ||
| const ready = createDynamicCommandsGate(load, onTimeout); | ||
|
|
||
| await vi.advanceTimersByTimeAsync(DYNAMIC_COMMANDS_READY_TIMEOUT_MS); | ||
|
|
||
| expect(onTimeout).toHaveBeenCalledWith( | ||
| 'Skill and plugin catalogs are still loading — slash commands may be incomplete for a moment.', | ||
| ); | ||
| await ready; | ||
|
|
||
| // A load that settles after the timeout still resolves quietly — the | ||
| // warning fires once. | ||
| resolveLoad(); | ||
| await ready; | ||
| expect(onTimeout).toHaveBeenCalledTimes(1); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
| } | ||
| }); | ||
|
|
||
| it('resolves without warning when the load settles before the timeout', async () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| const onTimeout = vi.fn(); | ||
| let resolveLoad!: () => void; | ||
| const load = new Promise<void>((resolve) => { | ||
| resolveLoad = resolve; | ||
| }); | ||
| const ready = createDynamicCommandsGate(load, onTimeout); | ||
|
|
||
| resolveLoad(); | ||
| await ready; | ||
| await vi.advanceTimersByTimeAsync(DYNAMIC_COMMANDS_READY_TIMEOUT_MS * 2); | ||
|
|
||
| expect(onTimeout).not.toHaveBeenCalled(); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
| } | ||
| }); | ||
|
|
||
| it('resolves even when the load rejects, so queued drains are never dropped', async () => { | ||
| const ready = createDynamicCommandsGate(Promise.reject(new Error('wedged IPC')), vi.fn()); | ||
| await expect(ready).resolves.toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When multiple inputs arrive during this gate, these independent promise callbacks preserve only callback-start order, not actual submission order. For example, with an active session, if the first prompt contains freshly pasted media,
sendNormalUserInputpauses atpendingMediaIngestions(lines 1352–1364), while a following plain prompt proceeds synchronously and starts the turn; when the first resumes, it is queued behind the second. Drain deferred inputs serially through the point where each input is accepted or queued so the FIFO guarantee is maintained for asynchronous preparation paths.Useful? React with 👍 / 👎.