Repository navigation
fix(session-id): atomic persisted id writes; Cursor MCP clients use persisted id - #56
Merged
Merged
Conversation
…ersisted id Write .local/<harness>-session-id via a 0600 temp file renamed into place, so concurrent readers never see a truncated file and a symlink at the target is replaced rather than followed. Mark the MCP resolution env with CURSOR_AGENT when the MCP client identifies itself as Cursor, so tool calls that omit sessionId can fall back to the persisted Cursor id. Closes #48 Closes #49 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MaU9nwkoytMMzPpAj6VERT
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
writePersistFilenow writes.local/<harness>-session-idto a unique temp file, created exclusively with mode0600, then renames it into place. Concurrent readers, such as the root-Codex strict read-back, see the old or the new id and never a truncated file. A symlink at the target is replaced rather than followed. If the write or rename fails, the temp file is removed.CallToolhandler passesserver.getClientVersion()?.nametowithClientHarnessMarker. When that name contains "cursor" andCURSOR_AGENTisn't already set, it addsCURSOR_AGENT=1to the env used to resolve the session id. Only the marker is set, never theruntimehint, so the persisted Cursor file is still read. The CLI still requiresCURSOR_AGENT.Cursor's MCP client name is reported as
cursor-vscodein a community index of MCP clients. Nobody has confirmed it in a live session yet, so the code matches any name containing "cursor", case-insensitively.Out of scope, as the issues already note: concurrent writers sharing one persisted file still resolve last-writer-wins.
Tests
persist-atomic.test.mts: checks0600mode, that no temp files are left behind, that a symlink at the target is replaced and its target left unchanged, and that the temp file is cleaned up when the rename fails.client-marker.test.mts: unit tests for the helper, plus an end-to-end MCP call overInMemoryTransport. With acursor-vscodeclient,entry_appendwithout asessionIdresolves to the persisted Cursor id; with any other client, it errors.pnpm lint,pnpm typecheckandpnpm test:coverage(100%) all pass locally.Closes #48
Closes #49
🤖 Generated with Claude Code
https://claude.ai/code/session_01MaU9nwkoytMMzPpAj6VERT