Skip to content

## Add a stall and degenerate-output watchdog for running agent containers #2735

Closed

Description

@propr-dev

Add a stall and degenerate-output watchdog for running agent containers

Context

The only backstop for a hung agent run today is the per-agent timeout (*_TIMEOUT_MS, default 24 hours). docs/docs/architecture/worker.md states explicitly: "No inactivity timeout is introduced." The task state reconciler (src/taskStateReconciler.ts, src/workerTaskStateRecovery.ts) detects orphaned tasks whose container or BullMQ job disappeared, but a container that is alive and silent — a provider stream that hung mid-turn, or an agent emitting only whitespace — keeps its worker slot and its repository capacity lease (packages/core/src/workflow/workflowConcurrency.ts) for up to a day while still being billed for any calls it does make.

ProPR already streams agent output live (packages/core/src/utils/eventPublisher.ts, packages/api/services/liveOutputStream.ts, per-agent output parsers for Claude/Codex/OpenCode/Vibe), so the signal needed to detect a stall exists; it is just not acted on.

Requirements

  1. Inactivity (stall) detection. Track the timestamp of the last meaningful output event per running task (any parsed agent event, tool call, text delta, or log line from the container). If no event arrives for AGENT_STALL_TIMEOUT_MS (default 10 minutes; 0 disables), stop the container through the existing stop path and finish the task with a new terminalReason value stalled in packages/core/src/utils/workerStateManager.types.ts. Partial work must be published the same way a timed-out run's partial work is today (packages/core/src/claude/docker/dockerExecutor.ts timeout handling; src/jobs/prCommentPostExecution.ts).
    • Long-running tool calls (test suites, builds, npm ci) must not trip the watchdog while the tool is still producing output; only true silence counts. If an agent protocol reports "tool running" without streaming output, treat the tool-start event as activity and apply a separate, longer threshold AGENT_TOOL_STALL_TIMEOUT_MS (default 30 minutes) measured from the tool-start event.
  2. Degenerate-output detection. If the agent produces N consecutive whitespace-only text deltas (default 50; env AGENT_DEGENERATE_OUTPUT_LIMIT, 0 disables), stop the run with terminalReason degenerate_output. Empty deltas are normal and must not count; only whitespace-only non-empty deltas count.
  3. Configuration. Env vars as above, plus instance settings in packages/core/src/config/configManager.ts so they can be changed in the Settings UI and propr settings without a restart (follow how ultrafix settings are stored and read). Env is the default; the DB setting overrides it when set. Invalid values fall back to the default with a warning.
  4. Observability. Write a task timeline event when the watchdog trips (which rule, threshold, seconds silent / count of degenerate deltas). Send an Inbox notification via packages/core/src/services/notificationService.ts. Post a short comment on the linked issue/PR using the existing failure-comment helpers. Count watchdog trips per rule in the Redis LLM metrics (packages/core/src/utils/llmMetrics.ts) so they show in GET /api/llm-metrics.
  5. Interplay with existing recovery. The repository capacity lease must be released when the watchdog stops a run. The reconciler must treat a watchdog-stopped task as terminal (not as orphaned). Provider usage-limit waits (src/jobs/errorHandlers.ts, AI-waiting label) must not be counted as stalls — a task that is parked in the queue has no running container.
  6. Per-agent correctness. Verify the "last activity" signal works for every supported agent (Claude stream-json, Codex, Antigravity, OpenCode, Vibe) — each has its own output parser; wire the activity timestamp at the common point where parsed events are published, not inside one agent's parser.

Documentation

  • Update docs/docs/architecture/worker.md (remove the "No inactivity timeout" statement and describe the watchdog) and docs/docs/features/execution-safety.md.
  • Document the env vars/settings in docs/docs/operations/configuration-reference.md and docs/docs/operations/settings-locations.md.
  • CHANGELOG.md Unreleased entry.

Tests

  • Unit tests for the watchdog state machine: silence past the threshold trips; output resets the timer; tool-start extends to the tool threshold; whitespace-only deltas count, empty deltas do not; disabled (0) never trips.
  • A test showing the stop path is called exactly once and the capacity lease is released.
  • A reconciler test showing a stalled task is not re-marked as orphaned.
  • Run npm run lint, npm run typecheck and the affected suites. Keep existing tests passing.

Submitted by @integry through ProPR.

Activity

  1. propr-dev commented on Oct 5, 2026

    @propr-dev
    ContributorAuthor

    🤖 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: 2735/claude-opus-5-5-add-a-stall-and-degenerat-20261005-2330-eo3
    • Base Branch: main
    • Worktree: issue-2735-20261005-2330-claude-opus-5-5-eo3

    🔍 Track Task Execution

  2. added a commit that references this issue on Oct 6, 2026
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