Index
daemon
¶
Marianne daemon service — long-running orchestration conductor.
Classes¶
BackpressureController
¶
Manages system load through adaptive backpressure.
Assesses memory usage (as a fraction of the configured limit) and
active rate limits to determine a PressureLevel. The scheduler
calls can_start_sheet() before dispatching each sheet and gets
back a (allowed, delay) tuple.
No internal lock is needed because:
- ResourceMonitor methods are thread/coroutine-safe.
- RateLimitCoordinator.active_limits is a property that
reads a dict snapshot.
- PressureLevel assessment is a pure function of those reads.
Source code in src/marianne/daemon/backpressure.py
Functions¶
current_level
¶
Assess current pressure level from resource metrics.
Thresholds (memory as % of ResourceLimitConfig.max_memory_mb):
- probe failure or monitor degraded → CRITICAL (fail-closed)
- >95% or monitor not accepting work → CRITICAL
- >85% or any active rate limit → HIGH
- >70% → MEDIUM
- >50% → LOW
- otherwise → NONE
Note: is_accepting_work() also checks child process count
against ResourceLimitConfig.max_processes. When process
count exceeds 80% of the configured limit, is_accepting_work()
returns False, which triggers the CRITICAL path here. This
means high process counts indirectly escalate backpressure to
CRITICAL even when memory usage is low.
TOCTOU fix (P007): memory is read once and reused for all
threshold checks. is_accepting_work() is still called for
its process-count check, but the memory percentage used in
threshold comparisons comes from the single snapshot above.
Source code in src/marianne/daemon/backpressure.py
can_start_sheet
async
¶
Whether the scheduler may dispatch a sheet, and any delay.
Satisfies the BackpressureChecker protocol used by
GlobalSheetScheduler.next_sheet().
Returns:
| Type | Description |
|---|---|
bool
|
|
float
|
is rejected ( |
tuple[bool, float]
|
delay is returned to slow dispatch. |
Source code in src/marianne/daemon/backpressure.py
should_accept_job
¶
Whether to accept new job submissions.
Returns False only under high resource pressure (memory
or process count). Rate limits do NOT cause job rejection —
they are per-instrument and handled at the sheet dispatch level
by the baton and scheduler (F-149).
This prevents a rate limit on instrument A from blocking jobs that target instrument B.
Source code in src/marianne/daemon/backpressure.py
rejection_reason
¶
Why would a job be rejected right now?
Returns:
| Type | Description |
|---|---|
str | None
|
|
str | None
|
|
Rate limits alone no longer cause rejection (F-149). They are per-instrument concerns handled at the sheet dispatch level. This prevents a rate limit on one instrument from blocking jobs targeting different instruments.
Source code in src/marianne/daemon/backpressure.py
estimate_job_resource_needs
async
¶
Query learned resource patterns for similar job types.
Looks up RESOURCE_CORRELATION patterns from the learning store
that match the given job config hash. Returns a ResourceEstimate
if sufficient historical data exists, otherwise None.
This is advisory — the caller uses it to adjust thresholds, not to block jobs outright.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_config_hash
|
str
|
Stable hash identifying the job type/config. |
required |
Returns:
| Type | Description |
|---|---|
ResourceEstimate | None
|
|
ResourceEstimate | None
|
and confidence, or |
Source code in src/marianne/daemon/backpressure.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
PressureLevel
¶
Bases: Enum
Graduated pressure levels for adaptive load management.
DaemonConfig
¶
Bases: BaseModel
Top-level configuration for the Marianne conductor.
Controls socket binding, PID file location, concurrency limits, resource constraints, and state backend selection. Follows the same Field() conventions as marianne.core.config.
HealthChecker
¶
Daemon health and readiness probes.
Evolution v25: Entropy Response Activation - added periodic entropy monitoring and automatic diversity injection when collapse is detected.
Parameters¶
manager:
The JobManager instance for job count queries.
monitor:
The ResourceMonitor instance for resource threshold checks.
learning_store:
Optional learning store for entropy monitoring. If None, entropy
checks are disabled.
Source code in src/marianne/daemon/health.py
Functions¶
liveness
async
¶
Is the daemon process alive and responsive?
This is the cheapest possible check — if the daemon can execute this handler and return a response, it's alive. No resource checks or I/O are performed.
Source code in src/marianne/daemon/health.py
readiness
async
¶
Is the daemon ready to accept new jobs?
Checks resource thresholds via the monitor, job failure rate
via the manager, and notification health. Returns "ready"
when resources are within limits, the failure rate is not
elevated, and notifications are functional; "not_ready"
otherwise.
Source code in src/marianne/daemon/health.py
on_job_completed
¶
Called by JobManager when a job completes.
Evolution v25: Entropy Response Activation - tracks completed jobs to trigger entropy checks every 10 completions.
Source code in src/marianne/daemon/health.py
start_periodic_checks
async
¶
Start background task for periodic entropy checks.
Evolution v25: Entropy Response Activation - runs entropy checks at configured intervals (default 1 hour).
Source code in src/marianne/daemon/health.py
stop_periodic_checks
async
¶
Stop the periodic entropy check task.
Evolution v25: Entropy Response Activation - cleanly shuts down the entropy monitoring loop.
Source code in src/marianne/daemon/health.py
JobService
¶
JobService(*, output=None, global_learning_store=None, rate_limit_callback=None, event_callback=None, state_publish_callback=None, registry=None, token_warning_threshold=None, token_error_threshold=None, pgroup_manager=None)
Core job execution service.
Encapsulates the logic from CLI run/resume/pause commands into a reusable service that can be called from CLI, daemon, dashboard, or MCP server.
All user-facing output goes through the OutputProtocol abstraction, allowing different frontends (Rich console, structlog, SSE, null) to receive execution events without code changes.
Source code in src/marianne/daemon/job_service.py
Attributes¶
notifications_degraded
property
¶
Whether notification delivery is degraded.
Returns True after _NOTIFICATION_DEGRADED_THRESHOLD consecutive
notification failures. Readable by HealthChecker.readiness()
to signal degraded notification capability to operators.
Functions¶
pause_job
async
¶
Pause a running job via signal file.
Mirrors the logic in cli/commands/pause.py::_pause_job(): Creates a pause signal file that the runner polls at sheet boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Job identifier to pause. |
required |
workspace
|
Path
|
Workspace directory containing job state. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if pause signal was created successfully. |
Raises:
| Type | Description |
|---|---|
JobSubmissionError
|
If job not found or not in a pausable state. |
Source code in src/marianne/daemon/job_service.py
get_status
async
¶
Get job status from state backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Job identifier. |
required |
workspace
|
Path
|
Workspace directory containing job state. |
required |
backend_type
|
str
|
State backend type (default "sqlite" for daemon). |
'sqlite'
|
Returns:
| Type | Description |
|---|---|
CheckpointState | None
|
CheckpointState if found, None if job doesn't exist. |
Source code in src/marianne/daemon/job_service.py
JobManager
¶
Manages concurrent job execution within the daemon.
Wraps JobService with task tracking and concurrency control. Each submitted job becomes an asyncio.Task that the manager tracks from start to completion/cancellation.
Source code in src/marianne/daemon/manager.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Attributes¶
active_job_count
property
¶
Number of concurrently executing jobs (used for fair-share scheduling).
Currently returns running_count (job-level granularity).
Phase 3 will replace this with self._scheduler.active_count
for sheet-level granularity once per-sheet dispatch is wired.
failure_rate_elevated
property
¶
Whether the recent job failure rate is elevated.
Returns True if more than _FAILURE_RATE_THRESHOLD unexpected
exceptions have occurred within the last _FAILURE_RATE_WINDOW
seconds. Used by HealthChecker.readiness() to degrade the
health signal when systemic failures are occurring.
notifications_degraded
property
¶
Whether notification delivery is degraded (forwarded from JobService).
rate_coordinator
property
¶
Access the rate limit coordinator for cross-job rate limiting.
Functions¶
start
async
¶
Start daemon subsystems (learning hub, monitor, etc.).
Source code in src/marianne/daemon/manager.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
apply_config
¶
Hot-apply reloadable config fields from a SIGHUP reload.
Compares the new config against the current one and applies
changes that can be safely updated at runtime. Rebuilds the
concurrency semaphore if max_concurrent_jobs changed.
Safe because asyncio is single-threaded — this runs in the
event loop, so no concurrent access to _config or
_concurrency_semaphore is possible.
Source code in src/marianne/daemon/manager.py
update_job_config_metadata
¶
Update config-derived metadata in the in-memory job map.
Source code in src/marianne/daemon/manager.py
submit_job
async
¶
Validate config, create task, return immediately.
Source code in src/marianne/daemon/manager.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 | |
get_job_status
async
¶
Get full status of a specific job.
Resolution order (no workspace/disk fallback): 1. Live in-memory state (running jobs) 2. Registry checkpoint (historical jobs — persisted on every save) 3. Basic metadata (jobs that never ran / pre-checkpoint registry)
Source code in src/marianne/daemon/manager.py
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
pause_job
async
¶
Send pause signal to a running job via in-process event.
Prefers the in-process _pause_events dict (set during
_run_managed_task). Falls back to JobService.pause_job
when no event exists (shouldn't happen in daemon mode, but
guards against edge cases).
Source code in src/marianne/daemon/manager.py
resume_job
async
¶
Resume a paused or failed job by creating a new task.
If an old task for this job is still running (e.g., not yet fully paused), it is cancelled before the new resume task is created to prevent detached/duplicate execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
ID of the job to resume. |
required |
workspace
|
Path | None
|
Optional workspace override. |
None
|
config_path
|
Path | None
|
Optional new config file path. When provided, updates meta.config_path so the resume task loads the new config. |
None
|
no_reload
|
bool
|
If True, skip auto-reload from disk and use cached
config snapshot. Threaded from CLI |
False
|
Source code in src/marianne/daemon/manager.py
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 | |
modify_job
async
¶
Pause a running job and queue automatic resume with new config.
If the job is already paused/failed/cancelled, resume immediately. If running, send pause signal and store pending_modify — _on_task_done will trigger the resume when the task completes (pauses).
Source code in src/marianne/daemon/manager.py
cancel_job
async
¶
Cancel a running or pending job.
For running jobs: sends the cancel signal and updates in-memory status immediately, then defers heavyweight I/O to a background task.
For pending jobs (queued during rate limit backpressure): removes from the pending queue and updates the registry.
Source code in src/marianne/daemon/manager.py
list_jobs
async
¶
List all jobs with live progress data.
In-memory _job_meta is authoritative for active jobs.
Live state from _live_states enriches active entries with
sheet-level progress so mzt list shows completion counts.
The registry fills in historical jobs.
Source code in src/marianne/daemon/manager.py
clear_jobs
async
¶
Clear terminal jobs from registry and in-memory metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statuses
|
list[str] | None
|
Status filter (defaults to terminal statuses). |
None
|
older_than_seconds
|
float | None
|
Age filter in seconds. |
None
|
job_ids
|
list[str] | None
|
Only clear these specific job IDs. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with "deleted" count. |
Source code in src/marianne/daemon/manager.py
clear_rate_limits
async
¶
Clear active rate limits from the coordinator and baton.
Removes the active rate limit so new sheets can be dispatched
immediately. Clears both the RateLimitCoordinator (used by
the legacy runner and scheduler) and the baton's per-instrument
InstrumentState (used by the baton dispatch loop).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument
|
str | None
|
Instrument name to clear, or |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with |
Source code in src/marianne/daemon/manager.py
get_job_errors
async
¶
Get errors for a specific job.
Returns the CheckpointState for the CLI to extract error information. Uses the same resolution as get_job_status: live state first, then registry, never workspace files.
Source code in src/marianne/daemon/manager.py
get_diagnostic_report
async
¶
Get diagnostic data for a specific job.
Returns the CheckpointState plus workspace path. Uses the same resolution as get_job_status: live state first, then registry.
Source code in src/marianne/daemon/manager.py
get_execution_history
async
¶
Get execution history for a specific job.
Requires the SQLite state backend for history records.
Source code in src/marianne/daemon/manager.py
recover_job
async
¶
Get state for recover operation.
Returns the job state and workspace for the CLI to run validations locally. The actual validation logic stays in the CLI command to avoid duplicating ValidationEngine setup in the daemon.
Source code in src/marianne/daemon/manager.py
get_daemon_status
async
¶
Build daemon status summary.
Returns all fields required by the DaemonStatus Pydantic model
so DaemonClient.status() can deserialize without crashing.
Source code in src/marianne/daemon/manager.py
shutdown
async
¶
Cancel all running jobs, optionally waiting for sheets.
Deregisters all active jobs from the global sheet scheduler to clean up any pending sheets, running-sheet tracking, and dependency data before the daemon exits.
Source code in src/marianne/daemon/manager.py
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 | |
JobMeta
dataclass
¶
JobMeta(job_id, config_path, workspace, submitted_at=time(), started_at=None, status=QUEUED, error_message=None, error_traceback=None, chain_depth=None, hook_config=None, concert_config=None, completed_new_work=False, observer=None, pending_modify=None, held_chain_hook=None)
Metadata tracked per job in the manager.
Functions¶
to_dict
¶
Serialize to a dict suitable for JSON-RPC responses.
Source code in src/marianne/daemon/manager.py
ResourceMonitor
¶
Periodic resource monitoring for the daemon.
Checks memory usage, child process count, and zombie processes on a configurable interval. Emits structured log warnings when approaching limits and can trigger hard actions (job cancellation) when hard limits are exceeded.
Source code in src/marianne/daemon/monitor.py
Attributes¶
seconds_since_last_check
property
¶
Seconds since the last successful monitoring check.
Returns float('inf') if no check has succeeded yet.
Consumers can use this to detect stale resource data.
is_degraded
property
¶
Whether the monitor has entered degraded mode due to repeated failures.
Functions¶
start
async
¶
Start the periodic monitoring loop.
Source code in src/marianne/daemon/monitor.py
stop
async
¶
Stop the monitoring loop.
Source code in src/marianne/daemon/monitor.py
check_now
async
¶
Run an immediate resource check and return snapshot.
Source code in src/marianne/daemon/monitor.py
is_accepting_work
¶
Check if resource usage is below warning thresholds.
Returns True when both memory and process counts are below
WARN_THRESHOLD percent of their configured limits. Used by
HealthChecker.readiness() to signal backpressure.
Fail-closed: returns False when probes fail or monitor is degraded.
Source code in src/marianne/daemon/monitor.py
current_memory_mb
¶
update_limits
¶
Hot-apply new resource limits from a SIGHUP config reload.
Replaces the internal _config reference. Safe because the
monitor only reads _config during periodic checks, and
asyncio's single-threaded event loop prevents concurrent access.
Source code in src/marianne/daemon/monitor.py
set_manager
¶
Wire up the job manager reference after construction.
Called by DaemonProcess after both the monitor and manager are created, avoiding the circular dependency of needing both at init.
Source code in src/marianne/daemon/monitor.py
ResourceSnapshot
dataclass
¶
ResourceSnapshot(timestamp, memory_usage_mb, child_process_count, running_jobs, active_sheets, zombie_pids=list(), probe_failed=False)
Point-in-time resource usage reading.
ConsoleOutput
¶
Bases: OutputProtocol
Rich Console wrapper for CLI backwards compatibility.
Bridges the OutputProtocol to Rich Console, so the existing CLI can adopt the protocol without changing its visual output.
Source code in src/marianne/daemon/output.py
NullOutput
¶
OutputProtocol
¶
Bases: ABC
Abstract output for job execution feedback.
Replaces tight coupling to Rich Console. Implementations: - NullOutput: no-op for tests - StructuredOutput: structlog for daemon - ConsoleOutput: wraps Rich for CLI backwards compat
StructuredOutput
¶
Bases: OutputProtocol
Structured logging output for daemon mode.
Routes all output through structlog, producing structured JSON events that daemon consumers (SSE, gRPC, log aggregators) can parse.
Source code in src/marianne/daemon/output.py
ProcessGroupManager
¶
Manages the daemon's process group to prevent orphans.
The daemon calls setup() early in its lifecycle to become the process group leader. During shutdown, kill_all_children() sends SIGTERM to the entire group, ensuring no child process (including deeply nested MCP servers) survives the daemon.
An atexit handler provides last-resort cleanup even if the normal shutdown path is skipped.
Source code in src/marianne/daemon/pgroup.py
Attributes¶
Functions¶
track_backend_pid
¶
Register a backend process PID for orphan tracking.
When a backend (claude, gemini-cli, etc.) spawns a process, call this with the process PID. On cleanup, any surviving children of dead tracked PIDs are killed as orphans — regardless of what they're called. This replaces cmdline pattern matching with ancestry-based detection.
Source code in src/marianne/daemon/pgroup.py
untrack_backend_pid
¶
Remove a backend PID from tracking after clean exit.
setup
¶
Create a new process group with the daemon as leader.
Must be called early in daemon startup, before spawning any child processes. Idempotent — safe to call multiple times.
Source code in src/marianne/daemon/pgroup.py
kill_all_children
¶
Send signal to all processes in our group except ourselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig
|
int
|
Signal number to send (default SIGTERM for graceful stop). |
SIGTERM
|
Returns:
| Type | Description |
|---|---|
int
|
The process group ID that was signaled, or 0 if no signal sent. |
Source code in src/marianne/daemon/pgroup.py
cleanup_orphans
¶
Find and clean up orphaned child processes in the daemon's tree.
Detects two categories: 1. Zombie children — reaped via waitpid 2. Orphaned MCP servers — processes whose parent has died (reparented to init/PID 1) that still match MCP patterns
Note: This only scans the daemon's own child tree. For processes that escaped the tree entirely (reparented to init), use reap_orphaned_backends() which does a system-wide scan.
Returns:
| Type | Description |
|---|---|
list[int]
|
List of PIDs that were cleaned up. |
Source code in src/marianne/daemon/pgroup.py
reap_orphaned_backends
¶
System-wide scan for orphaned backend child processes.
.. warning:: DISABLED — This method is a no-op.
The F-481 rewrite removed cmdline pattern filtering and replaced
it with ancestry-only detection (ppid in {0, 1}). Without
filtering, this kills EVERY user-owned process parented by
init/systemd — including the user's systemd session manager,
terminal emulators, and dbus. On WSL2, killing systemd
--user cascades into systemd-poweroff.service and shuts
down the entire VM (observed 9 times, exit code 9, all
terminals dead).
The replacement is per-job PID tracking in the conductor DB (see composer-notes.yaml "PROCESS CLEANUP SIMPLIFICATION"). Until that's implemented, orphaned MCP/LSP servers from dead backends accumulate but don't crash the system.
Returns:
| Type | Description |
|---|---|
list[int]
|
Empty list (no-op). |
Source code in src/marianne/daemon/pgroup.py
DaemonProcess
¶
Long-running Marianne daemon process.
Composes DaemonServer (IPC), JobManager (job tracking), and ResourceMonitor (limits) into a single lifecycle.
Source code in src/marianne/daemon/process.py
Functions¶
run
async
¶
Main daemon lifecycle: boot, serve, shutdown.
Source code in src/marianne/daemon/process.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
GlobalSheetScheduler
¶
Cross-job sheet-level scheduler using a priority min-heap.
Status: Phase 3 infrastructure — built and tested, not yet wired into the execution path.
Manages a global priority queue of sheets from all active jobs.
Enforces:
- max_concurrent_sheets from DaemonConfig
- Per-job fair-share limits (penalty-based, not hard-block)
- Per-job hard cap at fair_share * max_per_job_multiplier
- DAG dependency awareness via completed-set tracking
The scheduler does NOT own sheet execution — it decides which
sheet should run next and the JobManager performs the actual
execution.
Integration plan (future):
1. JobManager._run_job_task() calls register_job() with
all sheets parsed from the JobConfig.
2. A dispatch loop calls next_sheet() and spawns per-sheet
tasks instead of calling JobService.start_job() monolithically.
3. Each per-sheet task calls mark_complete() on finish.
4. cancel_job() / shutdown calls deregister_job() for cleanup.
Source code in src/marianne/daemon/scheduler.py
Attributes¶
Functions¶
set_rate_limiter
¶
set_backpressure
¶
register_job
async
¶
Register a job's sheets with the scheduler.
Enqueues sheets whose dependencies are already satisfied (or have
no dependencies). Remaining sheets are enqueued as their deps
complete via mark_complete().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier. |
required |
sheets
|
list[SheetInfo]
|
All sheets for this job. |
required |
dependencies
|
dict[int, set[int]] | None
|
Optional DAG — |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dependencies contain a cycle (would deadlock). |
Source code in src/marianne/daemon/scheduler.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
deregister_job
async
¶
Remove all pending sheets for a cancelled/completed job.
Source code in src/marianne/daemon/scheduler.py
next_sheet
async
¶
Pop the highest-priority ready sheet, respecting limits.
Returns None if no sheet can run (concurrency full, backpressure active, queue empty, or all queued sheets are rate-limited).
Single-caller constraint: The backpressure delay (asyncio.sleep)
runs outside the scheduler lock. If multiple coroutines call
next_sheet() concurrently, they may all pass the backpressure
check before any acquires the lock, effectively bypassing the delay
for concurrent callers. The intended usage is a single dispatch
loop calling next_sheet() sequentially — the JobManager
dispatch loop satisfies this constraint.
Source code in src/marianne/daemon/scheduler.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
mark_complete
async
¶
Mark a sheet as done and enqueue newly-ready dependents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job that owns this sheet. |
required |
sheet_num
|
int
|
Which sheet completed. |
required |
success
|
bool
|
Whether execution succeeded. |
required |
Source code in src/marianne/daemon/scheduler.py
get_stats
async
¶
Return a snapshot of scheduler state.
Source code in src/marianne/daemon/scheduler.py
SchedulerStats
dataclass
¶
Statistics snapshot from the scheduler.
SheetEntry
dataclass
¶
Priority queue entry for a schedulable sheet.
Ordered by (priority, submitted_at) — lower priority value = higher
urgency. The info field is excluded from comparison so that
heapq ordering is based solely on the numeric sort keys.
SheetInfo
dataclass
¶
SheetInfo(job_id, sheet_num, backend_type='claude_cli', model=None, estimated_cost=0.0, dag_depth=0, job_priority=5, retries_so_far=0)
Metadata about a sheet waiting to be scheduled.
DaemonStatus
¶
Bases: BaseModel
Current status snapshot of the running daemon.
Returned by health check / status queries. Provides a lightweight overview without per-job detail.
JobRequest
¶
Bases: BaseModel
Request to submit a job to the daemon.
Sent by clients (CLI, dashboard) to the daemon over IPC. The daemon validates the config and either accepts or rejects.
JobResponse
¶
Bases: BaseModel
Response from the daemon after a job submission.
Returned immediately — does not wait for job completion. Clients poll status separately via DaemonStatus or job-specific queries.