Skip to content

fix(resume-patterns): return the most recent resume command from scrollback - #364

Open
dormouse-bot wants to merge 1 commit into
mainfrom
fix/resume-patterns-most-recent
Open

fix(resume-patterns): return the most recent resume command from scrollback#364
dormouse-bot wants to merge 1 commit into
mainfrom
fix/resume-patterns-most-recent

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

Problem

detectResumeCommand scanned scrollback by matching each pattern against the whole joined text with a non-global regex:

const text = lines.join('\n');
for (const pattern of BUILTIN_PATTERNS) {
  const match = text.match(pattern.regex);
  if (match) return pattern.extract(match);
}

String.match with a non-global regex returns the first occurrence, i.e. the chronologically oldest one in the scrollback. When a pane resumes an agent more than once, each run prints its own resume hint (codex resume <id>), so the buffer holds several. session-save.ts persists the returned command as resumeCommand so a restored pane can resume the current session — but it was getting the stale, oldest id.

There was also a secondary recency bug across pattern types: codex was always checked before claude, so an older codex resume won over a more recent claude --resume.

Fix

Scan the last 50 lines newest-first and return the first match found, which is the most recent resume command regardless of type. Behavior for single-occurrence scrollback is unchanged.

Tests

Added two regression tests — repeated same-command hints (most recent wins) and most-recent-wins across pattern types. Both fail against the old first-match logic and pass with the fix. The existing seven tests are unchanged and still pass.

…llback

detectResumeCommand matched each pattern against the whole scrollback with
a non-global regex, which returns the first (oldest) occurrence. A pane that
resumed more than once prints a fresh resume hint each time, so the persisted
resumeCommand pointed at a stale session id. Scan lines newest-first instead,
returning the most recent match across all patterns.

Adds regression tests for repeated same-command hints and for most-recent-wins
across pattern types; both fail against the old first-match logic.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: f2ca6d6
Status: ✅  Deploy successful!
Preview URL: https://a3091070.mouseterm.pages.dev
Branch Preview URL: https://fix-resume-patterns-most-rec.mouseterm.pages.dev

View logs

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.

1 participant