Repository navigation
✨ Record what each kick came to: per-kick outcome record and read API #18923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
43f2a93
✨ Record what each kick came to: durable per-kick outcome and GET /ap…
clubanderson a5cd739
🐛 Reach the kick observer registry through a checked type assertion (…
clubanderson a5ef25d
🐛 Keep pkg/dashboard free of a new package import; lower the comment-…
clubanderson c9387cc
✅ Cover the kick outcome store; fix the API-reference citation (#18916)
clubanderson 8aee2e4
Merge branch 'v5' into feat/kick-outcome-record
hivecommons-hive[bot] 9b59348
Merge remote-tracking branch 'origin/v5' into feat/kick-outcome-record
hivecommons-hive[bot] ea477a9
🐛 Restore the comment-marker baseline to the v5 value (#18916)
clubanderson 5d39d3e
Merge branch 'v5' into feat/kick-outcome-record
hivecommons-hive[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Per-kick outcome record: the hive now keeps a durable, bounded record of what each kick of an agent came to (opened a PR, pushed a commit, commented, stood down, was refused, still running, or ended with no visible action), who or what triggered it, and when, derived only from signals it already has, and exposes it on `GET /api/kick-outcomes` (owner and read-write see detail; read-only sees a one-line summary) (#18916). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "log/slog" | ||
| "path/filepath" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/hivecommons/hive/crux" | ||
| "github.com/hivecommons/hive/pkg/config" | ||
| "github.com/hivecommons/hive/pkg/dashboard" | ||
| "github.com/hivecommons/hive/pkg/github" | ||
| "github.com/hivecommons/hive/pkg/kickoutcome" | ||
| wfstore "github.com/hivecommons/hive/pkg/workflowmodel/store" | ||
| ) | ||
|
|
||
| // Per-kick outcome record, host wiring (hivecommons/hive#18916). | ||
| // | ||
| // pkg/kickoutcome keeps the record; this file feeds it the signals the hive | ||
| // already has: the fan-out kick observer (a kick was delivered), the runtime's | ||
| // turn-end classification, the relay's pull-request, push and comment events, | ||
| // and the callers that know who or what is kicking (the governor here; the | ||
| // dashboard in pkg/dashboard). Nothing here reads agent text into a prompt. | ||
|
|
||
| // kickOutcomesFile is the durable record under the hive's data root. | ||
| const kickOutcomesFile = "kick-outcomes.json" | ||
|
|
||
| var ( | ||
| kickOutcomesOnce sync.Once | ||
| kickOutcomesStore *kickoutcome.Store | ||
| ) | ||
|
|
||
| // kickOutcomesFor is the process's kick outcome store, opened on first use. A | ||
| // corrupt or unreadable file starts the store empty with a warning: a lost | ||
| // record must not stop kicks. | ||
| func kickOutcomesFor(cfg *config.Config, logger *slog.Logger) *kickoutcome.Store { | ||
| kickOutcomesOnce.Do(func() { | ||
| path := "" | ||
| if cfg != nil { | ||
| path = filepath.Join(wfstore.Root(cfg.Data.WorkflowsDir), kickOutcomesFile) | ||
| } | ||
| s, err := kickoutcome.Open(path, logger) | ||
| if err != nil && logger != nil { | ||
| logger.Warn("kick outcomes unreadable; starting empty", "path", path, "error", err) | ||
| } | ||
| kickOutcomesStore = s | ||
| }) | ||
| return kickOutcomesStore | ||
| } | ||
|
|
||
| // kickOutcomeTurnEnded files how an agent's kicked turn ended. The agent | ||
| // manager's refusal flag, when set and not a startup deferral, also marks the | ||
| // kick as declined by the agent's own model. | ||
| func kickOutcomeTurnEnded(s *kickoutcome.Store, status func(agent string) (*crux.Process, error), agent string, o crux.KickOutcome) { | ||
| if s == nil { | ||
| return | ||
| } | ||
| s.TurnEnded(agent, o.Kind, o.Reason, o.KickAt, o.At) | ||
| if status == nil { | ||
| return | ||
| } | ||
| if p, err := status(agent); err == nil && p != nil && p.KickRefused && | ||
| !strings.Contains(p.KickRefusalReason, workflowStartupDeferral) && p.LastKick != nil && p.LastKick.Equal(o.KickAt) { | ||
| s.Declined(agent, p.KickRefusalReason, o.At) | ||
| } | ||
| } | ||
|
|
||
| // kickOutcomeDelivered files a delivered kick from a fan-out kick event. | ||
| func kickOutcomeDelivered(s *kickoutcome.Store, ev crux.KickEvent) { | ||
| if ev.Event == crux.KickEventDelivered { | ||
| s.Delivered(ev.Agent, ev.At) | ||
| } | ||
| } | ||
|
|
||
| // kickOutcomeAgentAction files a relay push or comment. | ||
| func kickOutcomeAgentAction(s *kickoutcome.Store, a github.AgentAction) { | ||
| switch a.Kind { | ||
| case github.AgentActionPush: | ||
| s.Pushed(a.Agent, a.Branch, a.SHA, a.At) | ||
| case github.AgentActionComment: | ||
| s.Commented(a.Agent, a.At) | ||
| } | ||
| } | ||
|
|
||
| // kickOutcomeSender wraps the governor's kick delivery: it says the kick is | ||
| // the governor's (or a workflow hand-off's, when workflowKick says so) and | ||
| // files a refusal the hive's delivery checks raise. A busy bounce is a | ||
| // deferral, not a refusal, and is left to the next pass. | ||
| func kickOutcomeSender(s *kickoutcome.Store, send func(agent, message string) error, workflowKick func(agent, message string) bool) func(agent, message string) error { | ||
| return func(agent, message string) error { | ||
| kind := kickoutcome.TriggerGovernor | ||
| if workflowKick != nil && workflowKick(agent, message) { | ||
| kind = kickoutcome.TriggerWorkflowDispatch | ||
| } | ||
| s.Intend(agent, kickoutcome.Trigger{Kind: kind, Actor: "governor"}) | ||
| err := send(agent, message) | ||
| if err != nil && !isKickBusy(err) { | ||
| if code := dashboard.ClassifyKickRefusal(err.Error()); code != "" { | ||
| s.Refused(agent, kickoutcome.Trigger{Kind: kind, Actor: "governor"}, code, err.Error(), time.Now()) | ||
| } | ||
| } | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // isKickBusy reports a busy bounce (agent mid-turn). | ||
| func isKickBusy(err error) bool { return errors.Is(err, crux.ErrAgentBusy) } | ||
|
|
||
| // kickOutcomeSource adapts the store to the dashboard's KickOutcomeSource, so | ||
| // the dashboard takes no import of pkg/kickoutcome. | ||
| type kickOutcomeSource struct{ s *kickoutcome.Store } | ||
|
|
||
| func (a kickOutcomeSource) Intend(agent, kind, actor string) { | ||
| a.s.Intend(agent, kickoutcome.Trigger{Kind: kind, Actor: actor}) | ||
| } | ||
|
|
||
| func (a kickOutcomeSource) Refused(agent, kind, actor, code, reason string, at time.Time) { | ||
| a.s.Refused(agent, kickoutcome.Trigger{Kind: kind, Actor: actor}, code, reason, at) | ||
| } | ||
|
|
||
| func (a kickOutcomeSource) Latest() any { return a.s.Latest() } | ||
|
|
||
| func (a kickOutcomeSource) Recent(agent string, n int) (any, any) { | ||
| kicks := a.s.Recent(agent, n) | ||
| if kicks == nil { | ||
| kicks = []kickoutcome.Detail{} | ||
| } | ||
| if len(kicks) == 0 { | ||
| return nil, kicks | ||
| } | ||
| return kicks[0].View, kicks | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Advisory:
Intendis set beforesend, but on a busy bounce or unclassified error the intent is never consumed, so the next delivery within 2 minutes is attributed to the governor. Drop the intent on those error paths (e.g. aStore.ClearIntent(agent)called whenerr != niland no refusal was filed).