Let Orchestra establish plan progress instead of the implementer asserting it

A detailed plan that nothing enforces is a document. This makes the phases
executable: the implementer may write exactly one status, and every other
status is a conclusion Orchestra reaches by running the plan's own commands.

    agent may request:  ready_for_verification
    agent may not assert: verified, awaiting_manual_verification, failed, skipped

The worker resolves commands from the coordinator, never from the request, so a
request cannot smuggle in a command the planner did not write. They run as argv
through exec with Dir set to the worktree, which is the quality gate's existing
envelope and not a weaker one. There is no shell, so a pipe is a literal
argument.

Project policy decides executable reach. registry.Project.Verification matches
argv positionally, and an absent policy refuses everything: a plan command is
agent-authored, so inheriting the operator-authored gate's reach by default
would be the wrong direction to fail in. A refused command is refused before
anything runs, and the refusal names the project and the command so the planner
learns its real reach.

Two bindings make the record mean something later. PlanRef, so progress earned
under plan A cannot survive into plan B. AtSHA, so "verified" does not outlive
the code that made it true: a record whose commit has moved is retained as
provenance and rendered as stale, never as a claim about the current tree.
Both are the same failure this codebase already fixed for reviews, which bind
to the commit they examined.

Manual steps hold a phase at awaiting_manual_verification. The sign-off is an
ordinary human decision whose subject carries the plan ref and the phase id, so
a later "looks good" on an unrelated thread cannot satisfy a gate nobody was
discussing.

A plan sealed before plan.md declares no executable unit, and says so: the
implement context states that phase progress is unavailable and the work
continues under the old semantics. Inventing phases it never had would be worse
than admitting it has none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVbaKucEYBjMqVeUgJUsc1
This commit is contained in:
2026-08-28 11:59:39 +04:00
parent 57c028f94f
commit a221502356
15 changed files with 1282 additions and 22 deletions
+48 -2
View File
@@ -253,6 +253,7 @@ func (s *Store) apply(e domain.Event) error {
// folded into the contract projection.
var p struct {
DecisionID string `json:"decision_id"`
Subject string `json:"subject"`
Source domain.HumanDecisionSource `json:"source"`
}
if err := json.Unmarshal(e.Payload, &p); err != nil {
@@ -261,6 +262,21 @@ func (s *Store) apply(e domain.Event) error {
if p.Source.ExternalID != "" {
s.decisionSource[p.Source.Provider+"\x00"+p.Source.ExternalID] = p.DecisionID
}
// A manual sign-off is the one decision that moves plan progress. The
// subject carries the plan ref and the phase id, so an approval
// applies to exactly the gate it named and to no other.
if t.PlanProgress != nil {
for i, rec := range t.PlanProgress.Phases {
if rec.Status != domain.PlanPhaseAwaitingManual {
continue
}
if p.Subject == domain.PlanPhaseSubject(rec.PlanRef, rec.PhaseID) {
t.PlanProgress.Phases[i].Status = domain.PlanPhaseVerified
t.Version = e.Version
s.replaceTask(e.TaskID, t)
}
}
}
}
if e.Type == "StandupAdvisory" || e.Type == "ApprovalGranted" || e.Type == "ApprovalDenied" {
return nil
@@ -282,8 +298,13 @@ func (s *Store) apply(e domain.Event) error {
t.ResearchRef = p.ArtifactRef
}
case domain.WorkPhasePlan:
if p.ArtifactRef != "" {
if p.ArtifactRef != "" && p.ArtifactRef != t.PlanRef {
// A new plan supersedes the old one, and the progress earned
// against the old one with it. PlanPhases would filter these
// out anyway; clearing here means a superseded record is not
// carried around waiting for a reader that forgets to.
t.PlanRef = p.ArtifactRef
t.PlanProgress = nil
}
}
t.WorkPhase = p.Phase
@@ -449,6 +470,31 @@ func (s *Store) apply(e domain.Event) error {
t.Version = e.Version
s.replaceTask(e.TaskID, t)
return nil
case domain.EventPlanPhaseVerified:
var pp domain.PlanPhaseRecord
if err := json.Unmarshal(e.Payload, &pp); err != nil {
return err
}
// Records are kept per plan. A record naming a plan the task no longer
// accepts is projected onto nothing: it stays in the log as
// provenance, and PlanPhases refuses to count it.
if t.PlanProgress == nil || t.PlanProgress.PlanRef != pp.PlanRef {
t.PlanProgress = &domain.PlanProgress{PlanRef: pp.PlanRef}
}
replaced := false
for i, existing := range t.PlanProgress.Phases {
if existing.PhaseID == pp.PhaseID {
t.PlanProgress.Phases[i] = pp
replaced = true
break
}
}
if !replaced {
t.PlanProgress.Phases = append(t.PlanProgress.Phases, pp)
}
t.Version = e.Version
s.replaceTask(e.TaskID, t)
return nil
case domain.EventReviewRecorded:
var rp struct {
ArtifactRef string `json:"artifact_ref"`
@@ -827,7 +873,7 @@ func (s *Store) validateTransition(e domain.Event, t domain.Task, exists bool, p
return nil
}
switch e.Type {
case "TaskLeaseRenewed", "TaskLaunchAcknowledged", "TaskReleased", "TaskPickupValidated", "TaskCompleted", "TaskBlocked", "TaskNeedsAttention", "TaskFailed", domain.EventTaskSubmitted:
case "TaskLeaseRenewed", "TaskLaunchAcknowledged", "TaskReleased", "TaskPickupValidated", "TaskCompleted", "TaskBlocked", "TaskNeedsAttention", "TaskFailed", domain.EventTaskSubmitted, domain.EventPlanPhaseVerified:
owner, _ := p["harness_id"].(string)
epoch, _ := p["lease_epoch"].(string)
// Expiry is the one coordinator-owned relinquish path. It still binds