Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/guides/dev/behaviour-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2190,4 +2190,17 @@ field. The poller itself treats an issue served without a labels array as
unlabeled — `state.labels` becomes an empty list — so neither shape an issue
arrives in loses events; the unit tests serve each shape directly.

**`jiramock` updated change:** an issue added with `AddIssue` now starts
with `updated` equal to `created`, instead of the time of the call.
`AddCommentFromActorAt` and `AddLabelChangeAt` (and so `AddComment`,
`AddCommentFromActor` and `AddLabelChange`) move it forward to the activity
time, never back; entity property calls leave it alone, as Jira does.
`SetIssueLabels` leaves it alone too and adds no changelog entry, unlike a
label edit in Jira, so use `AddLabelChange` when a label change should count
as activity. The Jira poller skips an issue whose `updated` is not after its
`lastCheck`, so the mock must serve it the way Jira does. This is
deliberately not treated as a breaking change: no function or signature
changed, and a scenario that adds activity after creating the issue sees
`updated` move with it.

Bump the pinned version when behaviour step vocabulary or `pkg/behaviourtest` APIs change.
28 changes: 19 additions & 9 deletions docs/guides/user/jira-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1714,14 +1714,19 @@ matches it. Use `labels: allowlist` if that group is broader than you want.

## Poll coordination

The poller uses Jira entity properties for distributed lock coordination and checkpoint tracking, following a write-then-verify protocol. Each cycle randomly selects up to N (default 5) issues from the candidate set for processing, spreading load across cycles. Two properties are stored on each processed issue:
The poller uses Jira entity properties for distributed lock coordination and checkpoint tracking, following a write-then-verify protocol. Each cycle first drops the candidates with no new activity, then randomly selects up to N (default 5) of the rest for processing, spreading load across cycles. A candidate has new activity when its `updated` time is after its `lastCheck`, clamped as described below; a candidate with no usable `lastCheck` (missing, unreadable, or more than two minutes in the future) or no usable `updated` time counts as new. Two properties are stored on each processed issue:

- **Lock** (`fullsend.poll.{owner}.{repo}.lock`) — prevents concurrent pollers from *detecting changes on* the same issue simultaneously. The lock covers the change-detection window only: it is released when an issue finishes processing, before the dispatch records are written and consumed by the downstream dispatch step, and it is not renewed while an issue is being processed — a cycle that stalls longer than the stale threshold (15 minutes) can have its lock reclaimed by a concurrent poller, which may produce duplicate dispatches. Lock ownership through dispatch scheduling is part of the same tracked follow-up as dispatch confirmation.
- **Last check** (`fullsend.poll.{owner}.{repo}.lastCheck`) — tracks the timestamp of the most recent processed change. Only changes newer than this timestamp trigger agent dispatch.
- **Last check** (`fullsend.poll.{owner}.{repo}.lastCheck`) — tracks the timestamp of the most recent processed change. Only changes newer than this timestamp trigger agent dispatch. After each look at an issue it also advances to the issue's `updated` time when that is later, so an issue with nothing new since is skipped the next cycle.
Comment thread
dhshah13 marked this conversation as resolved.
Resolved
If `updated` is less than 10 seconds before the look, the checkpoint stops
10 seconds before the look (the safety margin), so the issue stays active.
The first look that starts 10 or more seconds after `updated`, normally the
next one, can dispatch a change inside the margin again and then moves the
checkpoint to `updated`; after that the issue is skipped.

These properties are namespaced per target repo, so multiple repos can poll the same Jira project without interference. GitLab targets use a separate `fullsend.poll.gitlab.*` namespace that also includes the GitLab instance (see [GitLab runtime](#gitlab-runtime)). The properties are visible in Jira's issue properties API but do not appear in the issue UI.

> **Security note — coordination state is tamperable by any project editor.** Writing an issue entity property requires only Jira's **Edit Issues** permission, which is typically far broader than the project roles this driver maps to `write`. That means anyone who can edit a polled issue can write its `lastCheck` and lock properties. The driver treats both as untrusted: a `lastCheck` dated in the future is ignored (it would otherwise suppress all detection on the issue), and one rewound before the backfill window is clamped to the window's start, so a rewind can replay at most one backfill window of history rather than the whole issue — but within that window it can still re-surface old comments. Per-issue dispatch is capped to bound the blast radius. Even so, **treat Edit-Issues on a polled project as part of the trust boundary**: prefer scoping the poll to a project whose editors you trust, and remember that the authorization gate keys on the *comment's* Jira role, so who can edit issues (and comments) matters as much as who holds `write`.
> **Security note — coordination state is tamperable by any project editor.** Writing an issue entity property requires only Jira's **Edit Issues** permission, which is typically far broader than the project roles this driver maps to `write`. That means anyone who can edit a polled issue can write its `lastCheck` and lock properties. The driver treats both as untrusted: a `lastCheck` dated more than two minutes in the future is ignored (it would otherwise suppress all detection on the issue), and one rewound before the backfill window is clamped to the window's start, so a rewind can replay at most one backfill window of history rather than the whole issue — but within that window it can still re-surface old comments. Per-issue dispatch is capped to bound the blast radius. Even so, **treat Edit-Issues on a polled project as part of the trust boundary**: prefer scoping the poll to a project whose editors you trust, and remember that the authorization gate keys on the *comment's* Jira role, so who can edit issues (and comments) matters as much as who holds `write`.

Three edge cases of checkpoint tracking are worth knowing:

Expand All @@ -1733,9 +1738,14 @@ Three edge cases of checkpoint tracking are worth knowing:
is a security control (it prevents a rewound `lastCheck` from replaying an
issue's entire history), but it cannot distinguish a malicious rewind from a
legitimate long stop. Any Jira activity between the true checkpoint and the
clamped value is silently skipped. The cycle succeeds, the only evidence is
a `WARNING: lastCheck for <KEY> ("<timestamp>") predates the backfill window; clamping to <floor>`
line in the run log — treat this as an alert, not noise. Because detection
clamped value is silently skipped. The cycle succeeds, and the only evidence
is in the run log: an issue that is selected logs
`WARNING: lastCheck for <KEY> ("<timestamp>") predates the backfill window; clamping to <floor>`,
and an issue that is skipped, because its `updated` time is more than a second
after its `lastCheck` but still older than the window, is named in one
`WARNING: activity filter: …` line per cycle that contains the same phrase
`predates the backfill window`. Activity on such an issue may have been
missed. Treat either line as an alert, not noise. Because detection
is checkpoint-based, ordinary cron jitter and occasional skipped ticks are
harmless (schedule accuracy affects latency, not correctness); the guarantee
simply ends at 24 hours. A realistic trigger: **GitHub disables scheduled
Expand All @@ -1748,11 +1758,11 @@ Three edge cases of checkpoint tracking are worth knowing:
independently of GitHub Actions avoids the auto-disable risk.
- **Comment edits count as new activity, and are attributed to the editor.** The poller filters comments on the later of their created and updated timestamps, so editing a comment (for example, adding a slash command to an old comment) is detected on the next cycle. Jira bumps a comment's updated timestamp on modifications other than body edits too (such as visibility changes), and any such bump counts as activity. The flip side: modifying a comment whose slash command was already dispatched makes it look new again and can re-dispatch it. An edit-detected comment is attributed to the account that last modified it (Jira's `updateAuthor`), not the original author — so a user who edits someone else's comment to inject a command is authorized on *their own* role, not the original author's.

Because each cron run is a fresh process, per-cycle Jira API cost is worth sizing for: a cycle loads the project's role structure (a role-list call plus one detail call per role) only when some selected issue has an event that needs project-role resolution (no `jira` entry, `labels: project_roles`, or a slash command when the `jira` entry sets no lists), then, in such a cycle, makes one additional call for each distinct actor below the highest role priority the first time they're seen that cycle, to check their group memberships (cached per actor for the rest of the cycle, but not across cron runs). Cost scales with the number of distinct commenting actors per cycle rather than the size of the groups backing a role.
Because each cron run is a fresh process, per-cycle Jira API cost is worth sizing for: a cycle loads the project's role structure (a role-list call plus one detail call per role) only when some selected issue has an event that needs project-role resolution (no `jira` entry, `labels: project_roles`, or a slash command when the `jira` entry sets no lists), then, in such a cycle, makes one additional call for each distinct actor below the highest role priority the first time they're seen that cycle, to check their group memberships (cached per actor for the rest of the cycle, but not across cron runs). Cost scales with the number of distinct commenting actors per cycle rather than the size of the groups backing a role. The activity filter adds one property read per unlocked candidate (at most M per cycle); a candidate with nothing new costs no lock write, no comment or changelog listing and no `lastCheck` write.

Two more scaling limits:

- **Issues beyond the top M candidates can be starved.** Each cycle's JQL search returns at most M (default 50) candidates, ordered by `updated DESC`. If a project has more than M issues with in-scope activity at once, whichever issues aren't in that top-M window this cycle are simply never selected — there's no rotation across cycles to eventually reach them. This is expected to self-resolve for most projects (an issue with new activity moves toward the front of `updated DESC` on its own), but a project that consistently has more than M simultaneously-active issues will have some starved indefinitely. Narrow the default `--jql` (e.g. scope to a label or a subset of issue types) if this applies to you.
- **Issues beyond the top M candidates can be starved.** Each cycle's JQL search returns at most M (default 50) candidates, ordered by `updated DESC`. If a project has more than M issues with in-scope activity at once, whichever issues aren't in that top-M window this cycle are simply never selected — there's no rotation across cycles to eventually reach them. Issues with nothing new still take rows of the top M, because the activity filter runs on the rows the search returned. This is expected to self-resolve for most projects (an issue with new activity moves toward the front of `updated DESC` on its own), but a project that consistently has more than M simultaneously-active issues will have some starved indefinitely. Narrow the default `--jql` (e.g. scope to a label or a subset of issue types) if this applies to you.
- **Comments are re-listed in full, oldest-first, every cycle.** The Jira REST API has no way to filter comments server-side by date, so `ListComments` always paginates from the start of an issue's comment history; the poller then filters client-side by timestamp. For issues with very long comment histories, this means re-fetching (and re-decoding) old comments every cycle just to discard them. Listings are capped at 10,000 entries per issue; an issue beyond that cap has its newest activity invisible to the poller (a WARNING is logged when the cap is hit). Each API response is bounded to 10MB, but the accumulated per-issue comment history is bounded only by the page cap — a per-issue byte budget is a tracked follow-up; against real Jira Cloud (which caps individual comments) the realistic worst case is tens of MB per issue.
- **Sustained Jira errors can stall a cycle.** Each Jira call retries up to 5 times with exponential backoff, honoring `Retry-After` (capped at 5 minutes). Under a sustained 429 or outage a single cycle can therefore run long; the workflow's concurrency group queues subsequent cron runs rather than stacking them, and a failed cycle simply retries from its checkpoints on the next run.

Expand Down Expand Up @@ -1825,7 +1835,7 @@ However, more pollers against the same Jira project means more API calls per cyc
| `Jira polling is disabled` and no dispatches | `tracker.jira.poll.enabled` is not `true` | Set `tracker.jira.poll.enabled: true` |
| Duplicate dispatches | `lastCheck` was cleared or missing | The poller treats a missing `lastCheck` as "never polled" and processes all recent changes. This is self-correcting — the next cycle advances `lastCheck` past the duplicates |
| Old comment or label change on a newly polled issue never dispatches | Activity predates the first-poll backfill window | On an issue's first poll, activity older than the 24-hour backfill window is permanently skipped (the checkpoint advances past it). To pick up older activity, scope the initial `tracker.jira.poll.query` to recently updated issues and widen it gradually, or have someone re-trigger by commenting again |
| Activity during a long outage or disabled workflow is missing after resume | Poller gap exceeded the 24-hour backfill window | The same 24-hour window that bounds a first poll also bounds resumption — any `lastCheck` older than 24 hours is clamped forward. Check the run log for `predates the backfill window` — if present, events in the gap are permanently lost. Have affected users re-trigger by commenting again. See [Poll coordination](#poll-coordination) |
| Activity during a long outage or disabled workflow is missing after resume | Poller gap exceeded the 24-hour backfill window | The same 24-hour window that bounds a first poll also bounds resumption — any `lastCheck` older than 24 hours is clamped forward. Check the run log for `predates the backfill window` — if present, events in the gap may have been permanently lost. Have affected users re-trigger by commenting again. See [Poll coordination](#poll-coordination) |
| GitLab Jira dispatch fails with `does not accept Jira work items` | The project's scaffold predates Jira dispatch | Rerun `fullsend repos install` for the project and merge the scaffold update. See [GitLab runtime](#gitlab-runtime) |
| `WARNING: skipping event … for issue …: normalized event: …` in the poll log | The poller could not map the Jira event to a valid normalized event (for example a non-numeric issue id, or an author with neither an `accountId` nor a `name`) | The event is never dispatched: the checkpoint advances past it (for a GitLab target, once the issue's other dispatches succeed; until then each retry logs the warning again, see [Failures](#failures)) — unless *every* event of the cycle was dropped (failed validation or failed matching), in which case the poll fails and no checkpoint advances (see the next two rows). For an author with neither `accountId` nor `name`, a comment from another account maps cleanly and re-triggers. A non-numeric issue id belongs to the issue, so no new activity on it maps; report it to fullsend with the log line, which names the raw id Jira sent (an id the Jira UI does not show). An issue served without a `labels` field is treated as unlabeled, not skipped |
| The poll fails with `all N events this cycle failed normalized-event validation` | Every event of the cycle was dropped for failing normalized-event validation — either a systemic cause (a Jira response-shape change, or an adapter gap) or the cycle's one event being bad: the guard counts events, not issues, so a single bad event in a one-event cycle is "every event" | No checkpoint was advanced, so the events are retried next cycle — and, while the dropped events are the cycle's only activity, every cycle: the red runs repeat until the events age past the first-poll backfill floor (24h by default) or another selected issue produces a valid event. Read the per-event `WARNING: skipping event …` lines above the error for the cause; if they name one cause for every issue, the Jira response shape may have changed — report it to fullsend with the log lines |
Expand Down
12 changes: 8 additions & 4 deletions internal/forge/jira/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,14 @@ const maxSearchPages = 200
//
// This endpoint is eventually consistent: Atlassian documents that recent
// updates might not be immediately visible in results. For the poller that
// only means an issue can appear (or re-sort under ORDER BY updated) a
// cycle late — per-issue checkpoints come from the strongly-consistent
// direct comment/changelog GETs, never from search results, so no events
// are lost. Do not "fix" ordering assumptions by trusting search freshness.
// means an issue can appear, re-sort under ORDER BY updated, or show a
// stale updated value a cycle late. The poller skips an issue whose row's
// updated is not after its checkpoint (ADR 0160), so a stale row only
// delays the issue to a later cycle. A look raises the checkpoint to the
// row's updated value only after the direct comment/changelog GETs, and
// relies on them being at least as fresh as the row; if they lag it, an
// entry can be skipped. Do not "fix" ordering assumptions by trusting
// search freshness.
func (c *LiveClient) SearchIssues(ctx context.Context, jql string, limit int) ([]Issue, error) {
var all []Issue
var nextPageToken string
Expand Down
9 changes: 9 additions & 0 deletions internal/jirapoll/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ func (p *Poller) detectChanges(ctx context.Context, issue jira.Issue, lastCheck
}
}

// The checkpoint also reaches the issue's own updated value from the
// search row (ADR 0160, Decision item 3). Jira stamps updated a
// little after the newest entry; without this an issue whose updated
// is after every entry would pass the activity filter every cycle.
// The safety-margin cap below still applies.
if updated, err := parseJiraTimestamp(issue.Fields.Updated); err == nil && updated.After(maxSeen) {
maxSeen = updated
Comment thread
dhshah13 marked this conversation as resolved.
Resolved
}

if safeCeiling := fetchStart.Add(-changeDetectionSafetyMargin); maxSeen.After(safeCeiling) {
maxSeen = safeCeiling
}
Expand Down
Loading
Loading