Skip to content

fix(batch): give a batch's permission preflight its own budget, capped at 15 s - #57

Merged
gshost1 merged 3 commits into
mainfrom
fix/batch-preflight-budget
Nov 8, 2026
Merged

gshost1 merged 3 commits into
mainfrom
fix/batch-preflight-budget

Conversation

@gshost1

@gshost1 gshost1 commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

A top-level batch ran its permission preflight (adapter.permission_report, in main.rs) with the default 5 s Deadline::standard(), although the batch itself has a --timeout-ms budget (60 s by default). When that check is slow (on Linux it touches D-Bus, AT-SPI and the X11 stale-input sweep; a freshly started desktop session under load is enough), the whole batch failed with TIMEOUT before its first entry.

This is the cause of the batch_session_ended_* CLI process test flake (four local gate failures on 2026-11-08). The diagnostic from PR #53 captured the envelope on the next failure:

no data.results after 5.009148103s: {"command":"batch","error":{"code":"TIMEOUT","details":{"elapsed_ms":5000,"kind":"deadline","timeout_ms":5000},"disposition":{"delivery":"not_delivered","retry":"safe"},...

State before and after

before: batch --> preflight (5 s, fixed) --TIMEOUT--> batch error, no results
                                          \--> batch::execute (--timeout-ms clock) --> entries
after:  batch --> preflight (min(--timeout-ms, 15 s)) --> batch::execute (unchanged) --> entries
        other commands: preflight deadline unchanged (the caller's, else 5 s)

What changed

  • src/main.rs: preflight_deadline gives a top-level batch's permission report its --timeout-ms budget capped at BATCH_PREFLIGHT_CAP_MS (15 s). The batch's own execution and deadline semantics are unchanged.

How tested

  • main_tests::a_top_level_batch_preflight_gets_the_batch_budget_capped_not_five_seconds: batch --timeout-ms 60000 gets more than 10 s and at most 15 s; --timeout-ms 2000 gets at most 2 s; status keeps at most 5 s. With the batch arm put back to Deadline::standard(), it fails.
  • The CLI process flake itself cannot be forced deterministically (it needs the preflight to take more than 5 s).
  • Gates on head e04ed040 (main 9ea5d145): fmt, clippy -D warnings, source-rule and architecture scripts, core Windows check, Win32 leakage check, cargo tree, host-set tests 4901 passed, 0 failed. CI 13/13 green on that head.

Review: a first version moved the batch budget into the command context; the medium review showed it dropped the min with --timeout-ms, turned a budget spent in the preflight into a pre-dispatch TIMEOUT instead of not_started entries, and left the preflight uncapped. This version changes only the preflight's deadline.

Performance

None; the preflight's work is unchanged, only how long it may take.

Risks

  • A batch whose preflight hangs now fails after up to 15 s instead of 5 s.
  • The preflight time is not counted against --timeout-ms (as before).
  • status and permissions keep the 5 s preflight and could still time out on a very slow session.

What's left

Merge rule: rule 3. main moved to 45236e6a (fork PRs #12 and #6: tests/e2e/**, crates/macos/src/tree/element_bounds*.rs) after this head's CI; none of those files overlap this PR, and none is an always-overlap file. Prior art: none upstream.

A top-level batch ran the permission preflight with the default 5 s
deadline, ahead of its own --timeout-ms budget (60 s by default). When
that check is slow, as on a freshly started desktop session under load,
the whole batch failed with TIMEOUT before its first entry. This is the
cause of the batch_session_ended_* CLI test flake: the envelope captured
by the diagnostic from PR #53 was a batch-level TIMEOUT after 5.0 s,
kind deadline, not_delivered.

main now takes the batch's budget before the preflight, and the batch
spends from that inherited deadline instead of starting a fresh one, so
--timeout-ms covers the preflight and every entry.
Review of the first version found that handing the batch budget to the
context dropped the min with --timeout-ms, turned a budget spent in the
preflight into a pre-dispatch TIMEOUT instead of not_started entries,
and left the preflight with no cap of its own. This keeps the batch
exactly as on main and changes only the preflight's deadline: a
top-level batch's permission report gets its --timeout-ms budget capped
at 15 s instead of the 5 s default. The context getter is removed.
@gshost1 gshost1 changed the title fix(batch): run a batch's permission preflight under its own budget fix(batch): give a batch's permission preflight its own budget, capped at 15 s Nov 8, 2026
@gshost1
gshost1 merged commit 4742672 into main Nov 8, 2026
13 checks passed
@gshost1
gshost1 deleted the fix/batch-preflight-budget branch November 8, 2026 14:40
gshost1 added a commit that referenced this pull request Nov 8, 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.

1 participant