Tasks: a session never goes idle unnoticed
The last spec artifact. A DAG derived from the approved
design.mdandtesting-plan.md. It has no gate of its own (issue-281).
The short version
Seventeen tasks in five tracks, all in this repository and on pull request #552.
- Foundation (1–3): the contract, the events and config, and the session-state derivation that everything else reads.
- Prevent (4–8): the claim's answer, the stop check, the hooks, the declared wait.
- Detect (9–12): read-only inbound evaluation, the ask deadline, the watcher, the channel messages.
- Show (13): the status surfaces.
- Prove and document (14–17): the end-to-end test, the abuse-case sweep, the skill and the docs.
The risky ones are 3 (every later decision reads it), 7 (the hook must keep working against an older CLI and a dead service) and 11 (the daemon types into a session on its own initiative).
Task list
Every task is test-first: the named test goes red before the code that makes it green.
- [x] 1. Put the contract first
- Add to
docs/api-specs/openapi/the-loop.v1.yaml:defaultAfterSecondson the ask; the wait, stop-check and turn-start endpoints;assignmentandnexton the claim response;sessionon the check response; the two attention kinds. - Depends on: none
- Requirements: R1.6, R3, R4.7, R6.1, R7
- Test: T3 —
tests/test_api_contract_parity.py(red until tasks 4–13 add the routes)
- Add to
- [x] 2. Register the events, the config blocks and the duration parser
- Nine event names with their descriptions in
strings/en.json. routing.watchdogandrouting.asksin the CLI config schema (both copies), their defaults, and the page underdocs/config/cli/.- A strict parser for
45s,30m,2h. - Depends on: none
- Requirements: NFR configuration, NFR events, R6.5
- Test: T1 —
tests/test_eventlog.py,tests/test_configschema.py,tests/test_durations.py; T10 — a config without the blocks loads with the defaults
- Nine event names with their descriptions in
- [x] 3. Derive the state of a session from the event log
- One read-only derivation: working, waiting (with its reason and end), idle, stalled, notified, not watched. It also yields the stall id, the idle start and the nudge budget left for the node visit.
- Open asks close on
reply_sent,ask_answeredorask_default_taken. - Depends on: 2
- Requirements: R4.1–R4.10, R7
- Test: T1 —
tests/test_session_state.py, one test per arrow of the design's state diagram; T7 —-k cycle_budget; T10 —-k legacy
- [x] 4. Return the next assignment from a claim
- The claim envelope gains
assignmentandnext. A new prompt file carries the "continue in this turn" line; the human-gate text names the gate. - Depends on: 1
- Requirements: R1
- Test: T1 —
tests/test_graph_claim_assignment.py; T2 —Scenario: a claim returns the next assignment and says to continue,Scenario: an advance the daemon drives delivers the assignment once
- The claim envelope gains
- [x] 5. Decide a stop in the service
- The stop check, in the design's order, behind
the-loop sessions stop-checkand its endpoint. It recordssession.turn_endedwith the reason on every allow, and on--gave-up. It refuses a work item the calling session is not bound to. - The refusal text is a prompt file: node, unmet checks, resume command, the three ways out.
- Depends on: 1, 3
- Requirements: R3.1–R3.5, R3.7, R3.8
- Test: T1 —
tests/test_stop_check.py; T2 —Scenario: a stop with work owed is refused past an approved gate(the P3 regression),Scenario: a stop with an open ask is allowed; T8 —foreign_work_item
- The stop check, in the design's order, behind
- [x] 6. Record a turn's start
the-loop sessions turn-startand its endpoint. A new stdlib-only hook script calls it and always exits 0. The Claude Code, Codex and Cursor hook manifests gain the entry.- Depends on: 1, 2
- Requirements: R4.5, R4.6
- Test: T1 —
tests/test_session_state.py -k turn_started; T10 —tests/test_harness_gate.py -k turn_start_without_cli
- [x] 7. Make the Stop hook ask the service
- The hook forwards the harness payload to
stop-check, keeps its attempt cap, and reports a give-up. When the verb is missing or the service is silent, it falls back tothe-loop checkwith awaitbefore the pointer counted as passed. - Depends on: 5
- Requirements: R3.3, R3.4, R3.6, R3.7
- Test: T2 —
tests/test_gate_pointer_integration.py,Scenario: the gate gives up after its attempts and records why; T10 —tests/test_harness_gate.pyfallback cases; T8 — abuse case 7
- The hook forwards the harness payload to
- [x] 8. Add the declared wait
the-loop waitand its endpoint. Refused over the wait limit and on a human-owned node. The condition is capped at 200 characters. A wait covers the one stop that ends the turn it was made in.- Depends on: 1, 3, 5
- Requirements: R3.2.3, R4.7, R4.8
- Test: T1 —
tests/test_stop_check.py -k declared_wait; T8 — abuse case 4
- [x] 9. Evaluate an agent-owned node read-only on an inbound event
- A hook declares, where it is registered, that it reads the inbound event. The dispatcher advances as today for a human-owned node or such a hook. Otherwise it evaluates without an event and advances only on a pass. Same rule for a pull request's inner loop.
- Depends on: none
- Requirements: R5
- Test: T2 —
tests/test_inbound_readonly_integration.py:Scenario: a comment does not block an agent node,Scenario: a met exit gate still advances on a comment,Scenario: a human gate still classifies the comment it receives
- [x] 10. Give an ask a deadline
the-loop ask --after.session.awaiting_inputcarries the default, its time and an ask id in the event log. The posted question states the default and the time. The dispatcher writessession.ask_answeredwhen it delivers an authorized human comment to a session with an open ask.- Depends on: 1, 2, 3
- Requirements: R6.1, R6.3, R6.5, R6.6
- Test: T1 —
tests/test_durations.py -k minimum; T2 —tests/test_ask_deadline_integration.py:Scenario: an answer cancels the default; T8 — abuse case 1
- [x] 11. Run the watcher in the control-plane service
- One thread on a 30-second tick, started and stopped with the service. Each cycle: nudge within the node visit's budget, publish
session.stalledwhen the budget is spent, recordstall_ended, take ask defaults, send ask reminders. Each act is skipped when the log already holds it. - The nudge and the "proceed with your default" message are prompt files. The nudge inserts only the node id and the node's command.
routing.watchdog.enabled: falsesends no nudge and no notice.- Depends on: 3, 10
- Requirements: R4.1–R4.6, R4.9–R4.12, R6.2, R6.4, R6.7, R6.10
- Test: T2 —
tests/test_watchdog_integration.py:Scenario: an idle session is nudged, then a person is told once,Scenario: a restart repeats no nudge and no notice,Scenario: a stall ends when the session takes a turn, and the notice is edited,Scenario: a switched-off watchdog sends nothing and the gate still holds;tests/test_ask_deadline_integration.py:Scenario: a default is taken at its deadline, once, across a restart,Scenario: an answer after the default still reaches the session,Scenario: a question with no default is reminded once; T8 — abuse cases 2, 5,nudge_is_fixed
- One thread on a 30-second tick, started and stopped with the service. Each cycle: nudge within the node visit's budget, publish
- [x] 12. Post and edit the messages
- Slack and GitHub render
session.stalled,session.stall_ended,session.ask_default_takenandsession.ask_remindedwith the wording ofdesign/messages.html. The stall notice is remembered per stall id and edited when the stall ends.session.stalledjoins the default subscription and maps to the 🛑 status reaction. All text is instrings/en.json. - The condition and the default text pass through the channel defusing.
- Depends on: 11
- Requirements: R4.4, R4.5, R6.2, R6.7, R6.8, R7.4
- Test: T2 —
Scenario: the stall notice is a short form in the work item's conversation; T9 — thetextfallback; T8 — abuse cases 3, 6
- Slack and GitHub render
- [x] 13. Show the state on the status surfaces
- The
session:line and object ofthe-loop check, the state inthe-loop sessions list, thestalledanddeclared-waitattention kinds, the default on anawaiting-inputrow, and the control-plane UI's mirror of the open-ask rule. - Depends on: 1, 3
- Requirements: R5.6, R7.1–R7.3, R7.5
- Test: T1 —
tests/test_session_state.py -k surfaces; T3 — contract parity for the check and attention shapes; the UI's own unit tests (ui/,npm test)
- The
- [x] 14. Prove the path end to end
- A stub harness script and
tests/test_idle_watchdog_e2e.py: its own service, its own tmux server, the real hook scripts. It skips with a reason wheretmuxis missing. - Depends on: 6, 7, 11
- Requirements: R3, R4, R4.11
- Test: T4 —
tests/test_idle_watchdog_e2e.py
- A stub harness script and
- [x] 15. Rewrite the skill and the prompts
reference/context.md(the daemon row and the paragraph under it),SKILL.md,commands/work-on.md,reference/collaboration.md(the three ask cases, the legitimate stops, "take the step you announce"), and the interaction prompt.- Depends on: 5, 8, 10
- Requirements: R2, R6.9
- Test: T12 — the grep returns nothing;
tests/test_docs_parity.py
- [x] 16. Close the abuse-case sweep
- Check that each of the seven abuse cases and the two extra boundary tests has a named negative test, and add any that tasks 5–12 left out.
- Depends on: 5, 7, 8, 10, 11, 12
- Requirements: Security considerations, abuse cases 1–7
- Test: T8 —
pytest -q -k "abuse or unauthorized or foreign_work_item or nudge_is_fixed"
- [x] 17. Update the living docs
- Capability docs: process graph (the Stop gate, what an inbound event does), interactive sessions (turn records, the watcher, the declared wait), channels (the four events), CLI. The CLI command pages for
wait,ask,sessions,check. The observability reference's event list. One decision record for how the-loop observes a session. The README where it describes the Stop gate. - Depends on: 4–13
- Requirements: NFR documentation
- Test: T12 —
tests/test_docs_parity.py; T13 —uv run pre-commit run --all-files
- Capability docs: process graph (the Stop gate, what an inbound event does), interactive sessions (turn records, the watcher, the declared wait), channels (the four events), CLI. The CLI command pages for
Dependency graph (DAG)
Tasks 1, 2 and 9 have no dependency and can start together. Tasks 4, 9 and 13 touch files no other track touches.
Checkpoints
- After 3:
cd cli && uv run python -m pytest -q tests/test_session_state.py tests/test_eventlog.py tests/test_configschema.py tests/test_durations.py. - After 8 (Prevent is complete): the T1 command of the testing plan, plus
tests/test_harness_gate.py tests/test_gate_pointer_integration.py. - After 12 (Detect is complete): the T2 command of the testing plan.
- After 14: the whole CLI suite,
cd cli && uv run python -m pytest -q. - After 17:
uv run pre-commit run --all-files.
Each task's commit carries its test and names the red-to-green run. After the last task, the verification node executes testing-plan.md.
Review comments
Appended by the-loop's
record-feedbackhook when a human gate approves with comments (issue-109). Append-only and attributed: an approval never silently discards a reviewer's suggestions, and the feedback travels with the document it concerns rather than living in a side-channel tracker.