# scripts Plain script delivery and script jobs. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Building it - **M4.9 delivers scripts in three reviewed steps** (D292): M4.9a delivers script roots, TOML checking and standalone jobs; M4.9b delivers script tasks and `ScriptOperator`. M4.9c delivers params, outcomes and script cleanup and resource support; each step is reviewed and documented. ### Script roots - **The agent reads and checks schedr.toml** (D293): The Rust agent checks every `schedr.toml` key and builds standalone jobs as one-task DAGs; Python does not read TOML. During parsing, `ScriptOperator` requests checked declarations over the runner socket. Outside parsing it only records the reference; `schedr dags check` resolves references through `SCHEDR_SCRIPT_PATH`. - **Script roots and DAG roots cannot share a name** (D299): A script root and a DAG root with the same name cause a startup error naming both paths. `[scripts.roots]` can rename a script root. - **Workers withdraw DAG roots when required script roots are missing** (D303): A worker lacking a required script root withdraws the DAG root, neither parsing nor running it, and warns. The master omits script roots unreported by live workers after the configured five-minute grace, also observed from master startup; references remain import errors. *Not found in the code yet:* a worker that withdrew the root is not given its parse. - **The master sends workers each DAG root's script roots** (D304): Parsed files persist requested script roots, including missing ones. At registration and on changes, the master sends each DAG root’s current uses, excluding script roots absent beyond D303’s grace; the recorded uses survive restarts. ### From a DAG - **A changed script declaration re-parses its DAGs** (D294): A script root change re-parses DAGs whose `ScriptOperator`s refer to it, updating scheduling keys from the declaration. Workers run scripts at the script root hash expected by the master. *Not found in the code yet:* scheduling keys are updated from the declaration. - **A missing script root is a parse import error** (D295): A parsing worker reports an import error naming a script root it lacks. Workers parsing DAGs need the script roots those DAGs use. - **A DAG root's hash includes its used script roots** (D301): The agent folds the hashes of script roots used by the last parse into the reported DAG root hash. A script change causes a new DAG root hash and re-parse; tasks use the parsed versions of both roots. - **ScriptOperator overrides args, env and secrets** (D302): `args` replaces the declared list; `env` merges variables with the operator's values winning. `secrets` adds to the declared secrets. - **ScriptOperator references are checked during parsing** (D306): Outside a parse, `ScriptOperator` only records its reference. `schedr dags check` checks references against the configured script roots in `SCHEDR_SCRIPT_PATH`. - **Script resources reject contradictory declarations** (D312): ScriptResource and cleanup_script reject declarations with outcomes; cleanup_script also rejects cleanup. A ScriptResource setup retains its declared cleanup for a partly failed setup. ### What a job says - **An unscheduled script declaration is only for DAGs** (D296): A declaration without a schedule is not a standalone DAG or listed among DAGs; it is used through script operators and resources. Only `script` and `interpreter` are required, and DAG-level keys are errors. - **A standalone job's task has the job's name** (D300): A standalone job's one task uses the job name as its task ID. Job names contain only letters, digits, `_` and `-`; invalid names produce an import error. - **Script job parameters have types inferred from TOML values** (D310): Job parameter types come from string, integer, float, boolean, date, offset-free datetime in the job’s timezone, homogeneous-list, or nested-table defaults. Empty/mixed lists, empty tables and times without dates are import errors naming the key. Triggers replace nested objects whole; parameter names contain letters, digits and underscores. - **Declared script outcomes apply, while routing requires an enum** (D311): Declared outcomes define successful exit codes without an operator enum. An outcomes enum replaces them and enables enum routing and .outcome. Without one, only declared DefaultOutcome.SUCCESS can be routed on; other .on selections are parse errors, and so is .outcome unless SUCCESS is the only outcome declared. - **Script cleanup settings can override declaration defaults** (D313): ScriptOperator and ScriptResource cleanup settings override the declaration, then DAG defaults; the declared cleanup script cannot change, and cleanup_* without a declared cleanup is a parse error. cleanup_script options override declaration settings, then cleanup defaults: three retries, 30 seconds between them, no timeout, and the setup’s queue. - **Workers reject tasks whose cleanup script they cannot run** (D314): A worker missing a task cleanup’s interpreter or script rejects the task with rejection 3 or 5. Cleanup scripts use their task’s environment and working directory. Moved or recovered cleanups require only what the cleanup runs, so absence of the original task’s interpreter does not exclude a worker. ### From other topics - Standalone takes --dag-path and --script-path (D488, `code-delivery`; built M5.1n) ## Replaced - D298 (superseded by D416): A job's notify key is an import error until notifications exist ## Where in code - `crates/schedr-agent/src/agent.rs` (D293) - `crates/schedr-agent/src/agent.rs::fold_hash` (D301) - `crates/schedr-agent/src/agent.rs::report_changes` (D294, D303) - `crates/schedr-agent/src/agent.rs::set_uses` (D294, D304) - `crates/schedr-agent/src/attempt.rs` (D293) - `crates/schedr-agent/src/attempt.rs::can_run_cleanup_script` (D314) - `crates/schedr-agent/src/jobs.rs` (D292, D294, D299, D304) - `crates/schedr-agent/src/jobs.rs::job_of` (D296, D300) - `crates/schedr-agent/src/jobs.rs::lookup` (D295) - `crates/schedr-agent/src/jobs.rs::param_of` (D310) - `crates/schedr-agent/src/jobs.rs::read_root` (D293) - `crates/schedr-agent/src/jobs.rs::valid_name` (D300) - `crates/schedr-agent/src/parse.rs` (D304) - `crates/schedr-agent/src/parse.rs::ScriptDeclaration` (D293) - `crates/schedr-config/src/config.rs` (D303) - `crates/schedr-config/src/roots.rs::ScriptNamedAsDag` (D299) - `crates/schedr-config/src/sources.rs::OverrideValue` (D488) - `crates/schedr-master/src/core.rs::DEFAULT_SCRIPT_ROOT_GRACE` (D303) - `crates/schedr-master/src/core.rs::root_uses` (D304) - `crates/schedr-model/src/runner.rs::ScriptDeclaration` (D295) - `crates/schedr-proto/proto/schedr/protocol/v1/master.proto` (D301) - `crates/schedr-proto/proto/schedr/protocol/v1/master.proto::RootUses` (D304) - `crates/schedr/src/cli.rs::root_path` (D488) - `python/schedr/operators.py::_declaration` (D306) - `python/schedr/operators.py::_declared_cleanup` (D313) - `python/schedr/operators.py::_refuse_for_resource` (D312) - `python/schedr/operators.py::add_script` (D302) - `python/schedr/outcomes.py::from_declaration` (D311) - `python/schedr/resources.py::DEFAULT_CLEANUP_RETRIES` (D313) ## Open None. Details and edge cases, with the reasons; read them before changing this: - archive/PROJECT.md: Plain script delivery