happier icon indicating copy to clipboard operation
happier copied to clipboard

Claude unified-terminal queue stalls: collapsed multi-line paste treated as foreign draft (line-count rule rejects +18 for 13 newlines)

Open thomashillman opened this issue 1 month ago • 2 comments

Summary

A daemon-spawned Claude unified-terminal session stalls when a queued multi-line message is injected into a tmux pane. Claude collapses the paste to a marker, and the daemon's own-draft check doesn't recognize that marker, so it treats the composer as a foreign draft. Every later injection is deferred with foreign_draft, then starvation_escalated, and the queue never drains. Related to #328 (same starvation family, different trigger).

Environment

  • Happier CLI 0.2.14-dev.1 (hotfix happier-0.2.14-dev.1-subagent-completion-20261008)
  • Linux (aarch64), tmux terminal mode
  • Message: about 2.5 KB, 13 newlines

Steps to reproduce

  1. Start a daemon-managed Claude session in tmux.
  2. Queue a multi-line message (about 2.5 KB, 13 newlines).
  3. Observe the pane: Claude shows [Pasted text #1 +18 lines].

Expected

The queued message is delivered (or the outcome is resolved), and the queue drains.

Actual

  • unified.injection.outcome → failed, reason: verification_failed, phase: after_enter_unknown, duplicateRisk: possible
  • pendingQueue → delivery_outcome_uncertain, pendingBlockedCount: 1
  • Later attempts: unified.injection.draft_guard → foreign_draft (draftLength 26), then starvation_escalated after about 70–80 deferrals. Over 30,000 draft_guard lines in one session log.
  • The queue only unblocks when the composer is cleared by hand.

Root cause (from reading the source)

apps/cli/src/backends/claude/unifiedTerminal/ownComposerTextLog.ts (isCollapsedPasteMarkerMatch) only treats a collapsed-paste marker as the daemon's own draft if pastedTextLineCountMatchesPrompt accepts the marker's line count. That rule (claudePastedTextMarker.ts) accepts counts from newlines - 2 to newlines + 3:

  • Prompt with 13 newlines → accepted range 11–16.
  • Claude displays +18 lines → rejected → classifyClaudeOwnComposerDraft returns foreign.
  • clearOwnLeftoverComposerDraft only clears own drafts, so the paste is never cleared, and every injection defers.

I checked the rule directly: +13 and +16 match, +17 and +18 don't. Separately, isPromptInComposer treats any collapsed marker as "still pending", so a non-submitted paste fails verification as after_enter_unknown. Once the outcome is failed_ambiguous, nothing re-checks the transcript, so the queue stays blocked.

Why this isn't a one-line fix

ownComposerTextLog.test.ts pins the rule for a 40-newline prompt: +43 must match and +44 must not. Any count-based tolerance that accepts +5 at 13 newlines also accepts +44 at 40, so the tolerance can't satisfy both. It's also unclear why Claude counts 18 lines for a 13-newline message.

Possible directions

  1. Widen the tolerance and change the +44 assertion (policy change; can accept foreign pastes).
  2. Avoid collapsed pastes: send multi-line input line by line, so the composer shows raw text the guard already owns.
  3. Let the guard clear its own paste markers during the verification window, using the count-free matching that the submit path already uses.
  4. Resolve delivery_outcome_uncertain by checking the transcript after a timeout, rather than blocking the queue.

Option 2 looks most robust, since it removes the ambiguity. Options 1 and 3 change matching rules; option 4 is independent and would stop the indefinite block whatever the matching does.

Evidence

Session logs from the daemon (paths relative to ~/.happier/logs/):

  • 2026-10-13-18-30-25-pid-15448.log (session cmv70nkx…)
  • 2026-10-13-18-44-21-pid-41937.log (session cmv715j1…)

Local check: apps/cli vitest run ownComposerTextLog ownComposerDraftGuard claudePromptSubmitVerification: 48/48 pass on current source (baseline).

thomashillman avatar Oct 13 '26 19:10 thomashillman

Thanks @thomashillman for tracing the marker mismatch and recovery stall. A reproducible recovery defect is now corrected in c45b574fed, integrated into dev. The correction is also applied by intent on the 0.3 line in 9020711759.

The ownership log was counting newlines after semantic normalization, which removes outer blank lines and standalone paste-wrapper lines. In isolated Claude/tmux runs, a 13-newline body with five additional newline separators displayed +18 lines, while Happier had reduced its recorded identity to 13 and rejected the marker. A plain 13-newline prompt displayed +13 at three terminal widths, so width alone did not reproduce the discrepancy.

The existing log now retains the original injected text for marker comparison, including partial-write recovery. The redundant cached count is removed; the existing tolerance and foreign-draft protections remain in place. Normal submission verification remains count-free. The 0.3 implementation also preserves the original text through its existing respawn snapshot, without a new storage format.

The regressions failed before the change and pass afterward. Relevant 0.2 and 0.3 suites and both package typechecks pass. A live replay with Claude 2.1.294 verified that the 0.2 draft guard clears both reproduced residues. With Claude 2.1.296, the 0.3 log recognizes the real markers before and after rehydration.

This establishes the normalization-related recovery fix, but does not yet establish why your initial submission failed or that your exact incident had this trigger. The issue remains open pending your confirmation.

Your report uses the dev channel. Please retry once this issue reaches stage:dev, updating the CLI and restarting its daemon, then reproducing in a newly started Happier-managed Claude session so its runner loads the correction. Please confirm whether queued messages progress without manually clearing the Claude composer. Updating only the app or server will not load this CLI correction.

If it still blocks, please share the updated Happier CLI and Claude Code versions, the action sequence and approximate timestamps, and a minimal redacted prompt that preserves leading/trailing blank lines and any paste-wrapper lines. Those details will let us distinguish the remaining initial-submission failure from the corrected recovery mismatch.

Posted on behalf of @leeroybrun.

happier-bot avatar Oct 15 '26 12:10 happier-bot

@leeroybrun I found a matching input-deferral signature in another Claude unified-terminal incident log, on Happier CLI/daemon 0.2.21-dev.1 (Linux, aarch64). The runner recorded 7,584 unified.injection.draft_guard events with status foreign_draft over about 17 minutes (Nov 18, 09:15–09:32 UTC), with originKind: "ui_pending". This confirms that app input reached the runner but was repeatedly deferred by the composer draft guard. The log does not establish whether the draft was genuinely user-owned or stale, and the event stream did not show a corresponding starvation escalation.

This looks like the same failure family as #547, though I can’t confirm the trigger is the collapsed-paste marker described here. Separately, the same VM logs show Happier marking runners process-missing while their Claude tmux panes remained alive; I filed that distinct lifecycle report as #961.

thomashillman avatar Nov 19 '26 10:11 thomashillman