Skip to content

test(claude): wait for a pane's subagent list instead of asking once - #969

Merged
devswha merged 1 commit into
mainfrom
fix/claude-subagents-contract-race
Oct 13, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/claude-subagents-contract-race

Conversation

@devswha

@devswha devswha commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Problem

CI on main at eace9f0 (run 38429338201, job 115409436687, self-hosted runner, HERDR_TEST_SHARDS=4) failed server/claude-session.contract.test.ts:200 "lists a Claude pane's subagents, counts the running ones and pushes the count without a status": expected [{ id: "a1", status: "running" }], received [], in 120 ms. The test after it in the file and every later test passed.

Root cause: a race in the test, not a regression

  • The server's snapshot path starts claudeAgents.refresh() without waiting for it. If claudePaneSession answers null once for the pane (herdr's agent.get / pane.process_info busy or late), ClaudeSubagentStatus.ensure records path: null. It then skips a new lookup until refreshMs (5 s) has passed, and that includes the lookup /api/pane/omo-tasks makes when asked. So an ask inside that window answers [] fast, on purpose. The client retries.
  • The test asked once and treated that answer as final. Its comment ("before the server has had a snapshot") was already wrong: beforeAll waits for statusReady, and another test runs before this one.
  • Reproduced locally by making the first two claudePaneSession calls answer null. The result matched CI exactly: the same assertion, [], 107 ms, and the other 9 tests green. With this change the same injection passes.
  • No file in the lookup or subagent path changed in fix(relay): stop a relayed pane only past 256 KiB queued, like this PC #952–fix(terminal): attach again when a page put away comes back to a stopped output #968. A later main run with the same code (38430538375) passed integration. This is the only time this test has failed in the recent runs. The new factor is the self-hosted 4-shard runner (ci: validate fully outside pull requests and add an opt-in self-hosted runner #873). The log does not show which herdr call was late in CI. What is shown is that one null lookup gives exactly this failure.
  • 30 local runs (serial, and 6 in parallel on separate herdr sessions) and 3 full HERDR_TEST_SHARDS=4 integration runs were all green before the fix.

Change (test only)

  • Moved the bounded until poll (100 × 100 ms, allowed by the fixed-sleeps ratchet) to file scope. The plan test and this test both use it.
  • Poll the subagent list until a1 reads running, then keep the existing toMatchObject assertions.
  • Wait for the background_tasks === 1 frame starting from the socket's first frame, after the poll. Its 10 s window now starts once discovery is done, and a count pushed while the list was polled still counts.
  • Test timeout raised from 15 s to 25 s to cover the 5 s lookup cache on the slow path.

Not changed: an explicit ask after a failed background lookup still waits out the 5 s cache. That is the intended product behaviour. If an explicit ask should look again at once, that is a separate follow-up.

Checks

  • bun run check fast: ok
  • bun test server/claude-session.contract.test.ts on an isolated herdr session: 10 pass, with and without the injected lookup failure

🤖 Generated with Claude Code

The subagent contract asked /api/pane/omo-tasks once and expected the
running agent. The server's non-awaited background lookup can already
have resolved the pane to no transcript (herdr busy or late under the
4-shard self-hosted runner); ClaudeSubagentStatus.ensure then skips a
new lookup for refreshMs (5 s), so the first ask answers [] by design.
Poll the list with the file's bounded helper and look for the count
frame from the start of the socket's frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f9ffe2ec-c01c-4a9f-9ce8-c7b614ed8f61
📥 Commits

Reviewing files that changed from the base of the PR and between a338f8b and a7aa1e1.

📒 Files selected for processing (1)
  • server/claude-session.contract.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Tests
    • Improved reliability of subagent and plan tests by waiting for expected task states and using consistent polling.
    • Increased the subagent test timeout.

The contract tests add a shared asynchronous polling helper. The subagent test waits for the agent to report a running state before checking its status frame, and its timeout increases to 25 seconds. The plan test uses the shared helper.

Changes: Contract test synchronization

Layer / File(s) Summary
Shared polling and status checks
server/claude-session.contract.test.ts
Adds a shared polling helper, uses it to wait for the subagent’s running state before checking frames, and increases the test timeout to 25 seconds. The plan test reuses the helper.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other

Suggested reviewers: kilhyeonjun

Merge Risk: ⚪ Minimal · up to a7aa1

This change adjusts contract-test polling without changing server behavior. No concrete merge-blocking issue is evident from the supplied evidence.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the problem, root cause, test-only change, intended behavior, and validation results. It uses equivalent headings instead of the template's exact "## Change" and "## V…
Title check Passed The title is concise, specific, and accurately describes the main test change: waiting for a pane's subagent list instead of checking it once.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@devswha
devswha merged commit ead02fc into main Oct 13, 2026
29 of 33 checks passed
@devswha
devswha deleted the fix/claude-subagents-contract-race branch October 13, 2026 17:26
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