← Back to Pull requests

Implement ai.external: ExternalHarness, ExternalHarnessProvider and Session #346

Closed
unknown closed this pull request without merging on Nov 18, 2026 00:13 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 17:26 UTC
Author

A draft for ai.external. #347, the competing draft, is closed.

An external harness is a coding-agent CLI (Codex, Claude Code, Pi, fx) where a model goes. It has the shape of an ai.Model: plain data and a provider. The state is in a session.

  • ExternalHarness: the settings of the CLI. It holds no state.

  • ExternalHarnessProvider: name, executable, env, and the stream() that ai.stream and ai.Agent.run call.

  • Session: the state (id, messages) and direct control (start, send, events, interrupt, close).
  • harness = ai.external.Codex(cwd=".")
    async with harness.session() as session:
        async with agent.run(harness, messages) as run: ...
        await session.send(ai.user_message("And the tests?"))
    

    Sessions

  • async with harness.session() is the only way to start the CLI. A model call outside the block raises ExternalHarnessError. No call starts a CLI for one turn.

  • harness.session() is a new session. harness.session(session_id) continues one that the CLI has, and harness.session(messages=history) starts one with a past (lossy). To continue later, save session.id with the harness data.

  • A harness has one open session in a task: a second harness.session() in the block raises. Two tasks can each open one.

  • session.start() starts the CLI early in an open block. It does not open a session.
  • Compared with #347

  • Core changes less. ai.stream still calls model.provider.stream(model, ...); the diff outside ai/external is Model -> ModelLike annotations, one aclosing block in api.py, the Context.model annotation, and the two protocols (ModelLike, ProviderLike) in models/core/model.py. ai/__init__.py imports external, as it does durable and testing. hooks.py is as on main.

  • The state and direct control are on a separate Session, not on the harness.

  • Not here, and in #347: approvals through hooks, output_type, fork() and sync().
  • fx

    ai.external.Fx drives fx acp (Agent Client Protocol over stdio). The wire follows Codex; JsonRpcPeer moved to external/_jsonrpc.py so that both use it.

  • Fields: model_provider and effort. fx runs with --permission-mode full-access.

  • A new session with a past is written into the fx session store, with tool calls, results and images, and opened with session/load. If fx refuses it, the wire removes what it wrote and raises ExternalHarnessError with the fx version.

  • Limits, stated on Fx: a bridge tool must answer in 5 minutes; streamed tool results are short previews; instructions are fixed when the session starts; the built-in tools cannot be limited. The store format is internal to fx, so a new fx release can break the seed.

  • Session.interrupt() does nothing between the end of a turn and the start of the turn that fx makes from a late steer. After an interrupt, a steer that fx dropped goes again as a new prompt.
  • Status

  • Offline tests, ruff, mypy (src tests) and ty pass locally and in CI (Python 3.12 to 3.14) on 0073da8.

  • The live tests (AI_EXTERNAL_LIVE=1 uv run pytest tests/external/test_live.py) were not run after the session changes (d0dffe8 and later). The last recorded run is fx only, with fx 0.0.17 on 57bd861.
  • Diff: 406 lines (+304 / -102) across 5 files Reviewer: 1st1 Review duration: 10486m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 406 lines diff across 5 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #346"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.8% (MEDIUM) · Higher = larger blast radius
    49.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%