Files
openagent/docs/MISSION_API.md
Thomas Marchand c32f98f57f Clean up stuck tool detection and improve mission completion UX (#33)
* Ralph iteration 1: work in progress

* Fix mission events pagination and add update_skill MCP tool

- Increase default events limit from 1000 to 50000 to fix truncation issue
  where assistant messages at the end of long missions were being cut off
- Add update_skill MCP tool to host-mcp for agents to update skill content
  in the library, with automatic workspace syncing via backend API

* Clean up stuck tool detection and improve mission completion UX

- Remove aggressive stuck tool detection that was hijacking missions
  - Deleted TOOL_STUCK_TIMEOUT and recovery mechanism from opencode.rs
  - Frontend already shows "Agent may be stuck" warning after 60s
  - Let users control cancellation instead of auto-intervention

- Fix tool calls showing "Running" after mission completes
  - When mission status changes to non-active, mark pending tools as cancelled
  - Display cancelled tools with amber color and clear status
  - Prevents confusing "Running for X..." state when mission ends

- Improve mission completion message clarity
  - Replace truncated output with meaningful terminal_reason summary
  - Show specific reason: "Reached iteration limit", "No progress detected", etc.
  - Normal completions show no extra explanation

* Fix stuck detection and pending tool UI issues

- When mission fails (success=false), mark all pending tool calls as failed
  so subagent headers show "Failed" instead of staying "Running for X"

- Increase stall warning thresholds when tools are actively running:
  - Normal: 60s warning, 120s severe
  - With pending tools: 180s warning, 300s severe
  This prevents false "stuck" warnings during long desktop operations

* Fix queued status response for user messages

- Add respond channel to UserMessage command for accurate queue status
- Return actual queued state based on whether runner was already processing
- Fallback to status check if channel fails

* Add automatic OpenCode session cleanup to prevent memory pressure

- Add list_sessions() and delete_session() methods to OpenCode client
- Add cleanup_old_sessions() method that deletes sessions older than 1 hour
- Add background task that runs every 30 minutes to clean up old sessions
- Prevents session accumulation from causing OpenCode server memory pressure

* Fix review findings: remove test artifacts, fix blob URL leak, align failure detection

- Remove accidentally committed test files (ralph.txt, changes.txt, report.txt)
- Add LRU-style cache with URL.revokeObjectURL() cleanup for blob URLs to prevent
  memory leaks in long-running sessions
- Align streaming handler with eventsToItems by using strict equality (=== false)
  for failure detection, so undefined success doesn't incorrectly mark tools as failed

* Fix memory leak from concurrent image fetches

Revoke incoming duplicate blob URL when path is already cached
to prevent leaks during race conditions.
2026-01-14 23:23:08 -08:00

3.2 KiB

Mission API

All endpoints require authentication via Authorization: Bearer <token> header.

Create a Mission

POST /api/control/missions

Body (all optional):

{
  "title": "My Mission",
  "workspace_id": "uuid",
  "agent": "code-reviewer",
  "model_override": "anthropic/claude-sonnet-4-20250514"
}

Response: Mission object (see below).

Load/Switch to a Mission

POST /api/control/missions/:id/load

Loads the mission into the active control session. Required before sending messages.

Send a Message

POST /api/control/message

Body:

{
  "content": "Your message here",
  "agent": "optional-agent-override"
}

Response:

{
  "id": "uuid",
  "queued": false
}

queued: true means another message is being processed.

Cancel Current Execution

POST /api/control/cancel

Cancels the currently running agent task.

Cancel a Specific Mission

POST /api/control/missions/:id/cancel

Set Mission Status

POST /api/control/missions/:id/status

Body:

{
  "status": "completed"
}

Statuses: pending, active, completed, failed, interrupted.

Get Mission Events (History)

GET /api/control/missions/:id/events?types=user_message,assistant_message&limit=100&offset=0

Query params (all optional):

  • types: comma-separated event types to filter
  • limit: max events to return
  • offset: pagination offset

Response: Array of StoredEvent:

[
  {
    "id": 1,
    "mission_id": "uuid",
    "sequence": 1,
    "event_type": "user_message",
    "timestamp": "2025-01-13T10:00:00Z",
    "content": "...",
    "metadata": {}
  }
]

Stream Events (SSE)

GET /api/control/stream

Server-Sent Events stream for real-time updates. Events have event: and data: fields.

Event types:

  • status — control state changed (idle, running, tool_waiting)
  • user_message — user message received
  • assistant_message — agent response complete
  • thinking — agent reasoning (streaming)
  • tool_call — tool invocation
  • tool_result — tool result
  • error — error occurred
  • mission_status_changed — mission status updated

Example SSE event:

event: assistant_message
data: {"id":"uuid","content":"Done!","success":true,"cost_cents":5,"model":"claude-sonnet-4-20250514"}

Other Endpoints

Endpoint Method Description
/api/control/missions GET List missions
/api/control/missions/:id GET Get mission details
/api/control/missions/:id DELETE Delete mission
/api/control/missions/:id/tree GET Get agent tree for mission
/api/control/missions/current GET Get current active mission
/api/control/missions/:id/resume POST Resume interrupted mission
/api/control/tree GET Get live agent tree
/api/control/progress GET Get execution progress

Mission Object

{
  "id": "uuid",
  "status": "active",
  "title": "My Mission",
  "workspace_id": "uuid",
  "workspace_name": "my-workspace",
  "agent": "code-reviewer",
  "model_override": null,
  "history": [],
  "created_at": "2025-01-13T10:00:00Z",
  "updated_at": "2025-01-13T10:05:00Z"
}