feat(forge): GitHub webhook receiver for immediate issue dispatch

Add [forge] intake = "poll" (default) | "webhook" | "both", and a forge
webhook receiver (internal/forge/webhook) that verifies a GitHub webhook's
HMAC signature, decodes the "issues" event, and publishes a matched issue
through the same path the poller uses -- so a labelled or assigned issue
starts a task the moment it happens instead of waiting up to poll_interval
(bead archie-core-7d5u.4).

The dispatch predicate (workintake.MatchesDispatch/RequiresLabel) is now a
single shared definition consumed by both the poller and the webhook
receiver, so the two cannot drift -- including the empty-label guard from
63d0446 (an empty label must never match every open issue). Assignee
matching is case-insensitive to agree with AssignedIssues' server-side
GitHub filter; label matching stays case-sensitive, since GitHub labels
are case-distinct.

daemon.publishTask is exported as PublishTask, the single enqueue path
now shared by the poller and the webhook intake.

Two failure modes fixed during adversarial self-review before this landed:
a webhook secret that fails to resolve at runtime now degrades (logs and
skips the receiver) instead of aborting the whole daemon -- under
intake="both" the poll exists specifically as a backstop for this exact
misconfiguration, so crashing boot over it defeated its own purpose;
multi-identity deployments ([[identities]]) are explicitly unsupported for
now (webhook intake refuses to start, logs why, and leaves each identity's
own poll loop unaffected) rather than silently matching issues against the
wrong identity's dispatch rules.
This commit is contained in:
sam committed 2026-08-22 19:21:09 +10:00
1 parent aba035a396
commit 508a0ad48c
12 files changed
+770 -6

No files matched your search

+13 -6
View File
@@ -357,7 +357,9 @@ func (d *Daemon) maintainAndDrain(ctx context.Context) {
func (d *Daemon) pollIssuesWithConfig(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo) []forge.Issue {
switch cfg.Dispatch.Trigger {
case "label":
if cfg.Label == "" {
// Empty-label rule shared with workintake.MatchesDispatch: a label
// trigger needs a non-empty label or it would match every open issue.
if workintake.RequiresLabel(cfg.Dispatch.Trigger) && cfg.Label == "" {
d.Log.Error("label trigger configured with an empty label; refusing to poll (an empty label matches every open issue)", "repo", repo.FullName())
return nil
}
@@ -392,7 +394,7 @@ func (d *Daemon) pollEitherWithConfig(ctx context.Context, fg forge.Forge, cfg c
out = append(out, is)
}
}
if cfg.Label == "" {
if workintake.RequiresLabel(cfg.Dispatch.Trigger) && cfg.Label == "" {
d.Log.Error("either trigger configured with an empty label; skipping the label poll (an empty label matches every open issue)", "repo", repo.FullName())
return out
}
@@ -635,17 +637,22 @@ func (d *Daemon) pollNATS(ctx context.Context, fg forge.Forge, cfg config.Config
Identity: identity,
Kind: workintake.KindForLabels(parsed),
}
if err := d.publishTask(ctx, task); err != nil {
if err := d.PublishTask(ctx, task); err != nil {
d.Log.Error("task publish failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
return
}
d.acknowledge(ctx, fg, cfg, repo, is)
}
// publishTask validates, encodes and publishes a task envelope. The
// PublishTask validates, encodes and publishes a task envelope. The
// idempotency key means rediscovering the same issue on a later poll does not
// enqueue the work twice.
func (d *Daemon) publishTask(ctx context.Context, task workintake.TaskEnvelope) error {
// enqueue the work twice. It is the single enqueue path shared by the poller
// and the forge webhook intake, so neither can drift in how a discovered issue
// becomes a task.
func (d *Daemon) PublishTask(ctx context.Context, task workintake.TaskEnvelope) error {
if d.Tasks == nil {
return fmt.Errorf("publish task %s: no task bus configured (nats.mode is off)", task.Ref())
}
if err := task.Kind.Validate(); err != nil {
return fmt.Errorf("publish task %s: %w", task.Ref(), err)
}