Skip to content

Defer jobs whose agent is at its ceiling instead of holding a worker, and charge the actual direct agent #3479

Closed

Description

@integry

Problem

After the previous issue a launch on a saturated agent waits by polling at container create, deep inside execution, while holding a queue worker, the repository slot and the network-policy scope. With one global limit that was acceptable. With per-agent ceilings one saturated agent can tie up workers that other agents could use (#3386).

Goal

Check the agent's capacity as soon as the actual direct agent is known and, when it is full, defer the job the way repository-workflow capacity is deferred. The atomic acquire at container create stays the authoritative check.

Acceptance criteria

  • For issue jobs and pull request follow-ups, once the direct agent is resolved the job checks that alias's capacity before doing user-visible work. When the alias is at its ceiling the job is moved to delayed with backoff, one "waiting for agent capacity" row is kept on the task timeline (updated in place across repeated deferrals, like the repository-workflow row), and the queue worker is released.
  • A deferral does not consume the job's failure budget, is not a provider failure, and triggers neither provider replacement nor fallback to another agent or model.
  • Deferred jobs are woken when capacity for their alias is released, oldest first, in addition to the backoff timer.
  • The charge always goes to the actual direct agent. For a synthetic agent request, selection treats a member whose alias is at its ceiling as temporarily unavailable and may choose another eligible member of the same priority tier; it never records a failed attempt or moves to a lower tier because of capacity. When no member has capacity the job is deferred. For issue jobs the selection needed to learn the direct alias happens before the start comment, worktree and branch push, and the selected member is remembered across the deferral so a re-entered job does not select twice or advance the round-robin cursor twice.
  • The other job types are covered with the same guarantees (no failure budget consumed, no indefinite worker occupancy, other agents keep progressing): goal attempts, automation report and action runs, merge-conflict resolution, task import and pull request reviews (several reviewers and the scout can use several aliases in one job). Where a job type cannot be deferred before it claims its run, check capacity before the claim. Say in the PR which approach each job type uses.
  • Executions that have no queue job (chat, planner, dashboard summaries, health checks, indexing, MCP semantic search) keep waiting in the acquire loop, bounded by their existing caller timeout, and report a capacity wait rather than a provider error when that timeout expires.
  • Cancellation and deadlines are preserved: a cancelled task is not re-entered after a deferral, and a deferred job holds no repository slot, pull request lock or goal claim while it waits.
  • Losing the race at the authoritative acquire after a successful pre-check is handled: a short wait is acceptable; a long one turns into a deferral where the job type allows.
  • A saturated agent does not prevent another eligible agent from progressing, including when the capacity is held by an execution launched from the API process.
  • With no per-agent policy configured, no job is ever deferred for agent capacity and existing behaviour is unchanged.
  • Tests: real queue and real Redis like test/repositoryWorkflowAdmission.test.ts for deferral, wake-up and unchanged attemptsMade; synthetic selection skipping a saturated member and deferring when all are saturated without double selection; each job type's path; cancellation during a deferral; the race at the authoritative acquire. Required integration tests must not silently skip in CI.

Out of scope

  • Nested executions (next issue). Diagnostics endpoints (later issue). UI beyond showing the waiting row that the task timeline already renders for repository capacity.

Implementation

Key files: src/jobs/repositoryWorkflow.ts (deferRepositoryWorkflowJob catches only RepositoryWorkflowCapacityError, job.moveToDelayed + DelayedError; persistRepositoryWorkflowDeferral, recordRepositoryWorkflowDeferral with one row per wait; repositoryWorkflowDeferralDelayMs is generic; wakeRepositoryWorkflowWaiters promotes delayed jobs on release), packages/core/src/workflow/workflowConcurrency.ts, packages/core/src/queue/taskQueue.types.ts (RepositoryWorkflowDeferralData), src/jobs/processGitHubIssueJob.ts (alias resolved in initializeJobContext before repository admission; capacity error rethrown before failure handling), src/jobs/issueJob/context.ts, src/jobs/issueJob/agent.ts (every error from agent.executeTask is tagged markAgentExecutionFailure, which feeds provider replacement: a capacity outcome must not be), src/jobs/issueJob/worktree.ts, src/jobs/processPullRequestCommentJob.ts and src/jobs/prCommentAgentUtils.ts (resolveAndExecuteAgent runs after the start comment and worktree), packages/core/src/services/syntheticRoutingService.ts (select() is lazy, increments the round-robin cursor and writes a recordAttempt row; inspectMember already filters by usage caps; failover on any failure not classified non-retryable in syntheticRoutingTypes.ts), src/jobs/prReviewRunner.ts (routeReviewAssignments selects eagerly: the pattern to follow), src/jobs/processGoalJob.ts (claim before agent resolution; attempts: 1), src/jobs/processAgentRunJob.ts, src/jobs/processAgentActionJob.ts, src/jobs/mergeConflictAgentRunner.ts, src/jobs/processTaskImportJob.ts, src/jobs/providerReplacement.ts, src/taskReplacement/policy.ts, propr-ui/src/components/TaskDetails/TaskStatusTable.tsx (renders the repository waiting row from repositoryWorkflowDeferrals).

Generalise the deferral helpers so repository capacity and agent capacity share one implementation with different reason text and job-data fields, rather than copying them. Admission finish() wakes nobody today; add the wake-up there or next to it.

Tests: test/repositoryWorkflowAdmission.test.ts (real BullMQ queue and worker; asserts attemptsMade stays 0), packages/core/test/syntheticRoutingService.test.ts, test/prCommentAgentUtils.test.ts, test/processGoalJob.test.ts, test/processAgentRunJob.test.ts, test/agentRunAdmission.test.ts. Docs: docs/docs/architecture/agent-run-admission.md, docs/docs/features/repository-workflow.md. Verify with the standard commands.

Activity

  1. propr-dev commented on Nov 12, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3479/claude-opus-5-5-defer-jobs-whose-agent-is-20261112-1445-4kj
    • Base Branch: 3478-epic-per-agent-9uv
    • Worktree: issue-3479-20261112-1445-claude-opus-5-5-4kj

    🔍 Track Task Execution

  2. propr-dev commented on Nov 12, 2026

    @propr-dev
    Contributor

    ❌ AI processing failed before producing publishable work.

    System Error:
    Claude process exited with code 132 after reporting a successful result

    AI Processing Failed

    Execution Details:

    Summary:
    Still running (7 of ~110 suites done). Waiting for the completion notification.

    Detailed Logs:

    • Conversation: 266 messages
    • Session: 76c12998-eb3d-46c3-837e-109796067dc6

    Log files stored at:

    • conversation: /usr/src/app/logs/executions/issue-3479-2026-11-12T15-38-41-904Z-conversation.json
    • output: /usr/src/app/logs/executions/issue-3479-2026-11-12T15-38-41-904Z-output.txt
    Latest Conversation Messages
    ASSISTANT: [content unavailable]
    
    ASSISTANT: Earlier this suite passed 27/27 with the same admission code; this run overlapped my Playwright build. Re-running it alone.
    
    ASSISTANT: [content unavailable]
    
    

    This processing report was generated automatically by ProPR for issue #3479.

  3. added and removed on Nov 12, 2026
  4. propr-dev commented on Nov 12, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3479/claude-opus-5-5-defer-jobs-whose-agent-is-20261112-1539-3bs
    • Base Branch: 3478-epic-per-agent-9uv
    • Worktree: issue-3479-20261112-1539-claude-opus-5-5-3bs

    🔍 Track Task Execution

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions