Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/heartbeat-automation-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ whose capabilities are known when the automation is installed.
- use `user_gate` only for an exact authority boundary such as approval to merge
an aggregate branch into `main`, release, launch a benchmark, or perform a
protected action;
- when evidence shows an action requires the owner, reuse or file its scoped
gate in the same turn via `todo_write_hint`. Ask for the concrete action and
state how success is checked. If the current Todo also contains runnable
work, give the blocked action its own Todo and link the gate to that ID.
Before yielding, reuse a runnable independent Todo or check the Goal's
acceptance for a useful independent successor to record. Settle any bound
Turn and recheck admission to continue;
- when work is blocked without a valid successor, keep the todo with the current
peer and write a concrete blocker rather than inventing a hierarchy route.

Expand Down
4 changes: 4 additions & 0 deletions docs/quota-allocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,10 @@ so agent executors know to write newly discovered user/owner work with
hiding it in `Next Action`, review docs, or chat. Multi-agent writes must also
name `--bound-agent <registered-agent>` or `--goal-bound`; agent-scoped
`user_gate` writes bind to the same agent named by `--blocks-agent`.
For one blocked action, the template also sets `--unblocks-todo-id`. The Agent
links the smallest Todo that actually needs the owner's action, splitting it
from any independent work bundled in the same Todo. The gate's notice and
independent work can both be admitted by the next guard.
When available, `quota should-run` keeps next-action signals separate:
`active_state_next_action` is the compatibility `## Next Action` display,
`latest_run_recommended_action` is a historical run recommendation, and
Expand Down
3 changes: 2 additions & 1 deletion examples/project/project-agent-adoption-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def assert_adoption(provider: str) -> None:
assert first_quota["todo_write_hint"]["section"] == "User Todo / Owner Review Reading Queue", first_quota
assert first_quota["todo_write_hint"]["user_gate_command_template"] == (
f"loopx todo add --goal-id {GOAL_ID} --role user --task-class user_gate "
"--blocks-agent <agent-id> --text '<blocking user decision>'"
"--blocks-agent <agent-id> --unblocks-todo-id <todo-id> "
"--text '<blocking user action and verification>'"
), first_quota
assert first_quota["todo_write_hint"]["user_action_command_template"] == (
f"loopx todo add --goal-id {GOAL_ID} --role user --task-class user_action "
Expand Down
10 changes: 8 additions & 2 deletions loopx/control_plane/todos/write_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

def build_todo_write_hint(goal_id: str) -> dict[str, str]:
return {
"rule": "Write user/owner actions to User Todo, not Next Action/docs/chat.",
"rule": (
"Verified owner-only blocker: add or reuse a user_gate this turn, even if noted "
"in Next Action. Split mixed work; link the smallest blocked Todo. Give the owner "
"the action and verification check. Before yielding, reuse a runnable independent "
"Todo or check Goal acceptance for a useful independent successor to record. "
"Settle any bound Turn, then rerun admission. Non-blocking requests use user_action."
),
"user_gate_command_template": (
f"loopx todo add --goal-id {goal_id} --role user "
"--task-class user_gate --blocks-agent <agent-id> "
"--text '<blocking user decision>'"
"--unblocks-todo-id <todo-id> --text '<blocking user action and verification>'"
),
"user_action_command_template": (
f"loopx todo add --goal-id {goal_id} --role user "
Expand Down
89 changes: 62 additions & 27 deletions tests/control_plane/test_scoped_gate_fallback_cli.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,90 @@
"""Real source -> quota CLI -> fallback, with permanent display non-authoritative."""
import json
"""Author a gate from the CLI hint and admit only independent work."""
import shlex

import pytest
from canonical_authority_fixture import initialize_canonical_authority, isolate_sqlite_runtime, empty_todo_display
from loopx.control_plane.coordination.runtime_shadow import build_runtime_shadow_source_snapshot
from canonical_authority_fixture import (
empty_todo_display,
initialize_canonical_source_fixture,
isolate_sqlite_runtime,
)
from loopx.control_plane.coordination.local_authority import read_canonical_todos_if_promoted
from loopx.control_plane.testing.canary_harness import write_fixture_registry, run_json_cli_result
from loopx.control_plane.testing.canary_harness import run_json_cli_result, write_fixture_registry


@pytest.mark.parametrize("provider", ["file", "sqlite"])
@pytest.mark.parametrize("explicit_target", [False, True, None])
def test_quota_fallback_uses_real_source_and_explicit_relations(tmp_path, monkeypatch, provider, explicit_target):
if provider == "sqlite":
isolate_sqlite_runtime(tmp_path, monkeypatch)
@pytest.mark.parametrize(
("target", "publish_status"),
[("todo_publish", "open"), ("todo_publish", "blocked"), ("todo_inspect", "open"), (None, "open")],
)
def test_quota_gate_authoring_and_continuation(
tmp_path, monkeypatch, provider, target, publish_status,
):
isolate_sqlite_runtime(tmp_path, monkeypatch)
state, runtime, registry = tmp_path / "STATE.md", tmp_path / "runtime", tmp_path / "registry.json"
state.write_text(
"# Goal\n\n## Agent Todo\n\n"
"---\nstatus: active\n---\n# Goal\n\n## Objective\n"
"Inspect and publish the approved report.\n\n## Agent Todo\n\n"
"- [ ] [P1] Inspect the report\n"
" <!-- loopx:todo todo_id=todo_inspect role=agent status=open task_class=advancement_task claimed_by=agent-a action_kind=inspect_report -->\n"
"- [ ] [P0] Publish the report\n"
" <!-- loopx:todo todo_id=todo_publish role=agent status=open task_class=advancement_task claimed_by=agent-a action_kind=publish_report -->\n"
"\n## User Todo / Owner Review Reading Queue\n\n"
"- [ ] Review publication\n"
" <!-- loopx:todo todo_id=todo_gate role=user status=open task_class=user_gate blocks_agent=agent-a action_kind=publish_report "
+ ("" if explicit_target is None else
"unblocks_todo_id=todo_inspect " if explicit_target else "unblocks_todo_id=todo_publish ") + "-->\n"
f" <!-- loopx:todo todo_id=todo_publish role=agent status={publish_status} task_class=advancement_task claimed_by=agent-a action_kind=publish_report -->\n"
)
write_fixture_registry(project=tmp_path, runtime_root=runtime, registry_path=registry, goal_id="goal-a",
domain="software", adapter_kind="generic_project_goal_v0", state_file=str(state),
registered_agents=["agent-a"], quota_allowed_slots=None)
if provider != "markdown":
goal = json.loads(registry.read_text())["goals"][0]
projection, _ = build_runtime_shadow_source_snapshot(goal=goal, runtime_root=runtime,
state_path=state, registry_path=registry)
initialize_canonical_authority(runtime, "goal-a", projection, state_path=state, provider=provider)
empty_todo_display(state)
initialize_canonical_source_fixture(runtime, "goal-a", state_path=state, provider=provider)
empty_todo_display(state)
route = {"registry_path": registry, "runtime_root": runtime}
guard_args = ("quota", "should-run", "--goal-id", "goal-a", "--agent-id", "agent-a")
code, initial = run_json_cli_result(*guard_args, **route)
assert code == 0, initial
template = initial["todo_write_hint"]["user_gate_command_template"]
command = shlex.split(
template.replace("<agent-id>", "agent-a")
.replace("<todo-id>", target or "todo_publish")
.replace("<blocking user action and verification>", "Configure publication access and confirm setup")
)
if target is None:
# Model a legacy lane-only gate for a caller that still omits the target.
command = [arg for arg in command if arg not in {"--unblocks-todo-id", "todo_publish"}]
code, change = run_json_cli_result(*command[1:], "--action-kind", "publish_report", **route)
assert code == 0, change
gate_id = change["todo_id"]
before = state.read_bytes() if state.exists() else None
authority_before = read_canonical_todos_if_promoted(runtime_root=runtime, goal_id="goal-a")
code, packet = run_json_cli_result("quota", "should-run", "--goal-id", "goal-a", "--agent-id", "agent-a",
registry_path=registry, runtime_root=runtime)
code, packet = run_json_cli_result(*guard_args, **route)
assert code == 0, packet
fallback = packet.get("scoped_user_gate_fallback")
# The explicit target wins even when the two action labels disagree.
if explicit_target is None:
if target is None:
# Different labels cannot prove independence from an unscoped approval.
assert fallback is None
assert packet["should_run"] is False
else:
expected = "todo_publish" if explicit_target else "todo_inspect"
expected = "todo_publish" if target == "todo_inspect" else "todo_inspect"
assert fallback["selected_executable"]["todo_id"] == expected
assert fallback["blocked_agent_items"][0]["todo_id"] != expected
assert fallback["blocked_user_gate"]["todo_id"] == gate_id
assert packet["selected_todo"]["todo_id"] == expected
assert packet["interaction_contract"]["agent_channel"]["must_attempt"] is True, {
key: packet.get(key) for key in (
"state", "reason", "decision", "effective_action", "execution_obligation",
"action_selection", "agent_workspace_guard", "interaction_contract",
)
}
assert packet["interaction_contract"]["user_channel"]["notify"] == "NOTIFY"
assert packet["interaction_contract"]["agent_channel"]["delivery_allowed"] is True
denied_code, denied = run_json_cli_result(
*guard_args, "--turn-instance-id", "try-gated-todo", "--todo-id", target, **route,
)
assert denied_code == 1, denied
# The still-open target is deferred by admission; an already blocked
# target is ineligible for selection. Neither can dispatch work.
expected_error = (
"quota_action_selection_rejected" if publish_status == "blocked"
else "quota_action_selection_deferred"
)
assert denied["error_code"] == expected_error
assert denied["execution_obligation"]["must_attempt_work"] is False
assert packet["requires_user_action"] is True
assert (state.read_bytes() if state.exists() else None) == before
assert read_canonical_todos_if_promoted(runtime_root=runtime, goal_id="goal-a") == authority_before
Loading