Skip to content

fix(infinity-daemon): add keeps_session_alive flag - #90

Merged
akainth015 merged 1 commit into
mainfrom
feat/keeps_session_alive
Jul 30, 2026
Merged

fix(infinity-daemon): add keeps_session_alive flag#90
akainth015 merged 1 commit into
mainfrom
feat/keeps_session_alive

Conversation

@akainth015

Copy link
Copy Markdown
Member

to prevent non-interactive clients from blocking idle shutdown

Add a keeps_session_alive boolean field to ClientMessage::CreateSession and ClientMessage::Connect (defaulting to true via serde for backward compat). Connections that set this to false are tracked but do not prevent the session from idling out — enabling persistent but passive client connections (e.g. bots) that should not keep sessions warm indefinitely.

Key changes:

  • infinity-protocol: new keeps_session_alive field on CreateSession and Connect, with #[serde(default = "default_true")].

  • client_handler.rs: tracks connection_keeps_alive per connection and threads it through attach_client and send_input.

  • session/thread_worker.rs: replaces bare UnboundedSender subscriber lists with a Subscriber struct carrying tx + keeps_session_alive. Idle-exit and has-clients checks now only consider keep-alive subscribers.

  • session/mod.rs: exposes a worker_shutdown CancellationToken on sessions. send_input uses a retry loop (up to 2 attempts) to handle the race where the agent loop begins winding down between the restart check and the actual send — inputs arriving mid-wind-down now transparently restart the session.

  • infinity-agent-cli: all existing call sites pass keeps_session_alive: true (preserving current behavior for interactive CLI clients).

  • tests/keep_alive.rs: three integration tests covering non-keep-alive idle exit, keep-alive warmth, and input-after-idle-exit restart.

@akainth015
akainth015 requested review from a team and shadaj July 30, 2026 19:21
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 30, 2026

Copy link
Copy Markdown

Deploying infinity with  Cloudflare Pages  Cloudflare Pages

Latest commit: 71470ed
Status: ✅  Deploy successful!
Preview URL: https://f71f9962.infinity-dc7.pages.dev
Branch Preview URL: https://feat-keeps-session-alive.infinity-dc7.pages.dev

View logs

@akainth015
akainth015 force-pushed the feat/keeps_session_alive branch from 042335f to 71470ed Compare July 30, 2026 21:16

@shadaj shadaj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two fixup areas

/// Subscribe request: (client_tx, want_replay).
pub type SubscribeRequest = (mpsc::UnboundedSender<DaemonMessage>, bool);
/// Subscribe request: (client_tx, want_replay, keeps_session_alive).
pub type SubscribeRequest = (mpsc::UnboundedSender<DaemonMessage>, bool, bool);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should turn this into a struct with field name.

thread_id: &str,
msg: (InputMessage, Option<String>),
client_tx: Option<mpsc::UnboundedSender<DaemonMessage>>,
client_tx: Option<(mpsc::UnboundedSender<DaemonMessage>, bool)>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should use Subscriber here.

@akainth015
akainth015 force-pushed the feat/keeps_session_alive branch from 71470ed to de6322a Compare July 30, 2026 21:38
…nteractive clients from blocking idle shutdown

Add a `keeps_session_alive` boolean field to `ClientMessage::CreateSession` and
`ClientMessage::Connect` (defaulting to `true` via serde for backward compat).
Connections that set this to `false` are tracked but do not prevent the session
from idling out — enabling persistent but passive client connections (e.g. bots)
that should not keep sessions warm indefinitely.

Key changes:

* `infinity-protocol`: new `keeps_session_alive` field on `CreateSession` and
  `Connect`, with `#[serde(default = "default_true")]`.

* `client_handler.rs`: tracks `connection_keeps_alive` per connection and
  threads it through `attach_client` and `send_input`.

* `session/thread_worker.rs`: replaces bare `UnboundedSender` subscriber lists
  with a `Subscriber` struct carrying `tx` + `keeps_session_alive`. Idle-exit
  and has-clients checks now only consider keep-alive subscribers.

* `infinity-agent-cli`: all existing call sites pass `keeps_session_alive: true`
  (preserving current behavior for interactive CLI clients).

* `tests/keep_alive.rs`: integration tests covering non-keep-alive idle exit
  and keep-alive warmth.

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
@akainth015
akainth015 force-pushed the feat/keeps_session_alive branch from de6322a to c038739 Compare July 30, 2026 23:05
@akainth015
akainth015 merged commit 1b20fda into main Jul 30, 2026
7 checks passed
@akainth015
akainth015 deleted the feat/keeps_session_alive branch July 30, 2026 23:44
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.

2 participants