Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Guard Assistant composer submit dispatch

rcourtman3f57ee5a0b4f
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 7c918873bc..5fdad8631a 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -152,6 +152,18 @@ runtime cost control, and shared AI transport surfaces.
(lines 607-610). Pulse adapts that source behavior with a drawer-local
composer stash so normal close/reopen does not drop an unsent user thought
or downgrade a scoped queued follow-up into a plain prompt.
+ Composer submission must read the live input buffer at submit time and
+ suppress only overlapping dispatches from the same browser interaction. The
+ referenced OpenCode source at commit
+ `9ed17da55ab1f7360cc0e01075f763e27fa899e9`
+ `packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx` guards
+ `Prompt.submit()` with local `submitting` state (lines 910-924) and syncs
+ the live input `plainText` into prompt state before downstream reads
+ (lines 930-936) so double-dispatch and IME/composition races do not send a
+ stale or phantom prompt. Pulse adapts that by reading the live textarea
+ value before trimming and by using a one-dispatch composer guard that still
+ releases immediately for intentional queued follow-ups during an active
+ turn.
Failed-turn retry is part of that same local chat-runtime boundary: a
retryable in-memory assistant error may replay the original user turn's
structured mentions, finding id, approval override, handoff resources,
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index 728db0326d..5131df8c25 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -1320,6 +1320,64 @@ describe('AIChat', () => {
expect(mockChat.sendMessage).toHaveBeenCalledWith('hello world', undefined, undefined);
});
+ it('submits the live textarea value when composition text has not reached state', () => {
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+
+ textarea.value = ' final composed text ';
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ expect(mockChat.sendMessage).toHaveBeenCalledWith(
+ 'final composed text',
+ undefined,
+ undefined,
+ );
+ });
+
+ it('ignores overlapping submit dispatches before the composer clear reaches the DOM', () => {
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+ const form = textarea.closest('form');
+ expect(form).toBeTruthy();
+
+ fireEvent.input(textarea, { target: { value: 'duplicate prompt' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+ textarea.value = 'duplicate prompt';
+ fireEvent.submit(form!);
+
+ expect(mockChat.sendMessage).toHaveBeenCalledTimes(1);
+ expect(mockChat.sendMessage).toHaveBeenCalledWith(
+ 'duplicate prompt',
+ undefined,
+ undefined,
+ );
+ });
+
+ it('releases the submit guard for the next intentional follow-up', async () => {
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+
+ fireEvent.input(textarea, { target: { value: 'first prompt' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+ await Promise.resolve();
+
+ fireEvent.input(textarea, { target: { value: 'follow-up prompt' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ expect(mockChat.sendMessage).toHaveBeenCalledTimes(2);
+ expect(mockChat.sendMessage).toHaveBeenLastCalledWith(
+ 'follow-up prompt',
+ undefined,
+ undefined,
+ );
+ });
+
it('recalls submitted prompts with ArrowUp and ArrowDown from the empty composer', async () => {
renderChat();
const textarea = screen.getByPlaceholderText(
@@ -1328,6 +1386,7 @@ describe('AIChat', () => {
fireEvent.input(textarea, { target: { value: 'first prompt' } });
fireEvent.keyDown(textarea, { key: 'Enter' });
+ await Promise.resolve();
fireEvent.input(textarea, { target: { value: 'second prompt' } });
fireEvent.keyDown(textarea, { key: 'Enter' });
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index f07e9e0f53..b53225211b 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -567,6 +567,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
const [accumulatedMentions, setAccumulatedMentions] = createSignal<MentionResource[]>([]);
let textareaRef: HTMLTextAreaElement | undefined;
let interruptArmTimeout: ReturnType<typeof setTimeout> | undefined;
+ let composerSubmitDispatchLocked = false;
const focusComposer = () => {
queueMicrotask(() => {
@@ -1791,11 +1792,27 @@ export const AIChat: Component<AIChatProps> = (props) => {
});
};
+ const readComposerInputForSubmit = () => {
+ // Composition/IME updates can reach the textarea before the controlled signal
+ // flushes, so the live DOM value is authoritative for submit.
+ if (typeof textareaRef?.value === 'string') return textareaRef.value;
+ return input();
+ };
+
// Handle submit
const handleSubmit = () => {
- const submittedInput = input();
+ if (composerSubmitDispatchLocked) return;
+
+ const submittedInput = readComposerInputForSubmit();
const prompt = submittedInput.trim();
if (!prompt) return;
+ composerSubmitDispatchLocked = true;
+ queueMicrotask(() => {
+ composerSubmitDispatchLocked = false;
+ });
+ if (submittedInput !== input()) {
+ setInput(submittedInput);
+ }
const mentions = accumulatedMentions();
const submittedMentions = cloneMentions(mentions);
const mentionsForAPI =