fix(api): Ever ID unlink ends sessions; stale feed pages never end a new connection; stats link follows identity reset

Merged
EV
3d ago
+199-41

Fixes the three Greptile findings on the 0.24.0 release PR #634 before it goes to stage:

  1. Disconnected Ever ID tokens survived (ever-id-session.service.ts): unlink now ends the account's open Ever ID sessions in the same transaction that removes the identity. Sessions record the account, not the identity (as revokeIdentity already does for a subject-only logout). Password, API client and Google tokens carry no sid and are not affected. Test: the session is revoked after unlink; another account's session stays.
  2. Old responses ending new connections (ever-connect-scheduler.service.ts, refreshSelf): the connection key read with the page goes to endedByPlatform for instance.revoked / instance.disconnected, the 410 re-read, the feed error path and refreshSelf; endedByPlatform already ignores a key that is not the current one. Test: disconnect + connect while the long poll waits, then the old page's disconnected event leaves the new connection active.
  3. Stats link stale after an identity reset (refreshIntegrations / linkStats): the stored config records the linked statsInstanceId; a different current identity is linked again. Existing { linked: true } rows are linked once more. Test: reset → a second statsLink call with the new id.

Prettier 3.5.3 clean on the changed files.

🤖 Generated with Claude Code


Summary by cubic

Fixes three review findings on the 0.24.0 release before it goes to stage, and closes the races found in those fixes.

  • Unlinking an Ever ID identity now ends the account's open Ever ID sessions in the same transaction; sessions record the account, not the identity, so a later subject-only logout can no longer find them. A sign-in now opens its session only while that identity is still the account's, with the account's row locked, so a disconnect can no longer miss a session opened just before it.
  • Feed pages, 410 re-reads, and state reads for a connection replaced by a reconnect no longer end the new connection — the connection key is carried to endedByPlatform, which matches the key and state it read in the same transaction that deletes the connection's rows, so another process's disconnect + connect is never overwritten. A 410 re-read stores its continue cursor only for the connection and the cursor it started at.
  • The statistics link now records the linked statistics instance ID and is checked on every scheduler tick, so an identity the operator reset is linked again without waiting for an event, since { linked: true } rows previously stayed linked to the old identity. Its send writes only the stats_link config, and only while the same consent is still enabled and not pending a remote revoke.

Each fix has a test: session revocation on unlink, a stale page leaving the new connection active, and a second stats link after a reset.