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
52 changes: 48 additions & 4 deletions loopx/control_plane/goals/acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
from ...agent_registry import load_goal_from_registry, registered_agent_ids_for_goal
from ..coordination.local_authority import local_authority_is_promoted
from ..coordination.local_authority_shadow_adapter import effective_runtime_root
from ..effect_runtime import effect_runtime_result
from ..effect_runtime import (
CANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS,
effect_runtime_result,
)
from ..todos.completion_validation import (
_resolve_completion_validation_workspace,
run_declared_completion_validation_effect,
)
from .goal_ref_validation import exact_goal_ref


_INSPECT_METHOD = "goal.acceptance.inspect"
Expand All @@ -41,11 +45,27 @@ def _routing(
raise ValueError(
"Goal acceptance requires an existing canonical authority; activation never promotes a provider"
)
return {"runtime_root": str(root.resolve()), "goal_id": goal_id}
route: dict[str, Any] = {
"runtime_root": str(root.resolve()),
"goal_id": goal_id,
}
goal_instance_id = goal.get("goal_instance_id")
if goal_instance_id is not None:
route["goal_ref"] = exact_goal_ref(goal_id, goal_instance_id)
return route


def _result(method: str, request: Mapping[str, Any]) -> dict[str, Any]:
value = effect_runtime_result(method, dict(request))
def _result(
method: str,
request: Mapping[str, Any],
*,
timeout: float | None = None,
) -> dict[str, Any]:
value = effect_runtime_result(
method,
dict(request),
**({"timeout": timeout} if timeout is not None else {}),
)
if not isinstance(value, dict):
raise TypeError("Goal acceptance authority returned an invalid result")
if value.get("status") not in {
Expand All @@ -66,6 +86,30 @@ def _result(method: str, request: Mapping[str, Any]) -> dict[str, Any]:
return value


def transition_goal_acceptance_lifecycle(
*,
runtime_root: Path,
goal_id: str,
transition: Mapping[str, Any],
operation_id: str,
) -> dict[str, Any] | None:
"""Commit one source-owned acceptance lifecycle transition if promoted."""
root = runtime_root.resolve()
if not local_authority_is_promoted(runtime_root=root, goal_id=goal_id):
return None
return _result(
"goal.acceptance.lifecycle.transition",
{
"runtime_root": str(root.resolve()),
"goal_id": goal_id,
"actor_agent_id": None,
"operation_id": operation_id,
"transition": dict(transition),
},
timeout=CANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS,
)


def inspect_goal_acceptance(
*,
registry_path: Path,
Expand Down
18 changes: 18 additions & 0 deletions loopx/control_plane/goals/acceptance_authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ function planLifecycleTransition(
reason: "A retiring Goal instance cannot be rebound as active."};
}
if (current === null) {
if (transition.kind === "reconcile_recreated") {
const acceptance = readGoalAcceptance(head, goalId);
return {
kind: "commit",
lifecycle: {
schema_version: GOAL_ACCEPTANCE_LIFECYCLE_SCHEMA,
state: "active",
goal_ref: transition.goal_ref,
},
acceptance: acceptance === null
? null
: bindGoalAcceptanceStateOwner(acceptance, transition.retired_goal_ref),
};
}
return {kind: "failure", reason_code: "goal_acceptance_lifecycle_unbound",
reason: "Bind the existing Goal instance before changing its acceptance lifecycle."};
}
Expand All @@ -323,6 +337,10 @@ function planLifecycleTransition(
: {kind: "commit", lifecycle: {...current, state: "retiring"},
acceptance: readGoalAcceptance(head, goalId)};
}
if (transition.kind === "reconcile_recreated"
&& sameExactGoalRef(current.goal_ref, transition.goal_ref)) {
return {kind: "no_change", lifecycle: current};
}
if (current.state !== "retiring"
|| !sameExactGoalRef(current.goal_ref, transition.retired_goal_ref)) {
return lifecycleMismatch("Goal acceptance successor activation requires its exact retiring predecessor.");
Expand Down
6 changes: 3 additions & 3 deletions loopx/control_plane/goals/acceptance_lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type GoalAcceptanceLifecycleTransition =
| Readonly<{kind: "bind_existing"; goal_ref: WireExactGoalRef}>
| Readonly<{kind: "retire"; goal_ref: WireExactGoalRef}>
| Readonly<{
kind: "activate_successor";
kind: "activate_successor" | "reconcile_recreated";
retired_goal_ref: WireExactGoalRef;
goal_ref: WireExactGoalRef;
}>;
Expand Down Expand Up @@ -72,7 +72,7 @@ export function parseGoalAcceptanceLifecycleTransition(value: unknown): GoalAcce
"goal acceptance lifecycle transition fields are missing or unsupported");
return {kind: raw.kind, goal_ref: parseWireExactGoalRef(raw.goal_ref, "transition goal_ref")};
}
requireLifecycle(raw.kind === "activate_successor",
requireLifecycle(raw.kind === "activate_successor" || raw.kind === "reconcile_recreated",
"unsupported goal acceptance lifecycle transition");
requireLifecycle(Object.keys(raw).length === 3
&& Object.hasOwn(raw, "retired_goal_ref") && Object.hasOwn(raw, "goal_ref"),
Expand All @@ -83,5 +83,5 @@ export function parseGoalAcceptanceLifecycleTransition(value: unknown): GoalAcce
"goal acceptance successor must preserve the Goal alias");
requireLifecycle(!sameExactGoalRef(retiredGoalRef, goalRef),
"goal acceptance successor must use a new Goal instance");
return {kind: "activate_successor", retired_goal_ref: retiredGoalRef, goal_ref: goalRef};
return {kind: raw.kind, retired_goal_ref: retiredGoalRef, goal_ref: goalRef};
}
Loading
Loading