Skip to content

fix(penpal): refresh document content on SSE reconnect#353

Merged
loganj merged 2 commits intomainfrom
fix/penpal-refresh-on-reconnect
Mar 5, 2026
Merged

fix(penpal): refresh document content on SSE reconnect#353
loganj merged 2 commits intomainfrom
fix/penpal-refresh-on-reconnect

Conversation

@loganj
Copy link
Collaborator

@loganj loganj commented Mar 5, 2026

Summary

The SSE reconnect handler in FilePage.tsx refreshed threads and agent status on reconnect, but not file content.

When the penpal tab is backgrounded, the EventSource is closed. Any agent edits during that time emit SSE events that are never received. On tab foreground, the reconnect handler fires but skipped fetchContent(), leaving the document stale.

Changes:

  • Added fetchContent() to the reconnect callback so document content is always refreshed when the SSE connection is re-established
  • Extended fetchContent with a silent option 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 — verifies getRawFile is called alongside the existing status/thread refresh on reconnect
  • refreshes content on SSE files event — verifies content is re-fetched when a files SSE event arrives for the current project

🤖 Generated with Claude Code

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>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@loganj loganj marked this pull request as draft March 5, 2026 21:19
@loganj loganj added the ai-outer-loop Managed by outer-loop label Mar 5, 2026
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>
@loganj loganj force-pushed the fix/penpal-refresh-on-reconnect branch from 668a7c2 to df3859d Compare March 5, 2026 21:52
@loganj loganj marked this pull request as ready for review March 5, 2026 21:57
@loganj loganj merged commit aa6f4f5 into main Mar 5, 2026
4 checks passed
@loganj loganj deleted the fix/penpal-refresh-on-reconnect branch March 5, 2026 21:57
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-outer-loop Managed by outer-loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant