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
2 changes: 1 addition & 1 deletion examples/control_plane/todo-durability-fixture-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def assert_parseable_agent_todos(agent_todos: dict, *, hot_path: bool = False) -
if hot_path:
assert "first_open_items" not in agent_todos, agent_todos
assert agent_todos["payload_compaction"]["schema_version"] == (
"quota_cli_todo_summary_compaction_v0"
"quota_todo_summary_payload_compaction_v0"
), agent_todos
return

Expand Down
5 changes: 4 additions & 1 deletion examples/explore-result-layer-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def check_result_log_contract() -> dict[str, object]:

mermaid = projection["mermaid"]
assert mermaid.startswith("flowchart TD"), mermaid
assert "node_kcg" in mermaid and ":::blocked" in mermaid, mermaid
assert (
result_log.explore_mermaid_node_id("node_kcg") in mermaid
and ":::blocked" in mermaid
), mermaid
assert "-->|subtopic_of|" in mermaid, mermaid

focused = result_log.build_explore_graph_view(
Expand Down
81 changes: 72 additions & 9 deletions examples/issue-fix-validated-memory-writeback-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,55 @@
)


def _resolve_recovery_ref(repo_root: Path) -> str | None:
symbolic = subprocess.run(
["git", "symbolic-ref", "--quiet", "HEAD"],
cwd=repo_root,
text=True,
stdout=subprocess.PIPE,
check=False,
).stdout.strip()
if symbolic:
return symbolic
candidates = subprocess.run(
[
"git",
"for-each-ref",
"--points-at",
"HEAD",
"--format=%(refname)",
"refs/heads",
"refs/remotes",
"refs/tags",
],
cwd=repo_root,
text=True,
stdout=subprocess.PIPE,
check=False,
).stdout.splitlines()
valid = [
ref.strip()
for ref in candidates
if ref.strip() and 4 <= len(ref.strip()) <= 80
]
for preferred in ("refs/remotes/origin/main", "refs/heads/main"):
if preferred in valid:
return preferred
for prefix in ("refs/heads/", "refs/remotes/", "refs/tags/"):
for ref in valid:
if ref.startswith(prefix):
return ref
return None


REVISION = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.strip()
RECOVERY_REF = subprocess.run(
["git", "symbolic-ref", "--quiet", "HEAD"],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
check=False,
).stdout.strip() or "refs/remotes/origin/main"
RECOVERY_REF = _resolve_recovery_ref(ROOT)
OBSERVED_AT = "2026-07-11T08:40:00+08:00"


Expand Down Expand Up @@ -700,6 +735,34 @@ def main() -> int:
),
encoding="utf-8",
)
repo_path = ROOT
recovery_ref = RECOVERY_REF
if recovery_ref is None:
# Detached HEAD with no matching ref: bind an isolated local ref without mutating ROOT.
repo_path = tmp / "detached-recovery-repo"
subprocess.run(
["git", "clone", "--quiet", "--shared", "--no-checkout", str(ROOT), str(repo_path)],
check=True,
)
remotes = subprocess.run(
["git", "remote"],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.splitlines()
for name in [item.strip() for item in remotes if item.strip()]:
url = subprocess.run(
["git", "remote", "get-url", name],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.strip()
action = "set-url" if name == "origin" else "add"
subprocess.run(["git", "remote", action, name, url], cwd=repo_path, check=True)
recovery_ref = "refs/heads/smoke-recovery"
subprocess.run(["git", "update-ref", recovery_ref, REVISION], cwd=repo_path, check=True)
command = [
sys.executable,
"-m",
Expand All @@ -724,9 +787,9 @@ def main() -> int:
str(config_path),
"--write-repository-memory",
"--repo-path",
str(ROOT),
str(repo_path),
"--repository-ref",
RECOVERY_REF,
recovery_ref,
"--generated-at",
OBSERVED_AT,
]
Expand Down
2 changes: 2 additions & 0 deletions loopx/cli_commands/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def _prepare_quota_result_context(
*,
registry_path: Path,
heartbeat_turn_id: str | None,
attach_recall: bool = True,
) -> tuple[dict[str, object], dict[str, Any]]:
from .quota_result_delivery import prepare_quota_result_context

Expand All @@ -267,6 +268,7 @@ def _prepare_quota_result_context(
args,
registry_path=registry_path,
heartbeat_turn_id=heartbeat_turn_id,
attach_recall=attach_recall,
)


Expand Down
34 changes: 20 additions & 14 deletions loopx/cli_commands/quota_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ class QuotaCommandContext:
def _scheduler_execution_context_from_args(
args: argparse.Namespace,
) -> Mapping[str, object] | SchedulerExecutionContextResolution | None:
host_surface = getattr(args, "host_surface", None)
scheduler_owner = getattr(args, "scheduler_owner", None)
execution_mode = getattr(args, "execution_mode", None)
runtime_profile = getattr(args, "runtime_profile", None)
explicit_scheduler_fields = (
args.host_surface,
args.scheduler_owner,
args.execution_mode,
host_surface,
scheduler_owner,
execution_mode,
)
codex_app = bool(getattr(args, "codex_app", False))
trae_app = bool(getattr(args, "trae_app", False))
Expand All @@ -81,32 +85,34 @@ def _scheduler_execution_context_from_args(
raise QuotaCommandValidationError(
"--codex-app, --trae_app, and --antigravity_app are mutually exclusive"
)
if app_alias_count and (args.runtime_profile or any(explicit_scheduler_fields)):
if app_alias_count and (runtime_profile or any(explicit_scheduler_fields)):
raise QuotaCommandValidationError(
"app runtime aliases cannot be combined with --runtime-profile, "
"--host-surface, --scheduler-owner, or --execution-mode"
)
if args.runtime_profile and any(explicit_scheduler_fields):
if runtime_profile and any(explicit_scheduler_fields):
raise QuotaCommandValidationError(
"--runtime-profile cannot be combined with --host-surface, "
"--scheduler-owner, or --execution-mode"
)
runtime_profile = (
effective_runtime_profile = (
SchedulerRuntimeProfile.CODEX_APP_HEARTBEAT.value
if codex_app
else SchedulerRuntimeProfile.TRAE_APP.value
if trae_app
else SchedulerRuntimeProfile.ANTIGRAVITY_APP.value
if antigravity_app
else args.runtime_profile
else runtime_profile
)
if runtime_profile:
return scheduler_execution_context_for_runtime_profile(runtime_profile)
if effective_runtime_profile:
return scheduler_execution_context_for_runtime_profile(
effective_runtime_profile
)
if any(explicit_scheduler_fields):
return {
"host_surface": args.host_surface,
"scheduler_owner": args.scheduler_owner,
"execution_mode": args.execution_mode,
"host_surface": host_surface,
"scheduler_owner": scheduler_owner,
"execution_mode": execution_mode,
"source": "quota_cli_invocation",
}
return None
Expand Down Expand Up @@ -180,7 +186,7 @@ def validate_quota_command_context_request(
raise QuotaCommandValidationError(
"--replan-obligation-id cannot be combined with --todo-id"
)
if heartbeat_turn_id and not args.agent_id:
if heartbeat_turn_id and not getattr(args, "agent_id", None):
raise QuotaCommandValidationError(
"turn-scoped quota settlement requires --agent-id"
)
Expand Down Expand Up @@ -266,7 +272,7 @@ def validate_quota_command_context_request(
if (
(heartbeat_turn_id or begin_turn)
and command == "should-run"
and bool(args.dry_run)
and bool(getattr(args, "dry_run", False))
):
raise QuotaCommandValidationError(
"turn-scoped `quota should-run` cannot use --dry-run"
Expand Down
35 changes: 27 additions & 8 deletions loopx/cli_commands/quota_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,40 @@
from ..control_plane.scheduler.execution_context import SchedulerExecutionContextResolution


UNDECLARED_JSON_COMPLETE_TURN_OPTIONS = (
"complete_turn",
"turn_envelope",
"codex_context_dir",
"codex_context_root",
"prepared_capture_reference",
"defer_context_presentation",
"decision_handoff_socket",
)


def is_undeclared_json_quota_caller(
args: argparse.Namespace,
scheduler_context: Mapping[str, object] | SchedulerExecutionContextResolution | None,
) -> bool:
"""Return True when a JSON caller uses the currently qualified public quota packet."""
return (
getattr(args, "format", None) == "json"
and scheduler_context is None
and not any(
getattr(args, option, None)
for option in UNDECLARED_JSON_COMPLETE_TURN_OPTIONS
)
)


def compose_quota_work_contract(payload: dict[str, object], args: argparse.Namespace, *,
scheduler_context: Mapping[str, object] | SchedulerExecutionContextResolution | None,
capture_directory: Path | None,
record_capture: Callable[[dict[str, object], str], None] | None = None) -> dict[str, object]:
"""Compose Complete Turn sources before capture and display."""
if args.quota_command != "should-run" or not isinstance(payload.get("interaction_contract"), Mapping):
return payload
if (
args.format == "json"
and scheduler_context is None
and not any(getattr(args, option, None) for option in (
"complete_turn", "turn_envelope", "codex_context_dir", "codex_context_root",
"prepared_capture_reference", "defer_context_presentation", "decision_handoff_socket",
))
):
if is_undeclared_json_quota_caller(args, scheduler_context):
# Undeclared JSON callers use the currently qualified public quota packet.
return payload
from ..control_plane.effect_runtime import EffectRuntimeRemoteError, EffectRuntimeStartupError
Expand Down
32 changes: 20 additions & 12 deletions loopx/cli_commands/quota_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def register_quota_monitor_poll_request_arguments(
def validate_quota_command_request(args: argparse.Namespace) -> None:
command = args.quota_command
if getattr(args, "material_change_scope", None) and (
command != "monitor-poll" or not args.material_change
command != "monitor-poll" or not bool(getattr(args, "material_change", False))
):
raise QuotaCommandValidationError(
"--material-change-scope requires quota monitor-poll --material-change"
Expand All @@ -139,9 +139,13 @@ def validate_quota_command_request(args: argparse.Namespace) -> None:
lease_version = getattr(args, "task_lease_expected_version", None)
use_current_lease = bool(getattr(args, "use_current_task_lease", False))
if use_current_lease:
if command != "monitor-poll" or not args.execute:
if command != "monitor-poll" or not bool(getattr(args, "execute", False)):
raise QuotaCommandValidationError("--use-current-task-lease requires executing quota monitor-poll")
if not args.todo_id or not args.turn_instance_id or not args.agent_id:
if (
not getattr(args, "todo_id", None)
or not getattr(args, "turn_instance_id", None)
or not getattr(args, "agent_id", None)
):
raise QuotaCommandValidationError(
"--use-current-task-lease requires --todo-id, --turn-instance-id, and --agent-id"
)
Expand All @@ -154,14 +158,14 @@ def validate_quota_command_request(args: argparse.Namespace) -> None:
raise QuotaCommandValidationError("task lease proof is only valid with quota monitor-poll")
if not lease_key or lease_version is None or lease_version < 1 or lease_version > 9007199254740991:
raise QuotaCommandValidationError("Monitor lease proof requires an execution key and positive safe-integer version")
if not (args.todo_id or args.target_key):
if not (getattr(args, "todo_id", None) or getattr(args, "target_key", None)):
raise QuotaCommandValidationError("Monitor lease proof requires --todo-id or --target-key")
if getattr(args, "delivery_workspace_path", None) is not None and command != "spend-slot":
raise QuotaCommandValidationError(
"--delivery-workspace-path is only valid with `loopx quota spend-slot`"
)
begin_turn = bool(getattr(args, "begin_turn", False))
if command not in {"status", "plan"} and not args.goal_id:
if command not in {"status", "plan"} and not getattr(args, "goal_id", None):
raise QuotaCommandValidationError(
f"`loopx quota {command}` requires --goal-id"
)
Expand All @@ -170,34 +174,38 @@ def validate_quota_command_request(args: argparse.Namespace) -> None:
"scheduler-ack-current",
"scheduler-fail-current",
}
if command in scheduler_commands and not args.agent_id:
if command in scheduler_commands and not getattr(args, "agent_id", None):
raise QuotaCommandValidationError(
f"`loopx quota {command}` requires --agent-id"
)
if command == "void-slot" and not args.void_generated_at:
if command == "void-slot" and not getattr(args, "void_generated_at", None):
raise QuotaCommandValidationError(
"`loopx quota void-slot` requires --void-generated-at"
)
if command == "should-run" and args.todo_id and not (args.turn_instance_id or begin_turn):
if (
command == "should-run"
and getattr(args, "todo_id", None)
and not (getattr(args, "turn_instance_id", None) or begin_turn)
):
raise QuotaCommandValidationError(
"`loopx quota should-run --todo-id` requires --turn-instance-id or --begin-turn"
)
if begin_turn and command != "should-run":
raise QuotaCommandValidationError(
"--begin-turn is only valid with `loopx quota should-run`"
)
if begin_turn and args.turn_instance_id:
if begin_turn and getattr(args, "turn_instance_id", None):
raise QuotaCommandValidationError(
"--begin-turn cannot be combined with --turn-instance-id"
)
if begin_turn and not args.agent_id:
if begin_turn and not getattr(args, "agent_id", None):
raise QuotaCommandValidationError(
"--begin-turn requires exact --agent-id identity"
)
if (
command not in {"status", "plan", "should-run"}
and args.dry_run
and args.execute
and bool(getattr(args, "dry_run", False))
and bool(getattr(args, "execute", False))
):
raise QuotaCommandValidationError(
f"`loopx quota {command}` accepts only one of --dry-run or --execute"
Expand Down
Loading
Loading