Skip to content

test(memory): count heartbeat reads from the lock's replacement, not the operation's resume - #5638

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/fix/5634-memory-heartbeat-test-race
Nov 19, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/fix/5634-memory-heartbeat-test-race

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5634

Description

The memory test "stops refreshing a lock that was broken and re-taken while it ran (#5418)" failed on a slow runner, although the behavior it tests is correct. It cleared its count of lock-file reads once the operation resumed. On a loaded runner, the next heartbeat could read the lock before that point. Clearing then wiped the very read the test was waiting for, and the count stayed 0.

Two changes, both to the test:

  • The read count is now cleared inside the mocked heartbeat, at the moment the lock is replaced, so no read after the replacement can be lost.
  • The next heartbeat's read is waited for with vi.waitFor, up to 5 s, instead of a fixed 250 ms sleep. A slow runner only makes the test take longer.

The assertions are unchanged: exactly one refresh, at least one read after the replacement, and no further reads in the next 350 ms. There is no retry.

Server Details

  • Server: memory
  • Changes to: one test in __tests__/file-lock.test.ts. No server code, so no changeset and no README change.

Motivation and Context

#5634: it failed in Coverage memory (run 44417378815, job 135201148642) on a PR that did not touch src/memory/.

How Has This Been Tested?

  • All 57 tests in file-lock.test.ts pass.
  • The test passed 40 out of 40 times: 5 rounds of 8 parallel copies, to load the CPU.
  • npm run local:gate exits 0.
  • LLM client: not applicable, since only a test changed.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Protocol Documentation: not applicable, test-only
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly: no change to document
  • I have tested this with an LLM client: not applicable, test-only
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling: not applicable
  • I have documented all environment variables and configuration options: none added

🤖 Generated with Claude Code

…the operation's resume

"stops refreshing a lock that was broken and re-taken while it ran" cleared
its read count once the operation resumed. On a slow runner the next
heartbeat could read the lock before then, so clearing wiped the very read
it was waiting for and the count stayed 0. The count is now cleared inside
the mocked heartbeat, at the moment of the replacement, and the next beat's
read is waited for with vi.waitFor instead of a fixed 250 ms sleep.

Closes #5634

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3a62984

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

memory: MCP interface diff

Base: f420c88b9649 (Merge pull request #5631 from modelcontextprotocol/v2/chore/5598-docker-image-check)
Head: the build in this checkout, at 06f9fa68e250 (Merge 3a62984 into f420c88)

Diffed because it was named (--server).

✅ No interface changes detected.

Tools Prompts Resources Resource templates
Base 9 0 1 0
Head 9 0 1 0

Updated by this run for 3a62984fae8823f9989c248a0b9773d3588721a4.

Copilot AI 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.

🟡 Changes recommended

The test can erase the heartbeat’s final read with a late mock reset, causing a timeout despite correct lock behavior; move the reset before the replacement write.

1 open issue
What changed in this PR

This test-only PR addresses #5634 by adjusting how the memory server’s lock-heartbeat regression test observes ownership changes on slow runners. No server behavior changes.

Changes:

  • Moves the read-count reset into the mocked heartbeat after lock replacement.
  • Replaces a fixed 250 ms delay with vi.waitFor, allowing up to five seconds for a heartbeat read.
  • Preserves the refresh and stopped-read assertions without adding retries.
File Description
src/​memory/​__tests__/​file-lock.test.ts Adjusts read counting and waiting in the lock-ownership heartbeat regression test.

Review effort: Balanced

Comment thread src/memory/__tests__/file-lock.test.ts Resolved
Review of #5638: the next heartbeat can read the replacement token while
the second utimes is pending, and clearing after it would wipe that read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Round 1 answered in 3a62984 (gate exit 0). The one finding was valid: the read count is now cleared before the replacement token is written, so a heartbeat read that lands while the second utimes is pending can no longer be wiped.

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the test-only lock-heartbeat timing adjustment.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cliffhall
cliffhall merged commit ec089ce into v2/main Nov 19, 2026
48 checks passed
@cliffhall
cliffhall deleted the v2/fix/5634-memory-heartbeat-test-race branch November 19, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: file-lock test "stops refreshing a lock that was broken and re-taken" races its own heartbeat on a slow runner

2 participants