Skip to content

feat: add agent next-task endpoint#403

Merged
joryirving merged 6 commits into
mainfrom
feat/agent-next-task-endpoint
Jun 17, 2026
Merged

feat: add agent next-task endpoint#403
joryirving merged 6 commits into
mainfrom
feat/agent-next-task-endpoint

Conversation

@joryirving

@joryirving joryirving commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Closes #395.

Adds GET /api/agents/[agentName]/next-task — a cheap preflight that returns exactly one AgentTask for an agent.

Behavior

  • PR-fix items take precedence over issue work
  • Returns followup-pr task when a queued PR-fix item is first
    • Includes linked issue context (issue.repoFullName, issue.number) when the PR-fix has an issue number
    • Builds reasons from both the high-level reason and feedback[] (deduplicated)
  • Returns implement task when an issue is first in the queue
  • Returns idle when nothing is available (harness exits without burning tokens)
  • Preserves existing query params: lane, exclude_decomposed, includeClaimed, includeRenovate
  • Does not mutate issue state or claim work

Changes

  • src/app/api/agents/[agentName]/next-task/route.ts — endpoint handler
  • src/app/api/agents/[agentName]/next-task/route.test.ts — 13 tests

Reuses

  • buildAgentQueue from src/lib/agent-queue.ts
  • listQueuedPrFixItems, toAgentQueuePrFixItem from src/lib/pr-fix-queue.ts
  • createIdleTask, createImplementTask, createFollowupPrTask from src/lib/agent-task.ts

Validation

  • npm run lint
  • npm run typecheck
  • npm run test (13 tests)
  • npm run build

Define discriminated union AgentTask with four task types:
- idle: no work available
- implement: claim or work an issue, open/update one PR
- followup-pr: fix an existing PR
- groom: enrich issues with labels, lane, and status

Include helper builders (createIdleTask, createImplementTask,
createFollowupPrTask, createGroomTask) with strict default
instructions and forbidden actions. No API routes, no DB changes.
its-saffron[bot]

This comment was marked as outdated.

@joryirving joryirving closed this Jun 17, 2026
@joryirving joryirving reopened this Jun 17, 2026
@its-saffron its-saffron Bot dismissed their stale review June 17, 2026 03:21

Superseded by a newer automated review for this pull request.

its-saffron[bot]

This comment was marked as outdated.

@joryirving joryirving enabled auto-merge (squash) June 17, 2026 03:24
@joryirving joryirving merged commit e2628b4 into main Jun 17, 2026
3 checks passed
@joryirving joryirving deleted the feat/agent-next-task-endpoint branch June 17, 2026 03:26

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Automated Review

Full PR review.

Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — routed smart (risk match: public_route_changes)

PR PR 403: feat: add agent next-task endpoint

Recommendation

Approve. The new GET /api/agents/[agentName]/next-task endpoint is correctly implemented as a read-only preflight endpoint that follows existing repository conventions for agent queue endpoints.

Change-by-Change Findings

src/app/api/agents/[agentName]/next-task/route.ts (new file, 135 lines)

  • Adds a GET handler that returns exactly one AgentTask for an agent
  • Correctly queries PR-fix queue items first (precedence), then falls back to issues
  • Uses findLeasedIssueIds to filter already-leased issues, respecting concurrent work safety
  • Passes through existing query params: lane, exclude_decomposed, includeClaimed, includeRenovate
  • Returns idle task when no work is available (harness-friendly)
  • No database mutations — verified by tests checking issueFindMany is called with state: "open" filter

src/app/api/agents/[agentName]/next-task/route.test.ts (new file, 397 lines)

  • 13 comprehensive tests covering: empty queue, single implement task, followup-pr precedence, linked issue context, reason deduplication, lane filtering, includeClaimed behavior, no harness-specific fields, and mutation verification

Standards Compliance

Agent Task Contract: Endpoint reuses createIdleTask, createImplementTask, createFollowupPrTask from src/lib/agent-task.ts, ensuring consistency with the harness-agnostic contract added in PR 402.

Queue Integration: Reuses buildAgentQueue from src/lib/agent-queue.ts, listQueuedPrFixItems from src/lib/pr-fix-queue.ts — consistent with existing agent queue patterns.

PR-Fix Precedence: Correctly prioritizes PR-fix items over issue work per the worker execution contract.

Repository Conventions: Read-only endpoint follows the established pattern of other GET agent endpoints (e.g., /queue) that do not require explicit auth. Mutating endpoints (e.g., /agent-runs POST) require DISPATCH_AGENT_TOKEN bearer auth per AGENTS.md.

Linked Issue Fit

Issue PR 395 acceptance criteria verified:

  • ✅ "no LLM required to check for work" — endpoint returns structured AgentTask with shouldRun boolean
  • ✅ "one task per response" — tests explicitly verify Array.isArray(body) === false
  • ✅ "compatible with existing queue logic" — uses buildAgentQueue with same filtering options
  • ✅ "idle response lets any harness stop cleanly" — returns createIdleTask("No work available")

Issue states this closes PR 395. ✅

Required Checks

1. verify route access controls are in place
✅ Verified — The endpoint follows the repository's established pattern for read-only agent queue endpoints. The /api/agents/[agentName]/queue endpoint (documented in AGENTS.md) similarly requires no explicit auth for GET operations. Authentication (DISPATCH_AGENT_TOKEN bearer auth) is required only for mutating agent endpoints per README: "Agent/Worker Auth (DISPATCH_AGENT_TOKEN): Bearer token authentication for API calls from agents... This is required for all mutating API endpoints." The new endpoint only reads data and does not mutate state, consistent with unprotected read-only endpoints.

2. check for unintended public endpoints
✅ Verified — No authentication bypass or middleware changes introduced. The endpoint is scoped to /api/agents/[agentName]/next-task and only returns queue position data. It exposes no additional repository metadata beyond what is already accessible via the existing /api/agents/[agentName]/queue endpoint.

Evidence Provider Findings

None.

Tool Harness Findings

  • File read of route.ts confirmed implementation matches diff
  • No middleware, auth, or bearer token patterns found in the new route file (expected — follows existing read-only pattern)
  • Attempted read of sibling route.ts in [agentName] directory failed (not required for this review)

Unknowns / Needs Verification

None. CI checks (Docker Build, Validate) passed successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add next-task endpoint for one-task agent loops

1 participant