Skip to content

fix: keep receiving while a turn runs; /new, /model and /think act on the conversation - #156

Merged
royosherove merged 2 commits into
mainfrom
fix/gateway-responsiveness
Nov 21, 2026
Merged

royosherove merged 2 commits into
mainfrom
fix/gateway-responsiveness

Conversation

@royosherove

Copy link
Copy Markdown
Member

Why

A read-only survey of the Telegram experience, and the review of #155, found three defects that mattered more than any missing feature. Each was confirmed against the Chat SDK or pi source, and the first by an experiment with the real adapter.

  1. Nothing is received from Telegram while a turn runs. The Chat SDK's polling awaits the message handler before it asks for more updates, and roundhouse's handler awaited the whole agent turn. /cancel could not interrupt anything, and messages sent meanwhile were not delivered until the turn ended. This came in with the Chat SDK bump in fix(security): allowlist bypass, fail-closed gateway; move to pi 1.6 #153.
  2. /new reopened the conversation it had just closed. restart() disposed the session, and the next prompt called SessionManager.continueRecent, which opens the newest transcript.
  3. /model never reached an existing conversation. It wrote pi's default, and pi restores a session's model from its transcript.

What changes

Responsiveness

  • Handlers start the work and return. Ordinary messages are chained per chat in arrival order (so a text cannot overtake a photo that is still downloading); anything starting with / is handled at once.
  • A message now counts as delivered before its turn ends, so a turn cut off by a restart is neither redelivered nor repeated. A marker file in ~/.roundhouse/in-flight/ survives only an interrupted turn, and the next gateway tells the owner which request was cut off. This also closes finding 1 of the feat: compaction that follows the model, one-time standing context, reliable restart #155 review (a restart mid-turn re-ran the request).

Commands

  • /new leaves a marker so the next session starts empty, also if the gateway restarts before the next message, and marks memory for re-injection.
  • /model switches the conversation it is sent in, after the running turn if there is one, and says why when it cannot (unknown model, no credentials, a window the conversation has outgrown).
  • /think [level] shows or sets the thinking level.
  • /status shows session cost, token and cache use and the thinking level, and uses a cached update check instead of waiting up to 10 s for npm view.

Other

  • With pi, image attachments are passed to the model as images (up to five per message), sniffed from the file rather than trusted from the chat's type. The manifest marks them so the model does not read them again.
  • No "Agent returned no response" after /cancel.
  • No typing indicator after each Telegram answer: the typing loop's "clear" call is just another typing action there.

Behaviour changes to know

  • /cancel, /status and other commands now take effect during a turn.
  • An unfinished request is no longer re-run after a crash or restart; the owner gets a notice instead.
  • /model changes the current conversation's model, which makes the next reply re-read the conversation without the prompt cache.

Verification

  • npm test: 777 passing. npm run typecheck: clean.
  • test/telegram-slash-integration.test.ts runs the adapter's real polling loop against a stubbed Bot API: a turn is blocked, polling continues, /cancel arrives and aborts it. It fails when a handler awaits the turn again.
  • test/pi-adapter-session.test.ts: /new across a simulated restart; /model applied, refused and deferred; /think; images.
  • test/gateway-experience.test.ts: order per chat, commands skipping the line, the interrupted-turn notice, typing.
  • Not tested live: these paths against real Telegram and a real model.

… the conversation

Responsiveness
- The Chat SDK's Telegram polling awaits the message handler, and the
  handler awaited the whole agent turn. While a turn ran, nothing was
  received: /cancel could not interrupt it and later messages were not
  delivered until it ended. Handlers now start the work and return.
  Ordinary messages are chained per chat in arrival order; commands skip
  the chain. A test drives the adapter's real polling loop.
- Since a message now counts as delivered before its turn ends, a turn
  cut off by a restart is neither redelivered nor repeated. A marker
  file survives only an interrupted turn, and the next gateway tells
  the owner which request was cut off.

Commands
- /new only disposed the session; the next prompt reopened the newest
  transcript, which was the one just closed. It now leaves a marker so
  the next session starts empty, also across a gateway restart, and
  marks memory for re-injection.
- /model only wrote pi's default, and pi restores a session's model
  from its transcript. It now also switches the conversation it is sent
  in (after the running turn, if any) and reports when it cannot.
- /think shows or sets the thinking level.
- /status shows session cost, token and cache use and thinking level,
  and uses a cached update check instead of waiting for `npm view`.

Other
- With pi, image attachments go to the model as images (up to five),
  sniffed from the file rather than trusted from the chat's type.
- No "Agent returned no response" after a cancel; no typing indicator
  after an answer on Telegram, where the "clear" call is another typing
  action.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:51:32.124542Z 692b858 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9937235cc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/gateway.ts Resolved
Comment thread src/gateway/gateway.ts Resolved
Comment thread src/gateway/gateway.ts Resolved
From the independent review of this branch; each was reproduced by a
probe against the real Chat SDK, Telegram adapter and pi SDK.

Interrupted requests
- A message waiting at Telegram when the gateway started got a false
  "I was restarted" notice while its turn was running: the markers were
  read after polling had begun, so the gateway found its own. They are
  now read before chat.initialize().
- A message accepted but still waiting its turn was lost on restart
  without a word: the marker was written only when its turn started.
  It is now written when the message is accepted, and stop() stops
  polling first. One notice per chat lists every request that was cut
  off or never started. A notice that could not be posted is tried
  again at the next start.

Order
- "Starts with /" was the wrong test for skipping the queue. A command
  the gateway does not know is a prompt for the agent and overtook
  earlier messages; /new moved a message queued before it into the new
  conversation. Only pre-turn commands, descriptors marked `immediate`
  and pairing's /start skip the line now.
- Button handlers are detached too: a /model press waiting on the agent
  blocked polling like the message handlers used to.

/new
- A restart in the middle of the first turn after /new started a third,
  empty session, and "continue" reached a model with no history. The
  marker now names the fresh session's file, and an existing file is
  resumed.

/model, /think
- A deferred switch reported success and then failed silently, with the
  default already written. What can be checked is checked before
  answering, a deferred failure is posted to the chat, and a model that
  is unknown or has no credentials is not written as the default.
- "Busy" is the adapter queue, not only a running prompt, so a switch
  during a compaction is deferred instead of blocking.
- The conversation keeps its thinking level across a model switch.
- /think answers during a turn and applies after it. Its replies go
  through the transport, so the markup renders.
- The /model menu marks the conversation's model as current.

/cancel
- It aborted the session the chat currently points at, which after
  /topic is not the one whose turn is running, and it could not stop a
  turn that had not reached the model yet. The turn's abort signal now
  exists from acceptance and is found by chat. With nothing running it
  says so instead of "Cancelled."

Tests
- Three test files get their own roundhouse directory; the /model test
  no longer writes pi's real settings.
@royosherove

Copy link
Copy Markdown
Member Author

Independent review and what was done about it

A separate reviewer probed the branch against the real Chat SDK, Telegram adapter and pi SDK (stubbed network). Each finding was checked before acting on it. Fixes are in 692b858.

# Finding Outcome
1 Blocker. A message waiting at Telegram when the gateway starts got a false "I was restarted" notice while its turn was running, and its marker was deleted Fixed: markers are read before chat.initialize()
2 Messages accepted but still waiting their turn were lost on restart without notice; messages arriving during stop() were dropped Fixed: marker written at acceptance, polling stopped first, one notice per chat lists every unfinished request
3 /new, then a restart in the first turn, started a third empty session Fixed: the marker names the fresh session's file and an existing file is resumed
4 "Starts with /" let unknown commands overtake earlier messages, and /new moved a queued message into the new conversation Fixed: only commands about the running turn or the gateway skip the queue
5 A deferred /model reported success, then failed silently with the default already written Fixed: checks run before answering, a deferred failure is posted, an unusable model is not written as default
6 Button presses were still awaited by polling; /model during a compaction blocked Fixed: button handlers detached; "busy" is the adapter queue
7 /cancel said "Cancelled." without cancelling after /topic, and before the stream started Fixed: one abort signal per turn from acceptance, found by chat; says so when nothing is running
8 Tests wrote pi's real settings and shared the real in-flight directory Fixed: sandboxed
9 /new writes memory state without the thread lock Left: it now runs in the chat's queue, so no turn of that chat is in flight when it does
10 /think, /new, /compact did not answer until the turn ended /think now answers at once and applies after the turn; docs corrected for the others
11 /model reset the thinking level Fixed: kept when the new model has it
12 The image manifest claimed the model could see an image pi may have dropped Wording changed: read the file if you cannot see it
13 Test gaps (order with the chain removed, deferred failure, streaming images) Order, deferred failure, start-up and queued cases added
14 Claims the diff did not back Corrected in README, CHANGELOG and CLAUDE.md
15 Small things: /think markup shown literally, failed update check cached for 6 h, typing loops in /compact, marker deleted when the notice failed, menu showing the default as current Fixed, except typing loops in /doctor and /crons

Still not verified by anyone: these paths against real Telegram and a real model; Slack; the Kiro backend.

State at 692b858: 787 tests, typecheck clean.

@royosherove
royosherove merged commit dd8379e into main Nov 21, 2026
1 check passed
@royosherove
royosherove deleted the fix/gateway-responsiveness branch November 21, 2026 18:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 692b858beb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/gateway.ts
@@ -502,9 +558,19 @@ export class Gateway {
}
const result = await handler({ value: event.value, thread: event.thread });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Queue topic button actions behind earlier messages

When a message is queued behind a running turn, clicking a topic-selection button still invokes handleTopicAction immediately instead of joining the chat’s intake queue. It changes the active topic before the queued message computes applyTopicOverride, so that earlier message is sent to the newly selected conversation rather than the one active when it arrived. Queue topic-selection actions with the chat’s messages.

Useful? React with 👍 / 👎.

Comment thread src/gateway/gateway.ts
? `⚠️ I was restarted before I finished your request:\n${list}\nI have not run it again. Anything already done is in the conversation; say "continue" to pick it up, or send it again.`
: `⚠️ I was restarted before I finished these requests:\n${list}\nI have not run them again. Anything already done is in the conversation; say "continue", or send again what you still want.`;
try {
await this.chat.thread(threadId).post(text);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Chunk interrupted-request notices before posting

If many requests with full-length previews from one chat are interrupted, this combined notice can exceed the platform’s message limit. The direct thread.post(text) bypasses the message-splitting path; when posting fails, the markers are retained and the oversized notice is retried on each startup until the markers expire, so the owner may never be notified. Split or cap the notice before posting.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant