fix(penpal): refresh document content on SSE reconnect#353
Conversation
The SSE reconnect handler only refreshed threads and agent status but not file content. When the tab was backgrounded (closing the EventSource) and then foregrounded, any edits made in the interim would not appear. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 668a7c2edd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Extends the existing reconnect test to assert getRawFile is called, and adds a new test for the SSE 'files' event triggering fetchContent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
668a7c2 to
df3859d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df3859d74b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| [project, fetchThreads, fetchContent, fetchAgentStatus], | ||
| ), | ||
| useCallback(() => { | ||
| fetchContent({ silent: true }); |
There was a problem hiding this comment.
Skip reconnect refresh on initial SSE open
useSSE invokes onReconnect from es.onopen for the very first EventSource connection (apps/penpal/frontend/src/hooks/useSSE.ts, lines 18–20), and FilePage already does an initial fetchContent() in its mount effect. Calling fetchContent({ silent: true }) here adds a second raw-file request on every page load, which doubles startup payload for large files and can race loading/content state (the silent call can clear loading before the original fetch completes).
Useful? React with 👍 / 👎.
Summary
The SSE reconnect handler in
FilePage.tsxrefreshed threads and agent status on reconnect, but not file content.When the penpal tab is backgrounded, the
EventSourceis closed. Any agent edits during that time emit SSE events that are never received. On tab foreground, the reconnect handler fires but skippedfetchContent(), leaving the document stale.Changes:
fetchContent()to the reconnect callback so document content is always refreshed when the SSE connection is re-establishedfetchContentwith asilentoption to suppress error toasts during background reconnects (avoids flashing a stale error before the fetch resolves)Test plan
Covered by unit tests in
FilePage.test.tsx:refreshes content, agent status, and threads on SSE reconnect— verifiesgetRawFileis called alongside the existing status/thread refresh on reconnectrefreshes content on SSE files event— verifies content is re-fetched when afilesSSE event arrives for the current project🤖 Generated with Claude Code