Skip to content

fix(grok): discard resume cursor when a thread's workspace changes#5

Merged
justingray0 merged 1 commit into
mainfrom
fix/grok-discard-resume-cursor-on-cwd-change
Jun 29, 2026
Merged

fix(grok): discard resume cursor when a thread's workspace changes#5
justingray0 merged 1 commit into
mainfrom
fix/grok-discard-resume-cursor-on-cwd-change

Conversation

@justingray0

Copy link
Copy Markdown
Owner

Summary

A grok resume cursor is only valid against the working directory it was recorded in. When a thread moves to a different worktree/cwd, replaying the old cursor produces a stale or invalid resume. This change makes a thread start a fresh grok session whenever its workspace changes.

Changes

  • ProviderCommandReactor: when the preferred provider is grok and the cwd changed, pass an explicit null resume cursor when restarting the session. null is a discard sentinel, distinct from undefined ("use the persisted cursor"). Adds shouldDiscardResumeCursorForCwdChange to the restart log.
  • ProviderService: honor the null sentinel by dropping the cursor, and — independently — refuse to reuse a persisted cursor when an explicit cwd differs from the persisted one. Persisted-cwd lookup is hoisted so the cursor-reuse guard and effectiveCwd share it.

Tests

  • Reactor: discards grok resume cursors when the thread workspace changes (asserts resumeCursor: null and the new cwd on the second startSession).
  • Service: does not reuse a persisted resume cursor when an explicit cwd changes.

Note: the two files are intentionally in one PR — the reactor emits the null sentinel that the service-layer change is what interprets; split apart, the sentinel would be silently treated as "use persisted".

🤖 Generated with Claude Code

Resuming a grok session against a different working directory than the one
the cursor was recorded in produces a stale/invalid resume, so a thread that
moves to a new worktree must start a fresh session instead of replaying the
old cursor.

- ProviderCommandReactor: when the preferred provider is grok and the cwd
  changed, pass an explicit `null` resume cursor (a "discard" sentinel,
  distinct from `undefined` which means "use the persisted cursor") when
  restarting the session, and log `shouldDiscardResumeCursorForCwdChange`.
- ProviderService: honor the `null` sentinel by dropping the cursor, and
  independently refuse to reuse a persisted cursor when an explicit `cwd`
  differs from the persisted one. Persisted cwd lookup is hoisted so both
  the cursor-reuse guard and `effectiveCwd` share it.

Adds reactor- and service-level regression tests covering the
worktree/cwd-change paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Jun 29, 2026
@justingray0 justingray0 merged commit be5bd3b into main Jun 29, 2026
6 of 10 checks passed
@justingray0 justingray0 deleted the fix/grok-discard-resume-cursor-on-cwd-change branch June 29, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant