Skip to content

[BUG][CLI] cortex run --timeout N: **timeout exits the event-receive loop** but **does not cancel** the session task — **session_task.await** lets the agent keep running; timeout line **always prints N** not elapsed wall time #53273

@kiannidev

Description

@kiannidev

Project

cortex

Description

When --timeout is set (N > 0), the client loop polls elapsed time only between handled events on handle.event_rx. On timeout it sets interrupted, prints Timeout reached after {N} seconds, and breaks out of the loop.

The process then drop(handle) and session_task.await. The spawned session.run() task was not aborted, so the agent loop can continue, including outbound API requests. That matches logs where Timeout reached after 1 seconds is followed a few seconds later by 402 Payment Required / INSUFFICIENT_BALANCE — the 402 is billing (no token balance), but it illustrates that work did not stop at the timeout line.

Additionally, the printed message uses self.timeout (N), not measured elapsed time, and the first timeout check cannot run until after the first event is received; long startup intervals before the first event make “after 1 seconds” read as wall-clock misleading.

Error Message

Debug Logs

System Information

OS: Windows (reporter)
Example: cortex run --cwd D:/Projects/Bittensor/100platform/cortex --timeout 1 "Run cargo test"
Reporter also saw: API 402 INSUFFICIENT_BALANCE (account balance — separate from timeout semantics)

Screenshots

https://github.com/kiannidev/screens/blob/main/784a09dbd82af5b05c41d120ebfb323a.png

https://github.com/kiannidev/screens/blob/main/17166d14e8f22c1699a15bc8e8a19abd.png

Steps to Reproduce

  1. Run: cortex run --timeout 1 "<prompt that eventually starts agent loop>" (from a state that reaches the API).
  2. Observe Timeout reached after 1 seconds when the event loop decides elapsed > 1s (often on or after an event, not necessarily “1s from process start”).
  3. Observe further logs (e.g. API errors) after the timeout message while the process is still await-ing session_task.

Expected Behavior

  • --timeout: Cancels or **abort()**s the session / agent task (or closes the session cleanly) so no further API calls run after timeout, or the UX clearly states “display/interactive timeout; background session may continue.”
  • Error text: Prefer “Wall-clock limit: {N}s exceeded” (and optionally print elapsed) instead of implying exactly N seconds since user-visible start.

Actual Behavior

  • Loop breaks on timeout; session_task.await waits for full session exit.
  • API may still run; 402 can appear after “Timeout reached.”
  • Message always says after {N} seconds even when wall time before first event was longer.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions