Skip to content

fix: let Send become Stop while a turn is running - #38

Open
bluzername wants to merge 1 commit into
0xnyn:mainfrom
bluzername:fix/stop-in-progress-chat
Open

bluzername wants to merge 1 commit into
0xnyn:mainfrom
bluzername:fix/stop-in-progress-chat

Conversation

@bluzername

Copy link
Copy Markdown

Closes #29.

What is wrong

Right now the composer's Send button just goes disabled for the whole time
a turn is running. If you notice a mistake in what you asked right after
you send it, there is no way to stop and fix it, you just wait for the
answer to finish.

Why it was easy to add

The daemon already support cancelling. server/src/index.ts has a
case "cancel": jobs.get(parsed.jobId)?.abort?.abort(), and the protocol
already carry { type: "cancel", jobId }. Even the client comment at
keepVisual say a cancel keeps the pending deltas queued "so Send tries
again rather than starting from nothing" - it was designed for, just the
button never sent it.

The fix

While awaiting is true, the Send button now stay enabled and turn into
Stop (icon and aria-label change too). Clicking it while a job is running
send { type: "cancel", jobId: this.activeJobId } instead of trying to
submit again. Once the job finish (done or cancelled), the button go back
to Send.

I did not touch anything on the server side, it was already there.

Testing

Added packages/overlay/src/app.stop.test.ts, two cases:

  • Send flips to Stop once a turn start, and clicking Stop after
    job:created sends exactly one cancel message with the job id (not a
    second edit).
  • once job:done arrives the button go back to Send and a new turn can be
    submitted normally.

Both were RED on the old code first (I checked, the button just stayed
disabled and no cancel message ever appeared), then GREEN after the change.

Ran locally:

  • pnpm vitest run in packages/overlay - 77 files, 1175 tests, all pass
  • tsc --noEmit in packages/overlay - clean
  • biome check on the two changed files - clean (format + lint)

I used Claude Code to help write and test this change.

Right now the Send button just goes disabled the whole time a turn runs. If
you notice a mistake in what you asked, you have to wait for it to finish,
you cannot fix it early.

The daemon already know how to cancel a job, server/src/index.ts has a
"cancel" case that abort the job by id. Nothing in the composer ever sent
that message though.

This add a Stop state for the button while awaiting is true. It swap the
icon and label, and clicking it now sends {type: "cancel", jobId} instead
of doing nothing. When the job end (done or cancelled) the button go back
to Send.

Tests in app.stop.test.ts cover both directions: Send turns into Stop and
sends the cancel message with the right job id, and it reverts to Send once
job:done arrives so the next turn can go out normally.

This branch has not been deployed

No deployments
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.

Add ability to stop an in-progress chat response

1 participant