Board Program LEARN context, ruff 0.16, and verb-rejection observability (#700)

* fix(board): LEARN decisions name the item, not its per-cycle index

A cycle's reject reasons are rendered into the NEXT cycle's exploration
prompt, but the ref recorded alongside each reason was the item's stored
id (item-0/item-1) — a per-cycle index that means something different
every cycle and appears nowhere the explorer can resolve. The reason
survived the loop; what it was about did not.

Record the item's title instead, via a shared learn_ref() helper (falls
back to the id when title-less, and reads target_task_title for Scales,
whose items name the live task they mutate).

* chore(lint): satisfy ruff 0.16 — keyword-only signatures and markdown formatting

The dev toolchain resolved ruff 0.16.0, which stabilises PLR0917 (too many
positional arguments) and formats python code blocks inside markdown. Both
fired repo-wide and neither had anything to do with the code they flagged.

- 36 signatures gain a `*` so their tail arguments are keyword-only, and
  the 104 call sites that passed them positionally are converted. mypy was
  the safety net for the static ones; the full suite caught nine more that
  only bind at runtime (the MCP tool functions, whose real callers already
  pass named JSON arguments).
- 28 markdown files reformatted by 0.16's code-block formatter.
- One RUF036 (`None` mid-union) autofixed in the GitLab provider.

* fix(gateway): log the reason when a verb rejects

A rejected envelope rides an HTTP 200, its body is never logged, and there
is no trace table — so in the access log a verb an agent could not satisfy
looks identical to one that worked. On 2026-07-25 four Board Programs
(Periscope, Sentinel, Scales, Barfly) each POSTed their propose verb three
or four times, persisted nothing, and left their exploration tasks PENDING;
the reason was unrecoverable afterwards, from the logs or from the agents'
own transcripts.

Log error/message/remediate/missing plus the calling agent at
envelope_to_response — the one chokepoint every v1 flow and do route
returns through. Success envelopes stay silent.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
Renzo F
2026-07-26 15:07:28 +02:00
committed by GitHub
co-authored by Renn F
parent 401f8a2cc9
commit 879afc14a4
84 changed files with 932 additions and 567 deletions
@@ -95,7 +95,7 @@ async def test_pm_cannot_execute_code_writes_audit_row() -> None:
deps = _make_deps(task=task_svc, audit=audit_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(aid, tid, plan="x")
env = await c.i_will_work_on(agent_id=aid, task_id=tid, plan="x")
assert env.error == "not_authorized"
audit_svc.log_event.assert_awaited()
@@ -215,7 +215,7 @@ async def test_rejection_remediate_lands_in_audit_details() -> None:
deps = _make_deps(task=task_svc, audit=audit_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(aid, tid, plan="x")
env = await c.i_will_work_on(agent_id=aid, task_id=tid, plan="x")
assert env.error == "not_authorized"
assert env.remediate
@@ -239,7 +239,9 @@ async def test_i_will_work_on_refuses_at_cap() -> None:
task_svc.project_month_spend_usd = AsyncMock(return_value=999.0)
c = Choreographer(_make_deps(task_svc))
env = await c.i_will_work_on(agent_id, task_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state", body
assert "10.00" in body["message"] and "999.00" in body["message"]
@@ -131,7 +131,9 @@ async def test_i_will_work_on_blocks_when_agent_has_in_progress_task() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, target_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=target_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state"
assert str(other_id) in body["message"] or str(other_id) in body["remediate"]
@@ -165,7 +167,7 @@ async def test_i_will_work_on_resumption_does_not_self_block() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, steps=_STEPS)
env = await c.i_will_work_on(agent_id=agent_id, task_id=task_id, steps=_STEPS)
assert env.error is None
task_svc.start.assert_awaited_once_with(task_id, agent_id)
@@ -195,7 +197,9 @@ async def test_i_will_work_on_blocks_when_agent_has_paused_task() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, target_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=target_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state"
assert str(paused_id) in body["remediate"]
@@ -226,7 +230,9 @@ async def test_cell_pm_cannot_claim_code_task_via_i_will_work_on() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(pm_id, task_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=pm_id, task_id=task_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "not_authorized"
# Spec produces "role 'cell_pm' may not call 'i_will_work_on'".
@@ -253,7 +259,9 @@ async def test_main_pm_cannot_claim_code_task_via_i_will_work_on() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(pm_id, task_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=pm_id, task_id=task_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "not_authorized"
@@ -403,7 +411,7 @@ async def test_developer_cannot_claim_qa_status_task() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(dev_id, task_id, steps=_STEPS)
env = await c.i_will_work_on(agent_id=dev_id, task_id=task_id, steps=_STEPS)
body = env.as_dict()
assert body["error"] == "not_authorized"
assert "developer" in body["message"]
@@ -494,7 +502,9 @@ async def test_non_developer_role_cannot_claim_via_i_will_work_on() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(doc_id, task_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=doc_id, task_id=task_id, plan="x", steps=_STEPS
)
body = env.as_dict()
# Role-typed claim refuses with not_authorized
assert body["error"] == "not_authorized"
@@ -149,8 +149,8 @@ async def test_dev_claim_acquires_lock_before_guard_read() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
+9 -9
View File
@@ -167,8 +167,8 @@ async def test_i_will_work_on_pending_with_plan() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -213,7 +213,7 @@ async def test_i_will_work_on_pending_no_plan_returns_tracing_gap() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan=None)
env = await c.i_will_work_on(agent_id=agent_id, task_id=task_id, plan=None)
body = env.as_dict()
assert body["error"] == "tracing_gap"
assert "plan" in body["missing"]
@@ -263,8 +263,8 @@ async def test_i_will_work_on_needs_revision_re_starts() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -283,7 +283,7 @@ async def test_i_will_work_on_task_not_found_returns_not_found() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id)
env = await c.i_will_work_on(agent_id=agent_id, task_id=task_id)
body = env.as_dict()
assert body["error"] == "not_found"
@@ -316,7 +316,7 @@ async def test_i_will_work_on_invalid_state_returns_invalid_state() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id)
env = await c.i_will_work_on(agent_id=agent_id, task_id=task_id)
body = env.as_dict()
assert body["error"] == "invalid_state"
# Spec produces "task is in 'completed', 'claim' requires: ..."
@@ -376,8 +376,8 @@ async def test_i_will_work_on_blocks_when_journal_note_at_claim_missing() -> Non
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -173,8 +173,8 @@ async def test_i_will_work_on_pending_claim_raises_returns_invalid_state() -> No
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -196,8 +196,8 @@ async def test_i_will_work_on_pending_claim_returns_none_invalid_state() -> None
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -224,7 +224,9 @@ async def test_i_will_work_on_pending_no_plan_tracing_gap() -> None:
task_svc.claim.return_value = claimed_task
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan=None, steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan=None, steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "tracing_gap"
@@ -249,8 +251,8 @@ async def test_i_will_work_on_start_returns_none_invalid_state() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -279,8 +281,8 @@ async def test_needs_revision_branch_claim_fails_invalid_state() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -302,8 +304,8 @@ async def test_needs_revision_branch_start_fails() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -329,7 +331,9 @@ async def test_claimed_branch_returns_start_failed() -> None:
task_svc.start.return_value = None
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan="ok", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="ok", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state"
@@ -350,7 +354,9 @@ async def test_i_will_work_on_in_progress_assigned_to_self_idempotent() -> None:
task_svc.heartbeat = AsyncMock()
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan="ok", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="ok", steps=_STEPS
)
body = env.as_dict()
# No error — re-entry pass.
assert "error" not in body or body.get("error") is None
@@ -1095,7 +1101,9 @@ async def test_claimed_branch_already_active_guard() -> None:
task_svc.list_in_progress_for_agent.return_value = [in_prog]
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan="ok", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="ok", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state"
@@ -1231,8 +1239,8 @@ async def test_i_will_work_on_envelope_carries_introspection_on_success() -> Non
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -1258,7 +1266,9 @@ async def test_i_will_work_on_envelope_carries_introspection_on_rejection() -> N
task_svc = _wire_dev_task_svc(task_id, status="completed", assigned_to=agent_id)
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan="x", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="x", steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "invalid_state"
assert body["current_state"] == "completed"
@@ -1319,7 +1329,9 @@ async def test_i_will_work_on_missing_plan_does_not_claim_pending_task() -> None
task_svc = _wire_dev_task_svc(task_id, status="pending")
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan=None, steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan=None, steps=_STEPS
)
body = env.as_dict()
assert body["error"] == "tracing_gap"
assert "plan" in body["missing"]
@@ -1354,7 +1366,9 @@ async def test_i_will_work_on_claimed_with_no_plan_accepts_recovery_plan() -> No
task_svc.start.return_value = started
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, plan="recovery plan", steps=_STEPS)
env = await c.i_will_work_on(
agent_id=agent_id, task_id=task_id, plan="recovery plan", steps=_STEPS
)
body = env.as_dict()
assert body["error"] is None, f"expected success, got {body}"
task_svc.set_plan.assert_awaited_once()
+5 -5
View File
@@ -148,8 +148,8 @@ async def test_i_will_work_on_pending_calls_claim_with_task_id_first() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -207,8 +207,8 @@ async def test_i_will_work_on_needs_revision_calls_start_with_task_id_first() ->
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -261,7 +261,7 @@ async def test_i_will_work_on_claimed_resumption_calls_start_with_task_id_first(
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(agent_id, task_id, steps=_STEPS)
env = await c.i_will_work_on(agent_id=agent_id, task_id=task_id, steps=_STEPS)
task_svc.start.assert_awaited_once_with(task_id, agent_id)
assert env.error is None
+11 -7
View File
@@ -115,7 +115,7 @@ async def test_dev_fresh_claim_without_steps_is_rejected() -> None:
task_id = uuid4()
c = Choreographer(_make_deps(task=_dev_task_svc(task_id)))
env = await c.i_will_work_on(dev_id, task_id, plan="do the thing")
env = await c.i_will_work_on(agent_id=dev_id, task_id=task_id, plan="do the thing")
body = env.as_dict()
assert body["error"] == "incomplete_input", body
assert "steps" in (body.get("missing") or []), body
@@ -128,8 +128,8 @@ async def test_dev_thin_step_description_is_rejected() -> None:
c = Choreographer(_make_deps(task=_dev_task_svc(task_id)))
env = await c.i_will_work_on(
dev_id,
task_id,
agent_id=dev_id,
task_id=task_id,
plan="do the thing",
steps=[{"title": "Edit README", "description": "edit it"}],
)
@@ -162,7 +162,9 @@ async def test_dev_with_substantive_steps_passes_gate_and_persists_checklist() -
{"title": "Edit README", "description": _GOOD_STEP_DESC},
{"title": "Commit + open PR", "description": _GOOD_STEP_DESC},
]
env = await c.i_will_work_on(dev_id, task_id, **_full_plan_kwargs(steps_in))
env = await c.i_will_work_on(
agent_id=dev_id, task_id=task_id, **_full_plan_kwargs(steps_in)
)
body = env.as_dict()
assert body.get("error") != "incomplete_input", body
# The full rich plan was layered into the panel-shaped dict and persisted,
@@ -188,8 +190,8 @@ async def test_dev_fresh_claim_missing_considerations_and_risks_rejected() -> No
c = Choreographer(_make_deps(task=_dev_task_svc(task_id)))
env = await c.i_will_work_on(
dev_id,
task_id,
agent_id=dev_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=[{"title": "Edit README", "description": _GOOD_STEP_DESC}],
)
@@ -210,7 +212,9 @@ async def test_dev_reentry_in_progress_short_circuits_before_steps_gate() -> Non
svc.get.return_value.assigned_to = dev_id
c = Choreographer(_make_deps(task=svc))
env = await c.i_will_work_on(dev_id, task_id, plan="resume: keep going")
env = await c.i_will_work_on(
agent_id=dev_id, task_id=task_id, plan="resume: keep going"
)
body = env.as_dict()
assert body.get("error") is None, body
assert body.get("status") == "in_progress", body
@@ -95,7 +95,7 @@ async def test_heartbeat_fires_on_rejection_not_authorized() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
env = await c.i_will_work_on(aid, tid, plan="x")
env = await c.i_will_work_on(agent_id=aid, task_id=tid, plan="x")
assert env.error == "not_authorized"
task_svc.heartbeat.assert_awaited_with(tid)
+1 -1
View File
@@ -86,7 +86,7 @@ async def test_i_will_work_on_calls_heartbeat() -> None:
deps = _make_deps(task=task_svc)
c = Choreographer(deps)
await c.i_will_work_on(aid, tid, plan="go")
await c.i_will_work_on(agent_id=aid, task_id=tid, plan="go")
task_svc.heartbeat.assert_awaited_with(tid)
@@ -67,7 +67,12 @@ async def test_superseded_closes_pr_and_completes_without_merge(
)
env = await choreo._resolve_merge_conflict_on_complete(
uuid4(), uuid4(), t, "feature/frontend/root--cell", "notes", _EXC
pm_agent_id=uuid4(),
task_id=uuid4(),
t=t,
target="feature/frontend/root--cell",
notes="notes",
exc=_EXC,
)
git.close_pull_request.assert_awaited_once()
@@ -100,7 +105,12 @@ async def test_rebased_retries_merge_and_completes(
)
await choreo._resolve_merge_conflict_on_complete(
uuid4(), uuid4(), t, "feature/backend/root--cell", "notes", _EXC
pm_agent_id=uuid4(),
task_id=uuid4(),
t=t,
target="feature/backend/root--cell",
notes="notes",
exc=_EXC,
)
git.pr_merge.assert_awaited_once()
@@ -133,7 +143,12 @@ async def test_genuine_conflict_escalates_to_ceo_and_does_not_loop(
)
env = await choreo._resolve_merge_conflict_on_complete(
uuid4(), tid, t, "feature/backend/root--cell", "notes", _EXC
pm_agent_id=uuid4(),
task_id=tid,
t=t,
target="feature/backend/root--cell",
notes="notes",
exc=_EXC,
)
task.admin_set_status.assert_awaited_once()
@@ -171,7 +186,12 @@ async def test_diverged_rebase_outcome_escalates_rather_than_completing(
)
await choreo._resolve_merge_conflict_on_complete(
uuid4(), uuid4(), t, "feature/backend/root--cell", "notes", _EXC
pm_agent_id=uuid4(),
task_id=uuid4(),
t=t,
target="feature/backend/root--cell",
notes="notes",
exc=_EXC,
)
task.admin_set_status.assert_awaited_once()
@@ -198,7 +218,12 @@ async def test_unknown_rebase_outcome_escalates_rather_than_completing(
)
await choreo._resolve_merge_conflict_on_complete(
uuid4(), uuid4(), t, "feature/backend/root--cell", "notes", _EXC
pm_agent_id=uuid4(),
task_id=uuid4(),
t=t,
target="feature/backend/root--cell",
notes="notes",
exc=_EXC,
)
task.admin_set_status.assert_awaited_once()
@@ -148,8 +148,8 @@ async def test_i_will_work_on_calls_ensure_work_session() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,
@@ -290,8 +290,8 @@ async def test_ensure_work_session_not_called_when_start_fails() -> None:
c = Choreographer(deps)
env = await c.i_will_work_on(
agent_id,
task_id,
agent_id=agent_id,
task_id=task_id,
plan=_GOOD_PLAN,
steps=_STEPS,
technical_considerations=_GOOD_TC,