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
20 changes: 0 additions & 20 deletions loopx/control_plane/collaboration/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,26 +346,6 @@ function boundedReason(value: unknown, fallback: string): string {
return reason.length > 0 ? reason.slice(0, 4096) : fallback;
}

/** Preserve a rejected Turn plan as data before the host adapter reads its transaction. */
export function delegationTurnPlanDecision(params: JsonObject): JsonObject {
const plan = requireJsonObject(params.plan, "Turn plan");
if (plan.ok !== true) return {
schema_version: "loopx_delegation_turn_plan_decision_v0",
state: "rejected",
turn_key: null,
reason: boundedReason(plan.error ?? plan.reason, "Turn plan rejected without a reason"),
};
const transaction = requireJsonObject(plan.transaction, "Turn plan transaction");
requireThat(typeof transaction.turn_key === "string"
&& ENVELOPED_SHA256_PATTERN.test(transaction.turn_key), "Turn plan transaction requires a valid turn_key");
return {
schema_version: "loopx_delegation_turn_plan_decision_v0",
state: "planned",
turn_key: transaction.turn_key,
reason: null,
};
}

/** Preserve the host owner's public diagnosis, not its private configuration.
* Optional fields keep older host previews compatible; null means unprobed. */
export function delegationRuntimeFacts(executor: JsonObject): JsonObject {
Expand Down
8 changes: 0 additions & 8 deletions loopx/control_plane/coordination/local_authority_shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ export {
LOCAL_AUTHORITY_SHADOW_REQUEST_SCHEMA,
};

/** Compatibility tombstone for older clients: never open or mint a store. */
export async function recordLocalAuthorityShadow(_value: unknown): Promise<never> {
throw new EffectRuntimeRequestError(
"Post-commit observation is retired; configure runtime shadow and explicitly bootstrap its source lineage.",
"local_authority_shadow_retired",
);
}

export interface LocalAuthorityShadowDependencies {
openStore?: (directory: string, goalId: string) => AuthorityStore;
}
Expand Down
58 changes: 0 additions & 58 deletions loopx/control_plane/effect_runtime_handlers.ts

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions loopx/control_plane/governed_capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,3 @@ export function validateGovernedCapabilitySettlementCallback(input: {
}
return payload;
}

export function governedCapabilitySettlementStatus(
failure: unknown,
): "settlement_failed" | "committed" {
return failure === null ? "committed" : "settlement_failed";
}
34 changes: 0 additions & 34 deletions loopx/control_plane/work_items/task_lease_eligibility.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/** Owner eligibility is shared by acquisition, renewal, transfer and observation.
* It is not a lease grant: time, mode, proof, CAS and release remain with callers. */
import {EffectRuntimeRequestError} from "../effect_runtime_errors.ts";
import {requireJsonObject} from "../runtime_decode.ts";

export interface LeaseEligibilityTodo {
readonly status: string;
Expand Down Expand Up @@ -48,35 +46,3 @@ export function leaseOwnerConstraint(todo: LeaseEligibilityTodo | null | undefin
default: return {effective: false as const, reason};
}
}

function strings(value: unknown, label: string): string[] {
if (!Array.isArray(value) || value.some(item => typeof item !== "string")) {
throw new EffectRuntimeRequestError(`${label} must be an array of strings`);
}
return value as string[];
}

function nullableString(value: unknown, label: string): string | null {
if (value == null) return null;
if (typeof value !== "string") throw new EffectRuntimeRequestError(`${label} must be a string or null`);
return value;
}

/** A narrow adapter for the still-shipped Python coordination/inspection API.
* Inputs are normalized facts, not Markdown or a second authority snapshot. */
export function evaluateTaskLeaseOwnerEligibility(value: unknown) {
const input = requireJsonObject(value, "task lease owner eligibility");
const raw = input.todo == null ? null : requireJsonObject(input.todo, "todo");
let todo: LeaseEligibilityTodo | null = null;
if (raw !== null) {
if (typeof raw.status !== "string") throw new EffectRuntimeRequestError("todo.status must be a string");
todo = {status: raw.status, task_class: nullableString(raw.task_class, "todo.task_class"),
claimed_by: nullableString(raw.claimed_by, "todo.claimed_by"),
excluded_agents: strings(raw.excluded_agents, "todo.excluded_agents")};
}
const constraint = leaseOwnerConstraint(todo, nullableString(input.owner, "owner"),
strings(input.registered_agents, "registered_agents"));
return {schema_version: "task_lease_owner_eligibility_v0",
outcome: constraint.effective ? "apply" : "rejected",
code: constraint.effective ? "lease_owner_allowed" : constraint.reason, constraint};
}
15 changes: 1 addition & 14 deletions tests/control_plane_ts/delegation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from "node:test";
import assert from "node:assert/strict";
import {recordDelegationAdoption, decideDelegationStop, decideDelegationWakeObservation, delegationCheckedArtifacts, delegationInventoryItem, delegationInventoryQuery, delegationPreflight, delegationTurnPlanDecision, delegationTurnWorkContext, delegationValidationPlan, recoverValidatedDelegationSettlement, selectDelegationBinding, transitionDelegationObservation, verifyDelegationSourceReplay} from "../../loopx/control_plane/collaboration/delegation.ts";
import {recordDelegationAdoption, decideDelegationStop, decideDelegationWakeObservation, delegationCheckedArtifacts, delegationInventoryItem, delegationInventoryQuery, delegationPreflight, delegationTurnWorkContext, delegationValidationPlan, recoverValidatedDelegationSettlement, selectDelegationBinding, transitionDelegationObservation, verifyDelegationSourceReplay} from "../../loopx/control_plane/collaboration/delegation.ts";
import {canonicalAuthoritySha256} from "../../loopx/control_plane/coordination/authority_store_codec.ts";
import {projectTurnSelectionRejection} from "../../loopx/control_plane/turn_driver/selection_rejection.ts";

Expand Down Expand Up @@ -741,16 +741,3 @@ test("workspace faults are bounded observations, not authority or launch permits
assert.deepEqual(delegationPreflight({...unavailable, workspace: {state: "available"}}),
delegationPreflight(unavailable));
});

test("Turn plan decision preserves a rejection and validates a successful transaction", () => {
const rejected = delegationTurnPlanDecision({plan: {ok: false,
error: "Requested Turn Todo is not accepted by canonical authority"}});
assert.deepEqual(rejected, {
schema_version: "loopx_delegation_turn_plan_decision_v0", state: "rejected",
turn_key: null, reason: "Requested Turn Todo is not accepted by canonical authority",
});
const turnKey = `sha256:${"a".repeat(64)}`;
assert.equal(delegationTurnPlanDecision({plan: {ok: true,
transaction: {turn_key: turnKey}}}).turn_key, turnKey);
assert.throws(() => delegationTurnPlanDecision({plan: {ok: true, transaction: {}}}));
});
28 changes: 28 additions & 0 deletions tests/control_plane_ts/effect_runtime_handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,31 @@ test("preauthorized lease fence has no standalone runtime handler", async () =>
/unsupported Effect runtime method/,
);
});

for (const retired of [
"todo.field_update.plan",
"todo.public_update.plan",
"todo.claim.decide",
"todo.external_wait.plan",
"quota.automation_cadence.schedule",
"work_item.planning_horizon.project",
"work_item.planning_inventory.project",
"work_item.planning_inventory.detail",
"goal.vision_wait.coverage",
"task_lease.owner_eligibility",
"coordination.ownership_observation",
"coordination.local_authority.legacy_writer_fence.engage",
"scheduler.monitor_successor.plan",
"coordination.local_authority_shadow.record",
"coordination.runtime_shadow.commit_entry",
"governed_capability.validate_admission",
"governed_capability.settlement_status",
"collaboration.delegation.turn_plan",
"settlement.receipt_bound_terminal_phase",
]) {
test(`unused leaf RPC ${retired} fails closed`, async () => {
assert.equal(handlers.has(retired), false);
await assert.rejects(dispatchEffectRuntimeMethod(handlers, retired, {}),
{code: "unsupported_method"});
});
}
9 changes: 0 additions & 9 deletions tests/control_plane_ts/governed_capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import assert from "node:assert/strict";
import test from "node:test";

import {
governedCapabilitySettlementStatus,
validateGovernedCapabilityAdmission,
validateGovernedCapabilityResult,
validateGovernedCapabilitySettlementCallback,
Expand Down Expand Up @@ -435,14 +434,6 @@ test("writeback proves the effect receipt before settlement can spend", () => {
assert.equal(committed.ok, true);
});

test("settlement terminal state is TS-owned", () => {
assert.equal(governedCapabilitySettlementStatus(null), "committed");
assert.equal(
governedCapabilitySettlementStatus({ kind: "quota_spend_rejected" }),
"settlement_failed",
);
});

test("one lifecycle packet validates an observed provider result and projects its receipt", () => {
const journal = lifecycleJournal("starting", result("succeeded"));
const reduction = reduceLifecycle(journal, "observe_result");
Expand Down
11 changes: 6 additions & 5 deletions tests/control_plane_ts/local_authority_shadow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { mkdtemp, readdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { EffectRuntimeRequestError } from "../../loopx/control_plane/effect_runtime_errors.ts";
import {createEffectRuntimeHandlers, dispatchEffectRuntimeMethod} from "../../loopx/control_plane/effect_runtime_handlers.ts";
import { FileAuthorityStore } from "../../loopx/control_plane/coordination/file_authority_store.ts";
import {localAuthorityShadowHeadDigest, localAuthorityShadowPartitionDigest,
recordLocalAuthorityShadow, readLocalAuthorityShadow} from "../../loopx/control_plane/coordination/local_authority_shadow.ts";
readLocalAuthorityShadow} from "../../loopx/control_plane/coordination/local_authority_shadow.ts";

test("runtime shadow parity ignores only the resume evaluation observation clock", () => {
const head = {
Expand Down Expand Up @@ -62,11 +62,12 @@ test("runtime shadow parity ignores only the resume evaluation observation clock
test("retired record RPC rejects even a stale client without creating any storage", async t => {
const root = await mkdtemp(join(tmpdir(), "loopx-retired-observer-"));
t.after(() => rm(root, {recursive: true, force: true}));
for (const request of [null, {}, {schema_version: "loopx_local_authority_shadow_request_v0",
const handlers = createEffectRuntimeHandlers({fingerprint: "test", requestShutdown: () => undefined});
for (const request of [{}, {schema_version: "loopx_local_authority_shadow_request_v0",
mode: "file_one_way", runtime_root: root, goal_id: "goal-a", observation_id: "old-op",
source_digest: `sha256:${"a".repeat(64)}`, observation_trigger: "todo_update", source_projection: {}}]) {
await assert.rejects(recordLocalAuthorityShadow(request), error =>
error instanceof EffectRuntimeRequestError && error.code === "local_authority_shadow_retired");
await assert.rejects(dispatchEffectRuntimeMethod(handlers, "coordination.local_authority_shadow.record", request),
{code: "unsupported_method"});
}
assert.deepEqual(await readdir(root), []);
});
Expand Down
19 changes: 7 additions & 12 deletions tests/control_plane_ts/task_lease_eligibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import {evaluateTaskLeaseAcquireDecision} from "../../loopx/control_plane/work_items/task_lease_acquire_decision.ts";
import {decideTaskLeaseLifecycle, evaluateTaskLeaseLifecycleDecision} from "../../loopx/control_plane/work_items/task_lease_lifecycle_decision.ts";
import {evaluateTaskLeaseOwnerEligibility, leaseOwnerRejection, type LeaseEligibilityTodo} from
import {leaseOwnerConstraint, leaseOwnerRejection, type LeaseEligibilityTodo} from
"../../loopx/control_plane/work_items/task_lease_eligibility.ts";
import {productionScaleCoordinationFixture} from "./production_scale_coordination_fixture.ts";

Expand Down Expand Up @@ -45,8 +45,7 @@ test("release remains a fenced cleanup operation after owner eligibility is lost
test("User actions cannot acquire, renew or transfer execution but retained leases can be released", () => {
const action = {...todo, task_class: "user_action", bound_agent: "agent-a"};
for (const owner of ["agent-a", "agent-b"]) {
assert.equal(evaluateTaskLeaseOwnerEligibility({todo: action, owner,
registered_agents: ["agent-a", "agent-b"]}).code, "todo_not_executable");
assert.equal(leaseOwnerRejection(action, owner, ["agent-a", "agent-b"]), "todo_not_executable");
assert.equal(evaluateTaskLeaseAcquireDecision({...acquire(false), todo: action,
command: {...acquire(false).command, owner}}).code, "todo_not_executable");
}
Expand All @@ -73,8 +72,9 @@ test("owner eligibility has one precedence across adapters and renewal", () => {
];
for (const row of cases) {
assert.equal(leaseOwnerRejection(row.todo, row.owner, row.agents), row.reason);
const adapted = evaluateTaskLeaseOwnerEligibility({todo: row.todo, owner: row.owner, registered_agents: row.agents});
assert.equal(adapted.code, row.reason ?? "lease_owner_allowed");
const constraint = leaseOwnerConstraint(row.todo, row.owner, row.agents);
assert.equal(constraint.effective, row.reason === null);
if (!constraint.effective) assert.equal(constraint.reason, row.reason);
if (!row.owner) continue;
const renewed = decideTaskLeaseLifecycle({handoff_mode: "hard_lease", registered_agents: row.agents,
todo: row.todo && {...row.todo, todo_id: "todo_target"}, lease,
Expand All @@ -101,14 +101,9 @@ test("production-scale history preserves independent claim, exclusion and termin
}
});

test("eligibility decoder rejects malformed facts and does not infer authorisation from prose", () => {
for (const patch of [{registered_agents: "agent-a"}, {owner: 1},
{todo: {...todo, status: true}}, {todo: {...todo, excluded_agents: "agent-a"}}]) {
assert.throws(() => evaluateTaskLeaseOwnerEligibility({todo, owner: "agent-a", registered_agents: ["agent-a"], ...patch}));
}
test("owner eligibility does not infer authorisation from prose", () => {
const described = {...todo, text: "approved owner agent-a; safe to proceed", claimed_by: "agent-b"};
assert.equal(evaluateTaskLeaseOwnerEligibility({todo: described, owner: "agent-a", registered_agents: ["agent-a"]}).code,
"owner_conflicts_with_claim");
assert.equal(leaseOwnerRejection(described, "agent-a", ["agent-a"]), "owner_conflicts_with_claim");
});

for (const generation of ["version", "lease_epoch"] as const) {
Expand Down
Loading