---
name: grix-chat-state
description: Observe and manage chat task state and task queues — query the task state of all the owner's chats (`grix_chat_state_query`), manually override one chat's state (`grix_chat_state_update`), and inspect or control a session's queued tasks (`grix_chat_queue`). Trigger when the user asks which chats are running/done/waiting, wants a chat marked done/failed/idle, or wants queued tasks listed, cancelled, cleared, paused, edited, or reordered.
---

# Grix Chat State

The Grix account is resolved from the current agent context; you do not pass it.

## Query chat task states — `grix_chat_state_query`

Read-only; safe to call any time to orient yourself. Returns one entry per
session (direct and group) with a single mutually-exclusive state:

- `running` — working
- `waiting_approval` — blocked on the owner to approve/deny
- `waiting_question` — asked the owner a question, awaiting reply
- `completed` / `failed` — finished
- `idle` — no task / stopped

Parameters (all optional):

- `session_id` — query a single session; omit to list all sessions
- `page` (default 1), `page_size` (default 10, max 100)
- `state` — filter by one state

Each entry carries `task_title`. When `session_id` targets exactly one
**completed** session, the entry also contains one `final_result` object:
`found`, and when found `msg_id`, `content`, `created_at`. Use that
`final_result` directly — do not query message history merely to recover a
dispatched task's result. List queries and non-completed sessions never
include message content.

## Override a chat's state — `grix_chat_state_update`

Sets the task state of one session, e.g. to mark a chat done, failed, or idle
outside the normal task lifecycle. It only updates an **existing** state
record and errors if the session has none.

- `session_id` (required)
- `state` (required) — one of `running`, `waiting_approval`,
  `waiting_question`, `completed`, `failed`, `idle`
- `reason` (optional) — written to `stop_reason`

## Inspect and control the task queue — `grix_chat_queue`

One tool with an `action` parameter; `session_id` is always required. Other
parameters are passed through to the backend.

| action | extra parameters | effect |
| --- | --- | --- |
| `list` | `agent_id` (optional) | List queued tasks; returns `items` |
| `cancel` | `event_id` (required), `agent_id` | Drop one queued task |
| `clear` | `agent_id` (optional) | Drop all queued tasks |
| `hold` | `event_id`, `hold` (required), `ttl_ms` (optional), `agent_id` | Pause (`hold=true`) or resume (`hold=false`) one queued task |
| `edit` | `event_id`, `content` (required), `agent_id` | Rewrite a queued task's content |
| `reorder` | `ordered_event_ids` (required, non-empty string array), `agent_id` | Set the desired queue order |

Semantics to respect:

- `cancel`, `edit`, and `hold` only work on **queued** tasks. They cannot touch
  the task that is currently executing; if the user asks to change a running
  task, say so instead of pretending it worked.
- A held task that reaches the head of the queue stalls the **entire** queue
  until it is resumed or its TTL expires. Mention this when pausing a task near
  the head.
- `ttl_ms` is clamped by the backend to 60 seconds through 30 minutes, defaults
  to 10 minutes, and the hold is lifted automatically when it expires.
- `reorder` expresses a **desired order**: ids that no longer exist are ignored,
  and tasks that enter the queue later go to the tail.
- A response with `confirmed: true` carries the resulting `items`. A response
  with `confirmed: false, dispatched: true` means the command was sent but not
  yet acknowledged — call `list` again to verify the final state before
  reporting success to the owner. `list` may include `stale: true` when the
  connector is offline; treat that snapshot as possibly outdated.

## Rules

1. Never invent a `session_id`. Resolve it with `grix_query` (`session_search`)
   or from a list query first.
2. State overrides are visible to the owner in the App — only set a state the
   user actually asked for, and say which session you changed.
3. On a scope or permission error, report it as-is; do not retry with guessed
   parameters.
