Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Merge Bugbot's afterRun-outcome fix; keep the shared shape and its evidence

Claudede295e56a96b
diff --cc cli/beacon-hooks/cmd/cline_event.go
index 840d104d,296a8512..0c483e2c
--- a/cli/beacon-hooks/cmd/cline_event.go
+++ b/cli/beacon-hooks/cmd/cline_event.go
@@@ -690,48 -701,22 +690,54 @@@ func clineToolAfterEvents(input map[str
}}
}
-// clineRunStatus reads the outcome status from an afterRun payload.
+// Outcomes a run-completion payload can report, beyond plain success.
+const (
+ clineOutcomeCancelled = "cancelled"
+ clineOutcomeFailed = "failed"
+)
+
+// clineTaskOutcome reads how a Cline task actually finished.
//
-// Cline's AgentRunResult carries status: "completed" | "aborted" | "failed". The value may sit at
-// the top level (plugin SDK shape) or nested under result/run (file-based hook shape). An empty
-// return means a normal completion or an unrecognized shape, both of which are treated identically.
-func clineRunStatus(input map[string]interface{}) string {
- if s := getFirstStr(input, "status"); s != "" {
- return strings.ToLower(s)
- }
- for _, key := range []string{"result", "run"} {
- if nested := firstMap(input, key); nested != nil {
- if s := getFirstStr(nested, "status"); s != "" {
- return strings.ToLower(s)
+// This exists because the two Cline surfaces disagree about where the outcome lives. The
+// file-based hooks name it in the stage itself -- TaskCancel, error -- so the stage alone is
+// enough. The plugin SDK, which is the surface Beacon installs, has a single run-completion
+// handler for every outcome and reports the difference as a field on the context. Without this
+// read, an aborted or failed task reaches the log as a clean session.ended, and the cancel and
+// error paths below would be unreachable through Beacon's own plugin.
+//
++// The documented values are Cline's own: AgentRunResult.status is completed | aborted | failed.
++// Those three are what the plugin surface sends. The extra spellings accepted below are tolerance
++// for the file-based surface, whose status-like fields are free-form -- its stage is literally
++// named TaskCancel -- and they cost nothing to accept.
++//
+// Returns "" when nothing says otherwise, so a payload that reports no outcome stays a success --
- // the same behavior as before this read existed. Cline is not documented down to the field level
- // here, so several spellings are accepted and an unrecognized value is treated as success rather
- // than guessed at: mislabelling a completed task as failed is worse than missing a label.
++// the same behavior as before this read existed. An unrecognized value is also a success rather
++// than a guess: mislabelling a completed task as failed is worse than missing a label, and a
++// status Cline adds later must not turn every finished task into an incident.
+func clineTaskOutcome(input map[string]interface{}) string {
+ status := getFirstStr(input, "status", "outcome", "runStatus", "run_status", "completionStatus", "completion_status")
+ if status == "" {
+ for _, key := range []string{"result", "run", "task", "taskMetadata", "task_metadata", "metadata"} {
+ if nested := firstMap(input, key); nested != nil {
+ status = getFirstStr(nested, "status", "outcome", "runStatus", "run_status", "completionStatus", "completion_status")
+ if status != "" {
+ break
+ }
}
}
}
+ switch strings.ToLower(strings.TrimSpace(status)) {
- case "aborted", "abort", "cancelled", "canceled", "cancel", "user_cancelled", "user_canceled", "interrupted":
++ // "aborted" and "failed" are the documented enum; the rest are file-hook tolerance.
++ case "aborted", "cancelled", "canceled":
+ return clineOutcomeCancelled
- case "failed", "failure", "error", "errored":
++ case "failed", "failure", "error":
+ return clineOutcomeFailed
+ }
+ // Deliberately no fallback to "there is an error object on the payload". clineToolFailure
+ // answers that question for a tool call, where the error belongs to the call itself; a run
+ // context is not the same thing, and a run that carried an error field for any other reason
+ // would be reported as a failed task. A false session.error is worse than a missed one in a
+ // log people alert on, so the status field is the only signal until a capture shows another.
return ""
}