Skip to content

Conversation

@catbilyeu
Copy link
Contributor

Fixes #5651

Summary

When using /clear to reset the conversation, the context progress bar was showing the old token usage percentage instead of resetting to 0%.

This was because the /clear command cleared the messages but did not reset the token count metadata stored in the session database.

Changes:

  • Reset total_tokens, input_tokens, and output_tokens to 0 when clearing the conversation in the /clear command handler
  • Token counts are now properly synchronized with the cleared state

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

  • Manually tested by building and running goose-cli v1.13.0
  • Verified context bar resets to 0% after /clear command
  • Confirmed no compilation errors with cargo check

Related Issues

Relates to #5651
Discussion: #5651

Screenshots/Demos (for UX changes)

Before:
contextbarbug
After:
PNG image

Submitting a Recipe?

Email:

@catbilyeu catbilyeu force-pushed the fix/context-bar-reset-5651 branch 2 times, most recently from 99e9c7f to 396a338 Compare November 10, 2025 16:00
Fixes block#5651

When using /clear to reset the conversation, the context progress bar
was showing the old token usage percentage instead of resetting to 0%.

This was because the /clear command cleared the messages but did not
reset the token count metadata stored in the session database.

Changes:
- Reset total_tokens, input_tokens, and output_tokens to 0 when
  clearing the conversation in the /clear command handler
- Token counts are now properly synchronized with the cleared state

Testing:
- Manually tested by building and running goose-cli v1.13.0
- Verified context bar resets to 0% after /clear command
- Confirmed no compilation errors with cargo check

Signed-off-by: Cat Bilyeu <[email protected]>
@catbilyeu catbilyeu force-pushed the fix/context-bar-reset-5651 branch from 396a338 to f11da5c Compare November 10, 2025 16:04
@DOsinga DOsinga requested a review from katzdave November 10, 2025 16:39
@angiejones angiejones requested a review from Copilot November 10, 2025 19:38
Copy link
Contributor

Copilot AI left a comment

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 a bug where the context progress bar was not resetting to 0% after using the /clear command. The issue occurred because clearing the conversation only removed messages but did not reset the token count metadata stored in the session database.

Key changes:

  • Added token count reset logic to the /clear command handler
  • Token counts (total_tokens, input_tokens, output_tokens) are now set to 0 when clearing the conversation

Improved the /clear command to maintain consistency between in-memory
and database state, even if database operations fail:

- Perform database operations before clearing in-memory state
- Add recovery logic if token reset fails after conversation is cleared
- Reset accumulated token counts (previously missed)
- Clear in-memory messages only after confirming DB operations succeed

This prevents inconsistent states where messages and token counts could
become mismatched if database operations fail mid-execution.

Addresses Co-Pilot feedback on PR block#5652 with a more robust solution
that handles partial failure scenarios.

Signed-off-by: Cat Bilyeu <[email protected]>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Remove unnecessary comments
- Keep only current token counts reset (preserve accumulated tokens for desktop view)
- Remove recovery logic, just error and continue if operations fail
- Add newline before "Chat context cleared" message for better formatting

Signed-off-by: Cat Bilyeu <[email protected]>
Copy link
Collaborator

@katzdave katzdave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

tracing::info!("Chat context cleared by user.");
output::render_message(
&Message::assistant().with_text("Chat context cleared."),
&Message::assistant().with_text("\nChat context cleared."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think \n on the other end I wasn't seeing a line break before the next prompt but if this renders well can go with this too.

@katzdave katzdave merged commit 075cbb2 into block:main Nov 13, 2025
14 checks passed
katzdave added a commit that referenced this pull request Nov 13, 2025
…eanup

* 'main' of github.com:block/goose: (46 commits)
  Fix context progress bar not resetting after /clear command (#5652)
  docs: removing double announcements (#5714)
  docs: mcp sampling support (#5708)
  hackathon banner  (#5710)
  Fix documentation-only change detection for push events (#5712)
  Added transaction commits to multi sql functions in session_manager (#5693)
  fix: improve and simplify tool call chain rendering (#5704)
  Fix: Always show autocompact threshold ui (#5701)
  chore: Update governance to include Discord (#5690)
  Ollama improvements (#5609)
  feat: add Supabase MCP server to registry (#5629)
  Unlist VS Code extension tutorials from MCP and experimental sections (#5677)
  fix: make image processing work in github copilot provider (#5687)
  fix: do not take into account gitignore in developer mcp (#5688)
  docs: session storage migration (#5682)
  New maintainers (#5685)
  chore: Update governance (#5660)
  chore(release): release version 1.14.0 (minor) (#5676)
  fix : action icons overlap session title in chat history (#5684)
  Document recent goose PRs (#5683)
  ...
tlongwell-block added a commit that referenced this pull request Nov 14, 2025
* origin/main: (51 commits)
  Compaction resiliency improvements (#5618)
  docs: ask goose button (#5730)
  Update prompt injection detection metrics (due to errors exporting to datadog) (#5692)
  Spence/icon2 tokyo drift (#5728)
  docs: logs rotation and misc updates (#5727)
  docs: automatic ollama model detection (#5725)
  Fix context progress bar not resetting after /clear command (#5652)
  docs: removing double announcements (#5714)
  docs: mcp sampling support (#5708)
  hackathon banner  (#5710)
  Fix documentation-only change detection for push events (#5712)
  Added transaction commits to multi sql functions in session_manager (#5693)
  fix: improve and simplify tool call chain rendering (#5704)
  Fix: Always show autocompact threshold ui (#5701)
  chore: Update governance to include Discord (#5690)
  Ollama improvements (#5609)
  feat: add Supabase MCP server to registry (#5629)
  Unlist VS Code extension tutorials from MCP and experimental sections (#5677)
  fix: make image processing work in github copilot provider (#5687)
  fix: do not take into account gitignore in developer mcp (#5688)
  ...
wpfleger96 added a commit that referenced this pull request Nov 14, 2025
* main: (65 commits)
  Fix: Recipes respect the quiet flag (#5743)
  docs: update cli commands (#5744)
  Run smoke tests on a free runner (#5745)
  faster, cheaper (pick two): improve CI workflow and switch to free github runner (#5702)
  Compaction resiliency improvements (#5618)
  docs: ask goose button (#5730)
  Update prompt injection detection metrics (due to errors exporting to datadog) (#5692)
  Spence/icon2 tokyo drift (#5728)
  docs: logs rotation and misc updates (#5727)
  docs: automatic ollama model detection (#5725)
  Fix context progress bar not resetting after /clear command (#5652)
  docs: removing double announcements (#5714)
  docs: mcp sampling support (#5708)
  hackathon banner  (#5710)
  Fix documentation-only change detection for push events (#5712)
  Added transaction commits to multi sql functions in session_manager (#5693)
  fix: improve and simplify tool call chain rendering (#5704)
  Fix: Always show autocompact threshold ui (#5701)
  chore: Update governance to include Discord (#5690)
  Ollama improvements (#5609)
  ...
michaelneale added a commit that referenced this pull request Nov 17, 2025
* main:
  scan recipe for security when saving recipe (#5747)
  feat: trying grok for live test (#5732)
  Platform Extension MOIM (Minus One Info Message) (#5027)
  docs: remove hackathon banner (#5756)
  Fix: Recipes respect the quiet flag (#5743)
  docs: update cli commands (#5744)
  Run smoke tests on a free runner (#5745)
  faster, cheaper (pick two): improve CI workflow and switch to free github runner (#5702)
  Compaction resiliency improvements (#5618)
  docs: ask goose button (#5730)
  Update prompt injection detection metrics (due to errors exporting to datadog) (#5692)
  Spence/icon2 tokyo drift (#5728)
  docs: logs rotation and misc updates (#5727)
  docs: automatic ollama model detection (#5725)
  Fix context progress bar not resetting after /clear command (#5652)
  docs: removing double announcements (#5714)
  docs: mcp sampling support (#5708)
Surendhar-N-D pushed a commit to Surendhar-N-D/goose that referenced this pull request Nov 17, 2025
arul-cc pushed a commit to arul-cc/goose that referenced this pull request Nov 17, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
Signed-off-by: Cat Bilyeu <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: David Katz <[email protected]>
Signed-off-by: Blair Allan <[email protected]>
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.

Context progress bar not resetting after /clear command

2 participants