Skip to content

API Reference parrot.flows.dev_loop.sdd_coder.background

github-actions[bot] edited this page Nov 10, 2026 · 4 revisions

parrot.flows.dev_loop.sdd_coder.background

View source

Authoritative background registrations; never adopt arbitrary process ids.

Spec sdd/specs/sdd-execution-optimization.spec.md (FEAT-584), module M8 (background registry/status, R8). BackgroundRegistry binds an opaque handle -- emitted only at registration time, never a PID or caller path -- to its true launch identity (execution_id, launch_id, owner_instance_id, authority) and persists that identity durably under the shared evidence root (ExecutionEvidenceStore.root), so it survives a process restart.

status() is a bounded, non-blocking snapshot: it never shells out, never calls ps/kill -0, and never waits for a process/job/test suite to finish. Once the registering process (owner_instance_id) is gone and no terminal receipt was durably recorded, the state degrades to unknown with exit_code=None -- it never reconstructs a false "finished" from an empty log or a reused PID.

Only register()/status() are meant for external (MCP-facing) callers; _record_transition is internal bookkeeping for the owning engine/supervisor/host_observation authority to report a state change in this same process -- it takes an explicit, already-known state, never a PID to adopt, and never blocks waiting on anything itself.

Class BackgroundBudgetExceededError

Raised when a status() read exceeds its bounded 1s I/O budget.

A timeout here is an explicit error, never a terminal state: the caller must not interpret it as finished or unknown.

Class BackgroundConflictError

Raised when a handle is already bound to a different launch identity.

Never adopt a reused handle/PID: a second registration under the same handle with a different launch_id/owner_instance_id/kind is rejected instead of silently overwriting the original launch's identity.

Class BackgroundNotFoundError

Raised when no registration exists for the given (execution_id, handle) pair.

Also covers a "foreign" handle: one that was registered under a different execution_id than the one supplied -- the record simply never exists at that (execution_id, handle) path, so it is indistinguishable from (and exactly as safe as) "never registered".

Alias BackgroundRegistration

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

Class BackgroundRegistry

Bind opaque handles to execution, worktree, owner instance and authority.

Parameter Type Default Description
store ExecutionEvidenceStore
owner_instance_id str

Method BackgroundRegistry.register

Persist a launch-bound registration and emit its idempotent handle.

register(registration: BackgroundRegistration) -> str

Parameter Type Default Description
registration BackgroundRegistration

Returns: str

Method BackgroundRegistry.status

Read known state and a bounded registered log without waiting for completion.

status(execution_id: str, handle: str, since_revision: int | None = None, tail_bytes: int = 2048) -> BackgroundStatus

Parameter Type Default Description
execution_id str
handle str
since_revision int | None None
tail_bytes int 2048

Returns: BackgroundStatus

Alias BackgroundStatus

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

Alias BaselineVerdict

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.BaselineVerdict.

Alias EvidenceRef

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

Alias ExecutionEvidenceStore

Re-exported from parrot.flows.dev_loop.sdd_coder.evidence.ExecutionEvidenceStore.

Alias Invocation

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.Invocation.

Alias RunReport

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.RunReport.

Alias RunnerRegistry

Re-exported from parrot.flows.dev_loop.test_scope.runners.registry.RunnerRegistry.

Alias ScopePlan

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.ScopePlan.

Class ValidationSupervisor

Own admitted validation processes, bounded log drains, deadlines and terminal receipts.

start() admits ONE coder_run_validation-shaped request: it validates the request's own shape, persists it via BackgroundRegistry.register (idempotent by construction -- see _payload_hash), builds the tier-scoped selection from the existing test-scope selector (never a free-form argv), and spawns its first protected subprocess -- but it never awaits the suite's completion (spec R8: "devuelve handle sin esperar la suite"). Draining, the deadline and the terminal receipt run in a background asyncio.Task that reports through BackgroundRegistry._record_transition -- the SAME internal method BackgroundRegistry.status() already reads (spec/TASK-3563: no parallel state-transition path).

A request_id reused with an IDENTICAL payload never spawns a second process (idempotent replay, in-process claim); reused with a DIFFERENT payload is rejected by BackgroundRegistry.register itself (BackgroundConflictError), because launch_id is a canonical hash of that payload. A genuine admission failure (bad selection, a missing bwrap, a spawn error) never leaves a falsely-settled record: the registration stays pending (still blocking checkpoint/cleanup, per this module's own docstring) and the in-process claim is released so a later retry under the SAME request_id is not permanently locked out.

Known, bounded scope decisions: task_ids is validated for shape (TASK-<1-5 digits>, non-empty) and folded into the payload hash. When the engine supplies index_path, the supervisor reads those tasks' declared Validation Commands plus the index test_contract; legacy callers without an index retain the bounded fallback selector. The diff base remains server-derived and is deliberately excluded from the caller payload hash. Baseline comparison uses the index header's base_branch, falling back to origin/dev when unavailable.

Parameter Type Default Description
registry BackgroundRegistry
store ExecutionEvidenceStore

Method ValidationSupervisor.start

Admit only a declared, protected, idempotent selection; never await the suite.

base_ref is the diff base the tier-scoped selection is computed from. The caller (SddCoderEngine.run_validation) resolves it deterministically from the merged task branches themselves, so a merge-tier check covers what THIS chunk introduced instead of the feature branch's whole cumulative diff against origin/dev -- re-validating every previously merged task on every merge made the selection grow with the feature and escalated whole package suites (impact cap / core paths) long before the feature was done. None keeps the historical _DEFAULT_BASE_REF behaviour, which is also the deliberate fallback whenever the caller cannot resolve a narrower base: slower, never less covered.

It is deliberately NOT part of _payload_hash: the base is derived server-side from repository state, not declared by the caller, so folding it in would turn a legitimate idempotent replay (same request_id, same declared payload) into a BackgroundConflictError as soon as another task merged in between.

index_path is likewise resolved by the engine from the feature context and is not caller-declared payload, so it is deliberately excluded from _payload_hash.

start(*, feature: str, worktree: Path, execution_id: str, task_ids: list[str], tier: Literal['task', 'merge', 'feature'], timeout_seconds: int, request_id: str, base_ref: Optional[str] = None, index_path: Optional[Path] = None, attempt_uid: Optional[str] = None) -> BackgroundRegistration

Parameter Type Default Description
feature str
worktree Path
execution_id str
task_ids list[str]
tier Literal['task', 'merge', 'feature']
timeout_seconds int
request_id str
base_ref Optional[str] None
index_path Optional[Path] None
attempt_uid Optional[str] None

Returns: BackgroundRegistration

Raises:

  • ValueError — a malformed request (bad ids, tier, timeout, paths).
  • BackgroundConflictError — request_id reused with a different payload.
  • RuntimeError — bwrap is unavailable -- never silently unsandboxed.
  • OSError — the protected subprocess itself could not be spawned.

Method ValidationSupervisor.wait_verdict

Block until handle settles, then return its persisted validation verdict.

wait_verdict(execution_id: str, handle: str, timeout_s: float) -> 'ValidationVerdict'

Parameter Type Default Description
execution_id str
handle str
timeout_s float

Returns: 'ValidationVerdict'

Method ValidationSupervisor.wait

Block up to timeout_seconds for this handle's OWN settlement task, without cancelling it.

Returns True when a settlement task for (execution_id, handle) is owned by THIS supervisor instance and was awaited (whether it settled within the budget or the wait expired), False when there is nothing to await here -- a handle registered by another launch path, an already drained entry, or a process this instance no longer owns. The caller (SddCoderEngine.bg_wait) falls back to bounded polling on False, so a False answer never means "finished" and never invents a receipt.

The task is shield-ed: a caller's expiring budget must never cancel the supervision that owns the child process, its deadline and its terminal receipt. A settlement failure is not re-raised either -- it is already logged and recorded by _supervise; this method only ever reports whether it waited, never an outcome. The authoritative state stays BackgroundRegistry.status().

wait(execution_id: str, handle: str, timeout_seconds: float) -> bool

Parameter Type Default Description
execution_id str
handle str
timeout_seconds float

Returns: bool

Alias ValidationVerdict

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.ValidationVerdict.

Alias baseline

Re-exported from parrot.flows.dev_loop.test_scope.baseline.

Alias build_verdict

Re-exported from parrot.flows.dev_loop.test_scope.verdict.build_verdict.

Alias changed_files

Re-exported from parrot.flows.dev_loop.test_scope.select.changed_files.

Alias contract_from_index_header

Re-exported from parrot.flows.dev_loop.test_scope.contract.contract_from_index_header.

Alias green_cache

Re-exported from parrot.flows.dev_loop.test_scope.green_cache.

Alias iter_index_files

Re-exported from parrot.flows.dev_loop.task_scheduler.iter_index_files.

Alias load_index_header

Re-exported from parrot.flows.dev_loop.test_scope.contract.load_index_header.

Alias load_registry

Re-exported from parrot.flows.dev_loop.test_scope.runners.registry.load_registry.

Attribute logger

Alias parse_validation_commands

Re-exported from parrot.flows.dev_loop.test_scope.contract.parse_validation_commands.

Alias plan_tests

Re-exported from parrot.flows.dev_loop.test_scope.select.plan_tests.

Alias protected_argv

Re-exported from parrot.flows.dev_loop.worktree_environment.protected_argv.

Alias test_report

Re-exported from parrot.flows.dev_loop.test_scope.report.

Alias verdict_from_json

Re-exported from parrot.flows.dev_loop.test_scope.verdict.verdict_from_json.

Alias verdict_to_json

Re-exported from parrot.flows.dev_loop.test_scope.verdict.verdict_to_json.

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