Skip to content

fix(agent-status): clear sticky working after Claude /compact - #11353

Closed
mmarabel wants to merge 2 commits into
stablyai:mainfrom
mmarabel:gatsby74/stuck-working
Closed

mmarabel wants to merge 2 commits into
stablyai:mainfrom
mmarabel:gatsby74/stuck-working

Conversation

@mmarabel

Copy link
Copy Markdown
Contributor

Summary

Fixes Claude worktrees that stay stuck on Working… after /compact finishes (and the TUI is idle).

User-visible change: after compaction completes, the sidebar/card agent row returns to idle/done instead of spinning forever with an empty prompt and no tools.

Root cause

  1. Claude /compact injects a harness user turn (This session is being continued from a previous conversation…) that fires UserPromptSubmit.
  2. Orca mapped every Claude UserPromptSubmit → working, including harness machinery. There is no matching Stop.
  3. Claude PreCompact / PostCompact were ignored for status, so compact neither showed as busy nor cleared on completion.
  4. Hook status is authoritative; the idle title (✳ …) does not clear working, so the spinner sticks until the 30‑minute stale window or a new real turn.

Live diagnosis on Orca 1.4.161 / snapstudio local-moderation is documented in the issue.

Fix

  1. Ignore harness-injected UserPromptSubmit for Claude and Kimi (return no status update). Real activity still arrives via PreToolUse/PostToolUse/Stop.
  2. Map Claude/Kimi PreCompact → working and PostCompact → done so multi-minute compact shows activity and clears cleanly (also covers a real /compact slash-command submit without a Stop).

Tests

  • Harness UserPromptSubmit (task-notification / system-reminder / compact-summary) does not mint a sticky working row; cached user prompt is preserved for later real tool events.
  • PreCompact → working, PostCompact → done.
  • PostCompact clears working after a real /compact UserPromptSubmit.
pnpm exec vitest run src/shared/agent-hook-listener.test.ts
pnpm typecheck

Fixes #11352

Related

AI agent review summary

  • Cross-platform: Status normalization is shared/main-process hook logic; no UI/OS-specific paths. Same Claude/Kimi event names on macOS/Linux/Windows.
  • SSH/remote: Hooks still attribute by ORCA_PANE_KEY; no cwd-based resolution change. Dead remote hook ports remain a separate issue.
  • Agent/integration: Claude + Kimi (Claude-compatible hooks). Other agents unchanged. Devin still uses its own PostCompaction → working mapping.
  • Performance: Early null return for harness UserPromptSubmit; no extra I/O.
  • UI quality: Sidebar spinner clears after compact; PreCompact briefly shows working during long compact (honest busy state).
  • Security: No new network surface; only changes how already-received hook payloads map to status states.

Manual verification

  1. Resume a long Claude session in Orca; run /compact.
  2. While compacting, card may show working (PreCompact).
  3. After “Compacted” and idle ✳ title + ❯ prompt, card should not stay on Working….
  4. Real user prompts still show working with tools and clear on Stop.

Harness-injected UserPromptSubmit (compact summary, task notifications,
local-command machinery) no longer mints a working row without a Stop.
Claude PreCompact marks busy and PostCompact resolves to done so finished
compaction cannot leave the sidebar spinner stuck.

Fixes stablyai#11352
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where Claude (and Kimi) worktrees would stay stuck on a Working… spinner indefinitely after /compact completed. The root cause was that Claude's harness injects a UserPromptSubmit event during compaction (the "This session is being continued…" turn) without a matching Stop, so the agent row could never clear itself.

  • Introduces shouldIgnoreHarnessInjectedUserPromptSubmit, shared between normalizeClaudeEvent and normalizeKimiEvent, which short-circuits harness-injected UserPromptSubmit events by returning null instead of emitting a working state with no cleanup path.
  • Adds PreCompact → working and PostCompact → done mappings for both Claude and Kimi so the sidebar accurately reflects the compaction lifecycle and clears cleanly on completion.
  • Extends the test suite with new Claude and Kimi cases covering harness-guard, PreCompact/PostCompact, and the sticky-working regression scenario from issue [Bug]: Claude /compact leaves worktree stuck on "working" (harness UserPromptSubmit without Stop) #11352.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to two event normalizers, the guard delegates entirely to the pre-existing isKnownHarnessInjectedUserTurnText allowlist, and no prompt-cache or subagent-roster paths are touched.

Both changed code paths (normalizeClaudeEvent and normalizeKimiEvent) are well-isolated and thoroughly tested. The harness-guard short-circuits only when the event is UserPromptSubmit AND the prompt text matches a known harness prefix — real user prompts, array-format Kimi prompts, and custom-element pastes all pass through unchanged. PreCompact/PostCompact additions mirror the existing Devin PostCompaction pattern and have no side-effects on the subagent roster or prompt cache. The previous gap in Kimi test coverage is now closed.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/shared/agent-hook-listener.ts Adds shouldIgnoreHarnessInjectedUserPromptSubmit helper shared by Claude and Kimi normalizers; maps PreCompact→working and PostCompact→done for both agents. Logic is correct, guard correctly delegates to the pre-existing isKnownHarnessInjectedUserTurnText, and subagent/prompt-cache paths are unaffected.
src/shared/agent-hook-listener.test.ts Adds Kimi harness-guard and compact lifecycle tests (addressing the prior P2 comment), rewrites two Claude harness tests to match null-return semantics, and adds PreCompact/PostCompact and sticky-working regression tests for Claude. Coverage is thorough for all changed paths.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant C as Claude TUI
    participant H as Hook Listener
    participant S as Agent Status (sidebar)

    Note over U,S: Real user turn (unchanged)
    U->>C: types "fix login"
    C->>H: "UserPromptSubmit {prompt: "fix login"}"
    H->>S: working ("fix login")
    C->>H: "PreToolUse {tool: Bash}"
    H->>S: working ("fix login")
    C->>H: Stop
    H->>S: done ("fix login")

    Note over U,S: /compact BEFORE this PR (bug)
    U->>C: /compact
    C->>H: "UserPromptSubmit {prompt: "/compact"}"
    H->>S: working ("/compact")
    C->>H: "UserPromptSubmit {prompt: "This session is being continued..."}"
    H->>S: working ("") sticky, no Stop ever arrives

    Note over U,S: /compact AFTER this PR (fixed)
    U->>C: /compact
    C->>H: "UserPromptSubmit {prompt: "/compact"}"
    H->>S: working ("/compact")
    C->>H: PreCompact
    H->>S: working ("/compact")
    C->>H: "UserPromptSubmit {prompt: "This session is being continued..."}"
    H-->>S: null (ignored, harness machinery)
    C->>H: PostCompact
    H->>S: done ("/compact")
Loading

Reviews (2): Last reviewed commit: "test(agent-status): cover Kimi compact g..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca2d4451-21dc-4e7d-b14b-97c2d2e3555d

📥 Commits

Reviewing files that changed from the base of the PR and between 8346d7d and ccaca5e.

📒 Files selected for processing (2)
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-hook-listener.test.ts

📝 Walkthrough

Walkthrough

Updated Claude and Kimi event normalization to ignore harness-injected UserPromptSubmit events. Compact lifecycle events now map to explicit working and done states, with Claude also treating StopFailure as done. Tests cover cached prompt preservation, empty-cache behavior, compact transitions, and clearing sticky working states.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: clearing sticky working after Claude /compact.
Description check ✅ Passed It covers summary, testing, AI review, security, and notes content; only the screenshots section is missing.
Linked Issues check ✅ Passed The PR addresses #11352 by ignoring harness UserPromptSubmit, mapping PreCompact/PostCompact, and adding regression coverage.
Out of Scope Changes check ✅ Passed The changes stay focused on agent status normalization and tests; the Kimi parity work is still within the compact-status fix.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/shared/agent-hook-listener.ts (1)

2562-2569: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated harness-injected guard across normalizeClaudeEvent and normalizeKimiEvent. Both functions inline the identical eventName === 'UserPromptSubmit' && isKnownHarnessInjectedUserTurnText(promptText) check; extracting a shared helper avoids the two agent paths drifting apart on this exact bug class (issue #11352) in the future.

  • src/shared/agent-hook-listener.ts#L2562-L2569: replace the inline guard in normalizeClaudeEvent with a call to a shared shouldIgnoreHarnessInjectedUserPromptSubmit(eventName, promptText) helper.
  • src/shared/agent-hook-listener.ts#L2787-L2792: replace the inline guard in normalizeKimiEvent with the same shared helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 96102564-c96c-4196-b413-485b537c50e0

📥 Commits

Reviewing files that changed from the base of the PR and between 4543bb6 and 8346d7d.

📒 Files selected for processing (2)
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts

Comment thread src/shared/agent-hook-listener.test.ts Resolved
Address Greptile/CodeRabbit review on stablyai#11353: extract a shared
shouldIgnoreHarnessInjectedUserPromptSubmit helper for Claude and Kimi,
and add Kimi harness + PreCompact/PostCompact regression tests so the
parallel path cannot drift.
@mmarabel

Copy link
Copy Markdown
Contributor Author

Thanks Greptile + CodeRabbit — addressed in ccaca5ef6:

  1. Kimi coverage (Greptile P2 + CodeRabbit): harness-injected UserPromptSubmit ignore + PreCompact/PostCompact lifecycle tests for kimi, parallel to the Claude cases.
  2. Shared helper (CodeRabbit nit): shouldIgnoreHarnessInjectedUserPromptSubmit so Claude and Kimi cannot drift on the [Bug]: Claude /compact leaves worktree stuck on "working" (harness UserPromptSubmit without Stop) #11352 guard.

Skipped the Docstring Coverage pre-merge warning — this file follows the repo’s // Why: style rather than JSDoc on internal helpers.

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Thanks for working on the stuck /compact state. We reproduced the original problem, but we could not find a receiver-only implementation that is safe to land.

The blocking sequence is:

  1. Compact generation 1 completes.
  2. New provider work becomes authoritative.
  3. An identical same-session, same-trigger compact generation 2 starts.
  4. A delayed duplicate PostCompact from generation 1 arrives.

The hook payload has no provider-issued compact operation ID, so generation 1s delayed completion is indistinguishable from generation 2s valid completion. In our deterministic oracle, that stale event retires the newer work. The separate owner map also retained entries for 4,097 unique pane keys, so authenticated but untrusted hook payloads can grow memory without a lifecycle bound.

We also tested an owner-map-free rewrite that attached state to the authoritative status. It fixed the earlier stale-owner cases, but it still failed the identical-generation sequence because receiver-generated counters and timestamps cannot manufacture the missing correlation identity.

A safe version needs an opaque operation ID carried from PreCompact through PostCompact, including local, SSH/relay, restore, and persistence paths, and should fail closed when that identity is absent. If the provider cannot expose such an ID, the UI behavior needs to be narrowed so Orca does not claim authoritative completion.

I am closing this for now because the remaining fix requires protocol work beyond this PR. Please feel free to reopen with a provider-correlated design, or with reproduction evidence that disproves the sequence above.

@Jinwoo-H Jinwoo-H closed this Jul 30, 2026
brennanb2025 added a commit that referenced this pull request Aug 1, 2026
…d record exists

Review finding round 4: teammate ids persist across turns, so a delayed
stale SubagentStop parks a live teammate's row and the drain->done
inference retired newer work — PR #11353's uncorrelated-completion race.
With no lead record, only a live working child (working) or a one-shot
row removal (done; duplicate-proof since the row is gone) may speak;
teammate parks and idle-only refreshes stay silent.
OrcaWin pushed a commit that referenced this pull request Aug 3, 2026
Address Greptile/CodeRabbit review on #11353: extract a shared
shouldIgnoreHarnessInjectedUserPromptSubmit helper for Claude and Kimi,
and add Kimi harness + PreCompact/PostCompact regression tests so the
parallel path cannot drift.
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.

[Bug]: Claude /compact leaves worktree stuck on "working" (harness UserPromptSubmit without Stop)

3 participants