Cap a reported message's time at the server's clock, so a browser that runs ahead cannot hide what a routine said - #341
Open
kevin9327 wants to merge 1 commit into
Open
Conversation
…t runs ahead cannot hide what a routine said `POST /:channelId/activity` took `at` from the browser and `recordActivity` applied it with a forward-only guard, returning silently when nothing moved. The parser's comment said a wrong clock could lose a report, not corrupt the row. That is the clock that is behind. One that is ahead lands its report, stamps the row into the future, and then every correct report loses until real time catches up: the routine runner's, which is the one report a headless firing makes; a relayed handoff answer's; every other member's browser. The reply was in the thread and the roster never said so, and the run row read `succeeded`. A reported time is now capped at the server's own clock — a browser may say when, but not later than now. Clamped rather than refused, because clocks are a little ahead all the time; a stamp in the past is kept, so a message and its reply reported by the same clock still land in that order. `now` is injectable, and the test that pins the clamp fails before this change.
kevin9327
requested review from
MikeRyanDev,
davidmckayv,
guidovizoso and
tylerslaton
as code owners
September 2, 2026 22:10
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
POST /api/channels/:channelId/activitytakesatfrom the browser —new Date().toISOString()inchannel-chat.tsx'sreport— andChannelStore.recordActivityapplies it with a forward-only guard (lastMessageAt IS NULL OR lastMessageAt < at), returning silently when nothing moved. The parser's comment said a wrong clock "can lose a report, not corrupt the row". It loses the wrong report only when the clock is behind. When it is ahead, the wrong report lands, the row is stamped into the future, and every correct report after it loses — silently — until real time catches up:server/src/routines/runner.ts,say→recordActivitywith servernew Date()), whose whole job, per its own header, is that one report because no browser is open. The reply is in the thread; the roster line and unread dot never move; the run is recordedsucceeded;announceinserver/src/index.ts, also server time);A browser seven minutes ahead — a laptop that woke up before NTP did — hides seven minutes of everybody else's messages from the roster.
The parser now caps
atat the server's own clock: a report may say when, but not later than now. Clamped rather than refused, because clocks are a little ahead all the time and a report a second early is still the report. A stamp in the past is kept as it is, so a person's message and the reply, reported separately by the same clock, still land in the order that clock saw them.nowis an injectable parameter with a default, so the test can be about a specific gap.Where it runs
recordActivity.pg_notifyinside the same transaction.Boundary and audit
Changelog
Unreleased.Proof
New
server/tests/channel-activity-input.test.ts, no database needed. The clamp case fails before the change and passes after:bun run format:check,bun run lint, and the server typecheck pass.