Skip to content

mac: fix a second observe-then-defer-read flake in LayoutCapabilityConsumerTests (GH-680's class, needs #719 first) - #732

Closed
d-q222 wants to merge 1 commit into
agent/daniel-parent/transcript-flakefrom
agent/daniel-muse-lead/layoutcap-observer-flake
Closed

d-q222 wants to merge 1 commit into
agent/daniel-parent/transcript-flakefrom
agent/daniel-muse-lead/layoutcap-observer-flake

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Draft — depends on #719 merging first (this branch is stacked on
agent/daniel-parent/transcript-flake, which is itself stacked on #698).

Scope

Proactive fix for a second instance of GH-680's bug class, in
apps/mac/Tests/FlashTeXMacTests/LayoutCapabilityConsumerTests.swift's
private AppliedResults helper (Swift/Mac test infrastructure only;
crates/ untouched). Not filed against a numbered issue — found by
daniel-parent proactively after #719 fixed the first instance, since this
helper has the identical shape and would flake under load the same way.

AppliedResults used the same observe-resultID-then-defer-read pattern
#719 fixed for ResultIDChanges: withObservationTracking to detect a
change, then a Task { @MainActor ... } reading model.result?.revision/
model.negotiation on a later turn. Racy for the same reason: two
applies landing before the deferred read runs coalesce onto the second
value, silently dropping the first.

Not a copy-paste of #719's fix — a real ordering hazard found and handled
correctly.
#719's onResultApplied hook fires in handle(.result)
before bindLayout sets negotiation, so reusing that hook here would
have synchronously captured the previous reply's negotiation — a subtler,
silent-wrong-value bug, not just a race. Added a second, later hook,
onResultBound: ((Int, LayoutNegotiation) -> Void)?, fired immediately after
bindLayout returns so negotiation reflects the current reply. #719's own
hook and call site are untouched.

Overlap check

Compiler-only overlap: none (Swift-only change). No other open PR touches
ShellModel.swift's hook declarations or LayoutCapabilityConsumerTests.swift.

Test results

New regression test testAppliedResultsCapturesTwoBackToBackRepliesWithoutCoalescing:
two back-to-back applies (legacy reply, then an extended-capability reply)
with zero awaits between them, asserting both (revision, negotiation)
pairs are recorded with each reply's own negotiation — a stale-negotiation
hookup fails this test too, not just a dropped-entry regression.

Independently re-verified by the supervisor:

  • Reviewed the full diff: ShellModel.swift (+12, hook declaration + one
    call site after bindLayout), LayoutCapabilityConsumerTests.swift
    (rewrote AppliedResults to record synchronously through the hook,
    removing withObservationTracking/deferred Task; added the new test).
  • swift build --disable-sandbox: succeeds (pre-existing unrelated resource
    warnings only).
  • swift test --disable-sandbox --filter ShellLayoutNegotiationTests:
    11 passed, 0 failed (includes the new test).
  • Mutation check (re-run independently, not just trusted from the lane's
    report): changed the onResultBound call site to always pass .legacy
    (simulating a stale-negotiation bug), re-ran the new test: fails,
    confirming it genuinely discriminates a wrong-negotiation hookup, not just
    a missing one. Restored, re-ran: passes again.
  • Lane's own root-cause confirmation (scratch-only, not committed): the
    pre-fix observe-then-defer helper driven through the same two-apply
    sequence recorded the second reply's pair twice, losing the first —
    reproducing RuntimeTranscriptTests: flaky extra compile_result under full-suite load #680's exact failure mode deterministically.
  • Full apps/mac suite (lane's own report, load 7.2→13.8 across 2 runs with
    --skip "DesignSnapshots|Completion|IMECompositionTests|DocumentFiles" for
    the pre-existing crash/flake families mac: fix GH-680 flaky extra compile_result — test's observer, not the shell #719 already documented): identical
    13 pre-existing failures in both runs (unrelated: keychain-in-sandbox and
    timing-sensitive UI suites — confirmed present on the untouched base via
    git stash too), zero failures elsewhere, including
    ShellLayoutNegotiationTests and RuntimeTranscriptTests.

Not done

Nothing else in scope. apps/mac/Package.resolved is untracked/generated by
the test runs and deliberately left out of this PR.

🤖 Generated with Claude Code

…ound hook

LayoutCapabilityConsumerTests' AppliedResults had GH-680's exact
observe-then-defer-read race: it tracked resultID with
withObservationTracking and read result revision + negotiation in a
deferred Task, so two applies landing before the deferred read runs
coalesce and the first reply's pair is lost. A scratch probe of the old
helper through two back-to-back applies confirmed it: [(rev3, ext),
(rev3, ext)] -- rev2's legacy pair gone.

Fix, mirroring #719's ResultIDChanges rewrite: ShellModel gains a
test-only synchronous onResultBound hook fired after bindLayout (the
existing onResultApplied fires BEFORE bindLayout, so negotiation read
there would still hold the previous reply's value -- verified in
handle(.result)); AppliedResults records the hook's (revision,
negotiation) arguments synchronously. New deterministic regression test
testAppliedResultsCapturesTwoBackToBackRepliesWithoutCoalescing applies
a legacy then an extended reply with zero awaits between and asserts
both pairs, each with its own reply's negotiation.

Implementation-Agent: muse-spark-1.3-contributor
jay3332 added a commit that referenced this pull request Sep 19, 2026
…econd observe-then-defer-read flake in LayoutCapabilityConsumerTests

Stacked on #719 (already on main as agent/daniel-parent/transcript-flake);
only the branch's own commit lands. Test infrastructure plus one test-only
`onResultBound` hook on ShellModel.

Implementation-Agent: Claude Code (mac-claude-a / lane-integrate2)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
jay3332 added a commit that referenced this pull request Sep 19, 2026
…he integration batch + package definitions

The pin reads main again after the second integration pass (#827 cherry-picks,
#863, #950, #737/#739/#758/#732/#740/#825, visual-oracle tooling) and the
`metadata.packages` work (`crate::package_definitions`, tex-expansion's
`package_defs.rs`). `git archive` of this tree's `crates/compiler` and
`crates/tex-expansion`, PINs at the merge commit, VENDORING.md rows updated,
`scripts/check-vendor-pins.sh` both "up to date". render-pipeline 819/0 in
both profiles against the new pins; compiler 1368/0, tex-expansion 150/0
release; Mac inventory sync current; swift build clean.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
@jay3332

jay3332 commented Sep 19, 2026

Copy link
Copy Markdown
Member

Merged into main 2d6ac3e (merge commit on the integration branch; GitHub does not detect it because this PR's base is a stacked branch, whose content is already on main).

@jay3332 jay3332 closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants