We run a project's work as a DAG of small tasks in SQLite. Headless pi workers execute, review and close each
task; two helpers keep it moving; the orchestrator (a Claude session) handles what they cannot.
A project holds two folders at its root:
dag/: this repo, mounted as a git submodule. It is code and docs only, the same commit in every project.dag_data/: what the project owns:project.json, the database indb/, records and runtime state inruns/.
The project root is always the parent of dag/. The live page is where people read the DAG; no checklist file is maintained.
From the project root, with this repo mounted as dag/ (see the next section):
dag/scripts/dag_orch.sh --checklist <path> # a checklist in the format of dag/CHECKLIST_FORMAT.md
dag/scripts/dag_orch.sh --spec <path> # a spec file: the orchestrator drafts the checklist from it
dag/scripts/dag_orch.sh --task "<text>" # a task in words: the orchestrator drafts the checklist from it
dag/scripts/dag_orch.sh # no intake: take over a DAG that exists, or be asked which start you want- The launcher starts
unblock.pyand the page (http://127.0.0.1:8766) if they do not run for this root, then opens a Claude session.- The session gets
ORCHESTRATOR_PROMPT.md, plus oneIntake:line when a flag is given; it starts the scheduler itself.
- The session gets
- For a spec or a task, the session writes the draft to
dag_data/runs/intake_checklist.md, shows the milestones and tasks, and imports on a yes. - By hand, a checklist needs no session:
python3 dag/src/tm.py init, thenpython3 dag/src/tm.py import <checklist.md>. - Every intake builds the dependencies before it imports: import reads only
Depends:lines, so without them every task is ready at once.CHECKLIST_FORMAT.md, "Building the dependencies", holds the rules;tm.py readyafter the import is the check.
- The page alone:
dag/scripts/dag_site.sh, orpython3 dag/src/tm.py serve --port 8766.
Steps for a session asked to "add dag to this project". Run them as written, in one shell, from inside the target repo; ask the user only what the steps cannot answer.
-
Find the source and the target.
<source>is a git URL of this repo, or a local path to a clone of it. The target must be a git repo, becausedag/is a submodule: if it is not, stop and ask the user before anygit init. If$TARGET/dagor$TARGET/dag_dataexists, stop and report what is there; never overwrite either.SOURCE=<source> TARGET=$(git rev-parse --show-toplevel) || echo "STOP: not a git repo" for d in dag dag_data; do if [ -e "$TARGET/$d" ]; then ls -la "$TARGET/$d"; echo "STOP: $TARGET/$d exists"; fi; done
-
Mount the code as a submodule. It pins the source's current commit; the project moves the pin when it chooses (see
## Update dag in a project).git -C "$TARGET" -c protocol.file.allow=always submodule add "$SOURCE" dag
protocol.file.allow=alwaysis needed only for a local-path source; git refuses file transport in submodules without it.- A local-path source is recorded in
.gitmodulesas that absolute path, so it works on this machine only. Tell the user.
-
Create the project's data folder from the templates, and set
nameindag_data/project.jsonto the repo's name.mkdir -p "$TARGET/dag_data/db" "$TARGET/dag_data/runs" cp "$TARGET/dag/template/project.json" "$TARGET/dag_data/project.json" cp "$TARGET/dag/template/gitignore" "$TARGET/dag_data/.gitignore" python3 - "$TARGET" <<'EOF' import json, os, sys p = f'{sys.argv[1]}/dag_data/project.json' c = json.load(open(p)); c['name'] = os.path.basename(sys.argv[1]) open(p, 'w').write(json.dumps(c, indent=2) + '\n') EOF
- Change
rulesonly if the repo's rules file is notCLAUDE.md. - Set
cite_rootsonly if tasks will cite code outside the repo.
- Change
-
Git:
dag_data/.gitignoreignores the runtime files, so the repo's own ignore rules need nothing new.- Check that no repo rule hides the records:
git -C "$TARGET" check-ignore -v dag_data/db/tasks.db dag_data/runs/task_1_exec.mdmust print nothing.- If it prints a rule, tell the user which one; do not edit the repo's ignore file unasked.
- Tasks commit only while
dag_data/runs/COMMITexists and the root is a git repo. submodule addstages.gitmodulesanddag; do not commit or push anything as part of the install unless the user asks.
- Check that no repo rule hides the records:
-
Rules file: if
$TARGET/CLAUDE.mdexists, append this pointer; if it does not, create nothing unless asked.if [ -f "$TARGET/CLAUDE.md" ]; then cat >> "$TARGET/CLAUDE.md" <<'EOF' ## DAG - We run this project's tasks as a DAG; the code is the submodule `dag/`, read `dag/README.md` before touching it. - The live page (`python3 dag/src/tm.py serve`) is the source of truth for people; the data is in `dag_data/db/tasks.db`. - We change tasks only with `python3 dag/src/tm.py`; task records are in `dag_data/runs/`. - We never edit files under `dag/` from this project; changes go to the dag repo, then the pin moves. EOF fi
-
Check the install from
$TARGET.cd "$TARGET" python3 -c 'import sys; assert sys.version_info >= (3, 9), sys.version' && command -v pi claude python3 dag/src/tm.py init && python3 dag/src/tm.py check python3 -m pytest dag/src -q -p no:cacheprovider git -C dag status --short # must print nothing: the project writes no file under dag/
- Python under 3.9: tell the user the DAG needs 3.9 or newer.
pimissing: workers cannot run;claudemissing: the launcher cannot open the orchestrator. Tell the user which, and stop there.pytestmissing: say so; the DAG runs without it, only the tests do not.
-
Hand back and stop: adding dag starts no scheduler and creates no task. Tell the user:
- the four starts from
## Start here; - the page command:
dag/scripts/dag_site.sh.
- the four starts from
The submodule pins one commit of this repo, so a change here reaches a project only when the project moves its pin.
git -C dag fetch origin
git -C dag checkout <commit or origin/main> # the commit the project should run
python3 -m pytest dag/src -q -p no:cacheprovider
git add dag # the new pin; commit it with the project's next commit- Move the pin while no scheduler runs, or replace the scheduler after it (STOP handover) and restart
unblock.pyand the page. - A fresh clone of the project gets the code with
git submodule update --init(add-c protocol.file.allow=alwaysfor a local-path source). - We improve the DAG in this repo, never inside a project's
dag/: commit here, then move each project's pin.
In the project's dag_data/:
project.json: the only project-specific config: the project name, the rules file, the pi model and the cap defaults.cite_rootslists directory globs a citedpath:linemay resolve under, beside the root;src/host.pydocuments every key.
db/tasks.db: the task database, the source of truth.tm.py initcreates it,tm.py importfills it.runs/: task records and runtime state (below)..gitignore: ignores the runtime state, so the database and the records stay committable.
At the top of this repo (dag/ in a project):
scripts/:dag_orch.sh, the one-command launch, anddag_site.sh, the page.template/:project.jsonandgitignore, the files a newdag_data/starts from.README.md,CHECKLIST_FORMAT.md(the intake format) andORCHESTRATOR_PROMPT.md(the takeover prompt).
In src/, all code:
tm.py: the only way to read or changetasks.db(tasks, deps, caps, claims, locks, the page); a CLI everything calls.sched.py: workers that claim ready tasks and run each through pi; one daemon per handover.unblock.py: a daemon that gives each blocked task up to 2 retries, then escalates.autocap.py: an optional daemon that setsmax_runningevery 15 s from the GPU backend's load (below, "Caps").watchdog.py: one-shot; exits with a report on a new anomaly or after 5 min, which wakes the orchestrator.finish.py <n> [--fix]: fix, review and close one task outside the scheduler.precheck.py <n>: deterministic checks between exec and review; the scheduler calls it.- It checks the exec file exists, has
## Self-check, list lines are at most 200 characters, and each citedpath:lineresolves.
- It checks the exec file exists, has
host.py: every path and the config;piusage.py: token counts from a pi step log.dag_view.html: the live pagetm.py serverenders.test_*.py:python3 -m pytest dag/src/.
Elsewhere under the root: the project's own files and its rules file (CLAUDE.md by default). Every
worker reads the rules file first if it exists; project rules go there, never in dag/ or dag_data/.
- Records, worth committing:
task_<n>_exec.md, the executor's log;task_<n>_review.md(and_review_<k>.md), the reviews;task_<n>_result.md,task_<n>_precheck.md,task_<n>_assess.mdand any raw output a task saves astask_<n>_*;intake_checklist.md, the draft a spec or task intake was imported from.
- Disposable runtime state, ignored by
dag_data/.gitignore:status.log,unblock.log, per-step<n>_<step>.log,.errand.jsonl, and the daemons'*.out;STOP,COMMIT,watchdog_seen.json,task_<n>_commit.txt, andtasks_<why>.dbbackups.
DAG_DATA, DAG_DB, DAG_RUNS, DAG_CITE_ROOTS and DAG_PI override paths for tests and scratch runs.
tm.py serve is read-only and shows what a checklist would: milestones with progress, every task with its
status, kind and dependencies, and for a selected task its full section (Why, What, Details, Done when, Evidence),
its Result, links to its record files in runs/, its pi steps and its decisions. With nothing selected it lists
what runs, what is blocked, each open (user) question with its options, and the decision log.
/data.jsonis the snapshot the page polls;/task.json?id=<n>is one task's full record;/runs/<file>serves a record as text.tm.py renderexports the DAG as a markdown checklist to stdout, or to--out <file>. It is optional: nothing maintains or reads it.
tasks: id, milestone, kind (agentoruser), title, status, why, what, details, done_when, evidence, result, worker,assessed.- Status:
open,running,blocked,done,skipped,superseded,obsolete. - Title prefixes:
[orch]and[opus]tasks are the orchestrator's; a pi worker never claims one. - A
(user)task waits for the user and is never decided by an agent; its question and options are columns (tm.py decide).
- Status:
deps (task, dep): a task is ready when every dep is closed.milestones: id, title, order.meta: the caps (below),priority(the ids claim hands out first) and the imported preamble, Context intro and tail.runs: one row per pi step (exec, assess, fix0..n, review1..n, close) with rc, duration and tokens.blocks: the block audit trail; attempt 0 is the block, 1 and 2 are unblock attempts, thenescalated.locks: named locks with holder, pid and TTL:gitfor a commit,sched:<prefix>for a running scheduler. We use no lock files.context: the decision log (tm.py context "...").
tm.py claimpicks the ready task with the most open work downstream (priority ids first), within the running cap.- It skips a task that fails
tm.py lintand records why inmetaasclaim_skip:<id>.
- It skips a task that fails
- Split check (
assess): a task with no estimate, or one over 15 min, may be split into parts plus a merge (tm.py split).- A task whose Details say
estimate <n> minwith n at most 15 runs with no model call.
- A task whose Details say
exec: pi reads the rules file, does what the task section asks and writesruns/task_<n>_exec.md.- A result the task names no path for goes to
runs/task_<n>_result.md.
- A result the task names no path for goes to
precheck.py; findings go to one fix round (fix0).review1..3: an independent pi review intoruns/task_<n>_review.md; a FAIL gets a fix round and a fresh review.- On PASS,
closewrites the Result block and closes the task.- It commits by path (
task <n>: <title>) only whenruns/COMMITexists and the root is a git repo; otherwise it skips the commit silently.
- It commits by path (
- Three failed reviews, a
BLOCKED:line, a timeout or a missing exec file set the taskblocked;unblock.pytakes it from there.- A review fail gets
finish.py <n> --fix; a question or timeout is requeued with the reason added to What. - After two failed attempts the block is
escalated, and the watchdog reports it to the orchestrator.
- A review fail gets
Step caps: exec and fix 30 min, review 15 min, close and assess 10 min. To check order afterwards, use the runs
table and runs/status.log; tasks.updated is overwritten.
max_running(tm.py cap <n>): all running tasks; it gates new claims only, andtm.py cap 0restores the config default.max_opus(tm.py cap --opus <n>):[opus]tasks the orchestrator runs at once; the orchestrator reads it.dag_data/project.jsoncapssets both defaults (6 and 2 with no file);tm.py capandtm.py cap --opusprint the live values.autocap.pymovesmax_runningon its own when the tasks share a GPU backend with vLLM metrics; without it the cap is static.- Ceiling: 36 agents, 90 % of the 40 at which the measured GPU degrades (
tip_agentsinproject.jsonautocap). - Under the ceiling it holds requests in flight at 90 % of the knee (34, where output peaks) and the KV cache under 0.675.
- Requests waiting, a slow first token, preemptions or prefix-index churn cut the cap to 75 % of running.
- It never raises the knee itself: we do not cross the limit to find it. Raise
autocap_kneeinmetaby hand after a capacity change. - The cap is per project: two projects on one GPU must split the ceiling by hand with
DAG_AUTOCAP_HIuntil they coordinate. - Start:
nohup python3 $D/src/autocap.py >> $R/autocap.out 2>&1 &; it logs each poll toruns/autocap.log.
- Ceiling: 36 agents, 90 % of the 40 at which the measured GPU degrades (
D=$PWD/dag # absolute, so pgrep tells our daemons from another project's
R=$PWD/dag_data/runs # this project's records and runtime state
W=$(python3 $D/src/tm.py cap) # workers equal the running cap
nohup python3 $D/src/sched.py --workers $W --prefix a >> $R/sched_a.out 2>&1 &
nohup python3 $D/src/unblock.py >> $R/unblock.out 2>&1 &
nohup python3 $D/src/tm.py serve --port 8766 >> $R/serve.out 2>&1 & # the page, http://127.0.0.1:8766- With no
--ms, the scheduler serves every milestone;--ms M2,M3narrows it. - Commits are off by default.
git init(once, if the root is not a repo) plustouch dag_data/runs/COMMITturns them on. - Check what runs:
python3 dag/src/tm.py lock listshows each scheduler assched:<prefix>with its workers and milestones.pgrep -fl "$PWD/dag/src/(sched|unblock|tm)\.py"shows the processes; eachSTART schedline inruns/status.logmarks a run.
- The cap, not the worker count, limits concurrency. We run one scheduler only.
- A scheduler exits (
END sched) once its milestones hold no agent task that is open, running or blocked.[orch],[opus]and(user)tasks do not keep it alive; while one of them gates agent tasks, it waits.
- The page server loads
tm.pyonce: restart it after atm.pychange. It re-readsdag_view.htmlper request.
touch $R/STOP && sleep 1
nohup python3 $D/src/sched.py --workers $W --prefix <new letter> >> $R/sched_<letter>.out 2>&1 &STOP stops only schedulers started before its mtime, so we touch it first, then start the new one. Old workers
finish their current task and exit; nothing is killed. A prefix in use is refused; pick one tm.py lock list does not show.
Run python3 dag/src/watchdog.py in the background; when it exits, read its report, act, and run it again.
HEARTBEAT(every 5 min with nothing new): status only. Start the watchdog again after every exit.scheduler process is not running: it drained its milestones or died; start one if agent work remains.<n> ready for the orchestrator: an[orch]or[opus]task's dependencies are closed; run it by hand (below).<n> waits on the user: a(user)task is ready; tell the user, and never decide it.step ... near the 30 min caporrunning N min, written estimate M: the cap handles it; look only if it repeats.blocked N min with no unblock attempt: no one owns the block. Checkunblock.pyruns, or run the step yourself.- For a review fail:
python3 dag/src/finish.py <n> --fix; record it withtm.py block addandtm.py block end.
- For a review fail:
<n> blockedon an[orch]or[opus]task: yours;unblock.pyskips those.escalated after two unblock attempts: yours. Read the last review, then requeue with a note in What, close as partial or skipped, or rewrite the task.- Record the decision with
tm.py context.
- Record the decision with
orphan processorno step started or ended for N min: look at the process andruns/<n>_<step>.errbefore acting.
tm.py show <n>,ready [--user],list --ms M2 --status open,stats,check,lint <n>,cost --ms M2.tm.py add --ms <m> --assessed --title ... --what @file --details @file --done-when @file --deps 1,2.tm.py edit <n> --status open --force;tm.py edit <n> --add-deps 3;tm.py prio <ids>(0 clears).tm.py close <n> --result -;tm.py block list;tm.py lock list;tm.py context --task <n> "decision ...".- A user decision:
tm.py decide <n> --question ... --option "label: description"; the user's answer closes it withtm.py close. - A follow-up task: add it before closing the task that led to it, never after.
- Order:
tm.py add ..., thentm.py edit <dependent> --add-deps <new id>for each task that must wait, thentm.py close <n>. - Or close first with the dependents held:
tm.py close <n> --hold <ids>, then add the task and--add-deps, which lifts the hold. tm.py holdlists held tasks;tm.py hold --clear <ids|all>releases one that needs no follow-up; the watchdog reports a held task that is otherwise ready.- A dependency only gates claiming: closing first frees the dependents, and a worker claims one within seconds, on inputs the new task was meant to change.
- If a dependent is already running: stop its step,
tm.py release <n> --status open, and set its result file aside.
- Order:
- A hand-run (
[orch]or[opus]) task:tm.py edit <n> --status running --force(prints nothing), so the page shows it;- do it (an Opus sub-agent for
[opus]), writingruns/task_<n>_exec.mdand its outputs; - review it into
runs/task_<n>_review.md; the orchestrator reviews both kinds itself; tm.py close <n> --result -with the exec path, a nested one-line outcome and the review line;- with commits on:
git add -- <files>andgit commit -m "task <n>: <title>" -- <outputs> <exec> <review> dag_data/db/tasks.db.
- An
[opus]sub-agent's brief: the task id,tm.py show <n>, the files it may write (its outputs and its exec file), notasks.dbedits, no commit. - Replacing the whole DAG:
tm.py import --force <checklist.md>; it refuses without--forceonce the database holds tasks. - Backups before bulk edits:
cp dag_data/db/tasks.db dag_data/runs/tasks_<why>.db. - A backend outage (every step fails in seconds and tasks block in minutes): touch STOP and stop
unblock.py.- Probe with
pi -p --no-session --no-tools --model <model> "ok" </dev/null. - Once it answers, delete the outage's
blocksrows, reopen the tasks, and start a fresh scheduler andunblock.py.
- Probe with