Files
archie/internal/app/controlplane/workflow_definitions.go
T
sam c0ec3f6b8e fix(workflow): pin the roots, drop the dead vocabulary, guard the nil manager
Third review pass on the step-vocabulary shape, one fix per finding.

P1, roots unpinned. The agreement test built its own manager and injected it, so
it pinned the resolution sites and not the roots that decide the provider set; a
root regressed to workflow.NewManager() (no shipped stages) left go test green.
archied now resolves through one unit, stepVocabulary (step_vocabulary.go), and
agentworker's productionWorkerDependencies is exercised directly:
internal/app/agentworker/step_vocabulary_test.go and
internal/app/archied/step_vocabulary_test.go assert each root's manager resolves
the shared provider set's shipped stages and accepts a provider registered
through it. RunStateStore and openStateStoreAdapter own a SQLite file and a gRPC
dial, so their calls are pinned by source position, the way
composition_order_test.go pins the memory-engine ordering.

P2-B, dead vocabulary. archie-messaging registered a step vocabulary it never
resolved (its only control-plane call is RuntimeChatConfig) and could fail
startup on it before the State Store target guard. The workflow-definitions
surface is now its own type, controlplane.WorkflowDefinitionsClient, so the
vocabulary is a constructor dependency of the one surface that resolves step
types and of nothing else. The messaging root no longer imports workflowsteps.

P2-C, nil manager. A nil *workflow.Manager dereferenced on every resolution path.
stepRegistry and CompilePinnedWorkflow now refuse with an error naming the wiring
mistake; TestNilStepVocabularyFailsClosedAtEveryResolutionSite pins the refusal.

Claim-vs-code corrections: agreement is stated as within one build (vocabulary.go,
stepRegistry, openStateStoreControlPlane, openStateStoreAdapter); the Yaegi claim
now says no bridge to StepFactory has been built and cites
internal/secret/secretextract; the provider set names its three roots;
Manager.Register's ordering is documented as a constraint with its consequence,
and the shape rule no longer claims to reserve shipped stage names; the
shipped-stage test compares against the builtin factory's own stage.
2026-09-21 20:00:37 +10:00

55 lines
2.0 KiB
Go

package controlplane
import (
"encoding/json"
"errors"
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
const WorkflowDefinitionsKind = "workflow-definitions"
// stepRegistry is this package's single resolution site for the workflow step
// vocabulary, and the guard on the manager it must be handed. The manager is
// built at the composition root (infrastructure/workflowsteps.NewManager) and
// injected, so the State Store server -- the validating side -- and the
// workflow-definitions client both resolve the vocabulary that composition
// root registered. Agreement is within one build: the State Store and
// archie-agent are separately deployed binaries, so a State Store built from
// newer source than the agent it dispatches to can still disagree, and only a
// matching deploy fixes that.
func stepRegistry(steps *workflow.Manager) (workflow.StepRegistry, error) {
if steps == nil {
return nil, errors.New("control plane: no workflow step vocabulary: the composition root must register the provider set (infrastructure/workflowsteps.NewManager) before the first resolution")
}
return steps.Registry(), nil
}
func workflowDefinitionsDefinition(steps workflow.StepRegistry) Definition {
return Definition{
Kind: WorkflowDefinitionsKind,
Title: "Workflow definitions",
Schema: objectSchema,
ApplyMode: "live",
Seed: func(config.Config) any {
return workflow.ShippedDefinitions()
},
Defaults: func() any {
return workflow.ShippedDefinitions()
},
Validate: func(input []byte) error {
_, err := workflow.DecodeDefinitionCollection(input, steps)
return err
},
}
}
func encodeWorkflowDefinitions(collection workflow.WorkflowDefinitionCollection, steps workflow.StepRegistry) ([]byte, error) {
if err := workflow.ValidateDefinitionCollection(collection, steps); err != nil {
return nil, fmt.Errorf("%w: %w", ErrValidation, err)
}
return json.Marshal(collection)
}