Skip to content

Fix/compact disabled during approval - #10089

Merged
alexhancock merged 4 commits into
aaif-goose:mainfrom
thepetk:fix/compact-disabled-during-approval
Jul 13, 2026
Merged

Fix/compact disabled during approval#10089
alexhancock merged 4 commits into
aaif-goose:mainfrom
thepetk:fix/compact-disabled-during-approval

Conversation

@thepetk

@thepetk thepetk commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

The PR addresses an issue with the Compact now button which was clickable while the agent had pending approvals, however this wasn't possible on the backend. I think is because of this and I believe that's the right behavior. In my PR I'm just disabling the button when isLoading is True.

Testing

Compact Now Button

  1. Build and launch the desktop app (just run-ui).
  2. Submit a prompt that causes a long streaming response.
  3. While the streaming indicator is active, check the "Compact now" button in the context bar.
    • On main: button is enabled and fires.
    • On this branch: button is greyed out/disabled; re-enables only when streaming finishes.
  4. Added a unit test in AlertBox.test.tsx covering the disabled state while loading.

Related Issues

Relates to #9958
Discussion: LINK (if any)

Screenshots/Demos (for UX changes)

Before: "Compact now" button remains active (clickable) while agent is streaming.

image

After: "Compact now" button is disabled (greyed out, not-allowed cursor) while agent is streaming; re-enables once the stream finishes.

Screenshot from 2026-06-29 23-14-35

Assisted-by: Claude Sonnet 4.6

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7505c55feb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/agents/agent.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58fcadfd38

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/desktop/src/components/ChatInput.tsx
Signed-off-by: Theofanis Petkos <tpetkos@redhat.com>
@thepetk
thepetk force-pushed the fix/compact-disabled-during-approval branch from 58fcadf to e97589a Compare June 29, 2026 23:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e97589a687

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/agents/agent.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d8b6b4dbe

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/context_mgmt/mod.rs Outdated
Comment thread crates/goose/src/agents/agent.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36daaf9797

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/context_mgmt/mod.rs Outdated
@thepetk

thepetk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

I've added more tests to capture the fix, but also the further changes requested by copilot.

Now I've also added Some(stored) => (stored as usize).max(estimated_tokens). This was done as the token usage stored in the session is recorded right after the LLM call, so before tool responses are appended.

This means if we have large tool output this can go undetected by the threshold check. An approach here would be to take the max of the stored value and a local estimate of the current conversation, so compaction triggers correctly even when the stored count is stale.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23e1c62bf4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/context_mgmt/mod.rs Outdated
e3742526 added a commit to cephalopod-ai/gosling that referenced this pull request Jul 3, 2026
Regression audit follow-up for the aaif-goose/goose#10089 port.

The initial merge kept upstream's max(stored, estimated) compaction trigger, but accidentally restored per-message token estimation. Gosling had already moved to a single conversation pass to avoid repeated per-request primer overhead. Keep that local behavior while still using max(stored, estimated) so large tool outputs can trigger compaction.

Gate: source bin/activate-hermit && cargo fmt && cargo test -p goose --test compaction
@DOsinga

DOsinga commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this @thepetk!

The one-line UI fix here — disabling the Compact now button while a request is in flight (disabled={isLoading}) — is exactly the fix for what the PR describes, and I'm happy to take that on its own.

The backend changes, though, go well beyond "compact button disabled during approval" and I'd like to drop them from this PR:

  • check_if_compaction_needed now always tokenizes and uses max(stored, estimated). This changes token-accounting behavior for every session, not just approval-heavy ones. session.usage.total_tokens is the provider's authoritative count from the last call; estimated_tokens is a local heuristic that ignores tool schemas / prompt framing / provider overhead. Taking the max lets the estimate override ground truth and biases us toward compacting early on every check. The fact that this needs the comment // The stored value is recorded before tool responses are added... use whichever count is higher to make sense is a sign the code is expressing "pick the bigger number" when the real intent is "the snapshot is stale after tool output" — those aren't the same thing.
  • The in-loop auto-compact in reply_internal and the metadata-preservation change in compact_messages are also separate behavioral changes to the compaction engine.

These are all reasonable things to discuss, but they're distinct features/semantics changes that deserve their own issue and review rather than riding in under a UI-button bugfix. Could you strip this PR down to just the button disablement? If you'd like to pursue the mid-loop compaction / token-recount behavior, let's open an issue to discuss the approach first.

@thepetk

thepetk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for this @thepetk!

The one-line UI fix here — disabling the Compact now button while a request is in flight (disabled={isLoading}) — is exactly the fix for what the PR describes, and I'm happy to take that on its own.

The backend changes, though, go well beyond "compact button disabled during approval" and I'd like to drop them from this PR:

  • check_if_compaction_needed now always tokenizes and uses max(stored, estimated). This changes token-accounting behavior for every session, not just approval-heavy ones. session.usage.total_tokens is the provider's authoritative count from the last call; estimated_tokens is a local heuristic that ignores tool schemas / prompt framing / provider overhead. Taking the max lets the estimate override ground truth and biases us toward compacting early on every check. The fact that this needs the comment // The stored value is recorded before tool responses are added... use whichever count is higher to make sense is a sign the code is expressing "pick the bigger number" when the real intent is "the snapshot is stale after tool output" — those aren't the same thing.
  • The in-loop auto-compact in reply_internal and the metadata-preservation change in compact_messages are also separate behavioral changes to the compaction engine.

These are all reasonable things to discuss, but they're distinct features/semantics changes that deserve their own issue and review rather than riding in under a UI-button bugfix. Could you strip this PR down to just the button disablement? If you'd like to pursue the mid-loop compaction / token-recount behavior, let's open an issue to discuss the approach first.

Yeah @DOsinga I think you have a fair point.

Just tried to handle this as an "easy fix", mostly for my own curiosity on how we could handle this on the backend, but I do agree it's not. That said, I'll remove this part from the PR and proceed only with the UI fix.

Signed-off-by: thepetk@gmail.com <thepetk@gmail.com>
@thepetk
thepetk force-pushed the fix/compact-disabled-during-approval branch from 23e1c62 to 98410be Compare July 6, 2026 08:22
@thepetk

thepetk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for this @thepetk!
The one-line UI fix here — disabling the Compact now button while a request is in flight (disabled={isLoading}) — is exactly the fix for what the PR describes, and I'm happy to take that on its own.
The backend changes, though, go well beyond "compact button disabled during approval" and I'd like to drop them from this PR:

  • check_if_compaction_needed now always tokenizes and uses max(stored, estimated). This changes token-accounting behavior for every session, not just approval-heavy ones. session.usage.total_tokens is the provider's authoritative count from the last call; estimated_tokens is a local heuristic that ignores tool schemas / prompt framing / provider overhead. Taking the max lets the estimate override ground truth and biases us toward compacting early on every check. The fact that this needs the comment // The stored value is recorded before tool responses are added... use whichever count is higher to make sense is a sign the code is expressing "pick the bigger number" when the real intent is "the snapshot is stale after tool output" — those aren't the same thing.
  • The in-loop auto-compact in reply_internal and the metadata-preservation change in compact_messages are also separate behavioral changes to the compaction engine.

These are all reasonable things to discuss, but they're distinct features/semantics changes that deserve their own issue and review rather than riding in under a UI-button bugfix. Could you strip this PR down to just the button disablement? If you'd like to pursue the mid-loop compaction / token-recount behavior, let's open an issue to discuss the approach first.

Yeah @DOsinga I think you have a fair point.

Just tried to handle this as an "easy fix", mostly for my own curiosity on how we could handle this on the backend, but I do agree it's not. That said, I'll remove this part from the PR and proceed only with the UI fix.

@DOsinga I've updated the PR

I would be happy to start a discussion over the auto-compaction. Could do first a more thorough investigation and then bring it up here or in discord. Do you think it would worth the effort?

@DOsinga DOsinga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks — this is now focused on the UI regression, and I removed the redundant AlertBox tests that did not cover the changed wiring.

@thepetk

thepetk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — this is now focused on the UI regression, and I removed the redundant AlertBox tests that did not cover the changed wiring.

Thanks! Then I guess my "assisted-by" is not accurate anymore :D cause the only contrib left was those tests

@DOsinga let me know if I should do anything further to merge it

@alexhancock
alexhancock added this pull request to the merge queue Jul 13, 2026
Merged via the queue into aaif-goose:main with commit bb769fc Jul 13, 2026
22 checks passed
afternoon added a commit to afternoon/goose that referenced this pull request Jul 13, 2026
- feat: allow askai bot to read issues and PRs (aaif-goose#10398)
- fix: Fix Gemini OAuth onboarding (aaif-goose#10363)
- chore: remove unavailable models from cerebras catalog (aaif-goose#10407)
- feat(cli): Fix output.rs merge conflicts
- chore(deps): bump actions/stale from 10.3.0 to 10.4.0 (aaif-goose#10371)
- chore(deps): bump dorny/paths-filter from 4.0.1 to 4.0.2 (aaif-goose#10370)
- chore(deps): bump actions/cache from 6.0.0 to 6.1.0 (aaif-goose#10374)
- fix: treat empty-string finish_reason as non-terminal in streaming (aaif-goose#10258)
- chore(deps): bump step-security/harden-runner from 2.19.4 to 2.20.0 (aaif-goose#10372)
- chore(deps): bump docker/login-action from 4.2.0 to 4.4.0 (aaif-goose#10373)
- test: drop unavailable and preview Gemini smoke models (aaif-goose#10355)
- fix(ui): restore pnpm 11 project configuration (aaif-goose#10395)
- Fix/compact disabled during approval (aaif-goose#10089)
- fix(prompt): make prompt timestamps timezone-explicit (aaif-goose#10209)
- fix: preserve reasoning_content for DeepSeek thinking mode on multi-turn tool calls (aaif-goose#10366)

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.

3 participants