cosmotron_mcp.tools.jobs¶
submit_job ¶
submit_job(session_dir: str, argv: list[str], desc: str = 'job', jobspec: dict | None = None) -> dict
Submit a command as a non-blocking background job; return immediately.
argv is the command as a list (e.g. ["cosmosis", "pipeline.ini"]). jobspec
is an optional resource dict (backend "local"|"slurm", cpus, mem,
walltime, partition, nodes, env); omitted → a local single-process job.
For a remote Slurm job pass {"backend": "slurm", "site": "<site>"} (a
sites.yaml entry) — resources come from the tool's abstract
resource_class translated by the site, so nothing else is usually
needed; a remote job starts in status="staging". Logs and a
returncode marker land under {session_dir}/jobs/{job_id}/. Poll
with check_job(session_dir, job_id) — do NOT block waiting for completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory the job belongs to. |
required |
argv
|
list[str]
|
Command as a list, e.g. |
required |
desc
|
str
|
Short human-readable label for the job. |
'job'
|
jobspec
|
dict | None
|
Optional resource dict ( |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
fresh Slurm submit). |
Source code in cosmotron_mcp/server.py
check_job ¶
Poll a background job's status; return its state + log tails.
Reads the persisted record, polls the backend (returncode marker / pid
liveness — the local analogue of squeue/sacct), rewrites the record, and tails
the logs. wait=0 (default) returns immediately. Pass wait seconds (e.g.
wait=45, clamped to 45) to BLOCK server-side until the job is terminal or the
time elapses — use this instead of calling check_job many times in a row
while a chain runs (it returns early the moment the job finishes).
Never does network I/O, even for a remote (slurm) job: a detached watcher
process polls the cluster and pulls results back on its own, and this call
just reads the record that watcher maintains. So it cannot hang, and a long
remote run is followed by re-issuing wait=45 until the status is terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory the job belongs to. |
required |
job_id
|
str
|
Job identifier returned by |
required |
wait
|
float
|
Seconds to block server-side until the job is terminal (clamped
to 45); |
0.0
|
Returns:
| Type | Description |
|---|---|
dict
|
``{job_id, status, returncode, run_dir, stdout_tail, stderr_tail, |
dict
|
waited, running_secs, last_activity_secs} |
dict
|
|
dict
|
|
dict
|
a remote (slurm) job while its detached watcher is pushing/pulling |
dict
|
files; a local job never reports them. A remote job also carries |
dict
|
|
dict
|
|
dict
|
map silently falls back to the site's |
dict
|
the only place that's visible, so check it after any remote submit |
dict
|
that named a non-default queue or partition. A |
dict
|
carries |
dict
|
|
Source code in cosmotron_mcp/server.py
list_jobs ¶
List all jobs for a session (most recent first), polling each for fresh status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory to list jobs for. |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of |
list[dict]
|
plus (remote/slurm jobs only) |
list[dict]
|
(the watcher hasn't updated the record recently — check |
list[dict]
|
for a fresh poll rather than treating |
Source code in cosmotron_mcp/server.py
cancel_job ¶
Best-effort cancel a running job (local: kill its whole process group).
Escalates SIGTERM → ~5 s grace → SIGKILL so a stuck mpirun/cosmosis MPI run is
actually stopped. Pass force=True to SIGKILL immediately (runaway / overlong run).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory the job belongs to. |
required |
job_id
|
str
|
Job identifier returned by |
required |
force
|
bool
|
SIGKILL immediately instead of escalating from SIGTERM. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
terminal status if the job had already finished. |
Source code in cosmotron_mcp/server.py
list_remote_artefacts ¶
List artefacts registered as remote-only (bytes never pulled to the Spark).
Pure local read of results/artefact_registry.json — zero network I/O, always
instant. A remote job reporting status=done with no pull_error/merge_error
does NOT guarantee every artefact it produced is local: the automatic pull only
fetches a fixed set of file types on job completion. If a downstream tool
reports a missing artefact that a prior remote job's receipt claims it
produced, call this FIRST — the artefact may already exist on the remote site
and just need pull_remote_artefacts, not a recompute or resubmit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory to inspect. |
required |
job_id
|
str | None
|
Optional job id (from |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of |
Source code in cosmotron_mcp/server.py
pull_remote_artefacts ¶
Fetch specific remote-only artefacts for a job back to the Spark; returns immediately.
Spawns a detached pull phase (same idiom as the automatic stage/watch/
finalize lifecycle — no network I/O happens inside this call, so it cannot
hang or take the MCP connection down). Poll with check_remote_pull.
Use this instead of recomputing or resubmitting when list_remote_artefacts
shows a job produced an artefact that never made it back locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory the job belongs to. |
required |
job_id
|
str
|
Job identifier (must be a remote/slurm job that reached the
cluster — i.e. has a |
required |
paths
|
list[str] | None
|
Session-relative paths to pull (e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
check_remote_pull ¶
Poll an on-demand pull_remote_artefacts request; local file read only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory the job belongs to. |
required |
job_id
|
str
|
Job identifier passed to |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|