Skip to content

refactor(#9883): let the Jira poller take a set of project keys - #9887

Merged
csoceanu merged 2 commits into
mainfrom
agent/9883-jira-poller-multi-project
Nov 26, 2026
Merged

csoceanu merged 2 commits into
mainfrom
agent/9883-jira-poller-multi-project

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

Changes the Jira poller internals (internal/jirapoll) to take an explicit, non-empty set of Jira project keys instead of one project. The existing tracker.jira.project path passes its project as a one-item set and sends the same JQL as before. No user-facing configuration field is added or changed; #9884 can later supply several projects.

Related Issue

Part of #9677. Implements #9883.

Changes

  • internal/jirapoll/types.go: Options.JiraProjects []string replaces Options.JiraProject. Options.JQL now means the predicate before scoping. When it is empty, the poller uses config.DefaultJiraPollQuery.
  • internal/jirapoll/poller.go
    • Before the auth preflight, Run calls searchJQL. It checks the project set (non-empty, every key valid per config.ValidJiraProjectKey, no duplicates) and the predicate's parentheses. An empty or malformed set fails with zero Jira requests.
    • searchJQL scopes the predicate to exactly the set with config.ScopeJQLToProjects, putting the scoping clause outside the predicate's parentheses and keeping a trailing ORDER BY last. A predicate with its own project or OR clause cannot widen the search.
    • The set is searched once, so M, N and the client's pagination cap apply across the whole set. uniqueIssues drops repeated rows of the same issue (by ID, or by key when Jira serves no ID), so each issue is processed, locked, checkpointed and dispatched once per cycle.
    • The single roster fields (roleMembership, roleGroups, roleGroupsChecked, rolesLoaded) become rosters map[string]*projectRoster.
  • internal/jirapoll/auth.go, convert.go
    • Each issue's actor resolves through the roster of that issue's project. Rosters are loaded lazily, once per project per cycle.
    • A project outside the set never gets a roster, so its actors fail closed to external, as before.
    • A roster load failure for any project is still a roleLoadError that fails the whole cycle with no checkpoint advanced. The error now names that project.
  • internal/config/issue_targets.go: adds ScopeJQLToProjects. ScopeJQLToProject now calls it, so its output is unchanged. Exports ValidJiraProjectKey and JQLParensBalanced (renamed from jqlParensBalanced) so the poller checks keys and predicates exactly as the config gate does.
  • internal/cli/poll.go: jiraPollOptions passes JiraProjects: []string{tracker.jira.project} and the predicate before scoping (PollQuery()). The settings field jql is renamed to query.
  • Callers and tests: pkg/behaviourtest/steps and the existing jirapoll/cli tests now use JiraProjects; gofmt realignment makes up most of the line count.

Behaviour notes

  • Exact JQL is unchanged for the production (CLI) path. For example, project = "PROJ" AND (labels = "fullsend") ORDER BY updated DESC.
  • Default JQL for direct jirapoll.New callers changes slightly. Callers that set no JQL (tests, behaviour steps) used the poller's hard-coded project = "PROJ" AND statusCategory != Done ORDER BY updated DESC. They now get the config default, which differs only by parentheses: project = "PROJ" AND (statusCategory != Done) ORDER BY updated DESC.
  • Project-key validation now matches the config gate. The poller's old validProjectKey (2–10 letters and digits) only ran when no JQL was set, so it never ran on the CLI path. It is replaced by the config rule (^[A-Z][A-Z0-9_]*$), so every key that tracker.jira.project accepts keeps working.
  • "JQL-only mode" (no project key, every actor external) is gone. It was unreachable from the CLI because tracker.jira.project is required. An empty set is now an error, as the acceptance criteria require.
  • ADR 0085 is unaffected. Still one poller per repository: one Run, one search, one lock/checkpoint namespace per target repo.

Overlap with the open ADR 0085 / 0160 PR chain

This PR is based on current main and is not stacked on that chain (#9758 → #9852 → #9853 → #9854 → #9855 → #9876 → #9878 / #9879). Expected conflicts, all mechanical:

Testing

New internal/jirapoll/multi_project_test.go:

  • TestSearchJQL, TestSearchJQL_OneProjectMatchesConfigScoping: one-project JQL is identical to config.ScopeJQLToProject. Also covers two-project project in (...) scoping, a predicate with its own project/OR clause, and ORDER BY kept last.
  • TestSearchJQL_Rejects, TestRun_InvalidScopeMakesNoJiraRequest: empty, nil, malformed, quote-injection and duplicate keys, and unbalanced predicates all fail. The client panics on any call, which proves zero Jira requests.
  • TestRun_TwoProjectsShareOneSearch: one search with limit M across the set, and at most N issues processed across it.
  • TestRun_MixedProjectRoleResolution: each issue resolves through its own project's roster, which loads once per project.
  • TestRun_ProjectRosterFailureFailsClosedThenRetries: a roster failure for one project fails the cycle with no checkpoint advanced; the next cycle retries and dispatches.
  • TestRun_DuplicateCanonicalIssueProcessedOnce, TestUniqueIssues: duplicate rows, by ID and after a move, are processed once.
  • In auth_test.go: TestEnsureRoleStructure_ProjectOutsideSet and TestEnsureRoleStructure_LoadsOncePerProject.
  • In internal/config: TestScopeJQLToProjects and TestValidJiraProjectKey.
  • In internal/cli: the config tests assert the one-item set and that the poller's scoping reproduces the old PollJQL output.

Commands run:

go build ./... && go vet ./...
go test -count=1 -race ./internal/jirapoll/ ./internal/config/
go test -count=1 ./internal/cli/ ./pkg/behaviourtest/...

All pass. Every new or changed production function is 93–100% covered except searchCandidates, at 75% (its search-error return is not hit).

  • make lint passes: not run as a whole. pre-commit could not fetch its hook repositories (no network access in the sandbox). gofmt, go vet ./..., lint-broken-symlinks and git diff --check were run directly and pass, and gitleaks was covered by scan-secrets. semgrep-scan skipped because its pinned ruleset could not be downloaded, so CI's semgrep job is the first to scan this change.
  • Tests added/updated for new or modified logic

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO) — human and human-directed agent sessions only (autonomous agent commit; exempt)
  • I wrote this contribution myself and can explain all changes in it (written by the fullsend code agent)

🤖 Generated with Claude Code


Closes #9883

Post-script verification

  • Branch is not main/master (agent/9883-jira-poller-multi-project)
  • Secret scan passed (gitleaks — d9d65b1daec2fb82763f1babe0e55f3c050e3297..HEAD)
  • PR body secret scan passed (gitleaks — no-git)
  • Final PR description secret scan passed (gitleaks — no-git)

The poller assumed one Jira project: Options.JiraProject, one role
roster per cycle, and a search JQL the CLI scoped beforehand. This
change replaces that with an explicit project set. The config shape
does not change: tracker.jira.project is passed as a one-item set.

- Options.JiraProjects replaces JiraProject. Options.JQL is now the
  predicate before scoping. Run checks the set (non-empty, valid
  keys, no duplicates) and the predicate's parentheses before the
  auth preflight, so a bad scope makes no Jira request.
- The poller scopes every search itself with
  config.ScopeJQLToProjects, keeping a trailing ORDER BY last.
  A one-item set gives exactly the JQL PollJQL built before, so the
  CLI path sends unchanged JQL. Two or more projects use
  `project in (...)`.
- Role rosters are kept per project and loaded lazily. Each issue
  resolves its actor through its own project's roster. A load
  failure for any project still fails the cycle with no checkpoint
  advanced.
- The set is searched once, so M, N and pagination apply across it.
  Repeated rows of the same issue (same ID, or same key when the ID
  is missing) are dropped before processing.
- Key validation uses config.ValidJiraProjectKey, the same rule
  tracker.jira.project uses. The poller's own default predicate is
  now config.DefaultJiraPollQuery.

Note: pre-commit could not fetch its hook repos (no network). gofmt,
go vet ./..., lint-broken-symlinks and a whitespace check passed
when run directly. semgrep-scan skipped because its ruleset could
not be downloaded. gitleaks was covered by scan-secrets.

Closes #9883

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fullsend-ai-coder
fullsend-ai-coder Bot requested a review from a team as a code owner November 26, 2026 10:49
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Nov 26, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:53 AM UTC · Completed 11:04 AM UTC

Commit: cf628ed · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.79

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Nov 26, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Moderate risk due to large change size refactoring Jira poller internals without a feature flag, mitigated by a high test ratio (57%), zero protected path modifications, and complete alignment with linked issue acceptance criteria.

Previous run

Risk Assessment: moderate (2/5)

Details

Moderate risk due to large change size refactoring Jira poller internals without a feature flag, mitigated by a high test ratio (60%), zero protected path modifications, and complete alignment with linked issue acceptance criteria.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Review

Findings

Low

  • [design-smell] internal/jirapoll/poller.go:17 — internal/jirapoll imports internal/config for the JQL scoping helpers (ScopeJQLToProjects, JQLParensBalanced) and project-key validation (ValidJiraProjectKey, DefaultJiraPollQuery), so a lower-level driver package now depends on the configuration package. The PR description discloses this as an interim step until the helpers move to a neutral package (internal/jql, tracked in the open feat(jirapoll)!: search the whole backfill window, oldest change first #9878/feat(jirapoll): limit one issue to 250 records and 768 KB per cycle #9879 chain). Advisory, not blocking.
    Remediation: Move the JQL scoping helpers and key validation into a neutral shared package so internal/jirapoll does not import internal/config.

Earlier findings

  • docs/normative/normalized-event/v1/jira-poll-adapter.md:38 — stale-doc — resolved. The note now cites validateProjectSet / config.ValidJiraProjectKey instead of the removed searchCandidates key check.
Previous run

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJhcHByb3ZlIiwiZmluZGluZ3MiOlt7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJkZXNpZ24tc21lbGwiLCJmaWxlIjoiaW50ZXJuYWwvamlyYXBvbGwvcG9sbGVyLmdvIiwiaWQiOiJmXzdiMjQ4OWVkNDUwNWFkMzUiLCJsaW5lIjoxNywiYWN0aW9uYWJsZSI6ZmFsc2UsImRpbWVuc2lvbiI6ImludGVudC1jb2hlcmVuY2UifSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJzdGFsZS1kb2MiLCJmaWxlIjoiZG9jcy9ub3JtYXRpdmUvbm9ybWFsaXplZC1ldmVudC92MS9qaXJhLXBvbGwtYWRhcHRlci5tZCIsImlkIjoiZl8zMzYyNzZhNTNjNzBhM2I1IiwibGluZSI6MzgsImFjdGlvbmFibGUiOnRydWUsImRpbWVuc2lvbiI6ImRvY3MtY3VycmVuY3kifV0sImRpc3Bvc2l0aW9ucyI6W3siaWQiOiJmXzMzNjI3NmE1M2M3MGEzYjUiLCJzdGF0dXMiOiJyZXNvbHZlZF9ieV9jaGFuZ2UifSx7ImlkIjoiZl83YjI0ODllZDQ1MDVhZDM1Iiwic3RhdHVzIjoib3BlbiJ9XX0= -->

Review

Findings

Low

  • [design-smell] internal/jirapoll/poller.go:17 — internal/jirapoll imports internal/config for the JQL scoping helpers (ScopeJQLToProjects, JQLParensBalanced) and project-key validation (ValidJiraProjectKey, DefaultJiraPollQuery), so a lower-level driver package now depends on the configuration package. The PR description discloses this as an interim step until the helpers move to a neutral package (internal/jql, tracked in the open feat(jirapoll)!: search the whole backfill window, oldest change first #9878/feat(jirapoll): limit one issue to 250 records and 768 KB per cycle #9879 chain). Advisory, not blocking.
    Remediation: Move the JQL scoping helpers and key validation into a neutral shared package so internal/jirapoll does not import internal/config.

Earlier findings

  • docs/normative/normalized-event/v1/jira-poll-adapter.md:38 — stale-doc — resolved. The note now cites validateProjectSet / config.ValidJiraProjectKey instead of the removed searchCandidates key check.
Previous run (2)

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6InN0YWxlLWRvYyIsImZpbGUiOiJkb2NzL25vcm1hdGl2ZS9ub3JtYWxpemVkLWV2ZW50L3YxL2ppcmEtcG9sbC1hZGFwdGVyLm1kIiwiaWQiOiJmXzMzNjI3NmE1M2M3MGEzYjUiLCJsaW5lIjozOCwiYWN0aW9uYWJsZSI6dHJ1ZSwiZGltZW5zaW9uIjoiZG9jcy1jdXJyZW5jeSJ9LHsic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6ImRlc2lnbi1zbWVsbCIsImZpbGUiOiJpbnRlcm5hbC9qaXJhcG9sbC9wb2xsZXIuZ28iLCJpZCI6ImZfN2IyNDg5ZWQ0NTA1YWQzNSIsImxpbmUiOjE3LCJhY3Rpb25hYmxlIjpmYWxzZSwiZGltZW5zaW9uIjoiaW50ZW50LWNvaGVyZW5jZSJ9XX0= -->

Review

Findings

Low

  • [stale-doc] docs/normative/normalized-event/v1/jira-poll-adapter.md:38 — Lines 38–40 say "The project-key check inside searchCandidates runs only when no JQL is set at all — direct API use such as the behaviour-test step, not the CLI — so it never intercepts these keys." In this PR searchCandidates(ctx, jql string) takes already-scoped JQL and no longer checks project keys; validation moved to validateProjectSet, called from searchJQL on every cycle via config.ValidJiraProjectKey. The PR updated the matching test comment but not this normative doc.
    Remediation: Rewrite lines 38–40 to say the poller's project-set validation (validateProjectSet, via config.ValidJiraProjectKey) runs on every cycle and accepts the same keys as the config gate, so it never intercepts single-character keys. Remove the reference to a check inside searchCandidates.
  • [design-smell] internal/jirapoll/poller.go:17 — internal/jirapoll/poller.go now imports internal/config (ScopeJQLToProjects, ValidJiraProjectKey, JQLParensBalanced, DefaultJiraPollQuery), and Options.JQL in types.go:64 names config.DefaultJiraPollQuery. This contradicts the invariant in internal/jirapoll/types.go (~lines 77–79) that label constants are copied "so jirapoll does not depend on config". The PR body discloses this as an interim step, with feat(jirapoll)!: search the whole backfill window, oldest change first #9878/feat(jirapoll): limit one issue to 250 records and 768 KB per cycle #9879 expected to move the helpers to internal/jql.
    Remediation: When the helpers move to a neutral package (planned internal/jql), drop the config import from jirapoll; if the dependency is to stay, update the invariant comment in types.go.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 11:07 AM UTC · Completed 11:12 AM UTC

Commit: cf628ed · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.33

#9887

Rewrite the stale searchCandidates reference: project-set validation
now runs via validateProjectSet on every cycle.

Not addressed: the config import in internal/jirapoll is a disclosed
interim step until the helpers move to a neutral package.

Addresses #9887

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Fixed the stale normative doc passage. Left the interim jirapoll-to-config import as is, since the reviewer defers it to the planned helper move.

Fixed (1):

  1. stale-doc: normative Jira poll adapter doc still describes a project-key check inside searchCandidates (docs/normative/normalized-event/v1/jira-poll-adapter.md): Rewrote the passage to say the poller's project-set validation (validateProjectSet, via config.ValidJiraProjectKey) runs on every cycle and accepts the same keys as the config gate, so it never intercepts single-character keys.

Disagreed (1):

  1. design-smell: internal/jirapoll now imports internal/config, contradicting the types.go invariant: The reviewer's remediation is deferred: the dependency is a disclosed interim step until the helpers move to a neutral package in the follow-up issues, and the finding is marked non-actionable. Moving the helpers now is out of scope for this PR.

Tests: passed

CI inspections (6):

  1. test (unrelated, failure): The only failing test is a Forgejo agent-source resolution case for an unreachable instance in internal/cli, which this PR's Jira poller changes do not touch. It looks environment or network dependent. Recommend rerunning the job; if it keeps failing, file an issue for the owner of that test.
  2. behaviour-github-emulator (agents) (pending, in_progress): Still running when inspected.
  3. behaviour-github-emulator (passing, success)
  4. forgejo-behaviour (passing, success)
  5. commit-lint (passing, success)
  6. semgrep (passing, success)

Conflict update: skipped; strategy none; forge MERGEABLE; target main

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push

Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🤖 Review · ❌ Terminated · Started 11:18 AM UTC · Ended 11:25 AM UTC

Commit: 1ecce65 · View workflow run →

@github-actions

Copy link
Copy Markdown

Site preview

Preview: https://f3c140ee-site.fullsend-ai.workers.dev

Commit: 1ecce65b771ac66b5a3ed32802aab8f6004821bc

@fullsend-ai-review
fullsend-ai-review Bot dismissed their stale review November 26, 2026 11:24

Superseded by updated review

Comment thread internal/jirapoll/poller.go Resolved
@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Nov 26, 2026
@fullsend-ai-review

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:18 AM UTC · Completed 11:25 AM UTC

Commit: 1ecce65 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.44

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.32143% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/jirapoll/poller.go 94.82% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@csoceanu
csoceanu added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 17d68d0 Nov 26, 2026
74 checks passed
@csoceanu
csoceanu deleted the agent/9883-jira-poller-multi-project branch November 26, 2026 12:31

This branch was successfully deployed

1 active and 1 inactive deployments
site-preview — 1ecce65b Deployed Nov 26, 2026 by github-actions[bot]
forgejo-dev — 1ecce65b Deployed Nov 26, 2026 by fullsend-ai-coder[bot] via forgejo-behaviour #21352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Jira poller internals to accept multiple projects

2 participants