Repository navigation
fix(render): stop publishing a tokenless ack on a configure failure - #2990
Conversation
…e failure The presenter worker acknowledged a failing `configure` that had no frame waiting with the reserved `PRESENT_NON_FRAME_TOKEN` (`u64::MAX`) sentinel. `configure`/`resize` are sent on their own tick (opacity adoption, resize reflow), so that is the ordinary shape of a configure failure: the synthetic ack could therefore be the first ack a caller observed, ahead of the ack for a frame submitted moments later, and a frame submitted after the worker decided to exit was dropped without any ack at all. Ack ownership decision (recorded in the module docs, the configure branch and `PresentAck::token`): the worker owns every ack, and an ack always names the submitted frame it describes. A configure that carried a frame still acknowledges *that frame's* token as `error` (a frame built for the old extent must never be presented). A configure that carried no frame is not a frame outcome and publishes no ack; the worker exit is its signal, which the runtime already handles by retaining the damage and recovering (`is_active() == false` branch). `PRESENT_NON_FRAME_TOKEN` and the runtime's sentinel branch are removed rather than kept as a contract nothing may produce. Tests: acks are now attributed by token. The old-extent test blocks a frame in the acquire so the failing configure and its frame are taken together (the other ordering is a separate case), drains both acks in one pass and finds each by token; a new test asserts a frame-less configure failure publishes no ack, leaves the ring empty, and makes the following `submit` refuse the frame.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
CI status on head The macOS acceptance item ("10 consecutive macOS ARM64 runs of |
Xuepoo
left a comment
There was a problem hiding this comment.
Independent guard-lane review — PR #2990 (head 33787414)
Reviewed independently of the authoring lane: I read the diff, the PR body, and the touched code in a separate worktree (.worktrees/ctx-1735-present-ack), and re-ran the focused gates myself against CARGO_TARGET_DIR=.targets/ctx-1735. I did not modify, commit, or push the branch.
The change is small and the interesting question is not "does it compile" but "does deleting the sentinel silently drop a production state transition". It does not: the transition the sentinel branch performed (pending_full_redraw = true) is performed unconditionally by the inactive branch of the same poll_presenter call, and the dead-worker wake still happens through mark_exited.
Checks
1. Ownership claim — PASS.
Only two ack producers exist, both inside worker_loop and both carrying a real frame token:
crates/bitty-render/src/present.rs:745-750— configure failure,token: frame.token, only underif let Some(frame).crates/bitty-render/src/present.rs:785-788— present attempt,token: frame.token.
WorkerShared::push_ack is private (present.rs:567) and is the only writer to the ring; PresentAck.token is a plain u64 with no reserved value (present.rs:387-393); drain_acks (present.rs:1141) is the only reader and the runtime attributes by token (crates/bitty-runtime/src/runtime/present.rs:7403-7409). grep -rn PRESENT_NON_FRAME_TOKEN over the tree (excluding target/, .git/) returns nothing. The doc comment's claim is true of the code, not just of the commit message.
2. Deleted PRESENT_NON_FRAME_TOKEN — PASS.
- No consumer is unaccounted for: zero remaining references anywhere (rs and md).
- Configure-failure recovery still retains damage and requests a full redraw:
runtime/present.rs:7298-7302(inactivebranch) setspending_present = None; pending_full_redraw = true, and it runs in the samepoll_presenterinvocation that drained the acks (7229-7237), beforerecover()(7313-7332). - A dead worker still wakes the loop:
mark_exited(present.rs:591-612) storesstop = trueand fires the wake callback, sois_active()(941-943) goes false,submitrefuses (1105-1107), andRuntime::set_present_waker(runtime.rs:2892-2897) has the callback installed. - No now-dead state: the deleted branch's entire effect was
pending_full_redraw = true(it discarded the detail), which theinactivebranch sets unconditionally — the old branch is a strict subset, so nothing became unreachable.clippy -p bitty-render -p bitty-runtime --all-targets -- -D warningsis clean, so nodead_code. - Note (non-blocking): the const was
pubin a crate withpublish = true; its removal is an API-surface change worth a release note.
3. Behavioural contract — PASS.
- Frame taken with the failing configure: acked
Error("configure failed: …")with that frame's token, and thereturnatpresent.rs:751precedes the present path (756-788), so the old-extent frame is never presented. Test assertscontrol.presented() == 1(frame 0 only). - No frame: nothing is pushed; the exit is the signal. The runtime then refuses the next
submitand retains damage atruntime/present.rs:7827-7832, and theinactivebranch clearspending_presentand forces the redraw. - No production caller can block on an ack that will never arrive: the only production consumer is
poll_presenter(runtime/present.rs:7232), which drains at mostPRESENT_ACKS_PER_TICKand never waits.drain_until/wait_until/drain_tokenexist only inpresent/tests.rs(307-318,320-330,344-358) and all are deadline-bounded. There is norecv/wait/blocking-read on the ack ring anywhere. The stuck branch is also unreachable as a substitute wait:inactiveis evaluated after the ack drain and beforestuck(7298vs7347).
4. Test discrimination — PASS (with nits).
a_configure_failure_never_presents_the_old_extent_frameis deterministic, not just "less racy":Gate::enteris called insideFakeBackend::present(tests.rs:225,51-58),wait_entered(1)therefore proves frame 0 is already inside the acquire, the failingconfigureandsubmit(frame 1)both happen beforerelease()(tests.rs:799-819), and the worker takes frame+configure atomically (present.rs:697-716). Both acks are then matched by token (tests.rs:823-839), withacks.len() == 2andqueued_acks() == 0after exit (851-855).
Red if: frame 1 were presented (presented() == 2), acked under a token other thansecond, an extra ack appeared (len != 2orqueued_acks() != 0), or the recovered worker did not present. It would not go red if the sentinel emission were restored — the taken frame isSomein that scenario, which is exactly why the second test exists.a_configure_failure_without_a_frame_publishes_no_ack: red iff any ack is synthesised on the no-frame path — restoringmap_or(PRESENT_NON_FRAME_TOKEN, …)makesqueued_acks()(tests.rs:884-890) 1 instead of 0. The scenario is genuinely frame-less (nothing is ever submitted; the worker takes the configure alone).- Nits:
assert_eq!(second_ack.token(), second)(tests.rs:835-839) is tautological given thefindpredicate; "never presented" is proven by present count, not by extent. - Empirically deterministic here: 8/8 consecutive runs of both tests green, and the full
present::testsset 23/23.
5. Race soundness — PASS.
The ordering window is removed, not hidden: after this change there is no ordering between a configure's failure and an ack at all — the failing configure either acks the frame taken in the same lock acquisition (present.rs:697-716) or acks nothing. One residual ordering remains, and it is pre-existing and handled: between worker_loop's return (751) and mark_exited (691) — deliberately after the backend drop (present.rs:678-691) — is_active() is still true, so a submit in that window returns Some and its frame is absorbed without an ack. That is bounded by surface teardown (previously it extended indefinitely past the exit decision), and poll_presenter's inactive branch clears pending_present and forces the full redraw (7298-7302), so nothing is committed and no pixels are lost. The contract is therefore well defined: an ack always names a frame the worker took; a submission either gets its own ack or is covered by the exit signal, which the runtime treats as "retain everything".
6. MSRV 1.85 — PASS.
cargo +1.85 check -p bitty-render -p bitty-runtime --tests --offline --locked exits 0. The only new conditional is if let Some(frame) = frame.as_ref() (present.rs:745) — no let-chain. No const-eval-only constructs, no new cfg gates.
7. Hygiene — PASS.
English only, no host-specific values (test extents are synthetic), no new allow(...), no secrets. rustdoc: I forced fresh doc builds (cargo rustdoc -p bitty-render -- -D warnings, same for bitty-runtime), both exit 0, so the new module-doc link [PresentAck::token] (present.rs:56) resolves and no private item is linked.
- Nit:
present.rs:66calls it "the one-ack-per-submitted-frame mapping", but coalescing (present.rs:1113-1119) means a replaced submission is never taken and never acked. The invariant that actually holds — and the onetests.rs:335states correctly — is one ack per frame the worker took. Worth aligning the normative paragraph, since "every submission must be acked" is exactly the misreading that produced #2980. - Nit:
present.rs:57-58and1137-1140say a superseded frame's ack can arrive after a newer one. With one serial worker per generation and a synchronouspush_ackbefore the next take, acks in one ring are monotonic in token; the real defect was a tokenless ack, not reordering. Harmless defensive wording, but the justification is theoretical.
8. Scope — PASS.
Three files, +177/−38 against 4f32fd8a (crates/bitty-render/src/present.rs, present/tests.rs, crates/bitty-runtime/src/runtime/present.rs), all presenter ack plumbing. No Cargo.toml/Cargo.lock change, no dependency edge, no unrelated behaviour.
9. Honesty of the PR body — PASS.
The body admits just ci-local never reached the code gates (nix cannot resolve a git worktree gitdir inside the act container; sccache --show-stats exit 127), reports the two nextest soak budget failures and that they pass in isolation, and states plainly that the "10 consecutive macOS ARM64 runs" were not produced, keeping Part of #2980 rather than Closes. Nothing in the body cites evidence the diff does not support. Two caveats, both conservative rather than overclaims: (a) "the next submit is refused instead of being absorbed by a dead worker" holds only after mark_exited (see check 5); (b) CI now shows the macOS ARM64 leg green on this head — one run, not the ten the issue asks for; Windows is still pending.
Gates re-run in this lane
CARGO_TARGET_DIR=/mnt/data/Workspace/Projects/bitty-terminal/.targets/ctx-1735, in the PR worktree:
| command | result |
|---|---|
cargo fmt --all -- --check |
exit 0 |
cargo test -p bitty-render --lib present::tests |
23 passed, 0 failed |
8× cargo test -p bitty-render --lib present::tests::a_configure |
8/8 green (2 passed each) |
cargo test -p bitty-runtime --lib -- runtime::present |
151 passed, 0 failed |
cargo clippy -p bitty-render -p bitty-runtime --all-targets -- -D warnings |
exit 0 |
cargo +1.85 check -p bitty-render -p bitty-runtime --tests |
exit 0 |
cargo rustdoc -p bitty-render / -p bitty-runtime -- -D warnings (forced) |
exit 0 |
Findings
- No functional defect found. The sentinel's only production effect is preserved by the
inactivebranch, the dead-worker wake/is_activetransition is intact, and no consumer waits on an ack. - Three non-blocking nits: the "one ack per submitted frame" phrasing in the normative module doc (coalescing makes that false as written), the out-of-order-arrival justification, and a tautological assertion in the reworked test.
- One residual, pre-existing window documented rather than fixed: a
submitbetween the worker's loop return andmark_exited(after the backend drop) is accepted and never acked; the runtime covers it viainactive→ retain + full redraw, so it is safe, but the PR body's "next submit is refused" is only true after the exit marker.
Approving: the fix is correct, the deletion is not silent, and the new frame-less test is the one that would have caught #2980 deterministically.
VERDICT: APPROVE
What the issue asks
On the macOS ARM64 leg,
present::tests::a_configure_failure_never_presents_the_old_extent_framecollected one ack whose token wasu64::MAXinstead of the submitted frame's token0. This PR settles the ownership question and removes the ack that caused it.Ack ownership decision (recorded in code, not just here)
The presenter worker owns every acknowledgement — it is the only component that runs
configure/acquire/present, so the event-loop thread never synthesises one. An ack describes one submitted frame and carries that frame'sPresentAck::token; consumers attribute acks by token, never by arrival position.A tokenless ack may not exist. The pre-fix code emitted one (
PRESENT_NON_FRAME_TOKEN = u64::MAX) from the configure-failure branch whenever no frame was in the mailbox. That is the ordinary shape of a configure failure, becauseconfigure/resizeare queued on their own tick (set_window_opacity, resize reflow) ahead of the next frame:Both are observable behaviour, not test detail. The decision:
Error("configure failed: …")— a frame built for the old extent must never be presented (unchanged)presented/outdated/lost/timeout/other/error(unchanged)The no-frame case is already covered by the runtime:
poll_presenter'sinactivebranch retains every pixel as damage and recovers ("A dead or failed worker never acked the frame it held"), andmark_exitedwakes the loop, so nothing waits for the stuck bound. No consumer ever needed the sentinel: the runtime'sPRESENT_NON_FRAME_TOKENbranch only setpending_full_redraw, which that sameinactivebranch sets unconditionally, and it discarded the detail.The invariant now lives in code: the
# Acknowledgementsmodule section (crates/bitty-render/src/present.rs), the configure-failure branch inworker_loop,PresentAck::token,Presenter::drain_acks, andRuntime::apply_present_ack.Change
crates/bitty-render/src/present.rs: the configure-failure branch acks only a frame it actually took; the no-frame case publishes nothing.PRESENT_NON_FRAME_TOKENis deleted (a reserved sentinel nothing may produce is a dead contract, and the reserved value would otherwise stay part of the ack format).crates/bitty-runtime/src/runtime/present.rs: drop the sentinel branch inapply_present_ack(now unreachable by construction; an ack for any token other than the newest pending one is already ignored), document token-based attribution, drop the now-meaninglessassert_ne!(…, PRESENT_NON_FRAME_TOKEN)guard ina_stale_ack_cannot_commit_a_newer_pending_frame_or_arm_retry.crates/bitty-render/src/present/tests.rs:a_configure_failure_never_presents_the_old_extent_frameis no longer racy and no longer positional: frame 0 is blocked inside the acquire so the failing configure and the frame it must fail are taken together (deterministic), both acks are drained in one pass and each is found by token, and the test asserts exactly two acks (one per taken frame) and that the fresh worker afterwards presents.a_configure_failure_without_a_frame_publishes_no_ack: the frame-less configure failure leaves the ack ring empty, and the followingsubmitis refused (None) instead of being absorbed by a dead worker.Revert proof (red against the old production code)
Throwaway copy of the tree with only the production hunk reverted (old
map_or(PRESENT_NON_FRAME_TOKEN, …)emission restored), built with a separateCARGO_TARGET_DIR(.targets/ctx-1735-revert), per the false-green rule:Same copy, the pre-fix test body restored from
4f32fd8awith the configure-before-frame race widened (sleep betweenconfigureandsubmit), reproducing the CI assertion verbatim:For completeness: 200 consecutive runs of the pre-fix test against the pre-fix code on this Linux host passed 200/0 — the flake needs the worker to win the configure-before-frame race, which macOS hit. The widened-race run above shows the identical assertion, and the new frame-less test makes the same defect deterministic on any host.
Gates (all run in this worktree,
CARGO_TARGET_DIR=.targets/ctx-1735)cargo fmt --all -- --checkcargo clippy -p bitty-render --all-targets --offline -- -D warningscargo clippy -p bitty-runtime --all-targets --offline -- -D warningscargo test -p bitty-render --offline(457 lib + all integration suites)cargo test -p bitty-runtime --offline --lib -- runtime::present(151 tests)cargo +1.85 check -p bitty-render --offline --tests(MSRV)cargo +1.85 check -p bitty-runtime --offline --tests(MSRV)cargo check --workspace --all-targets --offlineRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-render -p bitty-runtime --no-deps --offlinecargo nextest run --workspace --offlinejust ci-localAlso ran the two configure-failure tests in
bitty-render15 consecutive times: 15/15 green (they are order-independent now).cargo nextest run --workspace— the two failures are wall-clock soak budgets under full-suite parallelism, not assertions about present behaviour:Both pass when run alone (same tree, same target dir):
Neither test exercises the presenter (they are runtime soak/CPU-budget tests), and the present suites are fully green; CI runs them with lower parallelism.
just ci-localwas attempted twice and could not reach the code gates on this host:First attempt aborted cloning an action:
Get "https://github.com/cachix/install-nix-action/info/refs?service=git-upload-pack": unexpected EOF(no proxy forwarded;NETWORK_PROXYis unset in non-interactive sessions on this box, so the wrapper'sHTTPS_PROXYwas empty).Second attempt (host proxy forwarded) reached the job, then stopped on two environment steps before fmt/clippy/nextest ran:
Verify flake.lock resolves:error: opening Git repository ".../ctx-1735-present-ack": failed to resolve path ".../bitty/.git/worktrees/ctx-1735-present-ack': No such file or directory— nix inside the container cannot resolve agit worktreegitdir whose common dir lives outside the bind mount;Show sccache stats (shard 1/2):--show-stats: command not found(exit 127).Neither step touches
bitty-render/bitty-runtimesources. That is why every code gate above was run directly instead.Acceptance
present::testsgreen": not produced — no macOS host available in this lane. Pending CI; the reviewer/guard decides whether the run history satisfies it. HencePart of #2980rather thanCloses #2980.Summary by CodeRabbit