Skip to content

test(orchestration): make the heartbeat straggler test able to fail - #15165

Closed
Tauri-EPO wants to merge 1 commit into
stablyai:mainfrom
Tauri-EPO:Tauri-EPO/heartbeat-straggler-test
Closed

Tauri-EPO wants to merge 1 commit into
stablyai:mainfrom
Tauri-EPO:Tauri-EPO/heartbeat-straggler-test

Conversation

@Tauri-EPO

@Tauri-EPO Tauri-EPO commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A test says "a heartbeat arriving after the job finished is ignored". It checked that the heartbeat column ended up empty — but the column starts empty, so the test passed without the code doing anything. Now it puts a real heartbeat in first, so the check has something to actually compare against.

What Changed

One test in src/main/runtime/orchestration/db.test.ts. No product code.

 it('recordHeartbeat is a no-op for completed rows (straggler ignored)', () => {
   const d = createDb()
   const task = d.createTask({ spec: 'work' })
   const ctx = d.createDispatchContext(task.id, 'term_a')
+  d.recordHeartbeat(ctx.id, '2026-05-03T00:00:00.000Z')
   d.completeDispatch(ctx.id)

   d.recordHeartbeat(ctx.id, '2026-05-04T00:00:00.000Z')
   const after = d.getDispatchContext(task.id)
-  expect(after?.last_heartbeat_at).toBeNull()
+  expect(after?.last_heartbeat_at).toBe('2026-05-03T00:00:00.000Z')
 })

Why

recordHeartbeat carries a status filter with a stated reason:

// Why: only bump status='dispatched' — a zombie heartbeat from a finished dispatch would mask a hung retry from the stale detector (§5.3.4).
"UPDATE dispatch_contexts SET last_heartbeat_at = ? WHERE id = ? AND status = 'dispatched'"

The test guarding it never gave the row a heartbeat before settling it, so last_heartbeat_at was null from creation and toBeNull() held for two different reasons: the filter excluded the row, or something cleared the column on the way to completed. It could not fail for the reason its name claims.

Seeding a heartbeat first makes the expected value a timestamp rather than the initial state, so both regressions are now distinguishable — null means the column was cleared, '2026-05-04…' means the guard is gone.

This is a test-only gap. recordHeartbeat is correct today; nothing would notice if it stopped being.

Linked Issue

Fixes #15164

Visual Proof

N/A — test-only change, no product code and no rendered UI. The before/after that matters is the assertion behaviour, shown under Testing.

Testing

Verified by regression injection, since a test that cannot fail is only provable by making it fail. Injected into completeDispatch:

-"UPDATE dispatch_contexts SET status = 'completed', completed_at = datetime('now'), …"
+"UPDATE dispatch_contexts SET status = 'completed', last_heartbeat_at = NULL, completed_at = datetime('now'), …"

main's assertion, against that regression — green, which is the bug:

 Test Files  1 passed (1)
      Tests  1 passed | 60 skipped (61)

This PR's assertion, same regression — red:

 - Expected: "2026-05-03T00:00:00.000Z"
 + Received: null
 ❯ src/main/runtime/orchestration/db.test.ts:669:40
 Test Files  1 failed (1)
      Tests  1 failed | 60 skipped (61)

The injected change was reverted before committing; the diff in this PR is the test file only.

With the tree clean, on Windows 11 / Node 24.19.0:

vitest run src/main/runtime/orchestration/db.test.ts
  Test Files  1 passed (1)   Tests  61 passed (61)

tsc --noEmit -p config/tsconfig.node.json        clean
oxlint src config tests --deny-warnings          clean
check-reliability-gates.mjs   passed for 85 gate(s)
check-max-lines-ratchet.mjs   OK — 190 grandfathered, no new bypasses
verify:bundled-skill-guides   clean

pnpm lint runs clean through those and then stops at verify:skill-bundle-manifest — this is #14479, not this change:

Generated skill artifacts are stale:
resources\skills\current-manifest.json
resources\skills\snapshot-registry.json
resources\skills\release-mapping.json

That is not from this change — it reproduces identically on a pristine detached upstream/main (60805f5c) in the same checkout, and this PR touches one test file. Flagging it rather than regenerating artifacts that have nothing to do with the diff.

Not run locally: pnpm build and the full suite. Platforms exercised: Windows only — the change is a SQLite assertion with no platform-dependent behaviour.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Claude Opus 5 was used to write the regression-injection proof, the change, and this description.

Review

Reviewed for the areas the template asks about; none are touched. No product code, so no security, performance, cross-platform, SSH/remote, mobile, or backwards-compatibility surface. The only cross-cutting consideration is the SQLite timestamp format, and the test stays on the explicit ISO strings the surrounding cases already use, so it does not depend on wall clock or timezone.

Overlap worth flagging: #14889 relocates this exact test to db-dispatch-liveness.test.ts without changing it. Whichever lands first, the other rebases cleanly — if #14889 goes first this assertion moves to the new file; if this goes first the relocation carries it. I kept them separate deliberately: #14889 is a byte-for-byte move, and its whole value is that a reviewer can confirm nothing changed inside it.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred) — see Testing for exactly what was run: pnpm build and the full suite were not, and pnpm lint stops on the verify:skill-bundle-manifest staleness reported in [Bug]: pnpm lint cannot pass on a stock Windows checkout (CRLF line endings) #14479, which reproduces on pristine main

Author

  • X / Twitter: @EnricoPin

The row never held a heartbeat before settling, so last_heartbeat_at was
null from creation and the assertion held whether the status filter did
its job or something cleared the column on completion. Seed a heartbeat
while the row is still dispatched, so the expected value is a timestamp:
null now means the column was cleared and the later stamp means the guard
is gone. Verified against both regressions.
@coderabbitai

coderabbitai Bot commented Aug 17, 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: b1e2da35-948d-4b4c-b671-75d9366b3602

📥 Commits

Reviewing files that changed from the base of the PR and between 32ee3b0 and 3d39601.

📒 Files selected for processing (1)
  • src/main/runtime/orchestration/db.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Updated the completed-dispatch heartbeat test to record an initial heartbeat before dispatch completion. The test now verifies that a later heartbeat does not overwrite the existing timestamp.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The test seeds a heartbeat before completion and verifies that a later heartbeat is ignored, satisfying issue #15164.
Out of Scope Changes check ✅ Passed The pull request changes only the targeted orchestration test and contains no unrelated product or documentation changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the orchestration heartbeat test change and explains its purpose.
Description check ✅ Passed The description covers the required sections, linked issue, test rationale, verification results, limitations, and scope.

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.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this @Tauri-EPO — the regression-injection proof in your description is exactly the right way to argue for a test change, and it made review trivial.

Fork PRs in this repo only run track-community-pr, not the full CI suite, so I carried your commit onto an internal branch to get it through everything: #15869. Your authorship is preserved on the commit (git log shows you as author).

Three things I changed on takeover, all noted in the PR:

  1. Collapsed the 3-line // Why: block to one line, per AGENTS.md's brevity rule.
  2. Rewrote the commit subject. "It can never fail" is a touch stronger than what's true — I re-ran it, and the old toBeNull() does fail if you remove the AND status = 'dispatched' filter outright, because the straggler write leaves '2026-05-04…'. What it couldn't see is the column-cleared confound (your injection C), which is the real gap and exactly what your change closes. The new subject says that instead.
  3. Added a sibling case for the failDispatch path, since the filter matches status = 'dispatched' exactly and so also ignores stragglers on failed / circuit_broken rows. Confirmed the gap was real: widening the filter to status != 'completed' passed the whole suite before, and now fails.

One more thing worth knowing — you were right to flag the overlap with #14889. db.test.ts is now at exactly 800 effective lines, the max-lines ceiling, which is why the new case went into dispatch-failure-idempotency.test.ts instead of next to its sibling. #14889 is what restores headroom; I'm leaving it open and it should rebase cleanly.

Leaving this open for you to close once #15869 lands.

@nwparker

Copy link
Copy Markdown
Contributor

Landed as #15869 — thank you @Tauri-EPO! 🎉

Your commit was cherry-picked and the squash carries a Co-authored-by trailer, so the fix is in main with your authorship intact. The separate PR was only needed because fork PRs in this repo run just track-community-pr — the full PR Checks matrix never actually ran against your branch, so carrying it to an internal branch was the only way to get it real CI.

Good catch — the assertion really was vacuous. The merged PR adds mutation-proof output showing the new assertion fails against a broken straggler guard where the old one stayed green, plus coverage for failed dispatches.

Closing this in favor of the merged PR.

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.

[Other]: the recordHeartbeat straggler test asserts the row's initial value, so it cannot fail

2 participants