Skip to content

fix(task): report emergency condense like the automatic path - #1838

Open
PierrunoYT wants to merge 1 commit into
Zoo-Code-Org:mainfrom
PierrunoYT:fix/1769-emergency-condense-event
Open

PierrunoYT wants to merge 1 commit into
Zoo-Code-Org:mainfrom
PierrunoYT:fix/1769-emergency-condense-event

Conversation

@PierrunoYT

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #1769

Description

The emergency condense in handleContextWindowExceededError copied the automatic path's result handling instead of sharing it, and the copy had drifted. This PR fixes the two defects from the issue and one of the argument divergences.

  • condenseId on the event. The emergency condense_context event had no condenseId, so MessageManager's id-based rewind cleanup could never remove the emergency summary. Deleting the condense row cut the history after the summary (summary at last message + 1, row emitted later), which left the summary in place.
  • Errors surfaced. An error returned by manageContext was dropped. It now shows as condense_context_error, as on the automatic path.
  • Shared reporter. Both paths now report through one reportContextManagementResult helper (error row, then the condense event or the truncation row), so the fields can't drift apart again. For the automatic path this is a pure move with no behaviour change.
  • Same condense settings (divergence 3). The emergency manageContext call now also passes the custom CONDENSE prompt, filesReadByRoo, cwd, and rooIgnoreController, so a recovery summary is built like an automatic one.

The manual condenseContext() path is unchanged. It calls summarizeConversation directly, returns early on error, and already emitted condenseId and the error row.

Not included: divergence 4, where a profile threshold can override the forced 75% during recovery. It changes recovery behaviour, so it belongs in a separate follow-up (Open question 2 in the issue).

Test Procedure

New regression tests:

  • Task.spec.ts → emergency condense reporting (#1769). These call the real handleContextWindowExceededError, not a mock:
    • A successful condense emits contextCondense.condenseId equal to the summary's id, and summarizes with the custom prompt and cwd.
    • A failed condense emits condense_context_error, followed by the fallback sliding_window_truncation row.
    • Both tests fail against the original Task.ts.
  • message-manager/index.spec.ts: deleting the emergency condense row removes the summary when the event carries a condenseId. A second case shows the summary survives when the id is missing, which was the pre-fix behaviour.

Commands:

cd src
npx vitest run core/task/__tests__/Task.spec.ts core/message-manager core/condense core/context-management
pnpm exec eslint --max-warnings=0 core/task/Task.ts core/task/__tests__/Task.spec.ts core/message-manager/index.spec.ts

Results: 378 tests passed; type checking and ESLint passed (also via the commit hook). ESLint suppression counts are unchanged.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Visual Snapshot (UI changes only): Not applicable; no UI changes.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Visual Snapshots

Not applicable; no UI changes.

Videos (interaction / animation only)

Not applicable.

Documentation Updates

  • No documentation updates are required.

Additional Notes

Follow-up candidate from the issue's open questions: let recovery take precedence over profileThresholds (an empty threshold map on the emergency call, or a forceThreshold flag on manageContext). With a profile threshold of 95%, today's emergency call can return the history unchanged with no event at all.

🤖 Generated with Claude Code

The emergency condense in handleContextWindowExceededError duplicated
the automatic path's result handling and had diverged:

- Its condense_context event carried no condenseId, so rewind cleanup
  could not remove the emergency summary; deleting the condense row cut
  after the summary and left it in place.
- A condense error returned by manageContext was dropped instead of
  being shown as condense_context_error.
- It ignored the custom CONDENSE prompt and did not pass filesReadByRoo,
  cwd, or rooIgnoreController.

Both paths now report through one reportContextManagementResult helper,
and the emergency call passes the same condense settings. The profile
threshold overriding the forced 75% is left for a follow-up.

Fixes Zoo-Code-Org#1769

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 65764785-64b1-4c7e-a354-e4abcc8c13f1

📥 Commits

Reviewing files that changed from the base of the PR and between 8bec7c1 and a4ef011.

📒 Files selected for processing (3)
  • src/core/message-manager/index.spec.ts
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.spec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Required CI passed. Waiting for automated review of the latest commit.

If automated review does not start, a maintainer must restart it.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Sep 28, 2026

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

awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit coderabbit-review-active Required CI passed; CodeRabbit review is active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Emergency condense emits incomplete condense_context event - breaks rewind and hides errors

1 participant