Skip to content

fix(session-id): atomic persisted id writes; Cursor MCP clients use persisted id - #56

Merged
jonathanong merged 1 commit into
mainfrom
fix/session-id-persist-and-cursor-mcp
Nov 21, 2026
Merged

jonathanong merged 1 commit into
mainfrom
fix/session-id-persist-and-cursor-mcp

Conversation

@jonathanong

Copy link
Copy Markdown
Owner

Summary

  • Write persisted session-id files atomically #48: writePersistFile now writes .local/<harness>-session-id to a unique temp file, created exclusively with mode 0600, 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.
  • MCP: mark Cursor clients so omitted session ids can use the persisted Cursor file #49: The MCP CallTool handler passes server.getClientVersion()?.name to withClientHarnessMarker. When that name contains "cursor" and CURSOR_AGENT isn't already set, it adds CURSOR_AGENT=1 to the env used to resolve the session id. Only the marker is set, never the runtime hint, so the persisted Cursor file is still read. The CLI still requires CURSOR_AGENT.

Cursor's MCP client name is reported as cursor-vscode in 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: checks 0600 mode, 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 over InMemoryTransport. With a cursor-vscode client, entry_append without a sessionId resolves to the persisted Cursor id; with any other client, it errors.
  • pnpm lint, pnpm typecheck and pnpm test:coverage (100%) all pass locally.

Closes #48
Closes #49

🤖 Generated with Claude Code

https://claude.ai/code/session_01MaU9nwkoytMMzPpAj6VERT

…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
@chatgpt-codex-connector

This comment has been minimized.

@chatgpt-codex-connector

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@codecov

This comment has been minimized.

@jonathanong
jonathanong merged commit fea4dba into main Nov 21, 2026
9 checks passed
@jonathanong
jonathanong deleted the fix/session-id-persist-and-cursor-mcp branch November 21, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: mark Cursor clients so omitted session ids can use the persisted Cursor file Write persisted session-id files atomically

1 participant