diff --git a/docs/ADRs/0061-harness-cel-dispatch.md b/docs/ADRs/0061-harness-cel-dispatch.md index f3d0d56dae..ecd1e6b5fc 100644 --- a/docs/ADRs/0061-harness-cel-dispatch.md +++ b/docs/ADRs/0061-harness-cel-dispatch.md @@ -32,6 +32,11 @@ floor may run before loading harnesses, with a narrow verified label grant for its exact transition. Each trusted harness's effective `human_min_role` is then enforced before its CEL predicate. Authorization remains a platform gate. +[ADR 0160](0160-queue-jira-work-by-search-so-no-request-expires.md) narrows, +for the `jira-poll` driver only, which trigger rules are served: a rule the +driver cannot read stops the poll with an error, and a reaction to a Jira +issue being closed or reopened is not served. + ## Context Custom agents should be easy to author and portable across forges. Today, adding diff --git a/docs/ADRs/0063-polling-based-work-discovery.md b/docs/ADRs/0063-polling-based-work-discovery.md index 81c97c5a54..5630699e90 100644 --- a/docs/ADRs/0063-polling-based-work-discovery.md +++ b/docs/ADRs/0063-polling-based-work-discovery.md @@ -41,13 +41,14 @@ and per-repository scope remain current. [ADR 0147](0147-evaluate-entity-cel-over-selectively-acquired-data.md) requires durable retry or proven rediscovery for provisional entity-source handoffs. The `lastCheck` advance-on-schedule rule below remains for legacy event -reconstruction. - -[ADR 0160](0160-spend-jira-poll-slots-only-on-candidates-with-new-activity.md) -refines the candidate selection step below: per-cycle slots are spent only -on candidates whose Jira `updated` is newer than their checkpoint, and M and -N become configurable within bounds. The lock protocol and the random pick -among candidates remain. +reconstruction, except in the `jira-poll` driver (ADR 0160, next paragraph). + +[ADR 0160](0160-queue-jira-work-by-search-so-no-request-expires.md) +supersedes, for the `jira-poll` driver, the candidate selection (up to M +results, N picked at random) and the `lastCheck` change detection below: the +driver finds work by searching for issues that carry a request and no label +saying it was handled, oldest first. The lock protocol and the dispatch path +remain current. ## Context diff --git a/docs/ADRs/0153-authorize-jira-poll-actors-without-project-administration.md b/docs/ADRs/0153-authorize-jira-poll-actors-without-project-administration.md index 69d548821a..00afc8421c 100644 --- a/docs/ADRs/0153-authorize-jira-poll-actors-without-project-administration.md +++ b/docs/ADRs/0153-authorize-jira-poll-actors-without-project-administration.md @@ -25,6 +25,11 @@ deprecates running the `jira-poll` driver without an entry and makes the entry required. The lists, `labels:` rules and roster loading decided here are unchanged. +[ADR 0160](0160-queue-jira-work-by-search-so-no-request-expires.md) extends +the `labels:` rules: a label that was not added by an edit in the project +(present when the issue was created, or added before the issue moved in) is +authorized as a command is, not by Edit Issues. + ## Context The `jira-poll` input driver diff --git a/docs/ADRs/0160-queue-jira-work-by-search-so-no-request-expires.md b/docs/ADRs/0160-queue-jira-work-by-search-so-no-request-expires.md new file mode 100644 index 0000000000..e3a9ab21e4 --- /dev/null +++ b/docs/ADRs/0160-queue-jira-work-by-search-so-no-request-expires.md @@ -0,0 +1,425 @@ +--- +title: "160. Queue Jira work by search so that no request expires" +status: Accepted +relates_to: + - agent-infrastructure + - agent-architecture + - security-threat-model +topics: + - polling + - jira + - dispatch + - scheduling + - labels +--- + +# 160. Queue Jira work by search so that no request expires + +Date: 2026-11-13 + +## Status + +Accepted + +The `jira-poll` driver finds work by searching for issues that carry a +request and no label saying it was handled, oldest first. This replaces the +candidate window, the random pick, and the per-issue checkpoint with its +24-hour floor. + +Partially supersedes [ADR 0063](0063-polling-based-work-discovery.md) for +the `jira-poll` driver: its candidate selection (up to M results, N picked +at random) and its `lastCheck` change detection. Its poll command, driver +architecture, lock protocol and dispatch path remain current. The lock and +the dispatch stay scoped to one repository; the queue's labels are shared +by every repository that polls a project. + +Extends +[ADR 0153](0153-authorize-jira-poll-actors-without-project-administration.md) +and [ADR 0157](0157-require-jira-authorization-entry-for-jira-poll.md): a +label that was not added by an edit in the project is authorized as a +command is, and removing an outcome label is checked against the person +who removed it (Decision item 6). The rest of the authorization path of +[ADR 0054](0054-require-authorization-on-all-agent-dispatch-paths.md) is +unchanged. + +Narrows what the `jira-poll` driver accepts from a trigger rule +([ADR 0061](0061-harness-cel-dispatch.md)): a rule the driver cannot read +stops the poll with an error, and a reaction to a Jira issue being closed +or reopened is not served (Decision item 1). + +This file replaces an earlier ADR 0160, "Spend Jira poll slots only on +candidates with new activity" +([#9166](https://github.com/fullsend-ai/fullsend/pull/9166)), accepted on +2026-11-10 and never implemented. It tuned the selection that this decision +removes. Its text remains in the history of that pull request. + +## Context + +[ADR 0063](0063-polling-based-work-discovery.md) defines how the `jira-poll` +driver chooses work. The configured query returns up to M candidates +(default 50), most recently updated first by default. The driver picks N of +them at random (default 5), and for each one reads the comments and +changelog newer than a checkpoint it keeps in an issue property, rebuilds +them as events, and dispatches. A checkpoint older than 24 hours is +floored at 24 hours, and an issue seen for the first time yields events +from the last 24 hours only (verified at fullsend commit `1b3f16b3f`, +evidence in the pull request description). + +That design assumes work arrives more slowly than agents take it. When it +arrives faster, for example a steady stream of vulnerability tickets, three +things happen: + +- No request has a bounded wait, because each cycle is an independent + random draw. +- A request outside the top M results is never drawn at all. +- A request not drawn within 24 hours is lost permanently while the poll + run still succeeds, because the checkpoint floor moves past it. + +A fourth gap is independent of load: a label that is already on an issue +when it is created produces no label event, so it does not start the +built-in code agent +([guide](../guides/user/jira-integration.md#labels-present-when-an-issue-is-created)). + +The earlier ADR 0160 filtered the pool to candidates with new activity and +made N and M configurable. That shortens the wait while arrivals stay below +capacity. It keeps the window, the random draw and the 24-hour floor, so +under sustained load requests still wait without bound and still expire. + +A replacement must reach every request eventually however long the backlog +grows, must expire nothing, must not cost more per cycle as history +accumulates, and must switch on without operator action for a repository +that uses the shipped trigger rules. It must also keep dispatch +fail-closed: every dispatch backed by a real event from a real actor, +authorized as today. + +Jira constrains the shape. Its search can test labels and comment text and +can sort by creation time. It cannot search the issue properties the +driver writes or compare two fields, and its history operators cover +status, assignee and a few other fields, not labels, summary or +description. A record that an issue was handled is therefore visible to a +search only as a label. + +[ADR 0098](0098-entity-first-harness-evaluation.md) decided that events are +a fast source of candidates and entity state is the authority on whether +work remains. Its execution path waits on contracts that do not exist yet +([#8418](https://github.com/fullsend-ai/fullsend/issues/8418)). This +decision takes the discovery half, state finds the candidates, and keeps +today's event-backed dispatch, so it depends on none of those contracts. + +This ADR aims to make the `jira-poll` driver reach every waiting request +eventually, lose none of them to age, and switch on without operator +action. + +## Options + +**A. Tune the existing selection.** The earlier ADR 0160. Rejected for the +reason above: no bound and continued expiry under sustained load. + +**B. Widen or page the window.** Scan further back, or make the 24-hour +cutoff configurable. Any cutoff still expires requests that are waiting, +removing it needs a stored start line, and the cost of a cycle grows with +the backlog. Rejected. + +**C. Queue by search, with labels as the record of what was handled.** +The waiting set is a search result, so it needs no cursor and no start +line, and a handled issue leaves it. It keeps one 24-hour limit, on how +soon the driver must notice an event that a search cannot see (item 4); a +request that is waiting has none. Oldest first is an order every poller +shares, which the random pick avoided: the managed GitHub workflow runs +one cycle of a repository at a time, and a cycle that cannot take an +issue's lock skips it and continues, so the cost of an overlap is at most +a repeated hand-off. Chosen. + +**D. Wait for entity-first execution.** The right long-term home +([ADR 0098](0098-entity-first-harness-evaluation.md)), and not available in +time. C moves toward it and can hand its per-agent terms to harness entity +filters when those exist. + +**E. Serve requests only, and drop automatic triggers on Jira.** One +mechanism and no staging, but triage would stop running when a person opens +or edits an issue unless each team added labelling inside Jira. Rejected as +a regression. + +**F. Configure each agent's labels and commands, or build them into +fullsend.** Per-agent fields do not belong in `config.yaml` +([ADR 0080](0080-config-yaml-vs-agent-env-var-scope.md)), and names built +into fullsend would duplicate the agents' trigger rules and go stale when a +repository changes one. Rejected in favour of reading the trigger rule. + +## Decision + +We adopt a queue found by search for the `jira-poll` driver. A request on +an issue with no outcome label is found at any age and reached in order of +issue age. Automatic triggers and repeated requests are noticed within 24 +hours and then wait without expiring. + +1. **What starts an agent is read from its trigger rule.** For each enabled + agent the driver takes the trigger rule it already evaluates + ([ADR 0061](0061-harness-cel-dispatch.md)), keeps the parts that can be + true for a Jira issue, and reads from them the labels whose addition + starts the agent, the commands that start it, and whether it starts when + a person opens or edits an issue. Nothing is configured, so a repository + that changes a trigger changes the queue with it. A rule the driver + cannot read this way stops the cycle with an error naming the agent and + the part. That covers a label or command matched by pattern or by + exclusion, a label event that does not require the label to be added, a + comment event with no fixed command, and a reaction to an issue being + closed or reopened, which the queue does not serve yet. `fullsend lint` + reports the same error from the same code. Doubt is an error, so no part + of a rule is skipped silently. +2. **Three labels per agent record its state on an issue.** They are + `ai--agent`, the hand-off label, `ai--queued` and + `ai--declined`, built from the agent's name: for the code agent, + `ai-code-agent`, `ai-code-queued` and `ai-code-declined`. The names + describe a role, not a product, and are not configurable in this + version. +3. **Waiting is a search condition.** An issue is waiting for an agent when + it matches the repository's poll query and either carries the agent's + queued label, or carries a request (one of the agent's labels, or a + comment containing one of its commands) and neither the agent's + hand-off label nor its declined label. Age is not part of the + condition. +4. **What a search cannot see is staged as a label.** A search cannot tell + that a person opened or edited an issue, or that a new request arrived + on an issue that already carries an outcome label. Before searching, the + driver lists the issues in the poll query that changed in the last 24 + hours, reads their summary, description and label history in bulk and, + where an issue carries an agent's hand-off or declined label, its + comments. + It adds the agent's queued label when, since the driver last recorded an + outcome for that agent on the issue, a person opened or edited the issue + (for an agent that starts on open or edit), posted or edited a comment + with one of the agent's commands, or added one of its labels again. For + an automatic trigger the driver's own removal of the queued label, read + from the label history, counts as a recorded outcome, so an open or + edit that was examined and not dispatched is not staged again. The + event must itself fall inside the 24 hours, and an event that lands + while a cycle is working on the issue must be staged by a later cycle: a + repeated hand-off is acceptable there and a lost event is not. Staging + hands nothing to an agent, so load cannot delay it. The 24 hours is + today's backfill window, kept so that an upgrade or a first install + stages what the current driver would have processed. One cycle reads at + most the 500 most recently changed issues in this pass and logs a + warning at the cap, so it misses an event only when more than 500 + issues change between two cycles. The cap is an initial value to revisit + with the first deployment that reaches it. +5. **Two lines, each oldest first.** Each cycle searches for two sets of + waiting issues, both inside the repository's query with its sort clause + removed and both ordered by creation time ascending. The first line is + issues with no outcome label for the agent they wait for: first requests + and newly opened issues. The second line is issues that carry an outcome + label and are queued again: repeated requests and edits. Jira's search + cannot select by permission, so the driver then asks Jira in bulk which + of those issues its account may edit and ignores the rest: an issue it + cannot label can be neither handed off nor declined. It asks per issue, + because a project can grant edit rights issue by issue and a + project-level answer then says yes where the issue says no. The driver + hands N issues to agents per cycle. One slot in every five, rounded + down and at least one when N is two or more, is reserved for the second + line; with N of one, a cycle serves the second line first one time in + five, chosen at random. A slot one line does not use goes to the other. + The ratio is an initial value to revisit with the first deployments. An + issue that is examined and not + handed off delays the ones behind it within the cycle and does not use a + slot. A cycle stops examining after five minutes, hands off what it has + and logs a warning; the next cycle searches again and continues with + what is left. Issues the account cannot edit are dropped before + examination and use none of that time. An issue that is still waiting + after it was examined, because its lock was held or a read failed in a + way a retry may fix, is skipped for the rest of the cycle and logged. An + issue returns to the + first line only when someone removes an outcome label, which item 6 + authorizes, so an edit or a repeated request on an old issue cannot move + ahead of a first request on a newer one. +6. **Pickup rebuilds the real events.** Under the existing lock the driver + reads the issue's labels, comments and history directly, skips an issue + whose labels no longer make it wait (Jira's search can lag behind a + label the driver has just written), and builds, for each agent the + issue is waiting for, every request the driver has not yet recorded an + outcome for, each with the actor from Jira's record: who added the + label; who wrote or last edited the command comment; who opened or + edited the issue. The actor is always the author of the content the + event carries. A label that was already on the issue when it was created + is a request by the issue's creator, the Jira field that nobody can + edit, and is authorized through the lists or project roles as a command + is, never through the Edit Issues rule for labels + ([ADR 0153](0153-authorize-jira-poll-actors-without-project-administration.md)), + because creating an issue does not require Edit Issues. The same holds + for a queued label present at creation and for a label added before the + issue moved into the project. A queued label added by anyone but the + driver's own account is that person's label request. Removing a + hand-off or declined label makes the issue's earlier requests wait + again; the driver serves them only when the person who removed the + label would be allowed to make the same request, and each still runs as + its own author. A label change made by the driver's own account is + never a request and never makes earlier requests wait again. Every + event passes bot filtering, authorization and the trigger rule as today. + The dispatch gate applies these rules, not the driver + ([ADR 0063](0063-polling-based-work-discovery.md) keeps authorization + out of input drivers): the driver marks an event whose label was not + added by an edit in the project, the gate applies the Edit Issues rule + only to an unmarked label event, and the person who removed a label is + put to the same gate. The driver dispatches the newest event that + passes, at most one per agent per pickup. The search finds candidates + and authorizes nothing. +7. **The outcome is written as a label.** When a dispatch is written the + driver adds the agent's hand-off label and removes its queued label, at the + point where the checkpoint is committed today, so a failed write repeats + a hand-off and fails the cycle visibly and never loses a request. Every + other outcome is written as soon as its issue has been examined, so a + cycle that is cut short still shortens the queue. An + issue the driver cannot label is never handed to an agent: the bulk + check enforces that for a missing permission, and the implementation + must show it holds where a workflow blocks edits. When none of an + agent's requests on the issue can be dispatched (the text is not a + command, the actor is a bot or lacks permission, the rule is false, or + the issue cannot be read, or its event validated or evaluated, for a + reason a retry will not fix) the driver adds the declined label, and + comments with the reason only when it refused a request from a person. + A cycle in which every event fails validation or evaluation fails as it + does today and declines nothing, because that points to the + configuration and not to the requests. An automatic trigger that is not + dispatched only loses its queued label. An outcome label records what + happened to the requests seen so far and does not close the issue to + later ones: a new command or a label added again is staged as item 4 + describes. +8. **The agent's own comment is the receipt.** A request that is followed + on the issue by a result or run-status comment from that agent has been + acted on: the driver records the hand-off label and does not dispatch. This + is what lets the queue switch on by default, with no setting and, for a + repository whose trigger rules the driver can read, no operator action. + On the first cycles every old request looks unhandled, + because the labels are new; the ones an agent answered are recognized + and skipped, and any other runs, however old, because a label or command + that was never acted on is still a request. The old checkpoint is + neither read nor written. The rule stays in force afterwards, so a + hand-off whose label write failed is not repeated once the agent has + answered. +9. **One per-cycle setting.** `tracker.jira.poll.max_issues_per_cycle` + sets N, the issues handed to agents (default 5, from 1 to 50). It lives + in `.fullsend/config.yaml`, the only source of Jira poll settings since + [#9077](https://github.com/fullsend-ai/fullsend/issues/9077). The + five-minute limit on examining is fixed and is not a setting. It fits + the managed poll job, which runs every five minutes and is stopped after + 15 by default, and it bounds the load one cycle puts on Jira. An + examined issue costs about seven calls, five of them the lock protocol + with its pause of 0.5 to 1.5 seconds, plus a label write and at most one + comment when it is declined. The staging pass adds its bulk reads and + one comment listing for each recently changed issue that carries an + outcome label. Both values are initial ones to revisit with + measurements from the first deployments. +10. **A cycle can be previewed.** `fullsend poll` gains a preview option + that reports what a cycle would stage, hand off and decline, and why, + and writes nothing to Jira and dispatches nothing. It replaces the + guide's dry-run tip, which today still advances checkpoints. + +## Forge scope + +Applies to the `jira-poll` input driver on both of its targets: GitHub, +where the managed workflow consumes the dispatch file, and GitLab, where +the driver starts the agent pipelines directly. The GitLab-native +cron poller ([ADR 0067](0067-gitlab-cron-polling-event-dispatch.md)) and +webhook fast-path +([ADR 0125](0125-gitlab-hybrid-webhook-poller-dispatch.md)) have their own +discovery and are unaffected. Forgejo has no Jira poll target. + +## Consequences + +- Under sustained load the backlog grows and every first request is still + reached, in creation order, because nothing enters the first line ahead + of it: it waits for the issues ahead of it divided by its share of N per + cycle. A repeated request or an edit waits in the second line, which has + a reserved share and no bound while such events on older issues arrive + faster than that share. +- The poller writes labels on Jira issues by default, where today it + writes none and the runner's `tracker.jira.run_label` is opt-in. The + queue is visible in Jira as a result: each label can be searched and + shown on a board. To ask again a person repeats the command or adds the + label again, as today, or removes the outcome label. The hand-off label + records that a dispatch was written, not that a run started: a request + whose dispatch fails downstream is recovered by asking again, as today. +- A new agent needs no change to the driver. The `cve` agent proposed in + [#9309](https://github.com/fullsend-ai/fullsend/pull/9309), for example, + would be queued on the label and the command its trigger rule names, and + its hand-offs recorded as `ai-cve-agent`. A request whose actor is an + automation account is still declined, as such events are ignored today; + [#9389](https://github.com/fullsend-ai/fullsend/issues/9389) proposes + letting a label added by a bot start an agent. +- The comment search matches text, so an issue that only mentions a command + is examined once and gets the declined label. A project that discusses + fullsend itself sees the most of this. +- Labels are shared by every repository that polls a project. An issue + usually describes a change to one codebase, so repositories that share a + project select their own issues, for example by component or by a field + naming the repository, as the + [guide](../guides/user/jira-integration.md#multi-repo-polling) already + recommends. An issue that two repositories both match is handled by + whichever reaches it first, or by both when their cycles overlap, since + the lock is per repository. Today each handles it independently, which + the guide describes as intentional, so that section is rewritten. + Some deployment may want every repository to act on one issue, for + example a project of product-wide mandates; that is out of scope until + one asks for it. The likely form is an optional suffix on the label + names, set once per repository, so that each repository reads and writes + only its own labels, as the lock and checkpoint properties are named per + repository today. A suffix the repository chooses, not one derived from + its name, keeps the labels valid when the repository is renamed. +- Anyone with Edit Issues can write these labels, as they can write the + checkpoint today. Adding a hand-off or declined label hides the requests made + so far, visibly and reversibly, and not a later one. Removing one makes + those requests wait again; they run only if the remover could make them, + and as their own authors. The trust requirement on Edit Issues is + unchanged. An agent's result writer must refuse to add or remove any + agent's three labels, as the triage writer refuses the labels that steer + triage today, so that an agent acting on issue text cannot hide a + request. That change is in the agents repository and the queue does not + wait for it: until it lands, such an agent can hide or delay requests on + the one issue it runs on, and can start nothing. +- The queue ignores every issue the poller's account cannot edit, and logs + how many each cycle. A poller that can read a project and not edit it + finds requests and acts on none of them, which the guide must state + beside the required permissions. +- A poll query with a rolling time limit, such as "updated in the last + day", brings expiry back for that repository, because the queue applies + the query as written. Nothing rejects such a clause, since a repository + may want one; the default query has none, and the guide must say what it + does and tell teams to remove one left over from the old driver. A fixed + start date on `created` expires nothing newer than it, and is the way to + keep older requests out of the queue. +- `tracker.jira.run_label` keeps its meaning: one label the runner adds on + every agent's run. A value equal to one of an enabled agent's three + labels is refused with an error, because the runner would then mark + requests that agent never handled. +- A request on an issue with no outcome label never expires. Automatic + triggers and repeated requests are staged within 24 hours, so a poller + outage longer than that loses the ones from the gap, where today any + trigger is lost when it is not drawn within 24 hours. Repeating the + request recovers any of them. +- An upgrade or a first install runs every label and command in the poll + query that no agent has answered and that passes authorization, oldest + first and N per cycle. A start date in the query limits that, and the + preview shows it beforehand. Two smaller effects follow an upgrade once. + A request that an agent acted on before agents wrote to the Jira issue + ([agents#1843](https://github.com/fullsend-ai/agents/pull/1843)) has no + comment to recognize it by and runs once more. An old command from a + person who was not allowed to give it, which the old driver ignored + silently, is refused with a comment however old it is. +- An upgrade stops the poller, with an error, for a repository whose + trigger rule the driver cannot read or which reacts to closed or reopened + Jira issues. No shipped agent is affected. One cycle dispatches at most N + issues times the number of agents. +- Going back to the previous release works. The old driver ignores the + labels and resumes from checkpoints that have not moved since the + upgrade, so it applies its 24-hour floor: it skips older activity and may + repeat hand-offs from the last day. The labels stay on the issues and do + nothing. A repository that set `max_issues_per_cycle` removes it first, + because the previous release rejects keys it does not know under + `tracker.jira.poll`. +- The rule reader is one package used by `fullsend lint` and + `fullsend poll`. `internal/jirapoll` loses the random pick, the + checkpoint and the backfill window; the Jira client gains label removal, + the bulk history read and the bulk permission check. The + [Jira integration guide](../guides/user/jira-integration.md), the + [config reference](../reference/config-reference.md), the normative + [`jira-poll` adapter](../normative/normalized-event/v1/jira-poll-adapter.md) + and the CLI and trigger references are updated to match. diff --git a/docs/ADRs/0160-spend-jira-poll-slots-only-on-candidates-with-new-activity.md b/docs/ADRs/0160-spend-jira-poll-slots-only-on-candidates-with-new-activity.md deleted file mode 100644 index 8e2ba89d4c..0000000000 --- a/docs/ADRs/0160-spend-jira-poll-slots-only-on-candidates-with-new-activity.md +++ /dev/null @@ -1,279 +0,0 @@ ---- -title: "160. Spend Jira poll slots only on candidates with new activity" -status: Accepted -relates_to: - - agent-infrastructure - - agent-architecture - - security-threat-model -topics: - - polling - - jira - - dispatch - - scheduling - - configuration ---- - -# 160. Spend Jira poll slots only on candidates with new activity - -Date: 2026-11-06 - -## Status - -Accepted - -Filters the candidate pool to issues with activity newer than their -checkpoint before the random pick, advances the checkpoint to at least the -issue's `updated` value, and makes N and M configurable. - -Refines the candidate selection step of -[ADR 0063](0063-polling-based-work-discovery.md). The lock protocol, -change detection, and authorization path of ADR 0063 and -[ADR 0153](0153-authorize-jira-poll-actors-without-project-administration.md) -are unchanged; the checkpoint rule gains one clause, so that the checkpoint -also advances to at least the issue's `updated` value. - -## Context - -[ADR 0063](0063-polling-based-work-discovery.md) defines how the `jira-poll` -input driver chooses work each cycle: the configured JQL returns up to M -candidate issues (default 50), the driver drops the ones another poller has -locked, picks N of the rest at random (default 5), and processes only those. -The small N was chosen to reduce contention among concurrent pollers, the -random pick to spread load across them, and the ADR documented that issues -beyond the top M results can be starved. Its configuration sketch promised -per-driver overrides of M and N. As implemented today (verified at fullsend -commit `1ae05959c`, evidence in the pull request description), M and N are -fixed in the driver: no `fullsend poll` flag and no key in -`.fullsend/config.yaml` sets them. The pool is the query result as returned, -so an issue the driver has already handled, with nothing new since its -checkpoint, stays in the pool for as long as the query matches it. Each time -it is picked it spends a slot for nothing, because the driver learns there -is nothing to do only after locking the issue and listing its comments and -changelog. - -A deployment preparing a gradual rollout of the code agent -(opendatahub-io/odh-dashboard, tracked as AISDLC-606) shows the cost. It -polls every 30 minutes with a query that matches issues carrying the -`ready-to-code` label or an `/fs-code` comment, updated within the last 24 -hours. The agent's own status comments bump each issue's `updated` field, so -a handled issue lingers in the pool for a further day. The driver keeps no -memory between cycles, so each cycle is an independent draw: - -| Unlocked candidates | Chance an issue is picked per cycle | Expected wait | One in twenty waits longer than | -|---|---|---|---| -| 5 or fewer | certain | next cycle | next cycle | -| 15 | 1 in 3 | about 90 minutes | about 4 hours | -| 30 | 1 in 6 | about 3 hours | about 8.5 hours | - -Below five candidates the cap is invisible, which is why a small team can -go live one trigger at a time; labelling a batch of issues would hit it at -once. Meanwhile the managed poll workflow's GitHub Actions concurrency group -already serializes cycles for one repository -([guide](../guides/user/jira-integration.md#scheduled-workflow)), so in a -single-poller deployment the contention N was meant to reduce does not -exist and the cap only adds latency. - -Whatever replaces this must keep what ADR 0063 bought: - -- a bounded per-cycle Jira API budget; -- safe overlap of several pollers on one project (several repositories, or - a manual run beside a scheduled one) with locks that have no - compare-and-swap, and the stale-lock reclaim; -- the 24-hour clamp and the untrusted-property stance on `lastCheck`, which - anyone with Edit Issues can rewrite - ([guide security note](../guides/user/jira-integration.md#poll-coordination)); -- fail-closed authorization per - [ADR 0054](0054-require-authorization-on-all-agent-dispatch-paths.md) and - ADR 0153, which selection must never bypass; -- honest documentation of starvation beyond the top M. - -Any selection input an issue editor can influence is attacker-influenced -([security threat model](../problems/security-threat-model.md)). - -This ADR aims to let a single poller serving an active project process every -new trigger within a bounded number of cycles, without weakening any of -those properties. - -## Options - -**A. Make M and N configurable, as ADR 0063 promised.** Raising N to the -pool size restores next-cycle latency. But a raised N raises the cost of -every cycle, quiet ones included: each selected issue costs the lock write, -verify and release round trips, a checkpoint read, and a full comment and -changelog listing, and N bounds how many events one cycle can route (N -times the per-issue event cap, each event dispatching to every harness it -matches). Operators would have to guess a pool size that the agent's own -comments inflate. Necessary, not sufficient on its own. - -**B. Spend slots only on candidates with new activity.** The search result -already carries each candidate's `updated` field. Reading the candidate's -checkpoint beside its lock in the filtering pass, and dropping candidates -whose `updated` is not after the checkpoint, turns the pool into the set of -issues that have something to do. It costs one more property read per -unlocked candidate (at most M per cycle) and nothing else; Jira's search -endpoint documents a parameter that returns issue property values with the -results, which would remove even that. The checkpoint is compared after the -clamps the driver already applies: a value more than two minutes in the -future is treated as unset, a value older than the backfill window is -floored at the window start, and a value inside the window is accepted as -stored. An unset or floored checkpoint makes the issue look active, which -is how today's driver treats every candidate. An accepted one is trusted: -an editor who writes a checkpoint later than an unprocessed trigger hides -that trigger from the filter until the next change to the issue. That is -not a new exposure. Today's change detection reads the same property and -skips the same entries once the issue is picked, so the filter adds no -capability an editor lacks today, and the guide already names Edit Issues -on a polled project as part of the trust boundary. `updated` is maintained -by Jira; an editor can advance it, which is genuine activity, but not turn -it back. - -**C. Prefer the most recently active candidates.** Gives the newest -triggers the best latency, but makes selection a deterministic function of -an editor-influenced field: an editor who keeps touching N issues holds all -N slots and starves the rest indefinitely, where random selection only lets -them dilute other issues' odds. It also discards the property random choice -was chosen for: concurrent pollers that sort identically would all try the -same N issues and race on locks that have no compare-and-swap. Oldest-first -resists the holding attack but aligns concurrent pollers in the same way. -Rejected. - -**D. A rotation or cursor across cycles to reach issues beyond M.** Needs -state that survives process restarts. A resident poller -([ADR 0144](0144-reuse-poll-and-entity-bound-run-processes.md)) could hold -a cursor in memory between cycles, but loses it on every restart, and the -managed GitHub workflow runs one cycle per job. The Jira-side stores are -issue properties (editor-writable and per issue) and project properties -(which need Administer Projects, the permission ADR 0153 removed); the -search API's page tokens are opaque and short-lived; the target repository -is not a store the poller writes. B does not shrink the window: the filter runs on -the rows the search returned, and idle issues still occupy those rows, so -with the default most-recent-first order a pending issue drops out of -reach once M other matching issues have changed after it, over however -many cycles that takes, and a custom order can keep M idle issues above an -unhandled one indefinitely. Deferred; a larger M or a narrower query covers -it today, and fetching further pages when the filter leaves fewer than N -active candidates is a possible later refinement with its own cost -analysis. - -**E. Keep the driver and work around it.** A shorter cron multiplies the -cost of quiet cycles. A narrower query cannot exclude handled issues, -because JQL cannot see entity properties. Rejected. - -## Decision - -We adopt an activity filter on the candidate pool, keep random selection -among the filtered candidates, and make N and M configurable within fixed -bounds, so that a single poller clears every pending trigger inside the -top-M window within a bounded number of cycles while ADR 0063's -coordination protocol and cost bounds stay as they are. - -1. **Pool.** The query result as today, at most M rows, minus locked - issues, minus candidates with no new activity. A candidate is active - when the `updated` value in its search result is after its checkpoint, - read in the same pass as its lock and clamped exactly as the driver - clamps it before change detection, so that the filter and the later - processing never disagree about an issue (comparing the raw stored value - instead would let a forward-dated checkpoint hide the issue). The filter - does not repeat the per-issue clamp WARNING, which would otherwise fire - for every quiet candidate every cycle and bury the signal the guide tells - operators to look for after an outage; it logs one line per cycle - naming the clamped candidates, and the per-issue WARNING stays in - processing for selected issues as today. An unset checkpoint is active, - and so is one that cannot be read or parsed, so the issue goes to - processing and the existing per-issue error path reports it as today - (skipping it, as the lock pass does on a failed read, would let any - editor silently remove an issue from the pool by writing garbage into - its checkpoint). Locked candidates are not read, as today. -2. **Selection.** N candidates at random from the active set, as today. - Random stays because it is the one order concurrent pollers cannot - share and the one an issue editor cannot steer. -3. **Everything after selection is unchanged, except one clause of the - checkpoint commit.** Lock acquisition with jitter and verification, the - checkpoint re-read under the lock, change detection, bot filtering, - authorization, and dispatch run as they do today. The checkpoint commit - advances to at least the `updated` value the search returned for the - issue, read before the fetch and still under the existing safety-margin - cap. Without that clause an issue would never go idle when Jira bumped - `updated` for something that leaves no comment or changelog entry (a - worklog, an attachment, a deleted comment) or stamped it a few - milliseconds after the newest entry; with it, only activity after the - search can move `updated` past the checkpoint. The filter dispatches - nothing; it decides only which issues the existing pipeline looks at. -4. **Configuration.** `tracker.jira.poll.max_issues_per_cycle` sets N - (default 5, from 1 to 50) and `tracker.jira.poll.max_candidates` sets M - (default 50, from N to 500). They live in `.fullsend/config.yaml`, which - has been the only source of Jira poll settings since the poll flags were - removed ([#9077](https://github.com/fullsend-ai/fullsend/issues/9077)), - and where a change goes through the repository's review. There is no - flag. The bounds are initial values. A cycle costs about one search - call per 50 candidates, two property reads (lock and checkpoint) per - unlocked candidate, and about ten calls (lock write, verify and - release, checkpoint read and advance, comment and changelog listings) - per selected issue: roughly 150 calls at the defaults and roughly 1,500 - at the maximums with nothing locked. 50 is one search page, so N never - exceeds M; 500 is ten pages, beyond which the per-candidate reads - dominate the budget, and the search parameter that returns property - values with the results would halve that term. Revisit the bounds when - a deployment needs more. -5. **Defaults are unchanged.** A repository that sets nothing keeps M = 50 - and N = 5 and gains the filter. - -## Forge scope - -Applies to the `jira-poll` input driver on both of its targets: GitHub, -where the managed workflow consumes the dispatch file, and GitLab, where the -driver starts the agent pipelines directly. The GitLab-native cron poller -([ADR 0067](0067-gitlab-cron-polling-event-dispatch.md)) and webhook -fast-path ([ADR 0125](0125-gitlab-hybrid-webhook-poller-dispatch.md)) have -their own discovery and are unaffected. Forgejo has no Jira poll target. - -## Consequences - -- Every processed issue becomes active once more, because the agent's - status comment advances `updated`, so A fresh triggers cost about 2A - slots and clear within 2A divided by N cycles, rounded up. Simulated at - the defaults, thirty fresh triggers are all handled within twelve cycles, - with a mean wait of about five and one in twenty waiting eleven, where - today the mean is six cycles, one in twenty waits seventeen, and there is - no bound. -- Per-cycle Jira cost gains at most M property reads for idle unlocked - candidates and loses about seven calls for every idle issue that would - have been selected; the agent's own comment makes its issue active once - more, costing one slot in a later cycle rather than a slot in every cycle - for a day. -- The config loader rejects unknown keys under `tracker.jira.poll`, so a - repository that sets the new keys while its workflow still pins an older - fullsend fails to load its config and stops polling; the keys are adopted - after the upgrade, and the config reference names the version that - introduced them. -- One cycle routes at most N times the per-issue cap of 100 events: 500 - events at the default N and 5,000 at the maximum. That bounds events, not - dispatches: each event produces one dispatch record per harness it - matches, so the dispatch count is that figure times the number of - matching harnesses, and nothing caps it separately. An operator raising - N accepts the larger event ceiling. -- Overlapping pollers see the same active set and still pick at random - under the unchanged lock protocol; when the active set is N or smaller - they all pick everything, exactly as today when the pool is small. -- A checkpoint an editor deletes, forward-dates past the skew allowance - or rewinds past the backfill window makes the issue active, which is - today's treatment of every candidate. A checkpoint an editor sets inside - the window is accepted and can hide unprocessed activity until the next - change to the issue, exactly as it already does in today's change - detection; the trust requirement on Edit Issues is unchanged. A - checkpoint write that fails after dispatch leaves the issue active and - it is re-examined next cycle, as today. -- `internal/jirapoll` gains the filter in the lock-filtering pass and - `internal/cli/poll.go` passes N and M from the two new config keys, which - `internal/config` validates against the bounds; the implementation must - confirm that entity property writes do not advance `updated` and that - comment edits do, so edit detection keeps working. -- The [Jira integration guide](../guides/user/jira-integration.md) "Poll - coordination" and "Two more scaling limits" sections, and the - [config reference](../reference/config-reference.md), describe the active - set, the two keys and their bounds, the revised per-cycle cost, and the - unchanged top-M starvation case; deployments that keep the defaults - change no configuration. -- Starvation beyond the top M stays documented and unmitigated: the filter - neither widens nor narrows the window, and the clearance bound above - applies only to candidates inside it. diff --git a/docs/architecture.md b/docs/architecture.md index af834fdd77..5ad475b20e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -486,11 +486,16 @@ The existing design principle is that [the repo is the coordinator](problems/age via source-native write-then-verify locks, and feeds the same dispatch pipeline as webhooks ([ADR 0063](ADRs/0063-polling-based-work-discovery.md)). Initial scope is per-repo mode only. -- Jira poll candidate selection spends per-cycle slots only on candidates - whose Jira `updated` is newer than their per-repository checkpoint, picks - at random among them, and reads the per-cycle caps (N, default 5, and M, - default 50) from `tracker.jira.poll` within fixed bounds - ([ADR 0160](ADRs/0160-spend-jira-poll-slots-only-on-candidates-with-new-activity.md)). +- Jira poll work discovery (target state): the driver finds work by + search, oldest first, for issues that carry a request (a label or command + read from an agent's trigger rule, or a queued label the driver adds when + a person opens or edits an issue or repeats a request) and no label + saying the agent handled it. A request on an issue with no outcome label + never expires; automatic triggers and repeated requests are staged within + 24 hours. A label that was not added by an edit in the project is + authorized as a command is. The number of issues handed to agents per + cycle (default 5) is read from `tracker.jira.poll` within fixed bounds + ([ADR 0160](ADRs/0160-queue-jira-work-by-search-so-no-request-expires.md)). - Jira poll actor authorization does not require the poller to administer the Jira project once a repository adds a `jira` provider under `authorization:`. With no `jira` entry, every Jira event resolves through the