Skip to content

ui test flake: useDeferredFirstSend's "first send creates one row and is replayed into it" races React's passive-effect flush under load (ejected #36869 from the merge queue) #36967

Description

@objectstack-fleet

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Filing gate: ① a test defect found by seat repo:objectstack#4 while handling a merge-queue ejection; it blocks the landing of PR #36869 (card #35399, p1). Untriaged: grade, domain and state are triage's.

Signature

Queue run 45373444137 (gh-readonly-queue/main/pr-36869-49c6bf3d51…), job Test UI (7/16):
FAIL dom packages/app-shell/src/console/ai/__tests__/useDeferredFirstSend.test.tsx > useDeferredFirstSend — the first send creates the conversation (objectstack#32031) > mounting creates nothing; the first send creates one row and is replayed into it — AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times at :358 (expect(doSend).toHaveBeenCalledTimes(1) right after await flushReplay()).

Reproduction attempts (seat's diagnosis run, no writes)

On the queue's merged tree (origin/main 49c6bf3d51 + #36869 head b36be4c714) and on origin/main alone, after CI's package build step:

  • the file alone, 10 runs each tree: 20/20 passed;
  • merged tree under CPU load (--pool forks --maxWorkers=1 plus 6 CPU hogs on 4 cores, load ~11), 10 runs: 10 passed;
  • merged tree, the full shard as CI runs it (pnpm --dir ui run test --shard=7/16), once: 445 files / 5247 tests, all passed in 649 s (the failing CI shard took 680 s and failed only this test).
    fix(core, console): the offboarding hand-over's owner follows each object's Change Owner switch #36869's diff does not touch console/ai/; its only reach into the test's import closure is one added i18n string per locale.

Mechanism (read from React and Testing Library source; not force-reproduced)

The hook's replay effect sends the stashed message from a setTimeout(0); the test's flushReplay() waits on its own setTimeout(0). setConversationId('conv-1') lands after await res.json() inside waitFor, where RTL has act off; React 19 commits on its scheduler and runs passive effects as a later task (scheduleCallback(NormalPriority, flushPassiveEffects)). waitFor resolves on the DOM change before the remounted pane's useEffect has set the replay timer; RTL's setTimeout(0) drain normally covers that gap, but on a starved runner the scheduler can yield past it — then flushReplay's timer is set first, fires first, and doSend has 0 calls.

Fix (test only)

Replace await flushReplay(); expect(doSend).toHaveBeenCalledTimes(1) with await waitFor(() => expect(doSend).toHaveBeenCalledTimes(1)) (and the same for any sibling case using flushReplay() before a call-count assertion in this file). No product change: the product's ordering is correct; the test's wait is too short.

Dedupe: useDeferredFirstSend flaky, flushReplay, queue-signature useDeferredFirstSend — no open card; the merge-queue triage comment on #36869 (7129251672) counts this the only hit in 24 h.

Activity

  1. added
    bug
    finding
    on Nov 24, 2026
  2. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: lands in area:ai · domain:ui · priority:p2 · Task · pm:queue · size XS.
    Rationale: a test-only fix: replace a fixed setTimeout(0) wait with waitFor. It is p2 because the flake ejected a p1 pull (#36869) from the merge queue and can do so again. repo:objectstack#4 found it and lands #36869, so it may fold the fix in or take the card.

  3. added
    area:ai
    domain:ui
    pm:queue
    priority:p2
    and removed
    bug
    on Nov 24, 2026
  4. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Claim: PM loop round 3 · 2026-11-24T14:25Z
    Session: session_01QSeKYpEsWWE9Y5YtSsDgqZ
    Account: os-justin
    Branch: claude/issue-36967-deferred-first-send-flake
    Worktree: objectstack-issue-36967
    Domain: domain:ui
    Seat: repo:objectstack#4
    File surface: ui/packages/app-shell/src/console/ai/__tests__/useDeferredFirstSend.test.tsx only (test-only; stop on breach; explain in the report)
    Container & model: S, mode:subagent, model: default tier — dispatch-gates.mjs --tier: "no path-derived mandate … the tier stays below the ceiling", effort: medium
    Clause-②: no
    Metadata-protocol: none
    Responsibility: n/a — test-only flake; the fixed setTimeout(0) wait at useDeferredFirstSend.test.tsx:37 races the hook's effect under shard load (ejected PR #36869 from the merge queue; 31 local green runs, does not reproduce in isolation)
    Thread-read: 7130239061
    Premise: holds (origin/main 305fe60 still carries the fixed wait at line 37)
    Serial constraints cleared: PR #36869 (card #35399, this seat) waits for this fix to re-queue; it does not touch this test file — none other

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 24, 2026
  6. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Removed finding: triage graded this card (comment 7130239061, priority:p2, pm:queue), and a graded card leaves finding in the grading stroke; the label was left behind.

  7. removed
    finding
    on Nov 24, 2026
  8. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
    os-dev-report

    {
      "issue": 36967,
      "status": "done",
      "branch": "claude/issue-36967-deferred-first-send-flake",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37014",
      "session": "session_01QSeKYpEsWWE9Y5YtSsDgqZ",
      "premise_still_valid": true,
      "summary": "Premise held: on origin/main 305fe60e6e9, line 37 of useDeferredFirstSend.test.tsx was the setTimeout(0) inside flushReplay(), used at 14 sites. flushReplay is gone. The 12 sites that should replay now await waitFor on the observable their next assertion reads: doSend's call count or call arguments, or, in the StrictMode case, pendingRef.current going null (the stash is cleared in the same task that sends). The 2 sites that must NOT replay (the c2 id change after a consumed send, and the targeted stash held by a mismatched pane) cannot use waitFor, because a waitFor on a negative passes before the replay has had its chance. They go through a new helper, actThenRunPendingTimers: fake setTimeout/clearTimeout only, act(step), then act(vi.runOnlyPendingTimers), with real timers restored in a finally. Every timer the step armed fires before the assertion reads. No assertion is weakened, nothing retries, nothing is skipped, and only the one test file changed (commit c2c6bbd1223, +40/-36).",
      "tests": "All readings on head c2c6bbd1223, every run under os-verify-lock. (1) The file 30 times in a row, `pnpm exec vitest run --maxWorkers=2 FILE` from ui/: 'TALLY pass=30 fail=0 of 30', each run 'Tests 15 passed (15)', VERDICT command-exit 0. (2) Under CPU load: six busy loops on 4 cores (recorded PIDs, killed by trap), --pool forks --maxWorkers=1, 10 runs, load average 14.08 down to 9.47: 'TALLY-LOAD pass=10 fail=0 of 10', VERDICT command-exit 0. (3) One-off mutations, not committed, through scripts/ablation-replace.mjs (anchor hit x1, blob changed, restore proven blob == HEAD a1b77730fb5d and git diff HEAD empty). Leg A, replay timer delayed from 0 to 50 ms in AiChatPage.tsx, which makes the queue failure deterministic: the new file got NEW_EXIT=0 'Tests 15 passed (15)'; the origin/main copy of the file got BASE_EXIT=1 'Tests 12 failed | 3 passed (15)', including 'mounting creates nothing; the first send creates one row and is replayed into it'. Leg B, the targeted-stash guard deleted, which shows the negative drain can fail: NEW_EXIT=1 'Tests 1 failed | 14 passed (15)', and the one failure is 'holds a targeted stash in a mismatched-agent pane' with 'expected \"vi.fn()\" to not be called at all, but actually been called 1 times'. (4) app-shell type-check: `pnpm exec turbo run type-check --concurrency=2 --filter=@object-ui/app-shell` ran tsc --noEmit and then tsc -p tsconfig.test.json: 'Tasks: 69 successful, 69 total', cache miss for app-shell:type-check, VERDICT command-exit 0. `tsc -p tsconfig.test.json --listFilesOnly` lists the edited file (1 hit among 6941 files). (5) `pnpm --dir ui exec vitest run scripts/`: 'Test Files 172 passed | 2 skipped (174)', 'Tests 5129 passed | 2 skipped (5131)'.",
      "gates": "Local subset: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 27 commands for the one path. All 27 ran on c2c6bbd1223 and every one exited 0, captured as `cmd > log 2>&1; rc=$?`. That includes check:nul-bytes, check:cross-package-test-inputs, check:test-source-alias, check:type-check-coverage, check:type-check-debt and check-comment-mask-corpus (23757 files, 0 disagree). --ran reconciliation with the exit codes recorded: 'Run reconciliation — 27 derived, 27 run, 0 NOT-MEASURED, 0 UNRUN', '✓ … a DERIVED zero — all 27 recorded an exit code and none of them is 3'. CI on PR #37014 at head c2c6bbd1223, read right after opening: Check Changeset success; Lint ·, Type Check ·, Governed Surface Queue Guard, PR-body guards and Check PR Size in_progress; the UI jobs (Test UI, Type Check UI, Lint UI) not yet listed. CI convergence is left to the seat. The full app-shell suite (2416 files) was not run locally. This is a declared narrowing: CI's 16-shard Test UI runs it.",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm (Clause-②: no)",
      "mcp_calls": "0",
      "api_writes": "2 seat-side writes, both through the fleet-write relay as objectstack-fleet[bot]. (1) POST /repos/objectstack-ai/objectstack/dispatches carrying pr_create. Relay run 45427020565 executed POST /repos/objectstack-ai/objectstack/pulls (draft, #37014), POST /repos/objectstack-ai/objectstack/issues/37014/assignees (os-justin) and POST /repos/objectstack-ai/objectstack/issues/37014/labels (skip-changeset). The read-back showed the body byte-identical (8372 B) with the assignee and label listed. (2) post-stamped.mjs --comment=36967: this report comment. git push of the branch is not a REST write.",
      "open_questions": [],
      "deviations": "(a) The dispatch asked for a condition wait at every fixed-tick wait. For the 2 negative-assertion sites a waitFor would have weakened the assertion, since it passes at once. I used a deterministic fake-timer drain there (actThenRunPendingTimers) and kept waitFor for the 12 positive sites. Leg B above shows the drain still fails when a replay leaks. (b) The empty-branch probe push before the first edit was refused by the session's auto-mode permission classifier. The branch was pushed with the first commit instead. (c) The three `await act(async () => {})` mount settles were left in place. They are act-scope microtask flushes, not timer waits, and the assertion after them is a negative ('mounting creates nothing'). This is noted in the PR's Acceptance notes. (d) Commit trailers are the repo's model-free pair (Claude-Session + Co-authored-by: Claude), as the dispatch and AGENTS.md require, rather than the harness's model-named Co-Authored-By line. (e) The worktree is removed: node_modules deleted, then `git worktree remove` exited 0 without --force, after the tree read clean and origin had c2c6bbd1223.",
      "security_findings": "none",
      "out_of_scope_findings": ["carrier: none · the three `await act(async () => {})` mount settles in the conversation-create describe were noted in the PR's Acceptance notes and not filed: they race no timer, so they are not a defect"]
    }
  9. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Close-out · 2026-11-24T16:31Z · PR #37014 merged, closing this card by Fixes #36967.

    Delivered: useDeferredFirstSend.test.tsx waits on the replay's own observable where a replay is expected and drains every pending timer before reading a negative; no assertion weakened. PR #36869 (#35399) is back in the merge queue on a main that carries the fix. pm:dispatched stripped in this stroke.

  10. removed
    pm:dispatched
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:uipriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions