Skip to content

fix(cockpit): stop c-input demo double-submitting the user message#727

Merged
blove merged 2 commits into
mainfrom
claude/fix-c-input-double-submit
Jun 23, 2026
Merged

fix(cockpit): stop c-input demo double-submitting the user message#727
blove merged 2 commits into
mainfrom
claude/fix-c-input-double-submit

Conversation

@blove

@blove blove commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What

The cockpit/chat/input demo (app-input) submitted every user turn twice, producing a phantom third chat-message in the list.

Root cause

<chat-input [agent]="agent"> already submits to its bound agent inside the primitive's onSubmit() and emits (submitted) purely as a post-submit notification. The demo also handled (submitted) by calling agent.submit() again:

<chat-input [agent]="agent" (submitted)="submitMessage($event)" />
// ...
submitMessage(content: string) { this.agent.submit({ message: content }); }

So each "Hello" produced two user messages with distinct ids → 3 chat-message elements where the e2e expects 2.

Fix

Drop the redundant (submitted) handler and the submitMessage method. The [agent] binding is the single submit path. Added a short comment so the pattern isn't reintroduced.

Verification

  • nx e2e cockpit-chat-input-angular2 passed (the chat-message-list renders both turns / toHaveCount(2) assertion now green).
  • nx lint/build for cockpit-chat-input-angular → green.

This is a pre-existing demo bug, surfaced (not caused) by the subagent-card work in #721 — fixed separately as requested.

🤖 Generated with Claude Code

The chat-input primitive submits to its bound [agent] inside onSubmit()
and emits (submitted) purely as a post-submit notification. The c-input
demo also handled (submitted) by calling agent.submit() again, so every
turn produced two user messages — surfacing as a phantom third
chat-message in the list (the c-input e2e count assertion caught it).

Drop the redundant (submitted) handler and the submitMessage method; the
[agent] binding is the single submit path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@blove blove enabled auto-merge (squash) June 23, 2026 01:30
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
threadplane Ready Ready Preview, Comment Jun 23, 2026 1:34am

Request Review

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 1m 0s —— View job


Review

  • Read diff and changed file
  • Checked (submitted) contract in chat-input.component.ts
  • Scanned other demo components for the same pattern
  • Posted findings

The fix is correct. ChatInputComponent.onSubmit() calls submitMessage(agent, text) internally and only then emits (submitted) as a post-submit notification (chat-input.component.ts:147–149). The removed submitMessage() handler was calling agent.submit() a second time, doubling every user turn.

The explanatory comment added in the template is good — the misuse pattern was easy to fall into and the comment prevents re-introduction.


Issue: same double-submit bug exists in the messages demo

cockpit/chat/messages/angular/src/app/messages.component.ts has an identical copy of the bug that wasn't touched by this PR:

// line 72
<chat-input [agent]="agent" (submitted)="submitMessage($event)" />

// lines 94-96
submitMessage(content: string) {
  this.agent.submit({ message: content });
}

This will produce the same duplicate-message behaviour in the cockpit/chat/messages demo. Fix this →

(The chat.component.ts usage of (submitted)="onUserSubmitted()" is fine — that handler only does UI bookkeeping like pinned.set(true), it never calls agent.submit() again.)


@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 43s —— View job


Review

  • Read diff and source file
  • Analyze correctness and patterns

Verdict: LGTM. The fix is correct and minimal.

The root cause diagnosis is accurate — (submitted) is a post-submit notification, not a submit trigger, and the old demo was calling agent.submit() twice. Removing the submitMessage() method and the event binding is exactly the right fix.

One minor suggestion: the added HTML comment spans two lines where the code style guidelines prefer single-line comments. It could be collapsed to:

<chat-input [agent]="agent" />

But the two-liner version is still clear and explains a genuinely non-obvious API contract, so this is not blocking.

No other issues found — no correctness bugs, no security issues, no type-safety regressions, no Angular/RxJS pitfalls.

@github-actions github-actions Bot 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.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove blove merged commit 2e69985 into main Jun 23, 2026
21 of 22 checks passed
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.

1 participant