# assignment Task assignment, rejections, placement, queues. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Limits and mapped tasks - **Concurrency limits use run and current DAG versions** (D87): `max_active_per_run` comes from each run’s own DAG version. Across-run `max_active_tasks` and `max_active` come from the current DAG version. - **Mapped instances each count toward concurrency limits** (D89): Each mapped instance counts toward all three task concurrency limits. The whole-task `-1` row does not count. - **Concurrency limits cannot be overridden through the API or CLI** (D95): Changing a concurrency limit without a code change has no API or CLI override. Limits shared across DAGs are a proposal for M6. ### Placement and ordering - **The master keeps concurrency counts in memory** (D88): The master counts running, cleaning-up and assigned-not-started instances per DAG and task. It rebuilds counts from the database at startup and checks them on assignment. - **Assignment stays oldest-ready-first; no priorities between DAGs** (D384): Eligible tasks are assigned oldest-ready-first. There are no task or DAG priorities and no fairness between DAGs. - **A round releases the core lock between its batches of assignments** (D469): A round no longer holds the master's core lock from start to end: it lets go between its batches of assignments (and between its other parts), so a worker's turn waiting for the lock gets in between them. Each batch is still one transaction; what a batch decides is read again after the lock is taken back. With one worker, the round's hold is what a `Started` waits for (M5.1a: scenario 23's rounds up to 4.1 s, a turn waiting up to 6.6 s). Not chosen: the round's hold left to M5.1d; M5.1d's set-based statements first. - **Tasks past a round's assignment cap are not visited; they show as pending** (D481): Once a round has made its assignments (`ASSIGNMENTS_PER_ROUND`), it stops going through the ready tasks: the rest are counted as waiting for the next round (`tasks_waiting`, `next_round`) and their reason becomes a pending one the UI shows ("pending: waiting for a round with room ..."), at most 500 a round (one statement; a longer backlog over the next rounds), written with the round's other reasons, instead of each being checked for its limits and workers; a round that reaches them writes their own reason again. A wait step among them switched off or out of time still ends in that round. Not chosen: visiting every ready task each round (1,340 visits, 1.6 s of a round in stress 23). - **The round's assignments set-based: wait-step checks once per round, claims and deadlines per batch** (D482): A round finds the ready wait steps that are switched off or past their `max_wait` with a query each for all of them, before assigning, instead of one or two queries per wait step at each visit; and it claims the round's batch of assignments (attempts, `try_number`, the instances' state) and keeps their deadlines in statements over the whole batch, as a turn's `Finished`s are written (decision 396). A batch that fails is still assigned one by one. Not chosen: the per-task statements (in stress 23, 10.8 s, 4.8 s and 1.5 s of 17.6 s of assignment). - **Each tick one probe statement; every check on a stored row or column; triggers and events in a round of their own** (D485): Each master round starts with one statement, the probe (`Database::probe`): for each read the round makes, whether it would find anything. Inside `Database::in_round` a read whose check said no returns nothing; the probe looks a tick ahead, and is taken again after a write ends or for a time-bounded read past what it covered. Every check reads a stored row or column: a scheduled DAG stores `next_fire_at` (unknown after a switch change, a time come already while due runs wait or it is held), so a round visits the DAGs due, queued or marked and keeps nothing in memory to decide it; the tick stays 1 s. Triggers and events get a round of their own, with their moments stored (M5.1f2). Not chosen: rounds gated by change signals, a stretched idle tick, an in-memory model of the state. - **started_at is the worker's start, in master time** (D490): `Started` carries the task's start in the master's time as the worker estimates it, the middle of the round trip of its sample with the narrowest one (`started_master_ms`, `started_timeline`, protocol 2.1). On its own timeline the master records that as `started_at`, never before the assignment nor after the message arrived, from the wall and master clocks read at one instant; otherwise (a 1.0.0 worker, no sample, another master's timeline) its own time, as before. `schedr_master_start_recorded_seconds` times a start to its recording. ### From other topics - A recorded task finish wakes a scheduler round (D42, `components`; built M3.6) - Task finishes and commands wake a scheduler round (D43, `components`; built M3.6) - A DAG is held while its file fails to import (D72, `code-delivery`; built M4.3a) - A mapped task keeps a whole-task row (D74, `python-api`; built M4.3b) - Mapped task state follows its instances (D75, `outcomes`; built M4.3b) - An unmapped task limit produces a parse warning (D90, `python-api`; built M4.4) - Concurrency waiting reasons name the limit and value (D91, `observability`; built M4.4) - Concurrency limits have integration and stress coverage (D92, `development`; built M4.4) - The DAG page shows concurrency limits with their current counts (D96, `ui-cli`; built M4.4) - A worker's move to new code or a revert makes that hash newest (D113, `code-delivery`; built M4.3e) - A task's timeout counts from its launch (D116, `task-processes`; built M4.3e) - Connection checks and tests run on a selected worker (D193, `connections`; built M4.7c) - Attempt timeouts include secret and connection reads (D213, `task-processes`; built (B160 fixed)) - An attempt whose process never started has no cleanup (D216, `cleanup`; built M4.8a) - Cleanup anywhere waits when no worker can take it (D221, `cleanup`; built M4.8b2) - Resource cleanup takes priority over waiting tasks (D225, `cleanup`; built M4.8c2) - A cleanup without a worker remains `cleaning_up` (D244, `cleanup`; built M4.8b2) - A moved cleanup goes ahead of waiting tasks (D246, `cleanup`; built M4.8b2) - A cleanup waits for an unschedulable user (D273, `cleanup`; built M4.8c2) - An assignment cannot start after its worker lease expires (D281, `workers`; built M4.8z) - The master holds approval and question steps (D283, `human-in-the-loop`; planned (M6)) - Workers reject tasks whose cleanup script they cannot run (D314, `scripts`; built M4.9c) - A wait step keeps its deadline across retries and moves (D321, `wait-steps`; built M4.11a4) ## Replaced None. ## Where in code - `crates/schedr-agent/src/agent.rs` (D193) - `crates/schedr-agent/src/agent.rs::NotNeeded` (D216) - `crates/schedr-agent/src/agent.rs::cut_off_if_late` (D281) - `crates/schedr-agent/src/agent.rs::silent_at` (D281) - `crates/schedr-agent/src/attempt.rs::can_run_cleanup_script` (D314) - `crates/schedr-agent/src/connection_jobs.rs` (D193) - `crates/schedr-agent/src/launch.rs::deadline` (D116, D213) - `crates/schedr-agent/src/master_time.rs::estimate` (D490) - `crates/schedr-api/src/routes.rs` (D72) - `crates/schedr-api/src/views.rs` (D72) - `crates/schedr-api/src/views.rs::LimitView` (D96) - `crates/schedr-config/src/loader.rs::RETIRED_TIMINGS` (D485) - `crates/schedr-db/migrations/postgres/0001_initial.sql` (D72) - `crates/schedr-db/src/attempts.rs` (D88, D273) - `crates/schedr-db/src/attempts.rs::active_counts` (D96) - `crates/schedr-db/src/attempts.rs::first_start` (D321) - `crates/schedr-db/src/attempts.rs::mark_started_many` (D490) - `crates/schedr-db/src/attempts.rs::ready_instances` (D225) - `crates/schedr-db/src/dags.rs::NO_FIRE` (D485) - `crates/schedr-db/src/dags.rs::scheduled_due` (D485) - `crates/schedr-db/src/instances.rs` (D74, D75) - `crates/schedr-db/src/probe.rs::in_round` (D485) - `crates/schedr-db/src/runs.rs::Held` (D72) - `crates/schedr-master/src/commands.rs::check_connections` (D193) - `crates/schedr-master/src/discovery.rs::record_switch` (D113) - `crates/schedr-master/src/dispatch.rs` (D88, D481, D482) - `crates/schedr-master/src/dispatch.rs::NO_CLEANUP_WORKER` (D221, D244) - `crates/schedr-master/src/dispatch.rs::assign_cleanups` (D246) - `crates/schedr-master/src/dispatch.rs::connection_worker` (D193) - `crates/schedr-master/src/dispatch.rs::resource_of_cleanup` (D225) - `crates/schedr-master/src/dispatch.rs::start_time` (D490) - `crates/schedr-master/src/dispatch.rs::timed_out_waiting` (D321) - `crates/schedr-master/src/dispatch.rs::unschedulable_timeout_ms` (D273) - `crates/schedr-master/src/dispatch/tests.rs` (D221) - `crates/schedr-master/src/execution.rs` (D75, D273) - `crates/schedr-master/src/faults.rs` (D88) - `crates/schedr-master/src/limits.rs` (D90) - `crates/schedr-master/src/limits.rs::Reached` (D91) - `crates/schedr-master/src/limits.rs::add` (D88) - `crates/schedr-master/src/limits.rs::load` (D88) - `crates/schedr-master/src/limits.rs::of_task` (D89) - `crates/schedr-master/src/limits.rs::reached` (D87) - `crates/schedr-master/src/mapping.rs` (D75) - `crates/schedr-master/src/mapping.rs::coordinates` (D74) - `crates/schedr-master/src/planning.rs::first_waiting` (D485) - `crates/schedr-master/src/progress.rs::Instances` (D74) - `crates/schedr-master/src/progress.rs::settle_mapped` (D75) - `crates/schedr-master/src/quiet.rs::QuietDags` (D485) - `crates/schedr-master/src/scheduler.rs::create_due` (D485) - `crates/schedr-master/src/service.rs::ROUND_GAP` (D42, D43) - `crates/schedr-master/src/service.rs::Wake` (D43) - `crates/schedr-model/src/dag.rs::unschedulable_timeout_ms` (D273) - `crates/schedr-model/src/states.rs` (D216) - `crates/schedr-model/src/task.rs` (D87) - `crates/schedr-ui/src/pages.rs` (D96) - `python/schedr/_build.py::hint_unmapped_per_run` (D90) - `python/tests/integration/test_testing.py::most_at_once` (D92) ## Open - Q4 (deferred until M6): Should concurrency limits be editable without a code change and shared across DAGs? Details and edge cases, with the reasons; read them before changing this: - JOURNAL.md: D384, D469, D481, D485, D490 - archive/PROJECT.md: Native API