C1c-2a: the step runner says a run's answer in step-ended, inline or as an object, and serves it
The puller's end of a run carries the run's program's last line of standard output as `output` up to StepEndedInlineMost, else keeps it with KeepOutput and names the object in `output-object`; a program that exits other than 0 ends failed. OutputTool serves the seat's verb `output` from the kept object, as the whole file the tool runner sends in chunks; OutputsStore names the store. Builds: design 47 G A-254, A-257, §602 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -81,6 +81,10 @@ type Puller struct {
|
||||
// every ProgressEvery while it runs, step-ended when an ask outside a pipeline ends (design 47 G §496, §602). Nil says
|
||||
// none, a test's. ProgressEvery defaults to DefaultProgressEvery.
|
||||
Say func(event string, body any, id string) error
|
||||
// KeepOutput keeps a run's answer over what step-ended carries inline (sdkstep.StepEndedInlineMost) as the object named
|
||||
// object, which the seat's verb `output` answers (design 47 G A-254); a holder keeps it in the object store its manifest
|
||||
// requires. Nil keeps none: such an answer ends the ask failed, saying so.
|
||||
KeepOutput func(object string, body []byte) error
|
||||
// Callers says which seats the build seat's definition lists as callers of an accepted kind (CallersFromDefinitions);
|
||||
// found is false while the seat list holds no such kind. Nil checks no named asker (design 47 G §543, A-163).
|
||||
Callers func(kind string) (callers []string, found bool)
|
||||
@@ -753,7 +757,7 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
|
||||
var dec *Declining
|
||||
if errors.As(err, &dec) && ctx.Err() == nil {
|
||||
p.declineRun(msg, ask, key, step, dec)
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text)
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text, nil)
|
||||
return
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
@@ -791,9 +795,9 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
|
||||
if len(outcome) > 300 {
|
||||
outcome = outcome[:300] + "..."
|
||||
}
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomeFailed, err.Error())
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomeFailed, err.Error(), nil)
|
||||
} else {
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomePassed, "")
|
||||
p.sayEnded(msg, ask, sdkstep.OutcomePassed, "", result)
|
||||
}
|
||||
p.logf("the %s ask %s ended on %s after %s, in its phase %q; %s", ask.Kind, ask.ID, p.Node,
|
||||
now().Sub(step.Started).Round(time.Second), step.Phase, outcome)
|
||||
@@ -976,18 +980,35 @@ func (p *Puller) say(event string, body any, id string) {
|
||||
}
|
||||
|
||||
// sayEnded says step-ended for an ask outside a pipeline, whatever its asker (design 47 G §602): a pipeline step's end is
|
||||
// its run's own (AskSteps.SayStep).
|
||||
func (p *Puller) sayEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string) {
|
||||
// its run's own (AskSteps.SayStep). The end of a run carries the run's answer (A-254): the last line of its program's
|
||||
// standard output, inline as `output` up to sdkstep.StepEndedInlineMost, else as `output-object`, kept by KeepOutput; a
|
||||
// program that exits other than 0 ends failed with its answer carried.
|
||||
func (p *Puller) sayEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string, result any) {
|
||||
if p.Say == nil || ask.Step != nil {
|
||||
return
|
||||
}
|
||||
end := sdkstep.StepEnded{ID: ask.ID, Asker: askerOf(msg, ask), Ask: ask.ID, Node: p.Node, Outcome: outcome, At: now().UTC()}
|
||||
if ans, ok := runAnswerOf(ask, result); ok {
|
||||
if ans.Exit != 0 && outcome == sdkstep.OutcomePassed {
|
||||
outcome, said = sdkstep.OutcomeFailed, fmt.Sprintf("the program exited %d: %s", ans.Exit, ans.Said)
|
||||
}
|
||||
if len(ans.Output) <= sdkstep.StepEndedInlineMost {
|
||||
end.Output = string(ans.Output)
|
||||
} else if object := sdkstep.OutputObjectName(ask.ID); p.KeepOutput == nil {
|
||||
outcome, said = sdkstep.OutcomeFailed, fmt.Sprintf("the run's answer is %d bytes, over what the end carries, and this holder keeps no object for it", len(ans.Output))
|
||||
} else if err := p.KeepOutput(object, ans.Output); err != nil {
|
||||
outcome, said = sdkstep.OutcomeFailed, fmt.Sprintf("the run's answer of %d bytes could not be kept: %v", len(ans.Output), err)
|
||||
} else {
|
||||
end.OutputObject = object
|
||||
}
|
||||
}
|
||||
if len(said) > 300 {
|
||||
said = said[:300] + "..."
|
||||
}
|
||||
if said == "" && outcome != sdkstep.OutcomePassed {
|
||||
said = "the ask did not pass"
|
||||
}
|
||||
end := sdkstep.StepEnded{ID: ask.ID, Asker: askerOf(msg, ask), Ask: ask.ID, Node: p.Node, Outcome: outcome, Said: said, At: now().UTC()}
|
||||
end.Outcome, end.Said = outcome, said
|
||||
body, err := sdkstep.EncodeStepEnded(end)
|
||||
if err != nil {
|
||||
p.logf("the end of the ask %s cannot be said on %s: %v", ask.ID, p.Node, err)
|
||||
@@ -995,3 +1016,19 @@ func (p *Puller) sayEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string
|
||||
}
|
||||
p.say("step-ended", json.RawMessage(body), "step-ended."+ask.ID)
|
||||
}
|
||||
|
||||
// runAnswerOf is the run answer a run ask's step handed back, whatever its form (the value or a pointer).
|
||||
func runAnswerOf(ask sdkstep.StepAsk, result any) (sdkstep.RunAnswer, bool) {
|
||||
if ask.Run == nil {
|
||||
return sdkstep.RunAnswer{}, false
|
||||
}
|
||||
switch a := result.(type) {
|
||||
case sdkstep.RunAnswer:
|
||||
return a, true
|
||||
case *sdkstep.RunAnswer:
|
||||
if a != nil {
|
||||
return *a, true
|
||||
}
|
||||
}
|
||||
return sdkstep.RunAnswer{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user