Skip to content

feat(sessions): the no-output watchdog as a session check, and an on-demand snapshot for the token-refresh sweep (task #211, step 2) - #668

Closed
aixle-com[bot] wants to merge 5 commits into
feature/session-checksfrom
feature/session-checks-no-output
Closed

aixle-com[bot] wants to merge 5 commits into
feature/session-checksfrom
feature/session-checks-no-output

Conversation

@aixle-com

@aixle-com aixle-com Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Step 2 of task #211 (decision 11.2), stacked on #667: base feature/session-checks. GitHub retargets it to develop once #667 merges. It moves the no-output watchdog and the token-refresh sweep onto the session monitor that #667 adds.

Sessions::Checks::NoOutput replaces Sessions::NoOutputWatchdog, Activities::Workflow::ScanNoOutputSessionsActivity, no_output_scan_workflow and its 5-minute schedule. It is the last check in Sessions::Monitor::CHECKS and reads the same snapshot as the quota scan's checks, with no exec of its own.

  • It has the same threshold (30 minutes), the same screen rule (SCREEN_RULE_RUNTIMES = %w[kiro_cli]; other runtimes use the log's mtime) and the same messages (expired login, turn end without finish_session, no output).
  • It skips the same sessions: interactive steps and auth-paused steps, while every other ready step is read from its start.
  • Its failure goes through Base#fail_session: a compare-and-set under the row lock.
  • Kept state: screen_digest and screen_changed_at, owned by the check and written in the pass's single update.

The token-refresh sweep uses an on-demand snapshot (decision 12). Right before it rotates a grant, RefreshExpiringTokensActivity#parked? reads each holder through Sessions::Monitor.snapshot, which uses the same read path and parts registry as the pass. It then runs Checks::NoOutput#silent_for?(snapshot, IDLE_BEFORE_REFRESH) on that snapshot. The read feeds the same kept record as the passes. A holder that cannot be read still counts as busy.

Kept state, now complete

Check Kept between passes Written by its action, under the row lock
QuotaError — —
BlockingPrompt — —
AuthPause — auth_paused_at, auth_pause_reason, auth_renewed_at, auth_heal_attempts, auth_heal_attempted_at
TurnEnd turn_end_screen, turn_end_seen_at turn_end_nudges
NoOutput screen_digest, screen_changed_at —

Behaviour changes, each explained

  • Cadence. The check runs on the monitor's 1-minute pass instead of every 5 minutes, so a silent session ends 30 to 31 minutes after its screen stopped changing, instead of 30 to 35. The threshold is unchanged. This follows from decision 1 (one mechanism every N minutes).
  • The screen digest is taken from the last 40 nonblank lines of the 1000-line scrollback instead of from a capture-pane -S -40. The two are the same lines unless the shorter capture held fewer than 40 nonblank lines. At the switch-over, such a session's digest changes once and its record restarts from the log's mtime, which only delays a verdict.
  • The expired-login message is detected on the current screen, the last 40 nonblank lines. The old capture was 40 lines plus the pane height.
  • On a pass where TurnEnd typed a reminder (:nudged, which stops the pass for that session), the no-output check does not run for that session. A session that was just typed into is not judged silent on the snapshot taken before the typing. Before, the two separate scans could both act within the same minute.
  • The token-refresh probe is capped at Settings.runners.scan_op_timeout (15 s) for a runner holder, as the pass is. Before, it used the 60 s default op timeout. A holder that does not answer still reads as busy.

Related issues

Board task #211. Depends on #667.

Type of change

  • Refactor / chore

How was this tested?

Ported tests, with the same assertions:

  • no_output_watchdog_test → test/services/sessions/checks/no_output_test.rb, run through the monitor and the fake runtime instead of a mocked LiveLogReader. It adds tests for the kept record, the auth-pause and interactive skips, and the re-check of a session that started finishing during the read.
  • The scan's 5-minute cadence test → test/temporal/activities/workflow/monitor_sessions_no_output_test.rb, at the 1-minute cadence. It asserts that the session ends within threshold + 1 minute, and that one exec per pass serves every check.

New tests in refresh_expiring_tokens_activity_test.rb:

  • A holder that started a turn after the last pass blocks the rotation. The last pass recorded the Kiro holder as parked for 20 minutes, but the on-demand read sees its working screen. Result: skipped_busy: 1, no refresh request, the old token is kept, and the read went through the snapshot and fed the record.
  • A holder still parked on the same screen lets the rotation go ahead.

Run on Coder (aixle-prod-2c822a0f, checkout 99d40423): rubocop on the 42 changed Ruby files against develop passed, and 659 targeted Rails tests passed with 0 failures. The targeted suites included sessions, the workflow activities, agent credentials, the token-refresh workflow, hosted-runtime-unchanged, runner session launch, the runner contract, docs and config.

Docs: docs/architecture/workflows.md (the no-output check row, the on-demand snapshot, the silence watchdog), docs/design/agent-credential-lifecycle.md, docs/design/agent-runtimes/DESIGN.md (8c now feeds the snapshot source).

Checklist

  • All my commits are signed off for the DCO (git commit -s).
  • I added/updated tests where it makes sense.
  • I updated documentation where it makes sense.

…demand snapshot for the token-refresh sweep (task #211, step 2)

Signed-off-by: Aixle Flow <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 8, 2026
# between "the agent went quiet" and "reconnect this agent". 41% of the sessions this
# watchdog reaped in the 14 days to 2026-09-17 carried such a banner.
def message(snapshot)
auth = AuthErrorDetector.detect(snapshot.screen.join("\n"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Recommendation] The failure message is now built from the unredacted pane.

Before this change, NoOutputWatchdog#message ran AuthErrorDetector on LiveLogReader#tail's text. tail passes the pane through Sessions::SecretRedactor.for_session(session) (live_log_reader.rb, "A live read is the same bytes the stored log would carry … so it gets the same redaction"). Snapshot#screen comes from the raw capture-pane output, so the matched auth line now lands in terminal_sessions.error_message unredacted. From there it reaches the step's error and the Slack failure notice (Chat::RunFailure). AuthErrorDetector.extract_message also falls back to the whole screen, truncated to 500 characters, when no single line matches.

The chance of a secret config value on that line is low. Still, the task says behaviour is unchanged, and this is a redaction the old path gave and the new one silently drops.

Suggestion: redact the message before it is stored, for example Sessions::SecretRedactor.for_session(session).call(auth.message). Doing it in Base#fail_session would also cover the quota, blocking-prompt and turn-end messages, which were never redacted. Then add a test with a secret config item whose value appears on the banner line.

Source: existing implementation pattern (Sessions::LiveLogReader), task acceptance ("Behaviour is unchanged").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 75aa47a5. Checks::NoOutput#message redacts the whole screen with Sessions::SecretRedactor.for_session(session).call before AuthErrorDetector, as LiveLogReader#tail did, so a secret wrapped across lines is masked as before. Checks::Base#fail_session also redacts the final message, which covers the quota, blocking-prompt and turn-end messages. Test in checks/no_output_test.rb: a secret config item whose value is on the banner line does not reach error_message.


::Sessions::NoOutputWatchdog.new(session).silent_for?(IDLE_BEFORE_REFRESH)
check = ::Sessions::Checks::NoOutput
snapshot = ::Sessions::Monitor.snapshot(session, parts: check.parts)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Must] (second review) Task decision 12 and docs/architecture/workflows.md say every holder is read on demand immediately before rotation, but the holder set is not synchronized with rotation here. run first classifies credentials through separate without_live_session/with_live_session queries, and refresh_held materializes holders before sequential probes. A session that becomes a holder after either classification or materialization is therefore either refreshed without any probe or omitted from both the safety decision and inline delivery. In a launch race, that new container can receive the revoked grant; refresh_if_expiring! can return :held before taking the refresh lease and reloading when another holder exists.

Please coordinate holder membership with the credential refresh lease: acquire the lease before the final holder query/probes, re-query and validate the complete holder set immediately before renewal, and make launches wait/reload when that lease is held before deciding :held. Deliver from the protected final holder set. Add an interleaving test that creates/starts another holder between the idle probe and renew! and verifies it cannot receive or retain the old grant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed in #211 (Alex, Fix CR round 1). The race predates this PR, which changes only how parked? reads a holder, not the order of the sweep's steps. It is tracked in task #213.

Aixle Flow added 4 commits November 8, 2026 19:00
…es (task #211, CR round 1)

Checks::NoOutput#message redacts the whole screen with
Sessions::SecretRedactor.for_session before AuthErrorDetector reads it,
as LiveLogReader#tail did. Checks::Base#fail_session redacts the final
message too, which also covers the quota, blocking-prompt and turn-end
messages.

Signed-off-by: Aixle Flow <[email protected]>
@aixle-com

aixle-com Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Reopened in Alex's name for the squash merge (task #211).

@aixle-com aixle-com Bot closed this Nov 9, 2026
aixle-com Bot pushed a commit that referenced this pull request Nov 10, 2026
Conflicts resolved:
- Files touched on staging only by the pre-squash branches of task #209 (PR #669)
  and task #211 (PRs #667/#668) take develop's version, which carries the
  reviewed, merged form of the same work (#670, #671, #672).
- test/integration/web/company/billing_test.rb: keeps the billing redesign's
  (#646) test body with develop's 14-day trial values (#678).
- CHANGELOG.md: develop's 1.11.0 entry for the 14-day trial; the billing
  redesign entry already present above is kept once.

Signed-off-by: Alex <[email protected]>
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.

0 participants