Skip to content

fix(pst): suppress double browser-open for same URL (10s dedup)#74

Merged
pstaylor-patrick merged 2 commits into
mainfrom
fix/open-on-post-dedup-double-open
Jun 22, 2026
Merged

fix(pst): suppress double browser-open for same URL (10s dedup)#74
pstaylor-patrick merged 2 commits into
mainfrom
fix/open-on-post-dedup-double-open

Conversation

@pstaylor-patrick

Copy link
Copy Markdown
Owner

Summary

  • Fixes a bug where gh pr create followed immediately by gh pr edit --body-file fired the open-on-post hook twice for the same PR URL, opening the browser back-to-back.
  • Root cause: both gh pr create and gh pr edit --body(-file) match the hook's posting-detection regex, so a create+immediate-description-update pattern produces two opens.
  • Fix: 10-second recency dedup cache at ~/.cache/pst-hooks/open-on-post-dedup.json. Same URL within 10s is suppressed; genuine re-opens after the TTL pass through normally.

Implementation details:

  • Atomic write via temp file + File.rename (POSIX-atomic, safe for concurrent hook processes)
  • Self-healing: JSON::ParserError deletes the corrupt cache and starts fresh
  • Cross-session scope is intentional and documented: two sessions suppressing each other within 10s is an acceptable trade-off (consequence = skipped tab, not a blocked open)
  • TTL is 10s, not 60s: covers milliseconds-apart create+edit while minimizing the false-suppression window

Test plan

  • Create a PR -- browser opens once, not twice
  • Edit a PR description 15+ seconds after creation -- browser opens (not suppressed)
  • Corrupt ~/.cache/pst-hooks/open-on-post-dedup.json manually -- next open self-heals (deletes file, opens normally)
  • PST_NO_BROWSER=1 gh pr create -- no browser open

🤖 Generated with Claude Code

pstaylor-patrick and others added 2 commits June 22, 2026 09:37
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gh pr create then gh pr edit --body-file fire the hook back-to-back
for the same URL, opening the browser twice. Fix: 10-second recency
dedup cache at ~/.cache/pst-hooks/open-on-post-dedup.json. Atomic
write (tmp+rename), self-healing on corrupt JSON, cross-session scope
documented in comments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pstaylor-patrick pstaylor-patrick merged commit 43129c9 into main Jun 22, 2026
1 check passed
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