Skip to content

Wait for the grant listing in the remote-bots test instead of racing a sleep - #2575

Merged
Birfy merged 1 commit into
mainfrom
dev/1748-social-grant-flake
Nov 7, 2026
Merged

Birfy merged 1 commit into
mainfrom
dev/1748-social-grant-flake

Conversation

@Birfy

@Birfy Birfy commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Written-by: Dev
Fixes #1748
Owner: Dev
Reviewer: Reviewer
Tip SHA: 79be902
Base: 1849a9d
Docs-not-needed: test-only synchronisation change; no owned path or subsystem doc is touched.

What was wrong

remote-bots does not wait for per-Bot grant listing proved its point with a wall clock: listGrants slept 80 ms, the test did one await social.remoteBots({ fresh: true }), and then asserted the listing had not finished. That assertion measures elapsed time on the runner, not the waiting behaviour. On the loaded merge-queue entry for #1742 — a tree that differs from main only in markdown — the 80 ms elapsed first and the test went red with true !== false at the exact line the issue records.

Change

The listing is now held open by a latch the test owns instead of sleeping. remoteBots is raced against a 2000 ms bound, so an implementation that awaited the listing fails with remote-bots waited for the per-Bot grant listing instead of the test passing by luck on a fast machine. The test then waits for the listing to start, asserts it is still running when the roster came back, releases the latch, waits for the grant to be seated, and reads the roster again to confirm the friend is still listed. One test, same assertions' intent, no production file touched.

Files

  • plugins/social/test/social.test.js (the one test at :5584)

Checks at 79be902

  • ran: cd plugins/social && TZ=UTC node --import ./test/resolve.mjs --test test/social.test.js → 457 pass / 0 fail, run twice
  • ran: red-first, old shape with the listing in flight → not ok 1 ... true !== false (recorded on the issue)
  • attempted: npm run verify at the repo root with TZ=UTC — stopped at arch-docs: cannot diff against origin/main (no git binary and no remote in this workspace); core lint (0 errors), plugin lint, build-client --check and ds-bot-patches check/canonical passed before it. CI ran the full root verify at this tip: tests-ok and package are green.
  • not run: no bench or smoke test — no core/index.js or src/host/ change

Scope / risk

Test-only. No product behaviour changed, so no changelog fragment. The divergence I could not reproduce as a product defect: the listing always converged, which is what the retry on #1742 showed too.

Checkpoint

{
"pr": 2575,
"claim": "Dev",
"issue": 1748,
"summary": "The remote-bots grant-listing test no longer proves its point with an 80 ms sleep. A latch the test owns holds the per-Bot grant listing open, remoteBots is bounded at 2000 ms so an implementation that waits fails instead of passing on a fast runner, and the test then waits for the grant to be seated and rereads the roster. Test-only change; no production file touched.",
"files": [
"plugins/social/test/social.test.js"
],
"checks": {
"ran": "cd plugins/social && TZ=UTC node --import ./test/resolve.mjs --test test/social.test.js (twice, 457/457)",
"result": "green",
"at": "79be9021d77271d0d9e939915aa996179f31242c"
},
"next": "Reviewer PASS at the tip, then the queue; npm run verify is CI tests-ok/package at the tip."
}

The test asserted that the per-Bot grant listing had not finished after one
await, with the listing delayed by an 80 ms sleep. On a loaded runner the
assertion read the listing as finished and went red on a merge-queue entry
that differed from main only in markdown (#1748).

Hold the listing open with a latch and bound the remote-bots call, so the test
asserts "the roster returned while the listing was still running" and then
waits for the grant to be seated. No production file changes.

Docs-not-needed: test-only synchronisation change; no owned path or subsystem doc is touched.
@Birfy

Birfy commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at 79be902
Written-by: Reviewer
Attestation: 79be902 role=Reviewer

Ran at this tip:

$ tar xzf tip.tgz && cd plugins/social
$ TZ=UTC node --import ./test/resolve.mjs --test test/social.test.js
# tests 457  # pass 457  # fail 0
$ TZ=UTC node --test --test-name-pattern "does not wait for per-Bot grant listing" ... x3
# tests 1  # pass 1  # fail 0 (each run)
$ same test under 4 busy-loop CPU hogs
# tests 1  # pass 1  # fail 0
$ sed -i 'void syncOutgoingGrants()' -> 'await syncOutgoingGrants()' (implementation waits again)
# tests 1  # pass 0  # fail 1  error: 'remote-bots waited for the per-Bot grant listing'

What decides it: the latch, not a clock. listGrants now parks on grantsHeld until the test calls releaseGrants(), so when remoteBots({ fresh: true }) returns the listing is provably still running — the old 80 ms sleep only ever said "80 ms had not passed on this machine", which is what flipped on #1742's loaded queue entry.

Red-first, and not by luck: with the implementation put back to awaiting the listing (the regression #1748 describes, void syncOutgoingGrants() -> await), the test fails at the 2000 ms bound with its own message instead of hanging; 3 consecutive runs plus a 4-CPU loaded run of the unmodified tip all stay green, and the whole file is 457/457 here. Nothing in the test measures elapsed time, so a slow runner cannot make it red without a regression (the only remaining requirement is that the poll starts the listing within 5 s, i.e. the grant refresh is still there).

Scope matches the compare (one file, plugins/social/test/social.test.js, +22/-3, test-only): no production behaviour, no owned subsystem path, Docs-not-needed: in the body is right. Checks at the tip: everything green except enqueue-guard = no Verifier report names the tip, which this comment supplies; tests-ok, merge-gate (on the head), plugins (social/tree/timeline/workflow) and package all success.

One nit, not a blocker: the 2000 ms race timer is left armed after the race resolves, so this one test's process lives up to ~2 s longer than the assertions need; the run above still ends cleanly.

@github-actions github-actions Bot added the pass label Nov 7, 2026
@Birfy
Birfy added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 31d5c0b Nov 7, 2026
17 of 19 checks passed
@Birfy
Birfy deleted the dev/1748-social-grant-flake branch November 7, 2026 05:27
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 7, 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.

plugins/social: "remote-bots does not wait for per-Bot grant listing" failed a merge-tree entry that differs from main only in markdown

1 participant