analyze_job
Diagnose slow Python/SQLAlchemy jobs by running them and getting the exact call site, query count, and fix, with optional per-unit trend analysis.
Instructions
Run a Python/SQLAlchemy job under wherewent and return WHY it was slow.
Use when a batch job is slow and you need the exact call site, query
count, and fix — wherewent counts/groups/attributes deterministically in
Python (zero token cost) and hands back machine fields to act on.
Args:
command: The job as an argv LIST, e.g. ["python", "job.py"] or
["python", "-m", "mypkg"]. TRUST BOUNDARY: this list is executed
directly with NO shell (no shell=True) — no interpolation, no
injection. The agent platform's sandbox is the outer boundary.
unit_function: Optional SPEC (e.g. "myapp.jobs:process_receivable")
to enable per-unit trend analysis (rising per-unit cost).
timeout_s: Max seconds to let the job run (default 600). Real jobs can
run for hours — on timeout the child is stopped and PARTIAL
results are returned with timed_out=True. Partial data is a
first-class use: read the per-unit growth trend.
Returns an envelope: {"result": <enriched wherewent JSON or null>,
"exit_code", "timed_out", "stderr_tail", "error"}. Each finding in
result.findings carries fix/call_site/calls/evidence. Act on `fix`; cite
`call_site` + `evidence`.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| timeout_s | No | ||
| unit_function | No |