activateForStarvation spawns a capability-matched worker for a starved run that no agent has claimed. The worker self-claims via `agh task next`; the scheduler never claims. It carries a TTL + spawn budget so the reaper bounds its lifetime. Dedup on (agent, channel, scope) keeps the effective per-wo
( ctx context.Context, taskRecord taskpkg.Task, run taskpkg.Run, spawner starvationSpawner, )
| 393 | // TTL + spawn budget so the reaper bounds its lifetime. Dedup on (agent, channel, scope) keeps the |
| 394 | // effective per-workspace cap at one active worker per role. |
| 395 | func (r *taskRoleRuntime) activateForStarvation( |
| 396 | ctx context.Context, |
| 397 | taskRecord taskpkg.Task, |
| 398 | run taskpkg.Run, |
| 399 | spawner starvationSpawner, |
| 400 | ) error { |
| 401 | if ctx == nil { |
| 402 | return errors.New("daemon: starvation activation context is required") |
| 403 | } |
| 404 | agentName, err := r.resolveStarvationAgent(ctx, taskRecord, run, spawner) |
| 405 | if err != nil { |
| 406 | return err |
| 407 | } |
| 408 | activation, ok, err := r.starvationActivation(taskRecord, run, agentName) |
| 409 | if err != nil || !ok { |
| 410 | return err |
| 411 | } |
| 412 | |
| 413 | r.mu.Lock() |
| 414 | defer r.mu.Unlock() |
| 415 | |
| 416 | existing, err := r.activeRoleSession(ctx, activation) |
| 417 | if err != nil { |
| 418 | return err |
| 419 | } |
| 420 | if existing != nil { |
| 421 | r.logger.Info( |
| 422 | "daemon: starvation worker already active", |
| 423 | taskRoleRuntimeTaskIDKey, activation.TaskID, |
| 424 | "run_id", activation.RunID, |
| 425 | "agent_name", activation.AgentName, |
| 426 | "channel", activation.Channel, |
| 427 | ) |
| 428 | return nil |
| 429 | } |
| 430 | info, err := r.startStarvationSession(ctx, activation) |
| 431 | if err != nil { |
| 432 | return err |
| 433 | } |
| 434 | r.logger.Info( |
| 435 | "daemon: starvation worker spawned", |
| 436 | "session_id", info.ID, |
| 437 | taskRoleRuntimeTaskIDKey, activation.TaskID, |
| 438 | "run_id", activation.RunID, |
| 439 | "agent_name", activation.AgentName, |
| 440 | "channel", activation.Channel, |
| 441 | ) |
| 442 | return nil |
| 443 | } |
| 444 | |
| 445 | func (r *taskRoleRuntime) resolveStarvationAgent( |
| 446 | ctx context.Context, |