Reduce TaskSpawner GitHub API traffic by decoupling polling from Task events and lazily fetching details
Open
Nobody has claimed this yet.
actor/kelos
kind/feature
priority/critical-urgent
triage-accepted
- Dominant language
- Go
- Stars
- 331
- Forks
- 40
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 70
Description
Summary
TaskSpawner currently generates more GitHub API traffic than necessary. The main causes are:
- Task status/deletion events can trigger a full GitHub rediscovery outside the normal poll interval
- GitHub issue/PR detail endpoints are fetched even when the active source config and templates do not need them
This issue proposes reducing GitHub traffic without changing the public TaskSpawner API.
Goals
- Keep GitHub discovery interval-driven only
- Stop Task activity from causing full GitHub rediscovery
- Fetch GitHub comments/reviews only when required by source config or templates
- Preserve existing public CRD/API shape
Proposed Plan
1. Split Task events from source polling
- Remove the Task watch from the poll controller so GitHub discovery only runs on:
- TaskSpawner create
- TaskSpawner spec generation changes
- scheduled
RequeueAfterpoll intervals
- Add a lightweight Task activity reconcile path/controller inside the spawner process for the single managed TaskSpawner
- On Task phase/deletion changes, the Task activity controller should:
- recompute and update
status.activeTasks - run per-Task GitHub reporting when reporting is enabled
- never call source discovery
- recompute and update
- Keep refill semantics simple:
- when
maxConcurrencyfrees up because a Task finishes, the next GitHub item is considered on the next scheduled poll only
- when
- Continue updating
status.totalDiscovered,status.totalTasksCreated, andstatus.lastDiscoveryTimeonly during poll cycles
2. Make GitHub detail fetching lazy
- Compute internal fetch requirements in
buildSourcefrom:- comment policy / legacy trigger and exclude comments
reviewState- fields referenced by
taskTemplate.promptTemplateor the default prompt - fields referenced by
taskTemplate.branch
- Detect referenced template fields by parsing Go templates and walking the AST
- Keep the
Sourceinterface unchanged - Extend internal GitHub source structs with fetch-requirement booleans
GitHub Issues rules
- Fetch issue comments only when:
- comment policy is configured, or
- a template references
.Comments
- Otherwise leave
WorkItem.Commentsempty and skip issue comment requests
GitHub Pull Requests rules
- Fetch reviews only when:
reviewState != any, or- comment policy is configured, or
- a template references
.ReviewState
- Fetch conversation comments only when:
- comment policy is configured, or
- a template references
.Comments
- Fetch review comments only when:
- comment policy is configured, or
- a template references
.ReviewComments
- Preserve current comment-policy semantics by still loading review bodies and review comments whenever comment policy is active
Public API / Compatibility
- No CRD changes
- No new user-facing fields
- No change to the existing
Sourceinterface
Acceptance Criteria
- Task phase/deletion changes no longer trigger GitHub rediscovery
- Task phase/deletion changes still update
activeTasks - Task phase/deletion changes still perform GitHub reporting when enabled
- TaskSpawner spec changes still trigger immediate discovery
- GitHub issues source skips comment requests when
.Commentsis not needed - GitHub pull request source only fetches reviews/comments required by config/template usage
- Default prompt behavior remains compatible with current output
Test Plan
Controller tests
- Task phase update/delete does not trigger GitHub discovery
- Task phase update still updates
activeTasks - Task phase update still performs GitHub reporting for that Task when enabled
- TaskSpawner spec changes still trigger immediate discovery
GitHub source tests
- Issues source with prompt/branch templates not referencing
.Commentsperforms no comment requests - Default prompt still causes issue comment fetches
- PR source with no comment/review fields and
reviewState=anyonly lists PRs - Referencing
.ReviewStatefetches reviews only - Referencing
.ReviewCommentsfetches review comments only - Comment policy enabled fetches reviews, conversation comments, and review comments
Template analyzer tests
- Detects fields in conditionals and nested template nodes
- Treats empty prompt as the current default prompt
Notes
This issue intentionally does not include:
- webhook support
- persistent backlog state
- cross-cycle authorization caching
- public API additions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the poll controller and the buildSource path, then inspect the internal GitHub source structs and template analyzer described in the plan. Run the controller, GitHub source, and template analyzer tests; done means Task activity no longer causes discovery while updating status/reporting, and GitHub details are fetched only when configuration or templates require them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github, go, kubernetes
- Domain
- backend, infrastructure
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100