Skip to content

feat(computer): take over a session's screen from the web terminal - #1699

Merged
edenreich merged 7 commits into
mainfrom
fix/issue-1697
Nov 5, 2026
Merged

edenreich merged 7 commits into
mainfrom
fix/issue-1697

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Resolves #1697

Summary

The web terminal's Screen view gains a take-over mode shaped like the handoff in agent computer: the person claims the session's screen with a Take over button, drives it directly (pointer clicks, double click, wheel, typed text, key combos inside the image), and hands it back with Done (or Esc twice). The agent is held while the person holds the screen and resumes from a fresh screenshot of what the person left behind. The invariant - exactly one actor drives a screen at a time - lives in the computer context, and everything upstream stays a relay on the existing read_frame path, so a teleported session works unchanged.

Changes

  • computer/domain: the ScreenControl contract (TakeOver, HandBack, Held, WaitRelease, Drive) beside Action, the ScreenInput value object (kind, x, y, text, combo, button, direction, amount in frame space) with the Action builder, and the IsInputAction predicate that tells agent apart from observation.
  • computer: screen_control.go keeps the invariant with a mutex and a release broadcast, publishes ScreenTakenOver / ScreenHandedBack through the UI notifier, and Drive scales frame coordinates with the existing scaler straight to the display controller - no tool layer, no approval, no judge, no conversation entry. input_dispatch.go carries the pointer, wheel, type and key mechanics the Computer tool's executor and the person's Drive share; executor.Do parks input actions on Held() with the call's context, so a cancelled turn never hangs on a held screen, while observations pass through.
  • agui: the run state gains the screenControl key, seeded, that the take-over and hand-back events patch - every client following the thread sees who drives the screen.
  • presentation/headless: the screen_input and screen_control panel unit beside panel_frame.go, answered by one screen_result with the request id; PanelDeps gains the worker's Screen control and the message queue. Hand-back queues "I took over the screen and handed it back, continue from what you see now." through the run input's own path and wakes the turn loop. A take-over resolves as rejected every open approval box the agent parks on for a Computer call (the interrupt registry now notes the tool each interrupted call names).
  • sessions: screen_input and screen_control ride the panel-request routing like read_frame - named-session-only, with screen_result replies matched by request id.
  • cmd/daemon + presentation/web: the screenControl and screenInput relays beside screenFrame, and POST /screen/?id= with the same bearer token as the GET. It answers {"held": ...}; an input for a screen nobody holds and a take-over of a screen somebody else holds are 409s, so a stale tab cannot drive what it handed back.
  • internal/container wiring creates one ScreenControl per worker/container and hands it to both the Computer tool's executor and the worker's panel.

Tests

  • computer: take over / hand back / held invariants and the wait-release loop, ScreenInput to Action mapping, executor parking on a held screen.
  • presentation/headless: the panel unit with counterfeiter fakes (take over, hand back, input, not-held refusal, continue message).
  • presentation/web: the POST handler (auth, statuses, 409s).
  • cmd/daemon: the screenInput relay round trip through a registry.

Docs

  • docs/web-terminal.md, docs/browser-extension-protocol.md, docs/computer-use.md and examples/computer-use/README.md updated in follow-up commits, with a [DOCS] ticket for inference-gateway/docs.

Out of scope (per the issue)

  • A real video stream instead of the faster poll; TUI take-over (no screen view there yet).
  • The runner cannot verify the examples/computer-use acceptance live (no X display in the CI job) - the coordinate scaling, input relay and hold logic are covered by unit tests instead.

The take-over invariant lives in the computer context: the person claims the screen, drives it directly with frame-space inputs, and hands it back. The executor parks input actions on Held() until the hand-back, the panel unit answers screen_control and screen_input frames, and a take-over resolves the open Computer-call approval and queues the hand-back continue message. Daemon and web delivery relay both directions beside read_frame.
The Screen view's Take over button claims the session's screen: the image takes focus, pointer clicks, wheel and keys inside it POST to /screen/ and land on the worker's display in frame coordinates, the poll drops to 250 ms while held, and Done or a second Esc hands it back, which resets the poll and queues the agent's continue message. The page hands a closed tab's screen back fire-and-forget. The counterfeiter fake for the ScreenControl contract is generated and its domain listed among the mock sources.
@inference-gateway-maintainer
inference-gateway-maintainer Bot marked this pull request as ready for review November 5, 2026 01:36
@inference-gateway-maintainer
inference-gateway-maintainer Bot requested a review from a team as a code owner November 5, 2026 01:36
@edenreich

Copy link
Copy Markdown
Contributor

@infer CI is failing - can you fix this?

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Model: ollama_cloud/glm-5.3-flash · Action: v0.59.4 · CLI: v0.244.0 · View Job

Todos

  • Inspect the failing lint CI check and logs
  • Fix the gci import grouping (3 test files) via the repo formatter
  • Fix the gocyclo violation in screen_post_test.go
  • Validate (full lint + targeted tests) and push

Pull Request

#1699

✅ Infer Result: Success

Working tree is clean and everything is pushed. Closing out the todos.

CI lint is fixed and pushed to PR #1699 (commit 48158f88).

What was failing

The lint check reported 4 issues, all in test files added by this PR:

  1. gci - "File is not properly formatted" in cmd/daemon/screen_test.go, internal/computer/screen_control_test.go, and internal/presentation/headless/panel_screen_test.go. The new test files had mixed the tests/mocks/* imports into the same group as the project-internal imports, breaking the repo's import-group order (tests/mocks is its own section that must come before the github.com/inference-gateway/cli internals).
  2. gocyclo - complexity 27 > 25 in TestScreenPOSTTakesTheScreenOverAndGuardsStaleInputs (internal/presentation/web/screen_post_test.go).

What I changed

  • Ran the repo's own formatter (golangci-lint fmt, the same command task fmt runs) to regroup the imports in the three test files - the tests/mocks alias group now sits in its own group ahead of the project-internal group, exactly matching the .golangci.yml gci sections. No other files were touched.
  • Added a reasoned //nolint:gocyclo,cyclop to TestScreenPOSTTakesTheScreenOverAndGuardsStaleInputs. The test is one cohesive scenario (one POST per asserted outcome, in order), and the repo's AGENTS.md says to prefer //nolint over splitting cohesive functions, matching the existing precedent in run_decoder_test.go and others.

Verification

  • Full golangci-lint run --timeout=10m --build-tags purego (the exact CI invocation) passes with 0 issues.
  • go test ./cmd/daemon ./internal/computer ./internal/presentation/headless ./internal/presentation/web - all pass.
  • The commit went through the repo's pre-commit hook (mod:tidy, fmt, lint:imports, golangci-lint, markdownlint) which also reported 0 issues, so task precommit:run's gate is green.

Commit: style(tests): regroup the screen-test imports and mark the POST test within the complexity cap. Working tree is clean and everything is pushed; CI will re-run the lint check on this push.

Not checked: I verified against the current state only; no re-review of the take-over feature itself beyond the lint scope. Risk: CI's golangci-lint is v2.14.0 vs my local v2.12.2 - the gci/gocyclo checks are config-driven and identical here, but if 2.14.0 adds new linter findings it could surface others on the next run.

Model: ollama_cloud/glm-5.3-flash · Action: v0.59.4 · CLI: v0.244.0 · Exit Code: 0 · Duration: 4m 48s

Tokens: 1,082,755 in · 16,116 out · 1,098,871 total (22 requests)

Tool calls: 36 total · 100% success rate

Traces
Session: 1793843295-713c7016

session (headless, success)                                                                        4m41s
├── chat ollama_cloud/glm-5.3-flash                                                                 1.9s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.9s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.9s
│           ╰── POST [inference-gateway, server]                                                    1.9s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.9s
├── execute_tool TodoWrite call_003eeb6t                                                            71µs
├── execute_tool Bash call_f8c24yje                                                                 1.1s [error: tool_error]
├── execute_tool Bash call_42hiem11                                                                  4ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.6s
│           ╰── POST [inference-gateway, server]                                                    1.6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.6s
├── execute_tool Bash call_wlb7g4oa                                                                 1.8s
├── chat ollama_cloud/glm-5.3-flash                                                                 2.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.1s
│           ╰── POST [inference-gateway, server]                                                    2.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.1s
├── execute_tool Read call_44gi06h6                                                                374µs
├── execute_tool Read call_cmzi6udk                                                                362µs
├── execute_tool Read call_3t5o3vi0                                                                361µs
├── execute_tool Read call_6c7p1v1f                                                                389µs
├── chat ollama_cloud/glm-5.3-flash                                                                 5.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.1s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                        5.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.1s
├── execute_tool Grep call_2ad3st98                                                                  1ms
├── execute_tool Read call_dm681pd0                                                                235µs
├── chat ollama_cloud/glm-5.3-flash                                                                 6.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       6.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     6.7s
│           ╰── POST [inference-gateway, server]                                                    6.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 6.7s
├── execute_tool Grep call_1oumnu7r                                                                367ms
├── execute_tool Read call_zipwfpzj                                                                247µs
├── chat ollama_cloud/glm-5.3-flash                                                                10.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      10.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    10.6s
│           ╰── POST [inference-gateway, server]                                                   10.6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                10.6s
├── execute_tool Grep call_kipgjj5u                                                                  1ms
├── execute_tool Grep call_i0k95jkt                                                                  1ms
├── chat ollama_cloud/glm-5.3-flash                                                                 2.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.0s
│           ╰── POST [inference-gateway, server]                                                    2.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.0s
├── execute_tool Read call_byf3glih                                                                239µs
├── execute_tool Memory call_7k88blpf                                                              106µs
├── chat ollama_cloud/glm-5.3-flash                                                                 9.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       9.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     9.1s
│           ╰── POST [inference-gateway, server]                                                    9.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 9.1s
├── execute_tool TodoWrite call_thxvoo1b                                                            52µs
├── execute_tool Bash call_xiunuo1b                                                                 56ms
├── chat ollama_cloud/glm-5.3-flash                                                                15.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      15.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    15.1s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                       15.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                15.1s
├── execute_tool Bash call_od239un4                                                                 1.4s
├── chat ollama_cloud/glm-5.3-flash                                                                 1.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.3s
│           ╰── POST [inference-gateway, server]                                                    1.3s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.3s
├── execute_tool Bash call_g5le7gku                                                                  4ms
├── execute_tool Bash call_ath6d9y2                                                                  6ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.3s
│           ╰── POST [inference-gateway, server]                                                    1.3s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.3s
├── execute_tool Bash call_iizvrlkt                                                                  4ms
├── chat ollama_cloud/glm-5.3-flash                                                                 5.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.5s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.5s
│           ╰── POST [inference-gateway, server]                                                    5.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.5s
├── execute_tool TodoWrite call_a7kwnlg3                                                            60µs
├── execute_tool Edit call_gn7zy5ua                                                                475µs
├── chat ollama_cloud/glm-5.3-flash                                                                 3.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.5s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.5s
│           ╰── POST [inference-gateway, server]                                                    3.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.5s
├── execute_tool TodoWrite call_6m4la9v1                                                            37µs
├── execute_tool Bash call_xd4b3p8r                                                                  1ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.4s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.4s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.4s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                        1.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.4s
├── execute_tool Bash call_nwz257qo                                                                2m25s
├── chat ollama_cloud/glm-5.3-flash                                                                 1.2s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.1s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                        1.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.1s
├── execute_tool Wait call_rcou9x70                                                                38.0s
├── chat ollama_cloud/glm-5.3-flash                                                                 4.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     4.6s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                        4.6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 4.6s
├── execute_tool Bash call_273hrlhf                                                                  5ms
├── execute_tool Bash call_nfc5klci                                                                  2ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.2s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.1s
│           ╰── POST /proxy/{provider}/{path...} [inference-gateway, server]                        1.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.1s
├── execute_tool Bash call_tio0bgft                                                                  7ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.4s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.4s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.4s
│           ╰── POST [inference-gateway, server]                                                    1.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.4s
├── execute_tool Bash call_6vk97i5t                                                                 5.1s
├── chat ollama_cloud/glm-5.3-flash                                                                 1.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.2s
│           ╰── POST [inference-gateway, server]                                                    1.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.2s
├── execute_tool Bash call_6o01ksfp                                                                 1.5s
├── chat ollama_cloud/glm-5.3-flash                                                                 1.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.1s
│           ╰── POST [inference-gateway, server]                                                    1.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.1s
├── execute_tool Bash call_nqnh4g24                                                                  5ms
├── execute_tool Bash call_dynlauxc                                                                  5ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.9s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.8s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.8s
│           ╰── POST [inference-gateway, server]                                                    1.8s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.8s
├── execute_tool TodoWrite call_z5ujc7ca                                                            71µs
╰── chat ollama_cloud/glm-5.3-flash                                                                 3.5s
    ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.5s
        ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.5s
            ╰── POST [inference-gateway, server]                                                    3.5s
                ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.5s
Stats
Tool Calls

╭───────────┬───────┬───────┬─────────╮
│ Tool      │ Calls │ Fail% │ Avg     │
├───────────┼───────┼───────┼─────────┤
│ Bash      │ 17    │ 6%    │ 9173ms  │
│ Read      │ 7     │ 0%    │ 308µs   │
│ TodoWrite │ 5     │ 0%    │ 58µs    │
│ Grep      │ 4     │ 0%    │ 93ms    │
│ Memory    │ 1     │ 0%    │ 95µs    │
│ Edit      │ 1     │ 0%    │ 422µs   │
│ Wait      │ 1     │ 0%    │ 38000ms │
╰───────────┴───────┴───────┴─────────╯

Token Usage

╭────────────────────────────┬─────────┬────────┬────────────┬─────────┬──────╮
│ Model                      │ Prompt  │ Cached │ Completion │ Total   │ Cost │
├────────────────────────────┼─────────┼────────┼────────────┼─────────┼──────┤
│ ollama_cloud/glm-5.3-flash │ 1082755 │ 766080 │ 16116      │ 1098871 │ -    │
╰────────────────────────────┴─────────┴────────┴────────────┴─────────┴──────╯

Sessions

╭───────────┬──────────┬──────────╮
│ Execution │ Mode     │ Sessions │
├───────────┼──────────┼──────────┤
│ headless  │ headless │ 1        │
╰───────────┴──────────┴──────────╯

Triggered by edenreich · Infer Action · OSS

…held invariant

- Build the screen control only when computer_use.enabled is set, so the
  POST /screen/ route cannot drive the host with computer use disabled.
- Drive refuses an unheld screen with ErrScreenNotHeld and HandBack reports
  whether it released, so the panel no longer checks then acts.
- The Screen view sends inputs one at a time in order, hands back when the
  view is hidden and adopts a hold another tab left behind.
- Relay the input as raw JSON instead of a duplicate web.ScreenInput, and
  drop the defaults and checks the display dispatch already applies.
- The daemon relay test uses the generated fake worker without a
  hand-written launcher or a sleep loop.
@edenreich
edenreich merged commit c8c8fa6 into main Nov 5, 2026
13 checks passed
@edenreich
edenreich deleted the fix/issue-1697 branch November 5, 2026 12:32
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.245.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 5, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Take over the session's screen from the web terminal

1 participant