Skip to content

feat(encounters): render Co-DM presence on the encounter runner (#2212) - #2213

Merged
AwsomeFox merged 2 commits into
mainfrom
copilot/backlog-2212-presence-ui
Aug 12, 2026
Merged

AwsomeFox merged 2 commits into
mainfrom
copilot/backlog-2212-presence-ui

Conversation

@AwsomeFox

Copy link
Copy Markdown
Owner

What

Slice 2 of #816 (Co-DM presence). The server foundation from #2209 (merged via #2210) broadcasts an encounter.presence snapshot over the campaign SSE stream and exposes GET/POST/DELETE /encounters/:id/presence. This PR is the web client that consumes those frames and renders human-collaborator presence on the encounter runner — the UI layer that makes the server-side foundation visible to DMs.

Closes #2212.

Changes

  • useEncounterPresence (new hook): while a DM holds open a running encounter it
    • declares presence (POST /encounters/:id/presence) on open and on every coarse-activity change (viewing ↔ editing), seeding the roster from the snapshot the server returns;
    • heartbeats every 30s while the tab is visible — well inside the 45s server TTL — and re-declares immediately on becoming visible (restoring presence if the tab was hidden past the TTL and the server reaped the entry);
    • leaves via a keepalive DELETE on unmount / navigate-away / loss of eligibility;
    • reconciles the roster from POST responses and from encounter.presence SSE snapshots (applySnapshot), and exposes redeclare() to restore presence on SSE reconnect/recovery.
  • EncounterPresenceIndicator (new presentational component): a compact chip per other collaborator showing name + coarse activity, the current user filtered out, hidden when nobody else is here. Names resolve from the membership roster every member already reads.
  • RunSessionPage: subscribes to encounter.presence frames for the current encounter (handled before the encounter-type filter, like the other non-encounter.updated signals), declares as a DM on a running encounter (activity = editing while a cockpit write is in flight, else viewing), re-declares on SSE reconnect/recovery, and renders the indicator beside the AI-DM presence chip.
  • useCampaignEvents: isCampaignEvent admits the encounter.presence variant (runtime shape guard for the SSE stream — the schema union already included it).
  • i18n: encounters.presence.{viewing,editing,personLabel,groupTitle} in en + ar.

Acceptance criteria (#2212)

Out of scope (later slices)

Advisory intent ("Bob is resolving this turn"), warnings/leases, tab-close/sleep detection beyond SSE disconnect + heartbeat, and presence on the AI driver panel — all called out in #2212.

Secrecy / invariants

No server change. Secrecy is unchanged and stays server-enforced (#2209): a non-DM on a hidden encounter never receives the frames, and the client performs no hiding. userId is the membership-roster identity space (no secret); the encounter id is the sensitive field and is gated server-side at emit time. Presence remains transport-level (in-memory, never audited) — no domain write, no proposal.

Validation

  • npm run typecheck ✅
  • npm run lint ✅ (0 errors)
  • npm run check:i18n ✅
  • npm run test:component:web ✅ (169 passed, incl. new encounter-presence.spec.tsx — 15 tests)
  • npm run test:unit:web ✅ (2674 passed)

Slice 2 of #816 (Co-DM presence). The server foundation from #2209
broadcasts an `encounter.presence` snapshot over the campaign SSE stream
and exposes GET/POST/DELETE /encounters/:id/presence; this is the web
client that makes it visible.

- `useEncounterPresence`: a DM on a running encounter declares presence
  on open, re-declares on a coarse activity change (viewing/editing),
  heartbeats every 30s while the tab is visible (well inside the 45s
  server TTL), and leaves via a keepalive DELETE on unmount / loss of
  eligibility. The roster is reconciled from POST responses and from
  `encounter.presence` SSE snapshots; `redeclare()` restores presence on
  SSE reconnect/recovery.
- `EncounterPresenceIndicator`: a compact chip per other collaborator
  (name + coarse activity), self filtered out, hidden when nobody else
  is here. Names resolve from the membership roster every member reads.
- `RunSessionPage` subscribes to `encounter.presence` frames for the
  current encounter, declares as a DM, and renders the indicator beside
  the AI-DM presence chip.
- `isCampaignEvent` admits the `encounter.presence` variant (runtime
  shape guard for the SSE stream).

Secrecy is unchanged and server-enforced (#2209): a non-DM on a hidden
encounter never receives the frames; the client performs no hiding.
Activity is intentionally coarse (viewing/editing); advisory intent is a
later slice.

Closes #2212

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

Copy link
Copy Markdown

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: 5919484ee2

ℹ️ 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".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds the web-client UI layer for Co-DM encounter presence by consuming encounter.presence campaign SSE snapshots, maintaining a live roster, and rendering a compact “other collaborators” indicator on the encounter runner.

Changes:

  • Introduces useEncounterPresence to declare/heartbeat/leave presence and reconcile snapshot rosters.
  • Adds EncounterPresenceIndicator and wires it into RunSessionPage alongside SSE handling + reconnect re-declare.
  • Extends the campaign-event runtime guard, adds i18n strings (en/ar), and adds component-level coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/web/src/features/encounters/useEncounterPresence.ts New hook for declare/heartbeat/leave + roster reconciliation, with tests relying on its API surface.
apps/web/src/features/encounters/EncounterPresenceIndicator.tsx New presentational indicator that renders “other collaborators” chips from the roster.
apps/web/src/features/encounters/RunSessionPage.tsx Subscribes to encounter.presence SSE frames, re-declares on reconnect/recovery, and renders the indicator.
apps/web/src/lib/useCampaignEvents.ts Updates isCampaignEvent to admit the encounter.presence event variant at runtime.
apps/web/src/i18n/locales/en/encounters.json Adds presence-related strings for the indicator.
apps/web/src/i18n/locales/ar/encounters.json Adds Arabic presence-related strings for the indicator.
apps/web/test/component/encounter-presence.spec.tsx New component/hook tests covering roster rendering, snapshot reconciliation, heartbeats, and leave-on-unmount.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Copy link
Copy Markdown

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: deb7e43bbc

ℹ️ 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".

…x docs

- Discard presence POST responses from an obsolete encounter: when
  navigating A -> B while A's POST is in flight, the response no longer
  overwrites B's roster (activeEncounterRef guard after the await).
- Null-safe self filter: when selfUserId is null (me still loading),
  filter by a sentinel that matches nothing rather than an empty string
  that could match a real userId, so the caller never briefly sees
  themselves (AC #2212.5).
- Fix enabled doc comment to match the actual keepalive-DELETE behavior.
- Remove unused campaignId from UseEncounterPresenceOptions (the hook
  never read it; encounterId is sufficient for the REST endpoints).
- The "include all encounter writes in editing signal" thread is
  out-of-scope by design: the coarse viewing/editing model is
  intentional for this slice (advisory intent is a subsequent slice).
@AwsomeFox
AwsomeFox force-pushed the copilot/backlog-2212-presence-ui branch from deb7e43 to 6f1b5c1 Compare August 12, 2026 02:04

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

Copy link
Copy Markdown

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: 6f1b5c112d

ℹ️ 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".

@AwsomeFox
AwsomeFox merged commit c457a3d into main Aug 12, 2026
16 checks 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.

Co-DM presence: web client renders human-collaborator presence on the encounter runner (#816 slice 2)

2 participants