Skip to content

fix(chat): /clear and /new actually reset the conversation#47

Merged
dnviti merged 1 commit into
chore/version-bump-5.1.2from
fix/issue-43-clear-reset
Jul 26, 2026
Merged

fix(chat): /clear and /new actually reset the conversation#47
dnviti merged 1 commit into
chore/version-bump-5.1.2from
fix/issue-43-clear-reset

Conversation

@dnviti

@dnviti dnviti commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • /clear and /new used to forward their text to the still-running agent process like any other message, then only add a cosmetic cleared marker that hid prior messages client-side. The very next message went to the same process with all its prior context, and a reconnect could resurrect the old transcript.
  • Routes clearing commands through the same "start fresh" restart path a manual relaunch already uses (ChatSessionStartOptions.startFresh): stop the live adapter, start a brand new one with no resume id. The cleared marker is now emitted by start() itself, after a genuinely new process is running — not before one has been asked to forget.
  • The session's persisted native id is cleared immediately and is repopulated once the new process announces itself, so a page reload / reconnect after a clear resumes the new conversation, not the old one.

Fixes #43

Test plan

  • npm run build && npx mocha --exit test/*.test.js — 1327 passing (was 1321; added test/chat-clear-reset.test.js)
  • npx tsc --noEmit (both server and client configs) — clean
  • Live-verified against the real claude CLI (not just adapter mocks): told the agent a secret word, sent /clear, then asked it to recall the secret — it correctly reported no memory of it, both on the very next message and after simulating a process stop + resume by the persisted native id (the reconnect scenario).

`/clear` and `/new` forwarded their text to the still-running agent
process like any other message, then only added a cosmetic marker
that hid prior messages in the UI. The next message sent it right
back into the same process, so the agent kept whatever context it
already had — the reset never really happened, only its display did.

Route clearing commands through the same restart path a manual
"start fresh" relaunch already uses: stop the live adapter and start
a new one with no resume id, so the next turn talks to a process that
was never handed the prior conversation. This also fixes the id
persisted for later reconnects, so a rejoin can't resurrect it either.

Fixes #43

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 26, 2026 15:15

Copilot AI 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.

Pull request overview

This PR fixes /clear and /new in chat sessions so they actually reset the agent’s underlying process/context (not just hiding prior messages client-side), aligning behavior with Issue #43 and ensuring a fresh conversation after clearing.

Changes:

  • Routes clearing commands through a new ChatSession.restart() path that stops the current adapter and starts a new one with startFresh: true and no resumeSessionId.
  • Stores the most recent launch options (lastStartOptions) to allow in-place restarts without reconstructing configuration.
  • Adds a mocha test suite to pin down expected /clear//new behavior at the ChatSession.send() level.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/server/chat/session.ts Adds lastStartOptions tracking and implements /clear//new as an actual adapter restart (restart()) instead of forwarding the command to the existing process.
test/chat-clear-reset.test.js Adds coverage ensuring clearing commands don’t reach the old adapter, trigger a fresh start with no resume id, and clear the in-memory native session id.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +579 to +583
await this.stop();
// Stale until the new process's own `init` event reports its id — cleared
// up front so nothing reads the old conversation's id in the meantime.
this.nativeSessionId = null;
await this.start({ ...options, resumeSessionId: undefined, startFresh: true });
Comment on lines +576 to +580
private async restart(): Promise<void> {
const options = this.lastStartOptions;
if (!options) return;
await this.stop();
// Stale until the new process's own `init` event reports its id — cleared
@dnviti
dnviti merged commit 70d26cf into chore/version-bump-5.1.2 Jul 26, 2026
5 checks passed
@dnviti
dnviti deleted the fix/issue-43-clear-reset branch July 26, 2026 15:22
dnviti added a commit that referenced this pull request Jul 26, 2026
…l /clear (v5.1.2) (#37)

* chore: bump version to 5.1.2

* feat(chat): let users override a conversation's model, independent of profile default (#39)

Adds a per-conversation model override so any chat session can switch or
type a custom model at any time, regardless of whether the underlying
runtime already supports it. Persisted on the session (mirrors the
chatBypassPermissions pattern), applied via a three-tier fallback
(live adapter.setModel -> best-effort /model slash command -> saved for
next launch), and always beats the runtime profile's default for that
conversation only. Composer's model chip becomes an always-enabled
combobox with free-text entry and honest per-outcome feedback, replacing
the old dead-end disabled state.

Closes #38

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>

* feat(chat): collapsible turn sections, auto-folded on a new turn (#34) (#40)

A long conversation used to be one unbroken wall of fully-expanded turns.
Each turn's strip now discloses/hides its own body; only the newest turn
opens by default, a turn the user has explicitly opened or closed stays
that way across new turns, and jumping to a turn via the rail or search
force-opens it. Expand-all/collapse-all lives in the turn index header.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>

* fix(chat): show Claude's slash commands from the moment a session opens (#41)

Claude's CLI does not report `slash_commands` until it has processed a
first turn's `system/init`, which only arrives after the first message
is written to its stdin. The chat session spawns the process as soon as
a chat is opened, well before any message is sent, so the command menu
and its composer button stayed empty — looking broken — until a
throwaway message unlocked them.

The adapter now advertises a static baseline built from this app's own
table of Claude's built-in commands as soon as it starts, so the menu
and button are populated immediately. The real `init` list — including
any project or plugin commands — still arrives with the first turn and
replaces this baseline outright, exactly as before.

ACP runtimes (kimi, omp) already report commands during their handshake,
before any message is sent, so they were never affected. codex, grok and
pi have no command support at all; the composer already hides the button
entirely rather than showing an empty menu, which is the honest behavior
for a runtime that offers none.

Closes #30

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>

* fix(chat): make /clear and /new actually reset the conversation (#47)

`/clear` and `/new` forwarded their text to the still-running agent
process like any other message, then only added a cosmetic marker
that hid prior messages in the UI. The next message sent it right
back into the same process, so the agent kept whatever context it
already had — the reset never really happened, only its display did.

Route clearing commands through the same restart path a manual
"start fresh" relaunch already uses: stop the live adapter and start
a new one with no resume id, so the next turn talks to a process that
was never handed the prior conversation. This also fixes the id
persisted for later reconnects, so a rejoin can't resurrect it either.

Fixes #43

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>

* fix(chat): show the answer as it streams, and keep a model override across /clear (#49)

Five defects introduced by the four PRs already merged onto the 5.1.2 branch.
Each one's own tests passed; all but one lived where two of them met.

The chat stopped rendering. MessageList looked messages up in a map memoised
on the messages array, but the transcript appends to that array in place, so
its identity never changes: the map was built once at mount and every message
after it resolved to nothing. The strips above kept ticking while the bodies
stayed empty, and reloading "fixed" it because reloading replaces the array.
Keyed on the transcript version instead, which is the cadence the neighbouring
memo already used — the list still does not re-render per token.

A model override no longer survives /clear. The restart replays the options
the session was launched with, and the model is the one thing in them that can
change while the session is alive, so the conversation quietly went back to
the model it opened with after the browser had been told the switch applied.
The choice now reaches those options too, by either door: the picker, and a
/model typed straight into the composer, which was forwarded untouched and hit
the same reversion.

A collapsed turn's title escaped its bar. It set neither a size nor nowrap
while every sibling in that fixed-height row sets both, so it inherited the
page default and wrapped — and without nowrap the ellipsis was inert.

An override could not be undone. The server had a "cleared" path, message and
all, that nothing in the UI could reach: the text field refuses to submit
empty and every listed model carries a name. A typo therefore stayed in force
for every later launch of that conversation.

Model names are now capped and stripped of control characters, which would
otherwise ride into the best-effort /model turn as extra lines.

The browser checks gated nothing: npm test runs only the unit suite, and the
runner exited 0 when Chrome was absent. With the rendering bug restored, npm
test passes 1357/1357 while the browser check fails. They now run in CI and
refuse to skip there. Their fixture also grew a second turn, without which no
turn is ever collapsed and the broken title was never rendered at all.

Every fix has a test confirmed to fail against the unfixed code.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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.

2 participants