Skip to content

Revamp: Headless mode needs complete overhaul #412

@tunahorse

Description

@tunahorse

Current State

Headless mode (tunacode run) is implemented in src/tunacode/ui/main.py:

Entry Point:

  • run_headless() function (lines 194-262)
  • Takes: prompt, --output-json, --auto-approve, --timeout, --cwd, --baseurl, --model

Flow:

  1. Validates cwd if provided
  2. Sets model and base URL overrides on session
  3. Enables auto_approve in user config settings
  4. Creates async task for process_request()
  5. Uses asyncio.wait_for() with asyncio.shield() for timeout enforcement
  6. On success: outputs JSON trajectory or plain text via resolve_output()
  7. On timeout/exception: cancels task and prints error

Related Files:

  • src/tunacode/ui/headless.py - Output resolution logic
  • tests/system/cli/test_headless_cli.py - REMOVED (flaky test)

Problem

The headless mode implementation has reliability issues:

  • The removed test was intermittently timing out at 15s despite the 5s timeout being configured correctly
  • Test passed in isolation but failed in full suite run
  • Suggests deeper issues with async task handling, subprocess management, or test environment interaction

Required Action

Complete overhaul of headless mode. The current implementation needs to be reconsidered from the ground up to ensure reliable, deterministic behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions