# task-processes Rust/Python integration, how tasks start (fork server), the runner. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Runner and channel - **A shim per task reports its start and exit** (D13): The fork server forks a shim for each task; the shim creates the task’s process group and reports its PID and exit. It reaps the task only after the agent closes the status socket. - **The shim reports process usage without controlling the task** (D14): The shim reports core dumps and process usage with the exit status. If usage cannot be read, it reports null and still reports the exit. - **Spawned process usage is read before the process is reaped** (D18): The agent reads CPU time and major faults from the spawned process’s zombie. Peak RSS and context switches are null; unreadable usage is null. ### Starting Python - **Forked tasks run their own interpreter shutdown steps** (D15): Before exiting, a forked task waits for non-daemon threads and runs its own exit handlers. Inherited server handlers are cleared; logging shutdown and task finalizers are retained. - **The fork server agent work is a separate plan step** (D17): M2.5.4 is split in two; M2.5.4a builds the agent side of the fork server. It starts and supervises fork servers and handles fork requests and fallback. - **Retry fork server preload import failures for a limited time** (D19): Preload import failures are retried with backoff for `[worker] fork_server_import_retry`, default 20 minutes. After that the server stays disabled until restart; 0s disables retries. - **Do not retry fork server thread or version failures** (D20): A disabled fork server is not retried for threads after preload or a version mismatch. The log reports failures and the disabled metric stays visible. ### Commands and supervision - **A cancelled process group keeps its remaining grace period** (D100): If the main process exits during cancellation, remaining group members keep the rest of the grace period, then are killed. The stop ends at once when the group is empty. - **A task's timeout counts from its launch** (D116): Timeout covers the whole attempt: secret and connection reads, runner or command startup, fork- server waits and request sending. The process receives only the remaining budget; exhaustion before launch starts no process and ends timed_out, removing connection files. Timeout or cancellation before hello stops the runner and ends the attempt accordingly. - **Attempt timeouts include secret and connection reads** (D213): The attempt timeout includes secret and connection reads and runner or command startup. The process receives only the remaining time. If reads exhaust it, no process starts: the attempt ends `timed_out` and its connection files are removed. ### Interpreters - **A worker's interpreters serve all its roots** (D385): A worker has one set of interpreters for all its DAG roots, never one per root. Workers are cheap: a different set of interpreters is a different worker with its own queues. ### From other topics - Cleanup runs in a fresh process after the task (D16, `cleanup`; built M4.8a) - Async task calls return coroutines outside a DAG (D49, `async-tasks`; built M4.10) - Limited tasks start through schedr task-exec (D50, `workers`; built M4.15) - Shell-string commands take no placeholders (D99, `python-api`; built M4.3e) - Parse jobs and tasks run from a read-only copy of the hashed code (D102, `code-delivery`; built M4.3e) - Replace NUL in command output text with U+FFFD (D110, `serialization`; built M4.3e) - Build mapped elements containing templates or dag_ctx per instance (D118, `python-api`; built M4.3e) - Each context caller sends its own socket end (D143, `task-context`; built M4.5b) - The context channel is inherited by command tasks (D146, `task-context`; built M4.5b) - Commands receive connections at startup or through task-ctx (D184, `connections`; built M4.7b2) - Command connection secrets go to files and prefixed variables (D190, `connections`; built M4.7b2) - Command connections use the Python clients' TLS defaults (D191, `connections`; built M4.7b2) - A wait step cannot start a process or thread (D336, `wait-steps`; built M4.11a2) ## Replaced None. ## Where in code - `crates/schedr-agent/src/agent.rs` (D102, D190) - `crates/schedr-agent/src/attempt.rs::add_connection_env` (D184) - `crates/schedr-agent/src/connection_env.rs::mysql` (D191) - `crates/schedr-agent/src/connection_env.rs::sql` (D191) - `crates/schedr-agent/src/connection_env.rs::view` (D190) - `crates/schedr-agent/src/connection_env.rs::write` (D184, D190) - `crates/schedr-agent/src/ctx.rs::MAX_CONNECTIONS` (D143) - `crates/schedr-agent/src/ctx.rs::channel` (D146) - `crates/schedr-agent/src/ctx.rs::serve` (D143) - `crates/schedr-agent/src/fork.rs::Cause` (D20) - `crates/schedr-agent/src/fork.rs::retried` (D19) - `crates/schedr-agent/src/launch.rs::CTX_FD_ENV` (D146) - `crates/schedr-agent/src/launch.rs::deadline` (D116, D213) - `crates/schedr-agent/src/output.rs::text` (D110) - `crates/schedr-agent/src/process.rs` (D18) - `crates/schedr-agent/src/render.rs::ShellPlaceholder` (D99) - `crates/schedr-agent/src/scan.rs::capture` (D102) - `crates/schedr-agent/src/secrets.rs` (D184, D190) - `crates/schedr-agent/src/supervise.rs::left_after_leader` (D100) - `crates/schedr-agent/src/usage.rs::zombie_usage` (D18) - `crates/schedr-agent/src/watchers.rs` (D336) - `crates/schedr-config/src/config.rs::fork_server_import_retry` (D19) - `crates/schedr-fd/src/lib.rs` (D143) - `crates/schedr-master/src/mapping.rs::built_by_runner` (D118) - `crates/schedr-master/src/validate.rs::shell_problems` (D99) - `crates/schedr-model/src/ctx.rs` (D143, D146) - `crates/schedr/src/ctx.rs` (D146) - `python/schedr/_model/tasks.py` (D99) - `python/schedr/_wait_rules.py::refused_in` (D336) - `python/schedr/runner/coroutines.py::run_coroutine` (D49) - `python/schedr/runner/fork_server.py::_exited` (D14) - `python/schedr/runner/fork_server.py::_forget_server_exit_handlers` (D15) - `python/schedr/runner/fork_server.py::_shim` (D13) - `python/schedr/runner/fork_server.py::_shut_down` (D15) - `python/schedr/runner/waiting.py::refuse_a_process` (D336) - `python/schedr/tasks.py::is_async` (D49) ## Open None. Details and edge cases, with the reasons; read them before changing this: - JOURNAL.md: D385 - archive/PROJECT.md: How Python tasks are started, Master–worker protocol, Task assignment