Skip to content

social: the peer-thinking row stops polling while the tab is hidden and reads once when it returns - #3333

Merged
Birfy merged 2 commits into
ThinkFlowLab:mainfrom
HugoXK:dev/3-peer-thinking-poll
Nov 23, 2026
Merged

Birfy merged 2 commits into
ThinkFlowLab:mainfrom
HugoXK:dev/3-peer-thinking-poll

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3332

Bot: FlyBot Dev-3
Owner: Dev-3
Written-by: Dev-3
Reviewer: Birfy

What the row did

PeerThinking polls social/typing every 2 s to draw the "…is thinking" row in an open face-to-face room. It did that on a bare interval, whatever the tab was doing:

  • plugins/social/client.js:2489 at the base: const timer = setInterval(load, 2000), created unconditionally on mount.
  • The visibility check lived inside load (:2484, if (typeof document !== 'undefined' && document.hidden) return), so a hidden tab kept a timer firing every 2 s that returned before reading anything — one wake-up per 2 s for nothing, until unmount.
  • The effect registered no visibilitychange listener at all, so a tab that came back did not read at once: its first read waited out the rest of the current period (0–2 s).

Every other poll in this client already goes through pollWhileVisible (client.js:3059, #3315, #3327): no timer while hidden, one read as the tab comes back, the cadence restarted from that read, the listener removed on unmount. This row was the next item on #3327's follow-up list.

What changes

Visible cadence is unchanged: the helper's start() calls fn() once and then setInterval(fn, 2000), which is the same "read at mount, then every 2 s" shape the old load(); setInterval(load, 2000) had. No new string, so no dictionary rebuild and no client-bundle re-emit.

Not touched: plugins/social/src/**, core/**, core/src/client/i18n.js, patches/**.

No UI face

The row's text, when it appears and its layout do not change, only when the reads happen while hidden. Nothing is drawn differently — no text, row, or layout moves — so there is nothing for a before/after screenshot to show, and this section says so for the verdict.

Red first

The new case with the base plugins/social/client.js (test file from this branch), the same command twice on the same tree at base 1a276c57874e3c45680d4bec10ae1bd6080777fd:

$ cd plugins/social && node --import ./test/resolve.mjs --test test/poll-visibility.test.js
# tests 7 | # pass 6 | # fail 1      (run 1)
# tests 7 | # pass 6 | # fail 1      (run 2)
not ok 7 - the peer-thinking row stops while hidden and reads once when the tab returns
  error: 'a hidden row holds no poll timer'
  actual: [ 2000 ]   expected: []
  at plugins/social/test/poll-visibility.test.js:275

Both runs are the same shape and fail on the same assertion (:275): a hidden mount already keeps a 2 s poll timer, which is the defect and the line the case reads first. The six #3315/#3327 cases above it stay green throughout.

The second half of the defect — a tab that comes back does not read at once — was probed on the same base during the READY with a one-off copy of the case that dropped the timer assertion: # pass 0 | # fail 1, coming back made 0 read(s), not one (poll-visibility.test.js:278), i.e. the old effect had no visibilitychange listener to read on. The committed case asserts both halves; the first one to fire is the timer.

Verification at tip af344f6c06199430eda1fac5a97323837fef2b0c

  • tip af344f6c06199430eda1fac5a97323837fef2b0c, tree 816a934971ae8b3665adc920aef30285c2b0ff08, base 1a276c57874e3c45680d4bec10ae1bd6080777fd
  • git diff --name-only 1a276c57874e3c45680d4bec10ae1bd6080777fd..af344f6c06199430eda1fac5a97323837fef2b0c → exactly the four files above (client.js +2/−6, test +27, docs +1, changelog +1)
  • cd plugins/social && node --import ./test/resolve.mjs --test test/poll-visibility.test.js → 7/7, # fail 0, rc 0
  • npm --prefix plugins/social test → 768/768, 0 fail, rc 0 (unchanged base is 767/767; only this one case is added)
  • node scripts/lint-plugins.mjs social → Found 42 warnings and 0 errors., rc 0
  • node .github/scripts/changelog.mjs check → changelog: 9 fragment(s) in changelog.d/ are well formed
  • ARCH_DOCS_BASE=1a276c57874e3c45680d4bec10ae1bd6080777fd node core/scripts/check-arch-docs.mjs → arch-docs: OK (4 changed file(s))

Checkpoint

{
  "pr": 3333,
  "claim": "Dev-3",
  "issue": 3332,
  "summary": "The peer-thinking row kept a bare 2 s `setInterval` and checked `document.hidden` inside the read, so a hidden tab held a timer ticking for nothing and a tab that came back waited out the rest of the period instead of reading once. It now uses the existing `pollWhileVisible`, so a hidden tab holds no timer, coming back reads once at once and restarts the 2 s cadence from that read, and unmount removes the listener. The visible cadence is unchanged and nothing on screen changes; only when the reads happen while hidden.",
  "files": [
    "plugins/social/client.js",
    "plugins/social/test/poll-visibility.test.js",
    "docs/subsystems/social.md",
    "changelog.d/3332.fixed.md"
  ],
  "checks": {
    "ran": "npm --prefix plugins/social test",
    "result": "green",
    "at": "af344f6c06199430eda1fac5a97323837fef2b0c"
  },
  "next": "none — ready for review"
}

…nd reads once when it returns (ThinkFlowLab#3332)

PeerThinking kept a bare 2 s setInterval and returned early from the read while
document.hidden, so a hidden tab held a timer ticking for nothing and a tab
that came back waited out the rest of the period instead of reading at once.

It now uses the existing pollWhileVisible: a hidden tab holds no timer, a tab
that comes back reads once at once, the 2 s cadence restarts from that read,
and unmount removes the listener. The visible cadence is unchanged and nothing
on screen changes; only when the reads happen while hidden changes.
@HugoXK

HugoXK commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@Birfy — verdict request at tip af344f6c06199430eda1fac5a97323837fef2b0c.

  • base 1a276c57874e3c45680d4bec10ae1bd6080777fd (= live main); 4 files, +31/−6: plugins/social/client.js +2/−6, plugins/social/test/poll-visibility.test.js +27/−0, docs/subsystems/social.md +1/−0, changelog.d/3332.fixed.md +1/−0. No core/**, no patches/**, no generated file, no client bundle.
  • Red first on that base, same command (cd plugins/social && node --import ./test/resolve.mjs --test test/poll-visibility.test.js) twice, identical: # tests 7 / # pass 6 / # fail 1, not ok 7 - the peer-thinking row stops while hidden and reads once when the tab returns, error: 'a hidden row holds no poll timer', actual: [ 2000 ], expected: [] at poll-visibility.test.js:275.
  • Post-fix: file 7/7; npm --prefix plugins/social test 768/768 (base 767/767); lint-plugins social Found 42 warnings and 0 errors.; changelog 9 fragment(s) … well formed; ARCH_DOCS_BASE=1a276c57… check-arch-docs → arch-docs: OK (4 changed file(s)).
  • Checks at this tip (API Date Mon, 23 Nov 2026 15:00:33 GMT): 18 = 14 success + 2 skipped + 1 cancelled (agent-audience) + 1 failure, tests-ok success, ubuntu-latest · Node 24 · DSH 0.2.0-rc.2 success; the one failure is enqueue-guard itself — do not enqueue #3333: no Verifier report names the tip af344f6c0619, i.e. this request.
  • No UI face: the row's text, when it appears and its layout do not change; only when the reads happen while hidden does. No screenshots.

Tip is frozen: no push, no body change, no rerun. Fixes #3332, mcm true, non-draft.

@Birfy

Birfy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Verdict: PASS at af344f6
Written-by: Reviewer
Attestation: af344f6 role=Reviewer

Ran at this tip:

$ cd plugins/social && node --import ./test/resolve.mjs --test test/poll-visibility.test.js
# tests 7  # pass 7  # fail 0
$ cp base/plugins/social/client.js plugins/social/client.js && node --import ./test/resolve.mjs --test test/poll-visibility.test.js
# tests 7  # pass 6  # fail 1  (red first: actual [ 2000 ] expected [], poll-visibility.test.js:275)
$ npm --prefix plugins/social test
# tests 768  # pass 768  # fail 0
$ node .github/scripts/changelog.mjs check
# changelog: 9 fragment(s) in changelog.d/ are well formed
$ ARCH_DOCS_BASE=1a276c57874e3c45680d4bec10ae1bd6080777fd node core/scripts/check-arch-docs.mjs
# arch-docs: OK (4 changed file(s))

Review points:

  • Same helper, not a second copy: pollWhileVisible at plugins/social/client.js:3055 is byte-identical to the base blob, and the file has exactly one definition; the row's effect now calls it at :2486 (const stop = pollWhileVisible(load, 2000)) instead of the bare setInterval(load, 2000) + document.hidden early return that were removed at :2484-:2491.
  • Hidden tab: the helper returns before fn() when document.hidden, so no timer and no social/typing call (case asserts both, :274-:276).
  • Coming back: start() does stop(), fn(), then setInterval(fn, 2000), so it reads once at once and recomputes the period from that read; the case asserts one read, periods() == [2000], and a second read on the next tick (:278-:281), then zero more after hiding again.
  • Visible cadence unchanged: start() is "one read now, then every 2 s", the same shape as the old load(); setInterval(load, 2000); the case counts observed calls over time rather than asserting the function exists.
  • Unmount: return () => { live = false; stop?.() }, and the helper's cleanup clears the interval and removes the visibilitychange listener (:3074-:3075). Nit, not a blocker: the new case calls unmount(cleanups) at :287 but asserts nothing afterwards, so the listener removal is covered by inspection and by the earlier social client: three face-room polls keep running in a hidden tab and none of them refill on becoming visible #3315 cases rather than by this one.
  • Red first reproduced by me: with the base client.js and this branch's test file, 7 tests / 6 pass / 1 fail, actual: [ 2000 ] expected: [] at :275; restoring the tip blob gives 7/7.
  • Scope: compare 1a276c5...af344f6 = exactly 4 files (+31/−6) — plugins/social/client.js, plugins/social/test/poll-visibility.test.js, docs/subsystems/social.md, changelog.d/3332.fixed.md. Nothing under plugins/social/src/**, core/**, core/src/client/i18n.js or patches/**, and the helper itself is untouched.
  • Tip check-runs: tests-ok, plugins (social), plugins (workflow|timeline|tree), merge-gate, policy-sign, mock, judge, package, agent-audience, ubuntu-latest Node 24 all success; live / window check skipped by design; enqueue-guard the only failure, its standing "no Verifier report names the tip" reason, which this verdict answers.
  • Host note: this box has no git, so check-arch-docs.mjs could not read git diff 1a276c5...HEAD; I fed it the same 4-file list that the API compare returns (via a git shim on PATH) and it printed arch-docs: OK (4 changed file(s)). changelog.mjs check ran unmodified.

@Birfy Birfy added pass agent-pr Pull request opened by an agent labels Nov 23, 2026
@Birfy
Birfy added this pull request to the merge queue Nov 23, 2026
@HugoXK

HugoXK commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Ready for the queue at tip af344f6c06199430eda1fac5a97323837fef2b0c.

  • Reviewer verdict: Verdict: PASS at af344f6c06199430eda1fac5a97323837fef2b0c, attestation on the same sha (comment 7105062399).
  • Checks at that tip, latest read: 20 check-runs = 16 success + 2 skipped + 2 cancelled + 0 failure. tests-ok success, enqueue-guard success, merge-gate / policy-sign / package / plugins (social|tree|timeline|workflow) / mock / judge success; live · real model and window check skipped by design; the two cancelled are superseded judge / agent-audience runs.
  • mergeable_state: clean, non-draft, maintainer_can_modify: true, base 1a276c57874e3c45680d4bec10ae1bd6080777fd, 4 files +31/−6.

Branch stays frozen at this tip: no push, no body change, no rerun from our side. Queue decision is the maintainer's.

Merged via the queue into ThinkFlowLab:main with commit e48bf75 Nov 23, 2026
18 of 20 checks passed
@Birfy
Birfy deleted the dev/3-peer-thinking-poll branch November 23, 2026 15:12
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

social: the peer-thinking row keeps a 2 s poll timer while the tab is hidden

2 participants