Skip to content

fix(computer): pick X11 or Wayland backend at runtime on Linux - #1309

Merged
edenreich merged 1 commit into
mainfrom
fix/computer-x11-purego
Sep 25, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/computer-x11-purego

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Release builds use -tags purego, which makes robotgo compile only its Wayland backend on Linux (wayland_n.go). On an X11 session, the Computer tool therefore reported a 0x0 display and every action failed. The README says both X11 and Wayland are supported, so switching the build tag to purego x11 would only have broken Wayland instead.

The display controller now calls robotgo's pure-Go x11 and wayland subpackages directly and chooses between them once, at startup:

  • X11 when DISPLAY is set and WAYLAND_DISPLAY is not
  • Wayland in every other case, including XWayland (the previous default)

macOS and Windows still use the top-level robotgo package, so they behave as before. No new dependencies; both subpackages come from the robotgo module we already use.

Testing

  • go build -tags purego ./... for darwin, linux and windows
  • Linux table test for the backend selection (TestUseX11)
  • Real X11 check in a golang:1.26 container running Xvfb (DISPLAY=:99): the X11 backend was picked, the display reported 1280x800 and a full-screen capture succeeded
  • task precommit:run, plus golangci-lint with GOOS=linux

Closes #1303

robotgo's purego build hard-wires its Wayland backend on Linux, so on an
X11 session the Computer tool saw a 0x0 display and every action failed.
Call robotgo's pure-Go x11 and wayland subpackages directly and choose
per session: X11 when DISPLAY is set without WAYLAND_DISPLAY, Wayland
otherwise (including XWayland). macOS and Windows are unchanged.

Closes #1303
@edenreich
edenreich requested a review from a team as a code owner September 25, 2026 12:29
@edenreich

Copy link
Copy Markdown
Contributor Author

@infer Can you review this PR? is it ready for merge? use /ponytail:ponytail /ponytail:ponytail-review /domain-driven-design /clean-architecture /clean-code

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Model: ollama_cloud/glm-5.3-flash · View Job

Todos

  • Read invoked skills (ponytail, ponytail-review, DDD, clean-architecture, clean-code)
  • Read PR diff and changed files
  • Review against skills' criteria and robotgo API correctness
  • Report findings in final message

Pull Request

#1309

✅ Infer Result: Success

Review: PR #1309 - ready to merge, no blocking findings

Verdict: yes, this is ready for merge once the still-pending test CI job lands. I verified the fix against robotgo's actual source, rebuilt all three platforms locally, and reviewed against the invoked skills. Nothing to change.

What I verified

The premise is correct. In robotgo v1.0.3-0.20260708194349-766c6abccc40 (the pinned version), the top-level backend files are:

  • robotgo.go: //go:build !wayland && !win && !libei && !mac && !x11 && !purego (default, excluded by purego)
  • wayland_n.go: //go:build linux && (wayland || purego) && !libei && !x11
  • x11_n.go: //go:build linux && x11

So -tags purego alone hard-wires Wayland on Linux, and purego x11 would just flip it to hard-wired X11 - there is no build-tag combination that supports both sessions in one binary. Runtime selection is the right fix, and the README's "both supported" claim becomes true.

Signature compatibility is exact. All 9 functions the controller uses exist in both robotgo/x11 and robotgo/wayland subpackages with types matching the robotBackend struct field-for-field (checked in the module cache). Both subpackages are internally //go:build linux, so they never leak into other platforms.

Builds pass everywhere (verified locally): go build ./internal/computer/... (linux default), go build -tags purego for linux, darwin and windows (via GOOS), plus go test ./internal/computer/... and go vet ./internal/computer/... - all green. CI is 11/12 green (lint, vet, build, build-macos, e2e, postgres, CodeQL all pass); only the test job was still running at review time.

Build-tag structure is correct. robot_backend.go uses //go:build !linux for darwin/windows; robot_backend_linux.go gets its Linux-only constraint from the _linux filename suffix, so there is no duplicate robot var on any platform.

Findings (all non-blocking)

  1. On Linux the CLI now never uses robotgo's top-level package - the pure-Go subpackages are used even in non-purego CGO dev builds. That is a parity improvement (dev builds match release behavior and no longer need X11 C headers), intentionally confined to the computer capability. Worth being aware of, nothing to change.
  2. depguard's robotgo-only-in-computer rule is unaffected: robotgo prefix matching confines everything under github.com/go-vgo/robotgo (including the new x11/wayland subpackage imports) to internal/computer/**, and the new imports live inside it. No .golangci.yml change needed.
  3. The useX11() heuristic is the mainstream one and covers the cases that matter: XWayland (both vars set) keeps Wayland, headless (neither) keeps the old Wayland default. XDG_SESSION_TYPE would add nothing - a Wayland session without WAYLAND_DISPLAY can't connect regardless. Skipping that is correct per YAGNI.
  4. The backend is chosen once at package init (var robot = linuxRobot()), which matches the stated "once, at startup" semantics; session env vars don't meaningfully change mid-process.

ponytail-review (over-engineering only)

No findings. Checked: all 9 struct fields are consumed at real call sites (no dead flexibility); no new dependencies (both subpackages come from the robotgo module already in go.mod); the two struct literals in linuxRobot() cannot be collapsed shorter in Go without adding an abstraction that is longer than the duplication; TestUseX11 is the minimum check, not bloat.

Lean already. Ship. (net: 0 lines possible)

Domain-driven design: 7/10 diagnostic, no violations introduced

The slice is a pure infrastructure adapter, so the relevant rows pass trivially and the one row this PR actively delivers is the strongest: an Anti-Corruption Layer at the external integration - robotgo's per-platform package layout is now behind the robotBackend seam instead of being imported directly by the controller's call sites. Bounded context boundaries are preserved (computer untouched at domain level, contracts untouched), names are in the language of the context (robotBackend, useX11), and the depguard map still enforces the boundary. Depth points don't apply because this slice contains no domain model - that is a feature of where the change sits, not a gap.

Clean architecture: 9-10 for the slice (7/7 diagnostic rows)

The Dependency Rule holds: the entire change is in the outermost circle (internal/computer/infrastructure/display), the inward contract DisplayController is untouched, and the framework detail of which robotgo package to call is now a wiring decision in the adapter - exactly where it belongs. The func-struct seam is a textbook Humble Object: the hard-to-test platform selection is isolated at the edge, the controller logic stays unchanged and testable. Main/composition-root wiring is untouched, as it should be for this scope.

Clean code: 8/10

Names reveal intent (robotBackend, linuxRobot, useX11, TestUseX11); the single comment is a genuine "why" (XWayland also sets DISPLAY, hence the priority order); functions are tiny; the table test is fast and independent. Not 10 because the wiring of the two struct literals and the init-time selection are covered only indirectly - mocking the subpackages to assert pass-through wiring would cost more than it protects, so that is the correct trade.

Bottom line

Correct root-cause fix, minimal diff, verified across all three release platforms, no over-engineering, architecture boundaries respected. Merge once the test CI job finishes.

Model: ollama_cloud/glm-5.3-flash · Exit Code: 0 · Duration: 5m 10s

Tokens: 1,073,060 in · 21,584 out · 1,094,644 total (19 requests)

Tool calls: 33 total · 100% success rate

Traces
Session: 1790339620-fa42dead

session (headless, success)                                                                         5m2s
├── chat ollama_cloud/glm-5.3-flash                                                                 9.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.4s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     4.4s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             4.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 4.4s
├── execute_tool TodoWrite call_y4wvyp3g                                                            69µs
├── execute_tool Read call_scfz1por                                                                131µs
├── execute_tool Read call_75magtw9                                                                122µs
├── chat ollama_cloud/glm-5.3-flash                                                                 2.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.5s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.5s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.5s
├── execute_tool Read call_hnyukx5z                                                                218µs
├── execute_tool Read call_4s0x4kg3                                                                226µs
├── execute_tool Read call_mu3ilpp9                                                                177µs
├── chat ollama_cloud/glm-5.3-flash                                                                 2.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.7s
├── execute_tool TodoWrite call_53di14yt                                                            45µs
├── execute_tool Bash call_oj0c0sk0                                                                  4ms
├── execute_tool Bash call_x30lvdjb                                                                  3ms
├── chat ollama_cloud/glm-5.3-flash                                                                44.9s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      44.9s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    44.8s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            44.8s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                44.8s
├── execute_tool TodoWrite call_um2uiexe                                                            75µs
├── execute_tool Grep call_ezfekpyr                                                                630µ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 /proxy/:provider/*path [inference-gateway, server]                             3.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.5s
├── execute_tool Bash call_03v6ojc1                                                                  2ms
├── execute_tool Bash call_rlw1zdhc                                                                  2ms
├── chat ollama_cloud/glm-5.3-flash                                                                 5.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.0s
├── execute_tool Grep call_0az3tw9h                                                                 22ms
├── execute_tool Grep call_17b8625v                                                                  3ms
├── execute_tool Grep call_9q7y1w5i                                                                  3ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1m6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1m6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1m6s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1m6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1m6s
├── execute_tool Grep call_fai2xdtv                                                                 97ms
├── execute_tool Bash call_eifwvgxp                                                                18.2s
├── chat ollama_cloud/glm-5.3-flash                                                                 5.4s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.3s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.3s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.3s
├── execute_tool Read call_gfphqfj5                                                                124µs
├── execute_tool Bash call_pux0u165                                                                 6.1s
├── chat ollama_cloud/glm-5.3-flash                                                                19.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      19.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    19.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            19.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                19.0s
├── execute_tool Bash call_0kx11fra                                                                 5.5s
├── execute_tool Bash call_m88asj1s                                                                 3.3s
├── execute_tool Bash call_f1yvkuet                                                                 1.1s [error: tool_error]
├── chat ollama_cloud/glm-5.3-flash                                                                 3.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.0s
├── execute_tool Bash call_fj72r9bq                                                                  4ms
├── chat ollama_cloud/glm-5.3-flash                                                                 1.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.7s
├── execute_tool Bash call_qqvfvkgr                                                                16.1s
├── 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 /proxy/:provider/*path [inference-gateway, server]                             1.6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.6s
├── execute_tool Bash call_wncpw30b                                                                  4ms
├── chat ollama_cloud/glm-5.3-flash                                                                 2.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.2s
├── execute_tool Bash call_sx7k6mod                                                                  5ms
├── chat ollama_cloud/glm-5.3-flash                                                                 2.0s
│   ╰── 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 /proxy/:provider/*path [inference-gateway, server]                             2.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.0s
├── execute_tool Bash call_6siq7qbt                                                                16.9s
├── chat ollama_cloud/glm-5.3-flash                                                                19.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      19.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    19.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            19.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                19.7s
├── execute_tool Bash call_2k7qbwmz                                                                  5ms
├── execute_tool TodoWrite call_pc168maq                                                            64µs
├── chat ollama_cloud/glm-5.3-flash                                                                 6.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       6.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     6.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             6.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 6.0s
├── chat ollama_cloud/glm-5.3-flash                                                                 3.9s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.9s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.9s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.9s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.9s
├── execute_tool Memory call_mvw3z71g                                                               1.7s
├── chat ollama_cloud/glm-5.3-flash                                                                18.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      18.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    18.1s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            18.1s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                18.1s
├── execute_tool TodoWrite call_o56d5l3t                                                            71µs
╰── chat ollama_cloud/glm-5.3-flash                                                                12.9s
    ╰── POST /v1/chat/completions [inference-gateway, server]                                      12.9s
        ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    12.9s
            ╰── POST /proxy/:provider/*path [inference-gateway, server]                            12.9s
                ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                12.9s
Stats
Tool Calls

╭───────────┬───────┬───────┬────────╮
│ Tool      │ Calls │ Fail% │ Avg    │
├───────────┼───────┼───────┼────────┤
│ Bash      │ 15    │ 7%    │ 4479ms │
│ Read      │ 6     │ 0%    │ 183µs  │
│ TodoWrite │ 5     │ 0%    │ 58µs   │
│ Grep      │ 5     │ 0%    │ 26ms   │
│ Memory    │ 1     │ 0%    │ 1749ms │
╰───────────┴───────┴───────┴────────╯

Token Usage

╭────────────────────────────┬─────────┬────────┬────────────┬─────────┬──────╮
│ Model                      │ Prompt  │ Cached │ Completion │ Total   │ Cost │
├────────────────────────────┼─────────┼────────┼────────────┼─────────┼──────┤
│ ollama_cloud/glm-5.3-flash │ 1073060 │ 779520 │ 21584      │ 1094644 │ -    │
╰────────────────────────────┴─────────┴────────┴────────────┴─────────┴──────╯

Sessions

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

Triggered by edenreich · Infer Action · OSS

@edenreich
edenreich merged commit 5eb4a45 into main Sep 25, 2026
1 check passed
@edenreich
edenreich deleted the fix/computer-x11-purego branch September 25, 2026 12:42
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.208.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 Sep 25, 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

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Computer tool reports a 0x0 display on Linux X11 in purego release builds

1 participant