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
21Provider-specific behavior belongs behind an adapter. Orchestration works with normalized commands
22and events, so adding a provider should not require branches throughout the domain or clients.
23See [provider constraints](./providers.md).
24
25## Durable intent and side effects
26
27The event log is the source of truth for orchestration state. The
28[engine](../../apps/server/src/orchestration/Layers/OrchestrationEngine.ts) serializes commands;
29the [decider](../../apps/server/src/orchestration/decider.ts) produces events without performing
30provider or filesystem work. Events, persisted projections, and the accepted command receipt commit
31in one database transaction. The in-memory state changes and subscribers receive events after that
32commit. This keeps command retries idempotent and prevents a persisted projection from getting
33ahead of the event log.
34
35Reactors perform side effects after intent has been recorded, then feed results back through
36commands. A command acknowledgement therefore means the intent committed, not that the provider,
37checkpoint, or other follow-up work finished. Keep external I/O out of the decider and the database
38transaction.
39
40Persisted events must remain decodable on replay. Changing a schema affects old environments at
41startup as well as live RPC traffic. Compatibility work must account for stored history, not just
42what the newest client sends.
43
44## Turn completion and checkpoints
45
46A turn ending and its follow-up work settling are separate milestones. The
47[projector](../../apps/server/src/orchestration/projector.ts) settles the turn from its session
48status. A late checkpoint or diff must not extend the recorded turn duration or keep the client
49showing provider work as active.
50
51[Checkpoints](../../apps/server/src/checkpointing/CheckpointStore.ts) use hidden Git refs to
52capture workspace state without adding commits to the user's branch. A revert must coordinate
53workspace state with the provider conversation. A provider that cannot roll back its conversation
54must reject that operation before changing the filesystem.
55
56## Waiting for asynchronous work
57
58Tests use [drainable workers](../../packages/shared/src/DrainableWorker.ts) to wait until both the
59queue and its current item have finished. An empty queue alone does not prove the worker is idle.
60
61Runtime receipts mark specific test milestones. Their
62[production layer](../../apps/server/src/orchestration/Layers/RuntimeReceiptBus.ts) is a no-op;
63production behavior must use persisted state and events. These test signals are separate from the
64durable command receipts that make dispatch idempotent.
65
66See the [glossary](./glossary.md) for shared terms and the
67[development runbook](../operations/development.md) for setup and checks.