SearchBook a call

RESEARCH / PAPERS

published

Troy: process isolation, resolver-level refusals, and endpoint trust in an agent browser

How Troy splits chrome, tabs, and CDP engine across processes, enforces resolver-level refusals and IPC checks, and hardens agent endpoint trust.

Web agents fail on two orthogonal fronts before they even click a button. Dumping raw HTML floods the context window with tens of thousands of tokens of wrappers, inline styles, and tracking noise; taking screenshots preserves visual truth (canvas dashboards, text baked into images, embedded PDFs, cross-origin iframes) while stripping away links, form fields, and actionable selectors. Underneath both sits an operational wall: browser automation frameworks start a clean, empty profile while the pages worth automating sit behind an existing login.

Troy is a Chromium-based agent browser built for a human pairing with a coding agent inside an already signed-in session. This report documents Troy’s Main/Renderer/Engine process split, its nine core architectural decisions, the endpoint trust probing and single-instance lock hardening applied to agent discovery, and the hard security and rendering invariants enforced by its test suite. All specifications, measurements, and invariants come strictly from Troy’s design documentation (docs/DESIGN.md, docs/PRD.md), source modules (src/browser/main.js, src/browser/endpoint.js), and engineering audit (docs/spec/2026-09-bugs-and-enhancements.md). For surrounding agent tooling work across the lab, see the Agent systems research area.

Facts at a glance:

  • Core architecture: three-way split across an Electron main process, a chrome webContents (y: 0 to 88px), isolated WebContentsView tabs (y: 88px to bottom), and a narrow Cdp engine port.
  • Explicit non-goals: beating Chrome at daily browsing, non-Chromium engines, cloud sync/accounts/telemetry, Apple notarisation (Homebrew cask clears quarantine instead), and MCP as the browser transport (CDP is the protocol).
  • Security stance: refusals live in tested code, never in prompts; main validates calling frame URLs on IPC; extensions load with allowFileAccess: false; debugging ports are closed by default and loopback-only when enabled.
  • Measured chrome performance: median frame 8.30 ms, p95 9.20 ms, worst 9.40 ms, zero stalls on a 120Hz Apple silicon machine running 16 busy tabs with continuous interaction.
  • Verification baseline: 127 tests at initial browser shipment (84 pure unit, 7 Chromium Cdp, 36 live Electron over real sockets), growing to 274 it() blocks across 24 test files in the September 2026 audit snapshot.

Process split: Main, Renderer, and Engine

Troy separates authority, user interface chrome, untrusted web content, and automation plumbing across explicit process and port boundaries:

Layer Key modules Responsibility and isolation guarantee
Main process main.js, omnibox.js, tracking.js, settings.js, shortcuts.js, extensions.js, resilience.js, endpoint.js Owns tab lifecycle, layout, navigation, menu, IPC authority, tracker blocking, crash resilience, and endpoint advertisement. Electron imports are isolated so pure modules unit-test in milliseconds without launching a browser.
Chrome renderer preload.cjs, renderer/chrome.* Runs in the window’s own webContents (y: 0 to 88px). Renders tab strip, toolbar, omnibox, agent panel, and progress bar over a fixed preload bridge (a closed action list and three subscriptions).
Tab renderers tab-preload.cjs, renderer/newtab.*, renderer/error.* One WebContentsView per tab (y: 88px to bottom). Separate frame tree, separate process, separate compositor from chrome; contextIsolation and sandbox enabled with no Node integration.
Engine cdp/types.ts, cdp/playwright.ts Narrow Cdp port (send, on, screenshot, evaluate, url, close) shared across launchHeadless, connectOverWs, launchPersistent, and live tab webContents.debugger.

That split yields two immediate properties. First, visited web pages render identically to Chrome and cannot repaint or script Troy’s chrome because they live in a separate frame tree and process. Second, every tab exposes Chrome DevTools Protocol through webContents.debugger, so the same read pipeline runs headless under Playwright or attached to the live signed-in tab without rewriting transport logic. Because chrome and page views do not share a compositor, however, CSS effects and layout overlays across the y = 88px boundary behave differently from a single-document web app—a constraint that drove two of Troy’s explicit design decisions and regression invariants.

The nine architectural decisions

docs/DESIGN.md records nine architectural decisions alongside the plausible alternative rejected for each.

1. Refusals live in the resolver, not at call sites

resolveOmnibox(input) in omnibox.js classifies every user or UI input into a tagged union: url, search, external, refused, or empty. Every entry point—the address bar, the new-tab search box, and shortcut tiles—routes through that single resolver so all three enforce identical scheme refusals.

The rejected alternative was validating schemes at each navigation call site, which invites drift across three separate paths. The concrete exploit motivating the rule ordering is javascript://example.com/%0aalert(1): it resembles a URL under naive pattern checks and, if pasted into a signed-in tab’s bar, executes JavaScript inside that origin. omnibox.js therefore checks refused schemes (javascript:, data:, blob:, and browser-internal schemes) before applying the generic scheme:// rule.

2. The main process is the sole authority on IPC

tab-preload.cjs attaches to every tab, meaning it executes alongside every third-party site visited. It exposes window.troyNewTab only when the document looks like Troy’s new-tab page. DESIGN.md treats that preload check strictly as tidiness, not security: the enforcement boundary sits in the main process, which inspects the calling frame’s URL on every new-tab IPC channel and refuses anything else. Trusting the preload check was rejected because a compromised renderer is precisely the party attempting to forge the call.

3. Tab lifetime safety via explicit liveness checks

In Electron, invoking getters on a destroyed webContents throws, and an unhandled exception inside a main-process event handler crashes the entire browser. Troy routes tab reads through alive(tab) and invokes pruneDeadTabs() before assembling chrome state. (The September 2026 audit later flagged one unguarded path—showFailure calling loadURL without alive() during a close/failure race—reinforcing why every main-process tab access must pass through the same guard.)

4. Coalesced state updates per event-loop turn

A single page navigation emits did-start-loading, did-navigate, page-title-updated, page-favicon-updated, and did-stop-loading in rapid succession. Instead of pushing each event straight to the chrome renderer, syncChrome() sets a dirty flag and transmits one coalesced state snapshot per turn of the event loop.

5. In-place tab strip mutation

The chrome renderer maintains a Map from tab ID to DOM element and updates existing nodes in place. Emptying and rebuilding the tab strip on every update looked simpler, but destroyed every favicon <img> element during load bursts, causing visible flicker and redundant icon refetches.

6. Window-level glass instead of CSS backdrop-filter

On macOS, Troy creates its window with vibrancy: 'header' and a clear background tinted by chrome, forbidding backdrop-filter anywhere in CSS. Frosting the toolbar with CSS was rejected for two reasons: it forces a full-width GPU blur pass on every repaint, and it cannot blur web page pixels anyway because backdrop-filter only samples behind an element within the same compositing surface, whereas the web page occupies a separate WebContentsView.

7. In-memory settings cache on the network hot path

tracking.js checks whether tracker blocking is enabled on every subresource request. Reading settings.json synchronously from disk on each check triggered roughly two hundred blocking main-process reads during a single page load, visibly stuttering the window. Because no external process writes settings.json, caching settings in memory and invalidating on Troy’s own writes is exact and eliminates synchronous I/O during navigation.

8. Mandatory ad-hoc bundle resealing

Electron ships linker-signed. Once electron-builder renames the binary, rewrites Info.plist, and injects resources, the original signature breaks (codesign --verify fails with "code has no resources but signature indicates they must be present"). On Apple silicon, macOS refuses to launch a bundle with a broken signature at all, reporting the app as damaged—and Control-click then Open cannot bypass a broken signature (it waives notarisation only). scripts/after-pack.cjs ad-hoc reseals and verifies every packaged bundle, failing the build if verification fails.

9. One native runner per architecture with Rosetta cross-builds

After GitHub retired Intel macOS runners, Troy cross-builds the x86_64 macOS package on Apple silicon with Rosetta installed first, and grants its packaged smoke test a generous timeout to absorb slow first-launch translation of the Electron framework.

Endpoint trust probing and single-instance locking

Because Troy advertises its local debugging port and typed agent socket through agent-endpoint.json inside the profile directory (userData), an agent discovers a running browser without the human copying port numbers by hand. The September 2026 audit (docs/spec/2026-09-bugs-and-enhancements.md, bug B4) identified why a naive advertisement file becomes a claim rather than a fact: a crash leaves a stale file that reads as live, a second launch against the same profile overwrites and later deletes the first instance’s endpoint on will-quit, and writing the file at whenReady before verifying Chromium bound the port advertises a dead socket.

Troy hardens endpoint discovery across src/browser/main.js and src/browser/endpoint.js with four interlocking mechanisms:

  • Single-instance profile lock: app.requestSingleInstanceLock() runs before command-line switches or port binding. If a second Troy process starts against the same profile, hasSingleInstanceLock is false, preventing it from binding cdpPort, starting agentSocket, overwriting agent-endpoint.json, or deleting the primary instance’s advertisement on exit; instead it focuses the running window and quits.
  • Active CDP port probing: before advertising a CDP port, main.js calls probeEndpoint(cdpPort) in endpoint.js, which issues an HTTP fetch to http://127.0.0.1:${port}/json/version guarded by an AbortController with a 1,500 ms timeout. An unresponsive or unbound port yields verifiedCdpPort = 0 so Troy never writes a dead CDP port to disk, while still allowing port: 0 when only the bearer-token-authenticated typed agent socket (agentPort, agentToken) is listening.
  • Atomic owner-only writes: writeEndpoint writes JSON to a PID-suffixed temp file (${file}.${process.pid}.tmp) with file mode 0o600—keeping the per-launch agentToken readable only by the owning user—and renames it atomically into place so concurrent readers never observe partial JSON.
  • PID liveness checks on read: readEndpoint validates that port and pid are numeric and runs pidAlive(pid) via process.kill(pid, 0). Receiving EPERM indicates the process exists under another user (alive); ESRCH indicates the process is gone, causing readEndpoint to return null rather than handing an agent a stale port from a crashed run.

When launched with an agent bridge (--cdp-port, --agent, --agent-socket, or TROY_AGENT_SOCKET=1), Troy also defaults to hidden launch mode (disable-backgrounding-occluded-windows and disable-renderer-backgrounding) so backgrounded agent sessions keep painting for screenshots without stealing desktop focus from the user until explicitly activated.

Hard invariants and security boundaries

docs/DESIGN.md pairs its architecture with concrete non-regression invariants, several discovered by real shipped bugs:

Invariant Specification and verification rule
4.1 Loading bar inside chrome bottom <= 88px. Placing the bar at top: 88px put it under the WebContentsView compositor; a test checking only CSS class on passed while the bar was completely invisible. Visibility geometry is asserted directly.
4.2 Close icon geometry Icon-to-button ratio > 0.5 and centering offset < 0.5px on both axes; centered-but-tiny fails.
4.3 Stale failure suppression Typing a dead address then a valid one must never let the delayed failure overwrite the newer page. Guarded by tab.pending and regression-tested against a route failing after 400 ms.
4.4 Failure-page reload target Reloading an error page retries the originally requested address, tested against a port that starts closed and opens before reload.
4.5 Main-process crash survival Three tests intentionally throw inside the main process and assert that Troy logs the error and continues navigating.
4.6 Opt-in agent port Tested in both directions: attachable when requested at launch, connection refused when not requested.
4.7 Chrome 60fps budget npm run stress fails below 60fps median, on any p95 miss, or on any single frame exceeding 100 ms.
4.8 Read pipeline truthfulness Hidden-text leaks must be zero on every fixture (including white-on-white text where foreground equals effective background), and a plain article must trigger zero OCR regions. Neither is a metric to trade off.

Security boundary enforcement

Troy explicitly scopes its threat model. It defends against visited pages reading browser internals or the filesystem, pasted addresses executing script in logged-in origins, pages spawning uncontrolled windows, extensions gaining unrequested file access, and local processes silently driving a session. It does not claim to defend against a user deliberately installing a malicious extension, a compromised host machine, or first-party tracking by sites the user chose to visit.

Boundary Enforcement mechanism
Page to chrome Separate WebContentsView; contextIsolation, sandbox, no Node integration
Page to main Fixed IPC surface; new-tab channels gated on calling frame URL in main
Address bar to origin Refused schemes checked in omnibox.js before generic scheme:// matching
Page to OS setWindowOpenHandler denies popups (routed into tabs); unknown schemes go to shell.openExternal
Page to devices Permission handler denies camera, microphone, geolocation, and notifications (allowing fullscreen and sanitized clipboard write)
Extension to disk allowFileAccess: false, always
Agent to browser Port closed by default, 127.0.0.1 loopback only, opt-in per launch, 0o600 endpoint file for bearer tokens

Privacy defaults follow the same principle: rememberHistory defaults to false (and toggling it off deletes history.json), nothing is sent over the network while typing in the omnibox, third-party analytics and ad beacons are cancelled, and tracking parameters are stripped before requests fire.

Performance model, verification, and known gaps

Troy treats the chrome layer as the user-facing performance surface and enforces five rules from DESIGN.md §6: animate transforms and opacity only (progress bar scales, tab spinner rotates, zero layout/paint triggers), no synchronous main-process I/O during page loads, no per-frame main-process work, in-place DOM edits instead of rebuilds, and no wasted GPU blur passes. Under that discipline, a 120Hz Apple silicon machine running 16 busy tabs with continuous interaction measured a 8.30 ms median frame time, 9.20 ms p95, 9.40 ms worst frame, and zero stalls.

Read pipeline and fused visual-DOM design

Over the narrow Cdp port, Troy’s five-stage read pipeline (settle, extract, visible, cover, fuse) produces one document combining DOM structure with targeted OCR:

  1. settle: waits for readyState, document.fonts.ready, and two consecutive frames without layout shift, returning after a timeout so perpetual-motion pages remain readable.
  2. extract: walks the document including open shadow roots in one evaluation, capturing text, role, bounding box, stable selector, and visibility verdict.
  3. visible: requires a non-zero rect, painted display/visibility, non-zero effective opacity, unclipped bounds, and foreground text color distinct from effective background (eliminating white-on-white prompt-injection poisoning).
  4. cover: isolates only painted regions the DOM cannot explain—canvas, img/svg lacking accessible text, cross-origin iframes, or substantial empty-text areas with high edge density—and merges overlaps so plain articles incur zero OCR calls.
  5. fuse: drops invisible blocks, groups columns by x-overlap, orders top-to-bottom, and merges OCR lines back by geometry with source attribution and bounding boxes, running Apple Vision on macOS and Tesseract elsewhere behind one interface.

Verification discipline and documented gaps

The shipped browser baseline ran 127 tests—84 pure unit tests, 7 real Chromium tests through the Cdp port, and 36 live Electron battle tests asserting only through visible chrome surfaces and a TROY_TEST=1 main-process layout snapshot hook. Test files execute serially so concurrent Electron launches do not race and corrupt lazy binary downloads. Cross-platform CI on macOS, Windows, and Linux paid for itself immediately by catching 'file://' + path.join() producing backslash URLs on Windows that leaked local file paths into the address bar, while scripts/smoke-packaged.mjs verifies packaged .asar startup and navigation that source-tree tests cannot observe.

Both docs/DESIGN.md and docs/spec/2026-09-bugs-and-enhancements.md keep remaining gaps explicit rather than papering over them:

  • No Intel Mac hardware behavioral testing: x86_64 macOS packages are built and smoke-launched under Rosetta on Apple silicon, proving startup rather than full Intel hardware parity.
  • No extension management UI or auto-update: unpacked extensions load from the profile directory without a toolbar surface, and upgrades rely on Homebrew or direct downloads.
  • Audit-tracked read/CLI convergence items: as the codebase expanded to 274 it() blocks across 24 test files with the live read pipeline, agent controller, command palette, bookmarks, and push-to-talk voice, the September 2026 audit documented concrete bugs to close before cutting v0.2.0—including CLI screenshot clip key mismatch (w/h vs CDP width/height), page_fill failing to reject disabled/readOnly inputs, >>> shadow-DOM selector consumption in the action layer, and Windows/Linux Tesseract wiring behind ocr-factory.js.

Troy’s architecture holds up because its security and reliability rules are structural rather than advisory: process boundaries separate untrusted pages from chrome, a single resolver refuses dangerous schemes before navigation, the main process verifies IPC frame origins and endpoint liveness, and every hard invariant is backed by a test against the running application.

← All papers