task-context

The in-task CLI, run parameters, dag_ctx / task_ctx.

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

Current

dag_ctx and task_ctx

  • Task context exposes the running instance identity (D84): task_ctx exposes task_id, try_number and map_index while a task runs. The map index is None for an unmapped task.

  • Async in-task calls use an a prefix (D315): Async tasks can await task_ctx.asecret, task_ctx.asecret_value and acleanup_handle. Sync calls remain available and block the event loop while waiting.

  • Tasks call schedr’s REST API through their agent (D356): schedr.api sends allowed task and trigger requests through the agent to the master’s API. Outside a task it uses HTTP; local DAG tests use their standalone master and database.

Parameters

  • Run parameters precede the agent channel and UI trigger form (D132): M4.5a builds parameter declaration, validation, storage, CLI and test inputs, references, typed access and the run summary. M4.5b builds the agent channel; M4.5c builds the UI trigger form.

  • The master checks run parameters and their schemas with jsonschema (D133): The master validates values with jsonschema, with formats checked and remote references disabled. DAG validation accepts only supported schema keywords and formats, annotations and local references; other keywords are DAG errors. Pydantic validators run when a task decodes values.

  • Run parameters are masked when shown (D134): Shown parameters are masked like task outputs; tasks receive originals. Refusals never quote parameter or schema values, mask names, and omit even the keyword beneath secret-named fields. The webserver rejects NUL before storing a command; run-DAG views retain only masked parameter defaults. Bad bodies, -p, invalid dataclass defaults and Pydantic default serialization produce no value- bearing diagnostics; invalid dataclass defaults also omit their type.

  • Run parameters are limited to 64 KiB of JSON (D135): A run’s parameters, including defaults, may occupy at most 64 KiB as JSON. An oversized set is refused at trigger time; a DAG with oversized defaults is refused at parse time.

  • A queued run keeps its validated parameter values (D137): A queued run keeps the values validated against the version on which it was created. They are not checked again when it starts.

  • Run parameters are described in DAG JSON and stored as tagged values (D138): DAG JSON carries the parameter type, JSON Schema and defaults. The master fills defaults, refuses unknown keys, validates values and stores them as tagged outputs; scheduled runs use defaults.

  • Durations may be given in weeks (D139): ISO 8601 durations may use weeks, each a fixed seven days. Years and months remain refused.

  • A whole number with a fraction fits an integer parameter (D140): A whole number written with a fraction, such as 1.0, fits an int field. It is stored as 1.

  • The master checks duration formats as ISO 8601 (D141): The master checks format: duration itself as ISO 8601. It accepts fractions of a second, including Pydantic timedelta values.

  • Trigger-time parameter values are masked (D142): Trigger-time values are masked in refusals, run views, errors and logs; stored parameters and defaults are shown masked. Code-authored text is shown as written where code is shown.

Inside a command or a script

  • Each context caller sends its own socket end (D143): Command-task processes inherit the datagram channel named by SCHEDR_CTX_FD; each caller passes one end of a fresh stream socket pair through SCM_RIGHTS and uses its own connection. It speaks length-prefixed JSON, beginning with protocol hello. The agent serves at most 64 connections open at once and refuses one more while they are; malformed descriptor messages are dropped and their descriptors closed. Linux and macOS are supported.

  • The context channel initially serves dag-ctx (D144): schedr dag-ctx provides params get and run get, each with optional --field. Parameter values print in the JSON form accepted by --params.

  • schedr.script decodes run context values (D145): In a command-task script, schedr.script.dag_ctx loads context on first read using one connection and two requests. Stored forms decode to native dates, timedeltas and tuples; object fields become dictionaries because the script does not know the declared class. dag_ctx.params(Cls) decodes strictly into the supplied class. Inside a Python task, its existing context values are used.

  • The context channel is inherited by command tasks (D146): Command tasks and their child processes inherit the context channel. Python tasks use their own dag_ctx; a closed inherited descriptor is reported.

  • The context channel accepts callers by protocol version (D148): The agent accepts context protocol 1 regardless of schedr version; hello supplies both, and incompatible-protocol refusals name both versions. Within a protocol, new requests and fields are allowed: unknown fields are ignored and unknown requests receive error. Other changes, including new enum values, require a new protocol.

Unsafe code

  • The inherited descriptor uses unsafe code in schedr-fd (D147): Only schedr-fd relaxes unsafe_code from forbid to deny, permitting its single unsafe site through #[expect]; every other crate retains forbid. It borrows the inherited descriptor solely to duplicate it close-on-exec, then validates the copy as a Unix datagram socket. It never owns or closes the inherited descriptor.

From other topics

  • Type checkers read task calls as their values (D57, python-api; built M4.2a)

  • The webserver describes the trigger form (D149, ui-cli; built M4.5c)

  • Secret-named parameter fields use empty password inputs (D150, ui-cli; built M4.5c)

  • Optional parameter fields have a none checkbox (D151, ui-cli; built M4.5c)

  • Complex parameter fields use JSON text boxes (D152, ui-cli; built M4.5c)

  • A stale trigger form is refused (D159, ui-cli; built M4.5c)

  • Failed on-demand secret reads can set the attempt error kind (D168, secrets; built M4.6b)

  • Connections use optional clients and worker-side checks and tests (D174, connections; built M4.7c)

  • Secrets are typed as their values (D176, secrets; built M4.6e)

  • Tasks declare the connections they open (D179, connections; built M4.7a)

  • Commands receive connections at startup or through task-ctx (D184, connections; built M4.7b2)

  • Command connections expose prefixed variables (D192, connections; built M4.7b2)

  • Handles are limited to 1 MiB per attempt (D228, cleanup; built M4.8a)

  • Script job parameters have types inferred from TOML values (D310, scripts; built M4.9c)

  • Tasks start runs with TriggerDagOperator (D365, chained-runs; built M4.12a)

Replaced

None.

Where in code

  • crates/schedr-agent/src/agent.rs (D168, D174)

  • crates/schedr-agent/src/agent/tests.rs (D168)

  • crates/schedr-agent/src/attempt.rs::add_connection_env (D184)

  • crates/schedr-agent/src/connection_env.rs::own (D192)

  • crates/schedr-agent/src/connection_env.rs::view (D192)

  • crates/schedr-agent/src/connection_env.rs::write (D184)

  • crates/schedr-agent/src/connection_jobs.rs::check (D174)

  • crates/schedr-agent/src/ctx.rs (D144, D145)

  • crates/schedr-agent/src/ctx.rs::MAX_CONNECTIONS (D143)

  • crates/schedr-agent/src/ctx.rs::channel (D146)

  • crates/schedr-agent/src/ctx.rs::converse (D148)

  • crates/schedr-agent/src/ctx.rs::serve (D143)

  • crates/schedr-agent/src/handles.rs::MAX_HANDLES_SIZE (D228)

  • crates/schedr-agent/src/jobs.rs::param_of (D310)

  • crates/schedr-agent/src/launch.rs::CTX_FD_ENV (D146)

  • crates/schedr-agent/src/render.rs (D138)

  • crates/schedr-agent/src/secrets.rs (D176, D184, D192)

  • crates/schedr-agent/src/secrets.rs::failed_kind (D168)

  • crates/schedr-agent/src/secrets.rs::with_connections (D179)

  • crates/schedr-api/src/routes.rs::mask_data (D134)

  • crates/schedr-api/src/views.rs (D133, D149, D179)

  • crates/schedr-api/src/views.rs::mask_data (D142)

  • crates/schedr-api/src/views/form.rs (D151, D152)

  • crates/schedr-api/src/views/form.rs::ParamFieldView (D149)

  • crates/schedr-api/src/views/form.rs::holds_secret (D150)

  • crates/schedr-config/src/masked.rs::mask_data (D142)

  • crates/schedr-db/src/runs.rs (D138)

  • crates/schedr-fd/Cargo.toml::unsafe_code (D147)

  • crates/schedr-fd/src/lib.rs (D143)

  • crates/schedr-fd/src/lib.rs::inherited_datagram (D147)

  • crates/schedr-master/src/dispatch.rs (D228)

  • crates/schedr-master/src/dispatch.rs::set_connections (D174)

  • crates/schedr-master/src/params.rs (D134, D135, D139)

  • crates/schedr-master/src/params.rs::is_duration (D141)

  • crates/schedr-master/src/params.rs::keyword_problems (D133)

  • crates/schedr-master/src/params.rs::run_params (D137, D138)

  • crates/schedr-master/src/params.rs::validator (D133)

  • crates/schedr-master/src/scheduler.rs (D133)

  • crates/schedr-model/src/commands.rs (D176)

  • crates/schedr-model/src/connection.rs::problems (D179)

  • crates/schedr-model/src/ctx.rs (D143, D145, D146, D147)

  • crates/schedr-model/src/ctx.rs::CTX_PROTOCOL (D148)

  • crates/schedr-model/src/ctx.rs::CtxRequest (D144)

  • crates/schedr-model/src/params.rs::MAX_PARAMS_BYTES (D135)

  • crates/schedr-model/src/params.rs::duration_micros (D139)

  • crates/schedr-model/src/params.rs::shown (D134)

  • crates/schedr-model/src/params.rs::whole (D140)

  • crates/schedr-model/src/secret.rs (D176)

  • crates/schedr-ui/src/params_form.rs (D134, D149, D150)

  • crates/schedr-ui/src/params_form.rs::entered (D151, D152)

  • crates/schedr-ui/src/params_form.rs::fingerprint (D159)

  • crates/schedr-ui/src/params_form/tests.rs (D159)

  • crates/schedr-ui/templates/trigger_params.html (D151, D152)

  • crates/schedr/src/ctx.rs (D145, D146)

  • crates/schedr/src/ctx.rs::run_dag_ctx (D144)

  • python/schedr/_params.py (D137)

  • python/schedr/_params.py::MAX_PARAMS_BYTES (D135)

  • python/schedr/_params.py::declare (D138)

  • python/schedr/_secrets.py::Secrets (D176)

  • python/schedr/api.py::_script_caller (D356)

  • python/schedr/chained.py::TriggerDagOperator (D365)

  • python/schedr/context.py::TaskValues (D84)

  • python/schedr/context.py::acleanup_handle (D315)

  • python/schedr/context.py::asecret (D315)

  • python/schedr/context.py::secret_value (D176)

  • python/schedr/outcomes.py::Data (D57)

  • python/schedr/script.py (D148)

  • python/schedr/script.py::_values (D145)

  • python/schedr/script.py::call_api (D356)

  • python/schedr/script.py::load (D145)

Open

None.

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

  • archive/PROJECT.md: Async task functions, In-task CLI: schedr task-ctx and schedr dag-ctx, Native API, Run parameters and the DAG context, Sensors and triggers