Skip to content

Enforce optional per-agent ceilings atomically in the agent-run admission script #3478

Closed

Description

@integry

Problem

Agent-run admission has one instance-wide limit. An operator who mixes a local inference server (one job at a time) with cloud agents (several) can only lower the whole instance (#3386). The admission boundary does not even know which agent a launch belongs to: it receives Docker arguments and a task id, and the identity passed down is the agent's config id, not its alias.

Goal

Optional ceilings keyed by direct agent alias, taken in the same atomic step as the global limit, so the existing reserve / attach / fence / recover lifecycle and its "never reuse until removal is confirmed" guarantee apply to them unchanged. These are ceilings, not reserved shares.

Acceptance criteria

  • Every admitted launch carries the alias of the actual direct agent to the admission boundary: container launches through executeDockerCommand and native goal sessions through spawnWithNetworkPolicy. The holder record stores the alias.
  • acquire checks the alias's holder count against that alias's ceiling next to the existing total-count check, inside the same script. Models that run under the same alias share its ceiling; different aliases are independent; an alias without a ceiling is subject only to the global limit. The global limit and the hosted entitlement stay hard ceilings.
  • Per-alias ceilings are not part of the fenced configuration identity. They are passed with each acquire, so raising or lowering one needs no generation bump and no drain: raising is always safe, and lowering only stops new admissions without stranding running work. The global limit keeps its current fencing.
  • The policy comes from PROPR_AGENT_RUN_ALIAS_LIMITS (alias to positive integer). A malformed value, a ceiling above the global limit's meaning (document the rule), or an alias that is not a configured direct agent is reported clearly at worker and API startup rather than silently leaving an agent uncapped. Synthetic agent aliases are rejected: the charge always goes to the direct agent.
  • A launch whose direct agent cannot be identified does not bypass a configured policy: it fails with a clear error. The paths that launch without a registered alias today (the legacy Claude analysis path, health checks on unsaved configurations, the implicit default agent) are each given a defined identity or a documented exemption, and the exemptions are listed in the architecture doc.
  • The caller can tell why an acquire did not succeed: global limit reached, this alias's ceiling reached, or a holder is recovering. Today these are the same reply.
  • Holder records written before the upgrade (no alias) count toward the global limit only and never cause an error. The docs state what to expect while processes on the old and new version share the keys during a rolling restart.
  • Capacity is never reused while the old execution can still run: a holder in the recovering state keeps counting against its alias until removal is confirmed.
  • With PROPR_AGENT_RUN_ALIAS_LIMITS unset, the script's decisions, the Redis data written for new holders apart from the added alias field, and all existing admission tests are unchanged. With admission off (no global limit configured) a per-alias policy is a startup error, not a silent no-op.
  • Tests use a real Redis and real multi-process contention, following the existing admission tests: both ceilings enforced under contention from several processes; a saturated alias does not stop another alias from being admitted; cancellation, create failure, holder crash, lease loss and repeated delivery neither leak alias capacity nor reuse it early; changing a ceiling between acquires takes effect without a generation change; old holder records without an alias.
  • These integration tests must not silently skip in CI: they honour the repository's existing switch for required Redis integration tests (PROPR_REQUIRE_REDIS_INTEGRATION) and fail instead of skipping when it is set.

Out of scope

  • Deferring jobs before they reach the boundary (next issue): in this issue a launch on a saturated alias waits in the existing acquire loop.
  • Nested executions (later issue), diagnostics endpoints (later issue), any UI.

Implementation

Key files: packages/core/src/agents/agentRunAdmission.ts (resolveAgentRunAdmission, the single Lua SCRIPT with ops acquire / initialize / expired / release / fence / attach, call() with fixed ARGV positions, prepareAdmittedAgent and AdmissionOptions, the wait loop, agentAdmissionMetrics, spawnAdmittedAgent), packages/core/src/claude/docker/dockerExecutor.ts (DockerCommandOptions, startDockerCommand: admission only for docker run without costCapExempt), packages/core/src/claude/docker/dockerNetworkPolicy.ts (spawnWithNetworkPolicy), the agent implementations under packages/core/src/agents/impl/ (ClaudeAgent.ts, CodexAgent.ts, AntigravityAgent.ts, OpenCodeAgent.ts, VibeAgent.ts: each passes diagnostics.agent = config.id while config.alias is in scope; native paths claudeNativeGoal.ts, codexAppServer.ts, antigravityNativeGoal.ts), packages/core/src/claude/claudeService.ts (legacy executeClaudeCode hard-codes claude and passes no identity), packages/api/services/agentHealthCheck.ts, packages/core/src/agents/AgentRegistry.ts and packages/core/src/config/configManagerAgents.ts (loadAgents() reads the configured aliases in any process), packages/shared/src/syntheticAgents.ts.

Startup validation points: src/worker.ts startWorker (already validates other config and exits non-zero), packages/api/server.ts start(). Aliases can change at runtime through config events, so re-validate on agents_update and log clearly rather than crash.

The script counts the total with HLEN and decodes holder values only in the recovering scan; counting per alias needs either a decode pass or a per-alias counter kept in step inside the script. Keep everything in the one script and the one EVAL.

Tests: test/agentRunAdmission.test.ts (spawns a real redis-server, simulated Docker via test/fixtures/agent-admission/docker.mjs, multi-process via fork('test/fixtures/agent-admission/worker.ts')); it currently skips when redis-server is absent. The required-Redis convention is in test/ultrafixRecoveryRedisIntegration.test.ts and scripts/ci-redis.sh. Docs: docs/docs/architecture/agent-run-admission.md, docs/docs/operations/configuration-reference.md (no PROPR_AGENT_RUN_* rows exist yet), .env.example, packages/api/mcp/settingsCatalog.ts (environment(...) entries; docs:settings generator and settingsCatalog.test.ts). Verify with npm run test:prepare, npm run typecheck, the changed tests via node scripts/run-test-suite.mjs, and eslint --max-warnings 0 per touched package.

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: 3478/claude-opus-5-5-enforce-optional-per-agen-20261112-1222-anp
    • Base Branch: 3478-epic-per-agent-9uv
    • Worktree: issue-3478-20261112-1222-claude-opus-5-5-anp

    🔍 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