wait-steps

Sensors, wait steps, the watcher host, first_of, delay / until.

Generated by make records from the decisions whose topic (or also) is this one; edit the decisions, not this page.

Current

The watcher host

  • A watcher host serves one interpreter and code set (D320): A watcher host holds one interpreter and set of root copies; new code uses a new host. Pokes move between calls after successful preparation, preserving deadline and retries, or remain on old code with a logged reason; full-control sensors remain until completion. Old hosts exit when empty, and memory_budget covers all worker hosts.

  • Watcher hosts stop when their last watcher ends (D334): A watcher host is spawned, never forked, and stops when its last watcher ends. Successful DAG imports are reused within the host; failed imports are retried for the next attempt. Its working folder is the worker log folder and its environment is the allow-list plus pass_env; wait steps obtain run values from dag_ctx and task_ctx and use absolute paths.

  • A poke moves to new code only when it can continue (D335): A poke finishes its current call and moves to new code without a retry or deadline change, if the new host can prepare it; otherwise it stays on old code. Full-control sensors stay until they end.

What a wait step is

  • A wait step keeps its deadline across retries and moves (D321): The max_wait clock starts at the instance’s first start and continues across retries and moves. A wait that runs out of time ends with TimedOut, including while waiting to run again.

  • Wait steps do not accept task cleanup options (D323): Wait steps accept applicable task options, using max_wait instead of timeout, and excluding cleanup and its settings, preload and fresh_process. Cleanup options cause a parse error directing the author to finally.

  • A wait step’s plain >> runs on its value (D324): A wait call reads as Waited[T], containing its value or TimedOut; passing it directly to a parameter accepting only T is rejected. Select the value with .on(T), the timeout with .on(TimedOut), or accept both explicitly. Plain >> selects the value; failed waits propagate upstream_failed, with ordinary run_if rules for untaken edges.

  • Wait steps use max_wait and shared StepDefaults (D325): Wait steps use max_wait and tasks use timeout; supplying the other kind’s key is an error. StepDefaults replaces TaskDefaults without an alias and supplies shared settings for both kinds, with each limit applying only to its kind. Wait limits follow step, group, DAG, then [sensors] default_max_wait precedence.

  • A timed-out wait step is grey and leaves its run successful (D344): A running wait step pulses unless reduced motion is requested; a failed one is red. A timeout is grey and says TimedOut, and the run stays successful.

  • A sensor poke tolerates overruns of every: it fails after poke_overruns in a row, or one at three times every (D458, planned (1.0.0)): Calls of a sensor’s poke never overlap. A call past every, by its own time (not a stall of the loop after it), is an overrun: it may finish, and the next call comes right after it. The poke fails (PokeTooSlowError, the usual retries) after [watchers] poke_overruns overruns in a row (3; 1 fails at the first, as decision 322 did), or at once when one call runs three times every, when it is cancelled. A call that doesn’t reach an await stays under [watchers] block_limit. A trigger’s poke is unchanged: a call past every is an error on its status, and the next comes. Not chosen: failing at the first overrun (a busy machine failed real runs); a margin on each call alone; a per-sensor option.

  • @sensor.poke and @trigger.poke accept a plain def (D489): @sensor.poke(every=...) and @trigger.poke(every=...) (with or without batch=) take a plain def beside an async def: each call runs on its host’s threads (to_thread, with the step’s context, log and secrets) and must end within the call’s window, the same as the async form’s (a sensor’s up to three times every with its overruns, a trigger’s every); past it, it is stopped as a to_thread call is (decision 337). The pool is sized from the host’s wait steps, and a plain function returning a coroutine is awaited. @sensor, @trigger and the wait_for= forms stay async def (the user confirmed, 2026-11-15). Not chosen: async only.

What a wait step may start

  • A wait step cannot start a process or thread (D336): At DAG definition, process and thread creation in the author’s code, including its own helpers and classes, is rejected. Runtime process creation is refused in inherited step contexts, except for the standard-library platform, ctypes.util and uuid helpers; library threads and asyncio.to_thread are allowed. This is not a sandbox: C code can bypass enforcement. Leftover asyncio tasks are cancelled and awaited.

  • A wait step owns its asyncio.to_thread calls (D337): asyncio.to_thread calls run in their wait step’s context and are tracked. Calls still running at cancellation or step end are stopped; a stuck thread ends with its host. A trigger’s next call waits for a failed call’s threads to stop, within the cancel grace.

  • Library threads in watcher hosts are watched (D339): Library threads are allowed and a thread alone is not a strike. A Python thread still alive at step end is logged; host thread counts are shown as tied and untied, and as a metric.

The 30-second rule

  • Repeatedly blocking wait steps and triggers are switched off (D338): Consecutive blocking strikes switch off a sensor or trigger after [watchers] switch_off_after. Success clears strikes; a command or new code switches it on, with one chance for new code.

  • Watcher host failures blame the responsible step when identifiable (D341): A step responsible for a blocked loop, stuck thread or ignored cancellation is blamed. Other watchers restart in the same attempt; unidentifiable host loss uses retries.

  • Watcher host crashes and memory kills are visible as losses (D342): Crashes and memory kills blame no wait step and switch none off; each lost attempt uses a retry. The error names the host’s wait steps and a metric counts losses per code set.

Nodes the master ends

  • first_of and at_least select completed outcomes (D347): Master-ended first_of yields the first taken edge’s value; at_least(n, ...) yields the first n values in completion order, with with_winner=True also supplying IDs. first_of is skipped if all edges are not taken, or becomes upstream_failed if an edge failed and none can still succeed. Losers continue; a failed loser still fails the run without changing the completed node or its downstream results.

  • A graph groups first_of options in a box (D351): The graph draws first_of options in one box with a dashed edge to the node, highlighting the winner. Where a box cannot be drawn, options have separate dashed edges.

  • User-set deadlines count on the wall clock (D478): Deadlines a person sets and the master enforces, a wait step’s max_wait and a resource’s unschedulable_timeout, count on the master’s wall clock from the time stored with the wait, not on master time (decision 442): they are set in wall time, and a restart counts from stored times anyway. A step of the master’s wall clock moves them (forward ends a wait early, back stretches it); the guide’s master-clock page says so. Not chosen: master time while one master leads.

delay and until

  • delay and until are plain Python wait steps (D355): delay waits from the first try’s start; until waits for a planned-time offset or aware datetime. Both return the moment they end, and retries of delay wait only the remaining time.

Built-in waits

  • No by_deadline wait (D392): delay and until are the built-in waits; there is no by_deadline wait.

first_of

  • first_of doesn’t cancel the tasks that didn’t win (D393): After first_of ends, the tasks that didn’t win keep running, and one that fails still fails the run; there is no option to cancel them.

From other topics

  • Async tasks and watcher hosts use uvloop whenever installed (D316, async-tasks; built M4.10)

  • Sensors and resources have their own endpoints (D340, ui-cli; built M4.11a3)

  • The UI shows watcher hosts and switched-off sensors (D343, observability; built M4.11a4)

  • A task starts after all its upstream tasks end (D345, outcomes; built M4.11c)

  • A trigger runs as a hidden sensor without an attempt (D348, triggers; built M4.11b)

  • RunOf waits for or triggers from another DAG’s run (D353, chained-runs; built M4.11d)

  • EventNamed waits for events posted through the API (D354, triggers; built M4.11e)

Replaced

  • D322 (superseded by D458): A poke that exceeds every fails

Where in code

  • crates/schedr-agent/src/agent.rs (D335, D353)

  • crates/schedr-agent/src/attempt.rs (D335, D338)

  • crates/schedr-agent/src/watchers.rs (D336)

  • crates/schedr-agent/src/watchers.rs::WatcherHosts (D320, D334)

  • crates/schedr-agent/src/watchers.rs::begin_move (D335)

  • crates/schedr-agent/src/watchers.rs::blame (D341)

  • crates/schedr-agent/src/watchers.rs::host_lost (D342)

  • crates/schedr-api/src/named_events.rs::post_event (D354)

  • crates/schedr-api/src/routes.rs (D338, D353)

  • crates/schedr-api/src/routes.rs::list_run_resources (D340)

  • crates/schedr-api/src/routes.rs::list_switched_off_sensors (D340)

  • crates/schedr-api/src/views.rs (D338, D353, D354)

  • crates/schedr-api/src/views.rs::SensorView (D343)

  • crates/schedr-api/src/views.rs::WatcherHostView (D343)

  • crates/schedr-client/src/lib.rs (D354)

  • crates/schedr-config/src/config.rs::poke_overruns (D458)

  • crates/schedr-config/src/config.rs::switch_off_after (D338)

  • crates/schedr-db/src/attempts.rs::first_start (D321)

  • crates/schedr-db/src/run_of.rs::runs_of (D353)

  • crates/schedr-master/src/core/triggers.rs::event_named_pass (D354)

  • crates/schedr-master/src/core/triggers.rs::start_trigger (D348)

  • crates/schedr-master/src/dispatch.rs::count_strike (D338)

  • crates/schedr-master/src/dispatch.rs::deadline (D478)

  • crates/schedr-master/src/dispatch.rs::fail_waiting_users (D478)

  • crates/schedr-master/src/dispatch.rs::timed_out_waiting (D321)

  • crates/schedr-master/src/progress.rs::readiness (D345)

  • crates/schedr-master/src/validate.rs::first_of_problems (D347)

  • crates/schedr-model/src/runner.rs (D337)

  • crates/schedr-model/src/runner.rs::WatchersRequest (D320)

  • crates/schedr-model/src/task.rs (D347)

  • crates/schedr-ui/src/runs.rs::TIMED_OUT (D344)

  • crates/schedr-ui/src/runs.rs::first_of_nodes (D351)

  • crates/schedr/src/cli.rs (D340)

  • python/schedr/_build.py (D324)

  • python/schedr/_wait_rules.py::refused_in (D336)

  • python/schedr/dag.py::StepDefaults (D325)

  • python/schedr/event_triggers.py::TriggerFunction (D489)

  • python/schedr/first_of.py::first_of (D347)

  • python/schedr/outcomes.py::Waited (D324)

  • python/schedr/run_of.py::RunOf (D353)

  • python/schedr/runner/coroutines.py::loop_factory (D316)

  • python/schedr/runner/task.py (D324)

  • python/schedr/runner/waiting.py (D337)

  • python/schedr/runner/waiting.py::OVERRUN_LIMIT (D458)

  • python/schedr/runner/waiting.py::awaited_poke (D489)

  • python/schedr/runner/waiting.py::refuse_a_process (D336)

  • python/schedr/runner/waiting.py::set_poke_overruns (D458)

  • python/schedr/runner/watchers.py (D320)

  • python/schedr/runner/watchers.py::_ThreadCall (D337)

  • python/schedr/runner/watchers.py::_WatcherThreads (D489)

  • python/schedr/runner/watchers.py::_warn_of_threads (D339)

  • python/schedr/sensors.py::SensorFunction (D489)

  • python/schedr/sensors.py::_no_cleanup (D323)

  • python/schedr/sensors.py::delay (D355)

  • python/schedr/sensors.py::until (D355)

Open

  • Q21 (deferred until M6): Should a wait step support .expand()?

Details and edge cases, with the reasons; read them before changing this:

  • JOURNAL.md: D392, D393, D458, D478, D489

  • archive/PROJECT.md: Sensors and triggers