plexus.cli.procedure.continuation_service module

Continuation service for procedure continuation and branching.

Provides high-level helpers used by both the CLI commands and MCP tools:

prepare_continuation(client, procedure_id, additional_cycles, hint)

Updates YAML params and clears checkpoints so the optimizer resumes from where it left off when re-dispatched.

prepare_branch(client, source_id, cycle, additional_cycles, hint, name)

Creates a new Procedure record with cloned state truncated to cycle N, ready to run from cycle N+1.

Neither function dispatches the procedure run — callers are responsible for invoking ProcedureService.run_procedure or run_procedure_with_task_tracking after calling these functions.

plexus.cli.procedure.continuation_service.build_continuation_context(client, procedure_id: str, *, max_iterations: int, hint: str | None = None) Dict[str, Any]

Reconstruct optimizer context for continue/branch redispatches.

Continuation runs do not get the original CLI context automatically. Recover it from the best available sources, in increasing confidence order:

  1. procedure YAML resolved params

  2. existing task metadata.run_parameters

  3. recent baseline evaluation parameters

  4. preserved optimizer State / procedure identifiers

plexus.cli.procedure.continuation_service.prepare_branch(client, source_id: str, cycle: int, additional_cycles: int = 3, hint: str | None = None, name: str | None = None, target_accuracy: float | None = None) Dict[str, Any]

Create a new procedure branched from source_id after cycle N.

Steps: 1. Load source procedure YAML + accountId 2. Update YAML params: max_iterations = cycle + additional_cycles, hint 3. Create new Procedure record via GraphQL 4. Clone State from source to new procedure, truncated to cycle N

(new procedure gets empty checkpoints → optimizer starts fresh from cycle N+1)

Returns dict with:

source_id, target_id, cycle, additional_cycles, new_max_iterations, target_name, hint_applied (bool)

plexus.cli.procedure.continuation_service.prepare_continuation(client, procedure_id: str, additional_cycles: int = 3, hint: str | None = None, target_accuracy: float | None = None) Dict[str, Any]

Prepare a completed procedure for continuation.

Steps: 1. Load current YAML (from DynamoDB code field or S3 via ProcedureService) 2. Count completed cycles from S3 State 3. Update params.max_iterations.value = completed + additional_cycles 4. Optionally update params.hint.value and params.target_accuracy.value 5. Save updated YAML back to procedure.code via GraphQL 6. Clear checkpoints only (preserve State) via reset_checkpoints_only

Returns dict with:

procedure_id, completed_cycles, additional_cycles, new_max_iterations, hint_applied (bool)