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
23 changes: 22 additions & 1 deletion docs/hitl-decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,23 @@ the producer weighed and dispositioned away, with `disposition` one of:
attestation may not use `deferred_to_plan` at all (plan is the last
decision surface).

The handoff is coverage-gated at plan propose time (#3564). Each deferred
candidate is rendered in the plan prompt with a stable `dq-<hash>` id
(first 8 hex chars of the SHA-256 of the normalized question;
`egg_contracts.decisions.deferred_question_id`). The plan producer that
received the section (the architect in concurrent mode) must echo every id
in its attestation's **`deferred_resolutions`**: `{deferred_id,
resolution: "registered", cq: "cq-N"}` when the question was registered
(reframing the text as the design firms up is fine — identity rides on the
id, not the wording), or `{deferred_id, resolution: "not_operator_grade",
why}` when the design dissolved it. The orchestrator recomputes the ids
from refine's attestation and rejects the propose when any deferred
question is unaccounted, when an echoed id matches nothing, or when a
`registered` echo cites a cq-N absent from the attestation's own
`decisions_registered`. CLI: repeatable `--deferred
"<dq-id> :: registered :: <cq-N>"` / `--deferred
"<dq-id> :: not_operator_grade :: <why>"`.

A single free-form rationale paragraph proved trivially satisfiable; #3526's
backfill showed refine-surfaced decisions collapsing from ~8 per pipeline to
~0 within weeks of the rationale form landing, with deferrals to plan never
Expand All @@ -439,11 +456,15 @@ when:

- the attestation is missing or malformed (neither field, both fields, a
non-`cq-N` id, an explicit-none with no candidates, a malformed candidate,
or a plan-phase `deferred_to_plan` disposition);
a malformed `deferred_resolutions` entry, a non-plan attestation carrying
`deferred_resolutions`, or a plan-phase `deferred_to_plan` disposition);
`attestation_schemas.DecisionSurfacingAttestation` and
`routes/signals/_validation.py::_validate_decision_attestation`, both built
on the shared `egg_contracts.decisions.decision_attestation_errors` shape
check;
- a refine-deferred question is unaccounted in the plan producer's
`deferred_resolutions` (#3564, `_validate_deferred_candidate_coverage` —
see the handoff paragraph above);
- an attested id is not registered on the contract, or is registered for a
different phase (cross-check against `contract.decisions`);
- the draft does not **cite** an attested `cq-N`
Expand Down
51 changes: 51 additions & 0 deletions orchestrator/attestation_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,46 @@ class ConsideredCandidate(BaseModel):
why: str = Field(..., description="One sentence justifying the disposition")


class DeferredResolution(BaseModel):
"""A refine-deferred question's plan-phase resolution (#3564).

Refine's ``deferred_to_plan`` candidates arrive in the plan prompt
with a stable ``dq-<hash>`` id. The plan producer echoes each id here
with what became of it: ``registered`` (possibly reframed) as a
``cq-N``, or ``not_operator_grade`` because the design dissolved the
choice. The propose-time gate recomputes the ids from the refine
attestation and NACKs any deferred question left unaccounted — the
echo is what makes exact matching safe while the planner freely
reframes the question text.
"""

deferred_id: str = Field(
...,
description=(
"The dq-<hash> id from the 'Deferred from refine' section of "
"the plan prompt, copied verbatim"
),
)
resolution: str = Field(
...,
description=(
"What became of the question: 'registered' (as a cq-N, "
"possibly reframed) or 'not_operator_grade' (the design "
"dissolved it into a call the planner/implementer owns)"
),
)
cq: str = Field(
default="",
description="The cq-N id it was registered as (required when resolution='registered')",
)
why: str = Field(
default="",
description=(
"How the design dissolved the question (required when resolution='not_operator_grade')"
),
)


class DecisionSurfacingAttestation(BaseModel):
"""Decision-ledger attestation for refine/plan producers (#3390, #3526).

Expand Down Expand Up @@ -142,6 +182,16 @@ class DecisionSurfacingAttestation(BaseModel):
"decisions_registered."
),
)
deferred_resolutions: list[DeferredResolution] = Field(
default_factory=list,
description=(
"Plan producers only (#3564): one entry per refine-deferred "
"dq-<hash> id surfaced in the plan prompt, recording whether "
"it was registered (as a cq-N) or dissolved "
"(not_operator_grade). The propose-time gate NACKs a plan "
"proposal whose deferred questions are not all covered."
),
)

@model_validator(mode="after")
def validate_ledger_shape(self) -> DecisionSurfacingAttestation:
Expand All @@ -152,6 +202,7 @@ def validate_ledger_shape(self) -> DecisionSurfacingAttestation:
self.decisions_registered,
self.no_decisions_rationale,
[c.model_dump() for c in self.candidates_considered],
[d.model_dump() for d in self.deferred_resolutions],
)
if errors:
raise ValueError("Decision-ledger attestation invalid: " + " ".join(errors))
Expand Down
1 change: 1 addition & 0 deletions orchestrator/routes/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ def stream_pipeline(pipeline_id: str) -> Response:
_build_deferred_candidates_section,
_find_deferred_plan_candidates,
_format_considered_candidates,
_format_deferred_candidates_with_ids,
_persist_decision_ledger_summary,
)
from ._decisions import ( # noqa: E402,F401
Expand Down
13 changes: 8 additions & 5 deletions orchestrator/routes/pipelines/_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,14 @@ def _get_plan_review_criteria() -> str:
"(a design call plan legitimately owns) with a concrete why — plan "
"is the last decision surface, so `deferred_to_plan` is rejected at "
"propose time. A bare rationale with no candidates, or a candidate "
"whose `why` is vacuous, is a **NACK**. Cross-check against the "
"refiner's deferred candidates surfaced in the plan prompt: each "
"must be registered as a `cq-N` or dispositioned `not_operator_grade` "
"here — a deferred candidate the plan silently drops is the leak "
"#3526 exists to close.\n"
"whose `why` is vacuous, is a **NACK**. The refiner's deferred "
"candidates surfaced in the plan prompt are coverage-gated at "
"propose time (#3564): the producer's `deferred_resolutions` must "
"echo every `dq-` id, so a silently-dropped candidate never "
"reaches you. Your job is the substance the gate cannot judge: "
"NACK a `registered` echo whose cq-N reframing loses the deferred "
"question's actual fork, and NACK a `not_operator_grade` echo "
"whose why does not hold up.\n"
"- **Task-named decisions — NACK an explicit-none ledger (#3462).** "
"If the task description or refine analysis names decisions as the "
"operator's to make (or directs that decisions be surfaced as HITL "
Expand Down
55 changes: 45 additions & 10 deletions orchestrator/routes/pipelines/_decision_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,43 @@ def _find_deferred_plan_candidates(pipeline_id: str) -> list[dict]:
return []


def _format_deferred_candidates_with_ids(candidates: list[dict]) -> str:
"""Render deferred candidates as bullets carrying their ``dq-`` ids (#3564).

Like :func:`_format_considered_candidates` but prefixes each bullet
with the stable ``dq-<hash>`` identity the propose-time coverage gate
recomputes (``egg_contracts.decisions.deferred_question_id``). The id
is what the plan producer echoes back in its attestation's
``deferred_resolutions``, so it must render verbatim and
copy-pastable. Malformed entries render best-effort — this surface
must never crash prompt assembly.
"""
from egg_contracts.decisions import deferred_question_id

lines = []
for c in candidates:
if not isinstance(c, dict):
continue
question = str(c.get("question") or "?").strip()
why = str(c.get("why") or "").strip()
lines.append(f"- `{deferred_question_id(question)}` — **{question}**: {why}")
return "\n".join(lines)


def _build_deferred_candidates_section(pipeline_id: str | None) -> list[str]:
"""Render refine's ``deferred_to_plan`` candidates for the plan prompt (#3526).

Backfill data on #3526 showed deferral-to-plan was a black hole: refine
registrations fell after the slice/packaging carve-out while plan
registrations never rose. This section makes deferral a handoff: the
planner receives the refiner's named deferred candidates as pre-seeded
items it must register or explicitly disposition. Returns an empty
list (no section) when the pipeline has no deferred candidates or the
message store is unavailable, matching pre-#3526 behavior.
items it must register or explicitly disposition. Each candidate
carries a stable ``dq-<hash>`` id (#3564) that the producer must echo
in its attestation's ``deferred_resolutions`` — the propose-time gate
recomputes the ids and NACKs a plan proposal that leaves one
unaccounted. Returns an empty list (no section) when the pipeline has
no deferred candidates or the message store is unavailable, matching
pre-#3526 behavior.
"""
if not pipeline_id:
return []
Expand All @@ -106,7 +133,7 @@ def _build_deferred_candidates_section(pipeline_id: str | None) -> list[str]:
return []
if not deferred:
return []
rendered = _pkg._format_considered_candidates(deferred)
rendered = _pkg._format_deferred_candidates_with_ids(deferred)
if not rendered:
return []
return [
Expand All @@ -118,12 +145,20 @@ def _build_deferred_candidates_section(pipeline_id: str | None) -> list[str]:
"",
"For EACH candidate above, either register it via "
"`egg-contract add-decision` once your design makes the options "
"concrete (put your recommended option first), or disposition it "
"`not_operator_grade` in your ledger attestation's "
"`candidates_considered` with a concrete why (e.g. the design "
"dissolved the choice). A deferred candidate you neither register "
"nor disposition is exactly the leak this section exists to "
"close.\n",
"concrete (put your recommended option first; reframing the "
"question as the design firms up is fine), or disposition it "
"`not_operator_grade` with a concrete why (e.g. the design "
"dissolved the choice).\n",
"Then, when you propose, echo EVERY `dq-` id above in your "
"attestation via repeated `--deferred` flags (#3564):\n",
"```bash",
'egg-orch consensus propose ... --deferred "dq-<hash> :: registered :: cq-<N>" \\',
' --deferred "dq-<hash> :: not_operator_grade :: <why the design dissolved it>"',
"```",
"The orchestrator recomputes these ids from the refine attestation "
"and REJECTS your proposal if any deferred question is neither "
"registered nor dissolved — a deferred candidate that silently "
"disappears is exactly the leak this section exists to close.\n",
]


Expand Down
2 changes: 2 additions & 0 deletions orchestrator/routes/signals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def get_logger(name: str, **kwargs) -> logging.Logger: # type: ignore[misc]
_DECISION_ATTESTING_PHASES,
_DECISION_ATTESTING_ROLES,
_DECISION_CITATION_SPECS,
_DEFERRAL_COVERAGE_ROLES,
_artifact_human_label,
_extract_attested_decision_fields,
_reject_extra_simplifier_drafts,
Expand All @@ -157,6 +158,7 @@ def get_logger(name: str, **kwargs) -> logging.Logger: # type: ignore[misc]
_validate_decision_attestation,
_validate_decision_attestation_shape,
_validate_decision_citations,
_validate_deferred_candidate_coverage,
_validate_plan_extensions,
_validate_plan_proposal,
_validate_producer_artifacts,
Expand Down
Loading
Loading