Repository navigation
test(app-shell): useDeferredFirstSend waits on the replay, not a fixed tick - #37014
Merged
objectstack-fleet[bot] merged 1 commit intoNov 24, 2026
Merged
Conversation
…d tick The replay of a deferred first send fires from a setTimeout(0) armed in the pane's effect. The test's flushReplay() waited on its own setTimeout(0), which races that effect whenever React flushes it outside act (the remount after the async create): on a starved merge-queue runner the test's tick fired first and `doSend` read 0 calls. Every positive step now waits on the observable its assertion reads (waitFor on doSend or the stash). The two no-replay steps, which have no observable to wait for, run under fake setTimeout and fire every timer the step armed before asserting. No assertion is weakened; no product change. Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Author
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
objectstack-fleet
Bot
deleted the
claude/issue-36967-deferred-first-send-flake
branch
November 24, 2026 16:22
This was referenced Nov 24, 2026
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.
Fixes #36967
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
ui/packages/app-shell/src/console/ai/__tests__/useDeferredFirstSend.test.tsxonly. TheflushReplay()helper, which waited on its ownsetTimeout(0), is gone; every call site now waits on a condition:waitForon the exact observable the next assertion reads:doSend's call count or its call arguments, or, in the StrictMode case, the stash being consumed (pendingRef.currentnull; the timer clears the stash and sends in the same task).c2id change after a consumed send, and the targeted stash held by a mismatched pane) cannot usewaitFor, because awaitForon a negative passes before the replay has had its chance. They run through a new helper,actThenRunPendingTimers(step): fakesetTimeout/clearTimeoutonly,act(step), thenact(vi.runOnlyPendingTimers), then real timers again in afinally. Any replay timer the step armed has fired before the negative assertion reads.No assertion is removed or loosened, there are no retries, and nothing is skipped. Where a
waitFornow holds the first assertion of a block, that assertion has moved into thewaitForand is not repeated after it. RTL'sasyncWrapperends everywaitForwith its ownsetTimeout(0)drain, so an exactly-once count read after awaitForstill sees any sibling timer that fired in the same tick.Why the old wait raced: the hook arms the replay from a
useEffectwithsetTimeout(0). In the conversation-create cases,setConversationId('conv-1')lands afterawait res.json()insidewaitFor, where RTL has turned act off. React 19 then runs the remounted pane's passive effects as a later scheduler task, so on a starved runner the test'ssetTimeout(0)could be registered before the replay timer was armed. The test's timer then fired first, anddoSendread 0 calls (queue run 45373444137,Test UI (7/16)). No product change is needed: the product's ordering is correct, and only the test's wait was too short.Read first (by risk):
actThenRunPendingTimersand its comment block near the top of the file: the only new mechanism. Check that it restores real timers infinally.mounting creates nothing; the first send creates one row and is replayed into it: the case that failed in the queue.the replayed first send survives the effect teardown StrictMode runs on mount: the wait moved from the abort check to stash consumption.Tests
All local readings are on head
c2c6bbd1223. Each section below folds its log excerpts.30 repeated runs of the file: 30/30 green
bash os-verify-lock.sh -- bash loop.sh 30, where each iteration runspnpm exec vitest run --maxWorkers=2 packages/app-shell/src/console/ai/__tests__/useDeferredFirstSend.test.tsxfromui/:Under CPU load: 10/10 green (six busy loops on 4 cores, one fork, load average 9.4 to 14.1)
The setup mirrors the seat's diagnosis run: six busy loops (recorded PIDs, killed by trap), and
vitest run --pool forks --maxWorkers=1on the file, ten times, under the lock. Other agents' work was also running on the same box.A green run under load cannot prove the race is closed: the old file also passed 31 local runs. The mutation run below is the deterministic evidence.
One-off mutations (not committed): the new waits are conditions and the negative drain can fail
Both mutations ran through
scripts/ablation-replace.mjs(anchor hit x1, blob changed, restore proven: blob == HEAD andgit diff HEADempty). They touch the product file only for the duration of the run.Leg A: replay delayed from 0 ms to 50 ms (
AiChatPage.tsxreplay timer}, 0);changed to}, 50);). This is the queue failure made deterministic: the replay timer fires after any fixedsetTimeout(0). The origin/main copy of this test file was run beside the new one, from a temporary sibling file that was deleted afterwards.Leg B: the targeted-stash guard deleted (a mismatched pane now replays). This checks that
actThenRunPendingTimersreally fires the replay timer before the negative assertion reads, so the check cannot pass trivially:app-shell type-check: green (both tsc programs, edited file compiled)
pnpm exec turbo run type-check --concurrency=2 --filter=@object-ui/app-shell, under the lock. It builds the^buildclosure first, then runstsc --noEmitfollowed bytsc -p tsconfig.test.json.tsc -p tsconfig.test.json --listFilesOnlylists the edited file (1 hit among 6941 files), so this reading covers it.My first attempt, a bare
pnpm --filter @object-ui/app-shell type-checkwithout the@object-ui/*dists built, exited 2 on TS2307 "cannot find module" cascades. That was a missing build, not a type-check verdict, so I re-ran it through turbo as above.Acceptance notes
await act(async () => {})lines in the three conversation-create cases ("let the mount-time resolve settle") are left as they are. They are act-scope flushes, not timer waits. On the cache-miss path the mount resolve runs synchronously inside the effect, so these lines race nothing. The assertion that follows them is a negative ("mounting creates nothing"), which no condition wait could express.@object-ui/app-shelltest suite (2416 files) is left to CI'sTest UI(16 shards). Locally I ran only the edited file, plus the derived gate families below.Verification
Two-minute check: from
ui/, runpnpm exec vitest run packages/app-shell/src/console/ai/__tests__/useDeferredFirstSend.test.tsx. ExpectTests 15 passed (15).Derived gate families: 27/27 run, all exit 0
The list comes from
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 27 commands for the one changed path. Each was run onc2c6bbd1223, with its exit code captured before any pipe. Reconciliation:pnpm --dir ui exec vitest run scripts/:Test Files 172 passed | 2 skipped (174),Tests 5129 passed | 2 skipped (5131).No changeset:
@object-ui/app-shellisprivate: true, and itsfileslist (dist,src/styles.css, README, CHANGELOG, LICENSE) does not ship tests. The PR therefore carriesskip-changeset.Generated by Claude Code