Skip to content

Finish session architecture with heartbeat, routing, and tap-to-resend - #9

Merged
Andyccr merged 1 commit into
mainfrom
cursor/arch-complete-7527
Sep 17, 2026
Merged

Andyccr merged 1 commit into
mainfrom
cursor/arch-complete-7527

Conversation

@Andyccr

@Andyccr Andyccr commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Completes the architecture split started in #6 and #8. ChatSession is now an orchestrator: heartbeat, payload routing, and status copy live in their own modules, RoomManager no longer leaks the session, and failed self messages can be tapped to resend on the existing v1 wire.

What changed

  • Heartbeat owns hello / relay-poll timers and visibility pause.
  • Payload router decodes v1 hello / typing / ack / chat; the session only applies effects.
  • Status is derived from the session machine (deriveStatus + sameStatus).
  • Outbound keeps the original payload after ack timeout so a late ack or tap-to-resend can settle.
  • Presence prunes peers that stop announcing (lastSeenAt).
  • Cache drops in-flight pending markers but keeps failed so reload can retry.
  • RoomManager exposes isJoined() / resend() instead of getSession().
  • UI: self lines show 发送中 / 未送达; tapping 未送达 resends the same id.

Still static GitHub Pages, public WebTorrent/Nostr signalling, no TURN, no libp2p, no PWA, no protocol v2, no restyle.

Test plan

  • npm test (53 tests)
  • npm run build:pages
  • Two windows, same room: send, see 发送中 then 送达 when the peer supports ack
  • Force a failed delivery (or wait for timeout with no ack-capable peer gone), tap 未送达 to resend
  • Switch rooms / reload: pending markers are not restored; failed lines remain retryable

CI on this branch is green. Local two-window check on the Vite app confirmed P2P join, bidirectional chat, and the 送达 mark on self bubbles.

Open in Web Open in Cursor 

Extract heartbeat, payload routing, and status derivation from ChatSession so it only orchestrates. Outbound keeps payloads for late acks and resend, presence prunes silent peers, and the room cache drops in-flight pending markers. RoomManager no longer leaks the session. Failed self messages show as 发送中/未送达 and can be tapped to retry over the same v1 wire.

Co-authored-by: Andy <mail@andychen.net>
@Andyccr
Andyccr marked this pull request as ready for review September 17, 2026 19:57
@Andyccr
Andyccr merged commit 4205b67 into main Sep 17, 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.

2 participants