Skip to content

fix(daemon): send self-compact nudge straight away instead of queueing for Stop#73

Closed
rogeriochaves wants to merge 1 commit into
mainfrom
headless-self-compact-straightaway
Closed

fix(daemon): send self-compact nudge straight away instead of queueing for Stop#73
rogeriochaves wants to merge 1 commit into
mainfrom
headless-self-compact-straightaway

Conversation

@rogeriochaves
Copy link
Copy Markdown
Contributor

Problem

The headless auto-compact guard escalates: at 500k/600k/700k it nudges the agent to self-compact, and at 750k it sends /compact directly. The 500/600/700k nudges were queued and only auto-sent when the agent next emitted a Stop hook.

A freshly-resumed or idle session never emits a Stop, so those gentle nudges never fired. Context coasted all the way up to the 750k hard /compact, which then fired on top of whatever prompt landed next (in practice, the morning scheduled nudge) and that prompt was lost — the agent skipped a day's work.

Fix

Paste the self-compact nudge straight into the session when the threshold is crossed, instead of parking it in the queue. Claude Code queues pasted input and runs it after the current turn, so:

  • a busy agent still finishes its current turn before self-compacting (graceful), and
  • a resumed/idle agent self-compacts immediately, well before its next scheduled prompt arrives.

lastTriggered still ensures each threshold nudges only once; the 750k hard /compact backstop is unchanged. Removed the now-unused enqueueOnce helper.

Tests

Updated the daemon auto-compact test to assert the nudge is pasted straight away (not queued) and not re-sent for the same threshold. Full suite green (197).

The auto-compact guard queued the 500k/600k/700k self-compact nudges and
relied on auto-send when the agent next emits a Stop. A freshly-resumed
or idle session never emits a Stop, so those gentle nudges never fired
and context coasted up to the 750k hard /compact — which then collided
with whatever prompt landed next (e.g. the morning nudge), losing it.

Paste the nudge straight into the session instead. Claude queues pasted
input and runs it after the current turn, so a busy agent still finishes
gracefully, while a resumed/idle session self-compacts immediately and
is well below the limit by the time its next prompt arrives.
@rogeriochaves
Copy link
Copy Markdown
Contributor Author

Dropping this. The queued self-compact nudge (fire at next Stop) is the intended behavior: a soft nudge should land at a stop point, and an idle session just rides up to the 750k hard /compact, after which the next prompt arrives post-compaction. The straight-away paste defeated the purpose of the queuePrompt path.

rogeriochaves added a commit that referenced this pull request May 28, 2026
The 500k/600k/700k soft nudges stay queued and auto-send on the next Stop,
as designed: a soft nudge is meant to land at a stop point, and an idle
session simply rides up to the 750k hard /compact, after which the next
prompt arrives post-compaction. Reverts the daemon paste-straight-away
change so the queuePrompt path is preserved.
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.

1 participant