# protocol The master–worker protocol. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Messages and limits - **The worker message size limit is configurable** (D58): `[grpc] max_message_size` limits worker messages, defaults to 64 MiB and ranges from 4 MiB to 1 GiB. The master announces it to workers in `Registered`. - **Oversized task results fail before they are sent** (D61): DAG loading rejects task output limits that cannot fit in a worker message. An oversized finished result becomes an unretried `output_too_large` failure before journalling. - **Parse results stream one file per message** (D62): `UploadParseResult` streams a header followed by one message per file. An oversized file is uploaded as `ParseResultTooLarge`; uploads run independently of heartbeats. ### Connection - **The master acknowledges each worker heartbeat** (D258): The master answers each `Heartbeat` with `HeartbeatAck` as it arrives. The response is not behind the master’s lock and is not sent while paused, nor on a stream a newer registration replaced (decision 443). - **Both sides number their messages and echo the other's; an assignment is taken back only once its worker's messages show it never started** (D460, planned (1.0.0)): Every message on a worker's stream is numbered and names the latest the other side had: a master message's `clock.sequence` and `heard_sequence` (the latest worker message received), a worker message's `WorkerClock` with its `sequence` and the latest master message it had handled. What a worker sends while handling a message (`Started` for an `AssignTask`) is queued before anything naming it. So an assignment a worker's message names as handled, with no `Started` before, never started there: the master takes it back at once (`assignment_expired`, no retry). Not named, it stays; a worker lost with it ends it `lost` (it may run), the same process registering again takes back what its journal lacks, a new incarnation holds it as a started one (decision 443). No start deadline: `start_by_ms`, `TOO_LATE`, the start grace and B234's wait are gone; protocol 2.0 (an rc1 worker is refused). Not chosen: numbering assignments only; a worker clock on its messages; a minor version. ### From other topics - The master sends each mapped instance its elements (D76, `python-api`; built M4.3b) - Database trouble ends the worker stream; data faults are handled separately (D108, `workers`; built M4.3e) - Only database trouble ends a worker stream (D115, `workers`; built M4.3e) - Each context caller sends its own socket end (D143, `task-context`; built M4.5b) - The context channel accepts callers by protocol version (D148, `task-context`; built M4.5b) - Task and cleanup results are reported separately (D229, `cleanup`; built M4.8b2) - `cleanup add` returns after journaling and sending the handle (D242, `cleanup`; built M4.8b) - A journaled cleanup waits for the master’s `Continue` (D248, `cleanup`; built M4.8b) - A disconnected task’s cleanup waits for the master (D253, `cleanup`; built M4.8b3) - An assignment cannot start after its worker lease expires (D281, `workers`; built M4.8z) - The master sends workers each DAG root's script roots (D304, `scripts`; built M4.9b) - The returning worker cleans handles the master never received (D308, `cleanup`; built (B169 fixed)) - From 1.0.0 the schema and the protocol change only additively (D456, `development`; rule) - Masters, workers and the webserver report their memory and CPU (D463, `observability`; built M5.1h) - started_at is the worker's start, in master time (D490, `assignment`; built M5.1m) ## Replaced - D54 (superseded by D397): A worker message turn shares one transaction ## Where in code - `crates/schedr-agent/src/agent.rs` (D248) - `crates/schedr-agent/src/agent.rs::cut_off_if_late` (D281) - `crates/schedr-agent/src/agent.rs::fit_result` (D61) - `crates/schedr-agent/src/agent.rs::fitted_file` (D62) - `crates/schedr-agent/src/agent.rs::kept_cleanup` (D229) - `crates/schedr-agent/src/agent.rs::send_handles` (D242) - `crates/schedr-agent/src/agent.rs::set_uses` (D304) - `crates/schedr-agent/src/agent.rs::silent_at` (D281) - `crates/schedr-agent/src/attempt.rs::CleanupGate` (D253) - `crates/schedr-agent/src/ctx.rs::MAX_CONNECTIONS` (D143) - `crates/schedr-agent/src/ctx.rs::converse` (D148) - `crates/schedr-agent/src/ctx.rs::serve` (D143) - `crates/schedr-agent/src/jobs.rs` (D304) - `crates/schedr-agent/src/master_time.rs::estimate` (D490) - `crates/schedr-agent/src/memory.rs::RunningMemory` (D463) - `crates/schedr-agent/src/memory.rs::node_usage` (D463) - `crates/schedr-agent/src/parse.rs` (D304) - `crates/schedr-api/src/views.rs::WorkerUsageView` (D463) - `crates/schedr-config/src/config.rs::max_message_size` (D58) - `crates/schedr-config/src/loader.rs::MIN_MESSAGE_SIZE` (D58) - `crates/schedr-db/src/attempts.rs` (D229) - `crates/schedr-db/src/attempts.rs::mark_started_many` (D490) - `crates/schedr-db/src/database.rs::is_data_fault` (D108, D115) - `crates/schedr-db/src/nodes.rs::set_worker_usage` (D463) - `crates/schedr-db/src/status.rs` (D456) - `crates/schedr-fd/src/lib.rs` (D143) - `crates/schedr-master/src/core.rs` (D229) - `crates/schedr-master/src/core.rs::CoreError` (D108) - `crates/schedr-master/src/core.rs::USAGE_EVERY` (D463) - `crates/schedr-master/src/core.rs::root_uses` (D304) - `crates/schedr-master/src/core.rs::take_back` (D308) - `crates/schedr-master/src/dispatch.rs` (D242) - `crates/schedr-master/src/dispatch.rs::RESULT_NOT_STORED` (D115) - `crates/schedr-master/src/dispatch.rs::start_time` (D490) - `crates/schedr-master/src/mapping.rs::into_inputs` (D76) - `crates/schedr-master/src/service.rs::HeartbeatAcks` (D258) - `crates/schedr-master/src/validate.rs::output_problems` (D61) - `crates/schedr-model/src/ctx.rs` (D143) - `crates/schedr-model/src/ctx.rs::CTX_PROTOCOL` (D148) - `crates/schedr-model/src/runner.rs::PARSE_RESULT_TOO_LARGE_EXCEPTION` (D62) - `crates/schedr-model/src/usage.rs` (D463) - `crates/schedr-proto/proto/schedr/protocol/v1/master.proto` (D242) - `crates/schedr-proto/proto/schedr/protocol/v1/master.proto::RootUses` (D304) - `crates/schedr-proto/src/version.rs::PROTOCOL_VERSION` (D456) - `python/schedr/runner/task.py` (D76) - `python/schedr/script.py` (D148) - `scripts/release.py` (D456) ## Open None. Details and edge cases, with the reasons; read them before changing this: - JOURNAL.md: D460 - archive/PROJECT.md: Cleanup and resources, Components and roles, Master–worker protocol