Open History to see the last commit
1# Architecture
2
3T3 Code keeps execution in the environment that owns the workspace. Web, desktop, and mobile
4clients control it over authenticated RPC. A remote client must never substitute its own filesystem,
5provider credentials, or machine state for the environment's. The desktop app bundles a server,
6but its renderer follows the same boundary.
7
8## Ownership boundaries
9
10Provider processes, terminals, Git, and project files belong to the server. Shared connection and
11domain state belongs in `packages/client-runtime`; clients supply platform services and UI.
12Keeping that logic shared prevents reconnect and multi-environment behavior from diverging between
13web and mobile. See [connection runtime](./connection-runtime.md) and
14[remote environments](./remote.md).
15
16The [RPC contract](../../packages/contracts/src/rpc.ts) is the boundary between independently
17versioned clients and servers. Subscriptions send the state a client needs, so a client viewing one
18thread does not pay for every thread's history. Authentication of a socket does not authorize every
19method on it. See [environment auth](./environment-auth.md).
20
21### Pull request linking compatibility
22
23Web, desktop, mobile, and environments upgrade independently. Negotiate linking through the
24environment descriptor, never through a client version or an assumed coordinated release:
25
26| Environment capability | Client behavior |
27| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
28| `threadPullRequests: true` | Use persisted `pullRequests[]`, multi-link commands, stack UI, and reverse thread lookup. |
29| Only `threadPullRequestLinking: true` | Use `linkedPullRequest` and the existing `thread.meta.update` single-link operation. Do not call multi-link RPCs. |
30| Neither flag | Hide linking actions; existing branch-discovered PR display remains available. |
31
32New environments continue advertising the legacy flag, accepting legacy metadata commands, and
33emitting the derived `linkedPullRequest` field for older clients. That hostless field includes only
34links in the thread project's own repository; cross-host and cross-repository links require the
35multi-link protocol. New clients accept snapshots that
36omit `pullRequests`. Retain the legacy wire fields, projection column, and replay support; this feature
37does not schedule their removal. Missing new capabilities must also override cached multi-link data
38after an environment downgrade.
39
40Provider-specific behavior belongs behind an adapter. Orchestration works with normalized commands
41and events, so adding a provider should not require branches throughout the domain or clients.
42See [provider constraints](./providers.md).
43
44## Durable intent and side effects
45
46The event log is the source of truth for orchestration state. The
47[engine](../../apps/server/src/orchestration/Layers/OrchestrationEngine.ts) serializes commands;
48the [decider](../../apps/server/src/orchestration/decider.ts) produces events without performing
49provider or filesystem work. Events, persisted projections, and the accepted command receipt commit
50in one database transaction. The in-memory state changes and subscribers receive events after that
51commit. This keeps command retries idempotent and prevents a persisted projection from getting
52ahead of the event log.
53
54Reactors perform side effects after intent has been recorded, then feed results back through
55commands. A command acknowledgement therefore means the intent committed, not that the provider,
56checkpoint, or other follow-up work finished. Keep external I/O out of the decider and the database
57transaction.
58
59Persisted events must remain decodable on replay. Changing a schema affects old environments at
60startup as well as live RPC traffic. Compatibility work must account for stored history, not just
61what the newest client sends.
62
63## Turn completion and checkpoints
64
65A turn ending and its follow-up work settling are separate milestones. The
66[projector](../../apps/server/src/orchestration/projector.ts) settles the turn from its session
67status. A late checkpoint or diff must not extend the recorded turn duration or keep the client
68showing provider work as active.
69
70[Checkpoints](../../apps/server/src/checkpointing/CheckpointStore.ts) use hidden Git refs to
71capture workspace state without adding commits to the user's branch. A revert must coordinate
72workspace state with the provider conversation. A provider that cannot roll back its conversation
73must reject that operation before changing the filesystem.
74
75## Waiting for asynchronous work
76
77Tests use [drainable workers](../../packages/shared/src/DrainableWorker.ts) to wait until both the
78queue and its current item have finished. An empty queue alone does not prove the worker is idle.
79
80Runtime receipts mark specific test milestones. Their
81[production layer](../../apps/server/src/orchestration/Layers/RuntimeReceiptBus.ts) is a no-op;
82production behavior must use persisted state and events. These test signals are separate from the
83durable command receipts that make dispatch idempotent.
84
85The Electron shell acquires `DesktopPreReadyPlatform.layer` synchronously before asynchronous
86services. On Linux this sets the desktop-entry identity and global-shortcut portal flags before
87Chromium initializes its portal connection. Setting the identity later in `DesktopAppIdentity`
88is too late: Chromium caches the first registration, including failures. The identity must match
89the installed entry managed by `DesktopLinuxUrlHandler`. Pre-ready setup also refreshes that entry's
90`Exec` path before portal registration: AppImage updates can remove the previous executable, which
91makes the old entry invalid even though its filename is correct. The later URL handler avoids
92rewriting an identical entry while the portal may be reading it. On Wayland, Electron's synchronous
93shortcut-registration result only confirms submission; it does not confirm desktop consent or
94an active binding.
95
96Native modules never load in the Electron main process on the startup path, and the two the
97snapshot feature keeps are isolated: `@crowecawcaw/xa11y` runs only in forked Node-mode children
98(`SnapShotAccessibilityWorker`, `RegionSnapShotWorker`) and a worker thread, and `ffi-rs` loads
99lazily inside `WindowsForeground.ts` for a handful of Win32 calls. macOS window lookup shells out
100to `osascript` instead of a native addon. A crash or stall in any of these must not take the app
101down, so new native capability goes in a child with a deadline, not an `import` in main.
102
103See the [glossary](./glossary.md) for shared terms and the
104[development runbook](../operations/development.md) for setup and checks.