Repository navigation
fix(sessions): remind a Kiro agent that ends its turn without finish_session, and judge silence by the screen (task #208) - #666
Merged
Conversation
…session, and judge silence by the screen Automatic sessions run the CLI's TUI, which waits for a person when a turn ends. The quota scan now types a reminder into a ready non_interactive Kiro step that sits at its idle prompt on two reads, holds it while a person has typed in the last 10 minutes, and fails the session after 3 reminders. The no-output watchdog judges silence by a digest of the rendered screen, so an idle TUI that keeps repainting no longer reads as busy. Kiro's Stop hook was measured on 3.0.0 and not used: it fires once per prompt and not on a provider error (task #208). Signed-off-by: Aixle Flow <[email protected]>
aixle-com Bot
pushed a commit
that referenced
this pull request
Nov 7, 2026
…#208) Signed-off-by: Aixle Flow <[email protected]>
NOX73
reviewed
Nov 8, 2026
added 2 commits
November 8, 2026 09:35
…ng, one tmux call (task #208 CR) - NoOutputWatchdog judges silence by the screen only for SCREEN_RULE_RUNTIMES (kiro_cli); other runtimes keep the log-mtime rule, for the watchdog and the token-refresh sweep. - ScanNoOutputSessionsActivity reads sessions from their start (no MIN_AGE) and runs every 5 minutes. - TurnEndNudge counts a reminder and forgets the confirmed screen under the row lock before typing, so a retry or a second scan types nothing. - Sessions::PaneInput types text and Enter in one tmux call, used by AuthPause and TurnEndNudge; ScreenDigest.lines replaces the copied pane normalization. - ScanQuotaErrorsActivity reads AuthPause's verdict with auth.paused?. Signed-off-by: Aixle Flow <[email protected]>
… watchdog delay from the recorded screen time Signed-off-by: Aixle Flow <[email protected]>
… the reminder cap; match Kiro's idle prompt at any pane width (task #208 CR) TurnEndNudge#give_up reads the session again under its row lock, as claim does, and fails it only if it still takes reminders (ready, non_interactive, workflow step, not auth-paused) and the cap is reached. SessionService.fail_session runs after the lock is released. TurnEndDetector matches Kiro's prompt on its start, allows three lines under it and no longer needs the Credits line's session figure on the same line: at 30 columns the placeholder, the hint and the Credits line wrap. New real kiro-cli captures: 3.0.0 at 80x24, 220x50 and 30x20, and 2.34.0 at 80x24. Signed-off-by: Aixle Flow <[email protected]>
5 tasks done
5 tasks done
This was referenced Nov 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task #208. An automatic Kiro session whose agent ends its turn without
finish_sessionno longer waits for a person. For Kiro, a screen that stopped changing now counts as silence, even while the pane keeps sending bytes. The screen rule covers Kiro only for now; the other runtimes keep the log-mtime rule.Which option, and what the measurement showed
Built: B (typed reminder) and C (silence judged by the screen). I measured A first and did not build it.
Measured on kiro-cli 3.0.0, the pin (checksum as in
docker/kiro-cli/Dockerfile), with--v3 chatin the TUI and a global~/.kiro/hooks/*.jsonStopcommand hook:{"decision":"block","reason":"…"}answer with exit 0 makes the agent continue in the same turn. The reason reaches it inside<HOOK_INSTRUCTION>.Proxy connection ended before receiving CONNECT response, then the Credits line and the idle prompt, and the hook never ran.{session_id, hook_event_name, cwd}, with Kiro's own session id. Nothing in it says whetherfinish_sessionwas called, or whether the platform session is finishing or paused.So A gives one continuation per session and misses case 2. A typed message is a new prompt: it works on every turn end, including one ended by an error. I checked that a reminder sent with
tmux send-keys -l … ; Enteris submitted and answered.The bytes in case 1. An idle 3.0.0 TUI with no client sent 0 bytes in 40 s. Two pane resizes made it repaint 12,238 bytes while
capture-panestayed byte-identical. A web terminal attaching to the pane or resizing it does exactly this, which fits the freshterminal_output.login case 1. I didn't reproduce the exact trigger in that session.What changed
B:
Sessions::TurnEndNudge+TurnEndDetector, called fromScanQuotaErrorsActivity. The scan already reads each pane once a minute, and this reuses that read.TurnEndDetectorrecognises Kiro's idle prompt (› ask a question or describe a task ↵). The prompt must be among the last lines of the current screen, with a▸ Credits: turn …summary just above it. A draft typed in the box, a working indicator, or the startup screen (no summary yet) does not match.turn_end_screendigest andturn_end_seen_atin metadata). The reminder is then claimed under the session's row lock: the session, the confirmed screen and the count are checked again, the count goes up and the screen is forgotten, before anything is typed. A Temporal retry of the scan, or a second scan of the same screen, types nothing. A reminder whose typing failed is used up. Then the reminder is typed: "Aixle: your turn ended, but this automatic session is not finished. If all work is done, callfinish_session. Otherwise continue from where you stopped."date +%s && tmux list-clients -t agent -F '#{client_readonly} #{client_activity}'. While a writable client has sent input within 10 minutes, nothing is typed, and the reminder goes out on the first scan after that. The rule is based on input: a read-only viewer never holds it. tmux setsclient_activitywhen a client attaches, so opening the owner's terminal also holds reminders for 10 minutes. Clients that cannot be read hold the reminder too.Sessions::PaneInput.typesends the text andEnterin one tmux call (send-keys -t agent -l MSG ; send-keys -t agent Enter), so a partial failure cannot leave an unsent draft.Sessions::AuthPause#nudgeuses it too.Sessions::ScreenDigest.lines(text, last:)is now the one place that turns a pane into its screen lines, forTurnEndDetector,ScreenDigest,AuthPause,InteractivePromptDetectorandQuotaErrorDetector.turn_end_nudges). The turn end after the third fails the session: "Session terminated: the agent ended its turn without callingfinish_session4 times, and Aixle's 3 reminders to finish or continue did not change that. …"ready(finishing ones included),interactivemode, non-workflow-step sessions, sessionsSessions::AuthPauseholds or has just acted on, and runtimes without a measured signature.C:
Sessions::NoOutputWatchdogjudges Kiro's silence by a digest of the rendered screen.NoOutputWatchdog::SCREEN_RULE_RUNTIMES, an opt-in list likeTurnEndDetector::SIGNATURESthat holdskiro_clionly. Every other runtime keeps the old rule, for the watchdog and for the token-refresh sweep: the log's mtime. Their working screens were not captured, and an indicator that animates only through colour could read as silence while the agent works. They move to the screen rule in a separate task, through the same list.ScanNoOutputSessionsActivityno longer skips sessions younger than 31 minutes, so the screen record starts at the first sweep.no_output_scan_workflownow runs every 5 minutes (*/5 * * * *,overlap: skip) to keep those reads affordable. A silent session is ended 30 to 35 minutes after its screen (or, for other runtimes, its log) stopped changing.screen_digestandscreen_changed_aton the session. A screen can't change without bytes, so the log mtime still caps the time: a first read, or a read that sees a changed screen, starts from the mtime. An unchanged screen keeps its recorded time, so 30 minutes of repaints now count as silence.finish_session. Other messages are unchanged.Kiro is working · 6s(measured).Token-refresh sweep (
RefreshExpiringTokensActivity#parked?). It still callssilent_for?(10.minutes). For Kiro it now reads the same screen record: a session parked at its prompt counts as parked even while it repaints. Before, it read as mid-turn and its rotating grant was not refreshed. An agent mid-turn changes its screen, so it still defers. The first read of a session judges by the mtime, as before, and an unreadable container still answers "not parked". Every other runtime is judged exactly as before this PR, by the log's mtime.Turn-end gap in other runtimes (out of scope)
Automatic sessions run the TUI on Claude Code, Cursor CLI, Codex, Gemini CLI, Grok and Kiro, so all of them wait at their prompt when a turn ends. Antigravity runs
--printin automatic mode and exits back to the shell. With this PR, every runtime is still ended by the watchdog after 30 to 35 minutes of silence: Kiro judged by its screen, the others by their log's bytes. Only Kiro has a reminder signature. Adding one for another runtime means measuring its idle screen and adding an entry toTurnEndDetector::SIGNATURES, with nothing else to change.Tests
The fixtures are real
capture-paneoutput from kiro-cli 3.0.0 (test/fixtures/files/terminal_panes/kiro_cli/): a normal turn end, a turn ended by a network error (case 2's shape), the turn after a reminder, and a working pane.test/services/turn_end_detector_test.rb: matches the turn end and the error-ended turn. A working pane, a draft, the startup screen, a turn end left in the scrollback and other runtimes don't match.test/services/sessions/turn_end_nudge_test.rb:test/services/sessions/no_output_watchdog_test.rb: a Kiro screen unchanged for 31 minutes is stale while the mtime stays fresh, and a ticking working screen is not. The first read uses the mtime as before. The refresh sweep's 10-minute question follows the screen. The idle-prompt message is checked. A runtime outsideSCREEN_RULE_RUNTIMESis judged by the log's mtime, forstale?andsilent_for?, and keeps no screen record.test/temporal/activities/workflow/scan_no_output_sessions_activity_test.rb: a Kiro session that starts with no screen record, whose screen stays unchanged while redraw bytes keep the mtime fresh, is ended by the real watchdog at the 5-minute cadence 30 to 35 minutes after its screen stopped changing.test/temporal/activities/workflow/scan_quota_errors_turn_end_test.rb: the scan sends the reminder on its second pass and fails the session after the cap.test/services/sessions/pane_input_test.rb: one tmux call for the text andEnter, and false on a refused or failed exec.FakeRuntime#set_terminal_clientsanswerstmux list-clients.Fix CR round 1, on Coder at
176ef030: the changed tests (151 runs) and the neighbouring suites (215 runs) pass, and rubocop on the changed files is clean. Details are in the task.First round, on Coder at
a2b99665:make rails_check_all(Vite build + the full backend suite, 9841 tests) is OK;Docs
docs/architecture/workflows.mdgets a new section, When an automatic session's agent stops withoutfinish_session.docs/design/agent-runtimes/DESIGN.mdanddocs/design/agent-credential-lifecycle.mdnow describe screen-based silence for Kiro and the 5-minute sweep.CHANGELOG.mdgets two Sessions & Runs fixes.How to test (QA, staging)
Staging has no Kiro credential and none can be connected there (Alex, 2026-11-08), so option B is verified by the automated tests built on real pane captures. On staging, the watchdog can be checked on any runtime: a Claude Code step parked at its prompt fails 30 to 35 minutes after its last output.
With a Kiro credential: