8 Commits

Author SHA1 Message Date
kshitijk4poor
d72b65595e fix(cli): a closing socket refuses before the send, and an unsent prompt keeps its turn
Three fixes from review:

- A keepalive timeout fails the socket into CLOSING. websockets then waits
  up to close_timeout (10 s) for the peer before the reader ends. A send in
  that window is never written, but it used to block the caller for that
  long and then report DISCONNECTED. GatewayClient.rpc now refuses with
  NOT_SENT whenever the socket isn't OPEN. Live probe with a silent peer: it
  now answers in 0.0 s with NOT_SENT; the previous head took 5.4 s, reported
  DISCONNECTED and logged "Future exception was never retrieved".
- When prompt.submit gets NOT_SENT, the turn is handled like a pre-submit
  notice: the /model --once pick goes back, no history row is written, and
  the result carries admitted=False. "Nothing was sent" is then true for the
  resend too.
- rpc reads the exception of a future the reader failed while the send was
  raising, so asyncio no longer logs it as never retrieved.

The test fakes for GatewayClient sockets now carry `state = State.OPEN`,
which every real websockets connection has.
2026-10-29 16:30:39 +05:30
Teknium
d439b578d1 docs(cli): /queue's shared gateway queue, move refusal, lost-answer note
The /queue docs said move acts on the pending queue mid-run; it is
refused for prompts the gateway holds. They now also say that
/queue list|rm|edit|clear act on the session's shared gateway queue
(every window's and automation's queued prompts), that queue-mode Enter
uses the same queue, and that a slash command typed after your own
/queue prompt waits briefly for its turn.

Code notes: what a QueueOutcomeUnknown leaves behind (the turn runs
once but is not painted live here), and why an unknown /queue admission
stays tracked and is re-read once per pending list.

Refs #134889 (N5)
2026-10-19 11:56:22 -07:00
Teknium
95dfcd5cdb fix(cli): a slash command typed after /queue X runs after X's turn
/queue X then /new (or /undo, /retry) typed during a turn: on main both
sat in _pending_input in that order. With X in the owner's FIFO, the
input loop took /new first; X's turn is adopted only once the owner's
message.start arrives, so /new could detach the session and X ran in a
session this terminal had left.

The input loop now holds a local item while this viewer's own /queue
admission is at the head of the owner's queue (gateway_queue
.OwnQueueHold). A turn the owner runs meanwhile (the adopted admission,
a notification header) runs first; the held item runs once that
admission was taken or left the queue. The wait is bounded: an unknown
row (a paused FIFO) never starts a hold, an idle list beyond the one a
settling turn publishes ends it, and OWN_QUEUE_HOLD_S (2 s) caps it.
The admission itself is never touched.

Refs #134889 (N5)
2026-10-19 11:56:22 -07:00
Teknium
1d10446af4 fix(cli): a /queue submit with a lost answer is never reported as refused
The owner commits a queued prompt before it answers. A timeout or a
dropped socket after the request was sent is a GatewayClientError, and
the CLI printed the refusal copy: "Nothing was queued; send it again".
Each resend got a fresh submission_id, so both copies could run.

Now only an owner verdict (GatewayRPCError) or a request that never
reached a socket is reported as nothing queued. A lost answer is asked
once more under the same submission_id. The owner returns the admission
it already holds (admit_session_input matches it by principal, session
and request id, hermes_state_runtime.py:149-155), so the prompt is
queued once. If that also gets no answer, the CLI says the outcome is
unknown and points to /queue list instead of asking for a resend (new
cli.queue.submit_unknown key in all 17 catalogs).

Refs #134889 (N5)
2026-10-19 07:13:34 -07:00
Teknium
9e5d442815 fix(cli): a refused /queue rm or edit says what was refused
/queue rm and /queue edit reused the submit refusal: "The gateway did not
queue it ... Nothing was queued; send it again when the turn ends." That
was false for a removal or edit the owner refused, and it told the user
to resend a prompt that was already running.

Each outcome now gets its own message:
- a refusal names the item and the reason (could not remove or edit
  queue item N);
- a row the drain had already claimed (stale_generation or
  admission_started) says it already started and runs as it was sent;
- an rm that raced the claim, which the owner answers by interrupting
  that run, says the gateway stopped it (before, it printed nothing);
- an rm or edit with no answer says the outcome is unknown and points
  to /queue list.

Only a cancelled row leaves queued_inputs, so a turn that started still
gets painted. The new strings are in all 17 locale catalogs.

Refs #134889 (N5)
2026-10-19 07:12:07 -07:00
Teknium
fa464f71fc fix(cli): the /queue dock drops an admission the owner no longer lists
published_queue added every queued_inputs entry missing from the owner's
published pending list. When Ink or Desktop cancelled, replaced or steered
this CLI's queued prompt, the owner's next list left it out, and the dock
still showed it as queued for the rest of the process.

The owner's published list is now authoritative. An entry is shown from
queued_inputs only while no list has been published since its submit,
which covers the short gap between the submit's receipt and the owner's
next session.info. The first list published after that decides.
queued_inputs itself still owes the turn a paint (F2), so the dock reads
the publish order instead of trimming it.

Refs #134889 (N5)
2026-10-19 07:08:38 -07:00
Teknium
2437fb0842 fix(cli): /queue list never erases a queued turn the CLI has not painted
A fast queued turn can finish while the CLI is still busy. queued_rows
then read its receipt as terminal and dropped the queued_inputs entry.
The idle tick later met that admission's buffered message.start with
nothing to match it, so it skipped it, and the user never saw the reply.

Listing now only leaves a started or settled admission out of the list.
It marks the admission for the idle tick, which paints the turn or, if
it never ran, forgets it. Queue membership comes from the owner's
receipt, and the "not painted yet" record is retired only by painting or
by a never-ran outcome.

Refs #134889 (N5)
2026-10-19 07:06:52 -07:00
Teknium
8fa422db49 fix(cli): /queue while a turn runs goes into the gateway's durable FIFO
The classic CLI held a busy-time /queue prompt in its own _pending_input.
That put it outside session_admissions and the restart contract, so an
owner restart or a disconnect (N2) lost or failed it.

Now /queue <prompt> typed while a turn runs is an ordinary queued
admission (prompt.submit {queued: true}), the way Ink and Desktop queue
busy input. The owner commits it when it accepts it, keeps it across a
restart and runs it once, in FIFO order. The CLI keeps no copy it could
send again. It records only which admissions it queued, so when the owner
starts one the idle tick paints it as the user's turn and
run_conversation pumps that admission without a second submit.

/queue list, edit, rm and clear read and change the owner's queue
(prompt.receipt, prompt.replace_queued, prompt.cancel). The live-work
dock shows the owner's published pending list. /queue move refuses to
reorder an owner row, because the FIFO runs rows in the order they were
sent. A refused submit is reported, and nothing is held locally. While
the session is idle, /queue still queues locally: the next turn
submits it at once.

Refs #134889 (N5)
Refs #134889 only
2026-10-19 03:21:33 -07:00