Background task output polling blocks /compact requests, consuming entire context window
Description
When a long-running background task is active (e.g., a Playwright E2E test suite running for 1+ hours), repeatedly polling TaskOutput consumes the context window. If the user requests /compact during this time, the compaction does not take priority — instead, the system continues polling the background task output, eventually filling the entire context window and forcing a "Context limit reached" error.
Steps to Reproduce
- Start a long-running background command (e.g.,
npx playwright test --workers=1with 600+ tests, ~1.5 hours) - The agent polls
TaskOutputperiodically to check progress - User types
/compactwhile the background task is still running - Expected: Compaction happens immediately, preserving context for continued work
- Actual: The
/compactrequest is ignored or deferred. The agent continues pollingTaskOutput, each poll adding thousands of lines to context. Eventually hits "Context limit reached" with no ability to compact.
Observed Behavior
In my session, I typed /compact twice while waiting for a Playwright run to finish. Both times, the system continued polling the background task instead of compacting. The context window filled completely, forcing a hard stop. The conversation history from the prior session transcript shows:
❯ /compact ← User request #1 (ignored)
[agent continues polling TaskOutput]
❯ /compact ← User request #2 (ignored)
[agent continues polling TaskOutput]
⎿ Context limit reached · /compact or /clear to continue
Impact
- Lost work context: The entire conversation history up to that point was lost because compaction never happened
- Wasted tokens/cost: Thousands of lines of test output were pulled into context unnecessarily
- User frustration: Explicit user commands to manage context were not honored
Suggested Fix
/compactshould take immediate priority over any pendingTaskOutputpolls- Long-running background tasks should not continuously dump output into the main context — perhaps summarize or truncate after a threshold
- Consider a mechanism where background task output is only pulled on-demand rather than auto-polled
Environment
- Claude Code v2.1.37
- Model: Opus 4.6
- Platform: Windows (MSYS/Git Bash)
- Task type: Background Bash command (
npx playwright test --workers=1 --reporter=line)
Additional Context
The background task eventually completed successfully — the issue is purely about context management and /compact priority.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗