Skip to content

Agent slot gate: four routes still start a run in an idle thread without a slot, plus #717 review minors #724

Closed

Description

@scuttletoby

Follow-up to #711 / #717. #717 gates the routes #711 names, plus the delegated-result reminder, PR-watch wake-ups and usage-limit resume. These four routes can still start a run in an idle thread with no slot:

  • The fork's context handoff (apps/server/src/fork/handoff/HandoffService.ts, start_immediately with fresh context). The idle-timer trigger (fork/handoff/handoffDecision.ts) fires after the thread's turn ended, when its slot is already free. It is fork code and opt-in, so it can be gated without a seam.
  • Provider continuation (orchestration-v2/ProviderContinuationService.ts, "Background task completed"). An agent that ends its turn while its own background work runs starts again when that work ends. This is common and has no bound. It needs a seam.
  • Delegated question replies (orchestration-v2/DelegatedTaskQuestionReactor.ts) wake an idle parent. Needs a seam.
  • Idle compaction (orchestration-v2/IdleCompactionService.ts, start_immediately). Needs a seam.

For each route: gate it like the other wake-ups (a refused one waits for a slot, is never lost and never sent twice, and survives a restart), or write down in docs/fork/README.md why it stays open.

Minors from the #717 round-2 reviews

Review B (comment):

  • m1. A refused PR-watch wake costs API quota. Upstream's reactor logs a warning on every sweep, and while a slot stays refused it reads the pull request in full again (detail + activity) every 2 min (fork/pullRequestWatchSlot.ts, PullRequestWatchReactor.ts sendOne). Several watched PRs on a full host spend GitHub API budget and fill the log. Either back off, or say so in the README.
  • m2. A granted thread that is then deleted or archived holds 2 slots until its hold expires (reserveSeconds, 120 s by default). WaitService hands the wait over as gone, but nothing drops the gate's memory hold, which also counts a wake-up that will never come. This fails safe and ends by time. Fix: gate.drop([key]) on the gone / stopped hand-over.
  • m3. SlotGate.ts:721 (childThreadId: into on the entry made in decide) has no failing test when it is removed. Add a test that runs a second acquire between acquire and started.

Review A (comment):

  • The orphan scan's retry has no cap and no log for unreadable (fork/delegatedResults/DelegatedOrphanScan.ts, untilSlot). A parent that stays unreadable (a deleted project, a broken linked machine) loops until the server stops, with nothing in the log. Log once, or stop after N tries and leave it to the next start.
  • The orphan scan's retry reuses its first list (checkParent(parentThreadId, first.linked)). An orphan of the same parent that ends while that parent waits for a slot is left until the next server start.
  • The PR-watch sets are never pruned (fork/pullRequestWatchSlot.ts, endingRefused / waiting). A watch that is removed, or whose thread is deleted, keeps its key until restart. Small memory cost only.
  • A slot wait whose wake-up waits keeps its hold only in memory. A delivering wait's hold expires after reserveSeconds and is gone after a restart, so its wake-up then competes like any other start. This means a late wake-up, never one over the limit. Add a README sentence.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions