No turn_completed workflow trigger — agent housekeeping can only run on a blind timer
- Dominant language
- Rust
- Stars
- 32.7k
- Forks
- 4.3k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 253
Description
## Summary
Workflow triggers are `message_posted`, `reaction_added`, `diff_posted`, `schedule`, `webhook` (`crates/buzz-workflow/src/schema.rs:38`). None of them fires when an agent finishes a turn, so a workflow cannot do anything *after* agent activity — only on a wall-clock timer that has no idea whether any work happened.
## Why the timer is not a substitute
The pattern this blocks is periodic agent housekeeping: memory consolidation, log rollup, end-of-session summaries. Every published version of this gates on *activity since last run*, not elapsed time — e.g. "4h since last AND ≥3 sessions since last." A `schedule` trigger can express the first half and not the second, so it fires on quiet weeks and burns a turn doing nothing.
## The signal already exists
`KIND_AGENT_TURN_METRIC` (44200) is emitted at the end of every agent turn (`crates/buzz-acp/src/pool.rs:3395`), carrying a stop reason and turn/cumulative counts. It is a regular stored kind, so the history needed for an "N turns since last run" gate is already being written.
It does not currently reach workflows: `WorkflowEngine::on_event` returns early when `event.channel_id` is `None` (`crates/buzz-workflow/src/lib.rs:281`), and turn metrics are p-tagged to the owner rather than channel-scoped.
## Requested
A `turn_completed` trigger keyed on the existing turn-metric event, exposing at minimum `trigger.agent` and `trigger.stop_reason`, plus an optional `min_turns_since_last` gate on the trigger definition (parallel to how `reaction_added` takes an optional `emoji`).
Owner-scoped rather than channel-scoped is the honest shape for this, which is why it interacts with #2981 (no community-wide workflow scope) — a per-channel binding does not fit an event that isn't about a channel.
## Not blocking on this
Stated plainly so the priority is clear: I have a workable manual path today and am not stuck. This is the missing primitive for a class of automation, not an outage.
Contributor guide
Research direction
Read crates/buzz-workflow/src/schema.rs:38, crates/buzz-acp/src/pool.rs:3395, and crates/buzz-workflow/src/lib.rs:281 to trace trigger definitions, turn-metric emission, and event handling. Review #2981 for workflow scope implications; done means an owner-scoped turn_completed trigger exposes the requested fields and supports the optional min_turns_since_last gate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100