Skip to content

API Reference parrot.sdd.scripts.finalize_task

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.sdd.scripts.finalize_task

View source

Finalize a verified task deterministically without committing or pushing.

Spec sdd/specs/sdd-execution-optimization.spec.md (FEAT-584), module M4 (R4 "Cierre de tarea mecánico"). Replaces the multi-step Edit/Write/jq/mv dance a worker performs to close a task with one verifiable call:

  1. Validate identity/evidence/HEAD (never mutates on a stale or incomplete input) and reject a divergent active/completed twin before doing anything destructive.
  2. Render a deterministic Completion Note + metrics table and persist a resumable journal, OUTSIDE the worktree, under the same durable root parrot.flows.dev_loop.sdd_coder.telemetry.resolve_durable_root resolves for telemetry/evidence -- a crash between phases resumes from observed disk/git state instead of duplicating effects.
  3. Invoke the existing scripts/sdd/close_task.sh primitive under an isolated GIT_INDEX_FILE, so its internal git add -u sdd/tasks/active can never stage another task's pending edits, then transfer ONLY this task's own index entries (its active/completed .md file and its per-spec index) into the real index with a compare-and-swap guard against a concurrent change to those same paths.
  4. Verify the close_task.sh postconditions itself (no active survivor, a completed copy carrying the rendered note, index status "done") before reporting success.

This module never runs git add ., git reset, git commit, git push or closes any task other than the one named by the evidence. It returns staged paths, the removed active/ path and a suggested commit message; the worker performs the commit and any semantic review decisions.

Class ConcurrentChangeError

The real git index changed for this task's own paths mid-operation.

Alias EvidenceRef

Re-exported from parrot.flows.dev_loop.sdd_coder.optimization_models.EvidenceRef.

Class FinalizeTaskError

Base class for every domain error finalize_task/main can raise.

Class InvalidEvidenceError

Malformed input: bad SHA shape, missing evidence, unresolvable task file.

Class OperationError

close_task.sh failed, or a postcondition did not hold afterward.

Alias ReviewArtifact

Re-exported from parrot.flows.dev_loop.sdd_coder.optimization_models.ReviewArtifact.

Alias TaskCompletionEvidence

Re-exported from parrot.flows.dev_loop.sdd_coder.optimization_models.TaskCompletionEvidence.

Class TaskEvidenceStaleError

HEAD moved, the evidence names a commit outside expected_head's history, or a closed task's journal already recorded a different operation (a new SHA/evidence payload requires a deliberate new operation, never a silent redo).

Class TaskTwinConflictError

An active and a completed copy of the same task disagree on content.

Alias check_fidelity

Re-exported from parrot.flows.dev_loop.sdd_coder.fidelity.check_fidelity.

Function finalize_task

Validate evidence, journal intent, close one task and return staged paths.

Never git add ., reset, commit or push, and never closes a task other than evidence.task_id. Idempotent replay for an identical task_id + implementation_sha + evidence triple; a different SHA or evidence for an already-closed task raises TaskEvidenceStaleError instead of silently redoing the close.

finalize_task(*, evidence: TaskCompletionEvidence, worktree: Path, expected_head: str) -> dict[str, object]

Parameter Type Default Description
evidence TaskCompletionEvidence
worktree Path
expected_head str

Returns: dict[str, object]

Function main

Exit 0 success/replay, 1 operation error, 2 invalid input, 3 stale/busy.

main(argv: list[str] | None = None) -> int

Parameter Type Default Description
argv list[str] | None None

Returns: int

Alias parse_task_files

Re-exported from parrot.flows.dev_loop.sdd_coder.fidelity.parse_task_files.

Alias resolve_durable_root

Re-exported from parrot.flows.dev_loop.sdd_coder.telemetry.resolve_durable_root.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally