Architecture#
Rat Things implements the OpenAI Agents API in infrastructure you own. The API, agent harness, Session coordination, encrypted storage and execution environments run in your AWS account. Model requests use your configured provider. The Agents API guide explains the public resource model and deployment transports.
Request to result#
The API authenticates the caller before deriving an owner. Session creation snapshots the Agent configuration and resolves its environment. Input receipts, Turn transitions and pending outbox operations are committed before asynchronous work is dispatched. Retries use the saved occurrence and operation identities. Deleting a Session fences later input and closes its harness.
RunSessionExecution translates Session work into a private execution request.
A private Run identifies a harness launch and its worker generation; it is not
another public resource or a synonym for a Turn. One live harness can execute
several Turns. Further input reaches that harness through authenticated private
control, and its runtime journal saves Items, Turns and native checkpoint state.
Input during an active Turn steers that Turn. Canceling a Turn keeps the Session; deleting the Session closes its runtime. Function results must match an outstanding call and Turn. SSE observes live state; saved Items and Turns provide durable history after disconnects.
Code boundaries and effects#
| Layer | Responsibility |
|---|---|
src/domain |
Resource contracts, validation, identity and state transitions |
src/core |
Session, Turn, environment, Vault, schedule and outbox services against ports |
src/identity |
Distinct actor, owner, source, destination and credential subject |
src/ingress |
Provider authentication and normalization behind ingress ports |
src/delivery |
Destination resolution, saved Turn delivery and outcome fencing |
src/credentials |
Host secret-reader contracts and credential parsing |
src/execution |
Private dispatch, executor registry and liveness reconciliation |
src/plugins |
Trusted provider manifests, connection lifecycle and grants |
src/adapters |
AWS storage, queues, scheduling and MicroVM implementations |
src/app |
Composition and translation between Session and private execution ports |
src/lambdas |
Transport adapters and scheduled/event handlers |
src/runner |
Trusted harness orchestration and isolated child execution |
Planning functions transform supplied values into decisions. Services obtain clock values, read storage, perform conditional writes and invoke external operations. For example, recovery planning receives a stored execution and a timestamp; the reconciler sends the resulting message. Keeping effects explicit preserves the order in which acceptance, dispatch and terminal evidence become durable.
Compute and environments#
The dispatcher conditionally claims a queued execution before launching the configured EC2 or Lambda MicroVM worker with a stable launch identity. The launch payload contains resource references and bounded configuration; prompts and credentials remain outside it. Individual workers are transient executions, not Terraform-managed instances.
The root lifecycle server controls mounts and process supervision. Trusted runner code uses narrowly scoped AWS access. Agent processes run under a separate non-root UID with a sanitized environment. A guest network policy prevents that UID from calling the root lifecycle/control listener. External control requires an AWS-issued, port-scoped proxy token.
The Session pins either Codex App Server or Pi Durable as its runtime. Both use the same execution and storage ports. Pi Durable's native tasks and conversations are coordinated by the Rat Things adapter. An environment supplies command and filesystem context:
nonesupplies no command environment.openai_hosteduses the upstream wire name for a managed environment provisioned by Rat Things in your AWS account.self_hostedremains in the upstream wire schema but is unsupported. Local subscription-backed execution runs its harness and workspace on your computer; AWS execution uses a managed AWS worker.
Managed environments use /workspace, declared tools, prepared capabilities and
network policy. Session workers capture /workspace/outputs as immutable artifacts
when a Turn reaches a terminal outcome and the worker can capture output. Local
execution retains its private artifact workflow.
Durable state#
DynamoDB stores owned resource indexes, conditional state, outbox references and bounded summaries. Complete definitions, input, runtime snapshots and file content live in encrypted S3. Secret values live in Secrets Manager; stored records contain references. The durability guide explains Session recovery.
Pi Durable stores native commits through encrypted S3 and conditional DynamoDB
records. A commit must be acknowledged before the worker applies it locally.
Run identity and ownership version fence writes from replaced workers. Pending
tool results and background children retain their identities during recovery.
Managed Pi workspaces require S3 Files and checkpoints; environment none does not
need a managed workspace. See agent runtimes.
For Codex, optional S3 Files storage preserves native journals across replacement workers.
SQLite databases, including those used by setup commands, use a worker-local bind
mount so concurrent agents do not share database locks through the network filesystem.
A replacement worker rebuilds those databases while resuming the durable native thread.
Ordinary hosted sandbox replacement clears the old workspace and reapplies declared inputs;
conversation recovery uses the native journal or saved Items. Its directory key
hashes the owner and Session ID together. Native thread identity comes from the
Session runtime journal. The filesystem's historical
Terraform resource names and /conversations access-point root stay unchanged so
existing Session state remains reachable; they do not imply a second coordination
service.
The opt-in session_checkpoints_enabled deployment setting adds a private host checkpoint
protocol for idle managed Sessions with S3 Files. The host seals input and file admission,
flushes and closes the selected runtime, stops remaining guest writers, drains the
Session journal and strictly syncs storage. Codex requires each loaded native thread to
acknowledge persistence shutdown. Pi closes its engine after saving the root context.
Only then does it publish a single-use handoff. A replacement claims that handoff before any
workspace preparation, verifies the setup and execution authority, and restores the saved
runtime state. It retains workspace files and sandbox identity without replaying setup commands.
System packages are reinstalled on the new worker. Failed or ambiguous shutdown cannot publish
a new handoff. Abandoned or consumed handoffs recover on durable input retry only after the exact
previous execution is confirmed terminated. Automatic idle hibernation is a separate policy.
Session forks build on explicit checkpointing. The source's Session admission lock and bounded
snapshot lease prevent new work and deletion during copying. A trusted child worker copies only
the permitted workspace files using directory handles without following symbolic links.
After syncing and publishing an immutable snapshot, it releases the source and creates a separate
mutable child root. Child credentials are prepared under the child's identity, and vault and
network policies may only narrow. Codex also copies the root native rollout and uses
thread/fork at the captured Turn boundary. Pi saves the root's model context and recovery
history, then initializes a new conversation from that snapshot. Lineage and private recovery
Items belong to the child, so deleting
the source cannot remove the child's conversation context. Public child Items and Turns describe
only work performed after the fork.
Recovery and delivery#
Queue messages are wake-up hints. Durable records determine whether work is still pending. A missed Session outbox send can be repaired from pending state; a missed private execution enqueue is repaired using the same Run ID. Duplicate wake-ups cannot create an independent execution identity.
Workers heartbeat only while the Run ID, worker ID, generation and running status match. The reconciler combines AWS state with a root-supervised worker health check. It records ambiguous identity and can quarantine repeated uncertainty. Read-only probes continue so a later confirmed termination can settle the Run. Native MicroVM suspension is recorded separately from uncertain identity, without proxy traffic that would wake the guest. After resume, the generation-checked health response carries the trusted lifecycle resume time so a pre-suspension heartbeat cannot immediately expire the worker. Cancellation still stops a suspended execution. It never treats uncertainty as permission to terminate another worker. Confirmed loss can finish cancellation or record an execution failure; reconciliation does not blindly replay an agent's external side effects.
Authenticated provider input resolves an owned Agent/environment binding and durable Session input receipt. Schedules reserve occurrences before dispatch and retain overlap policy. Provider notification is a separate outbox operation based on a saved terminal root Turn. Delivery fences distinguish confirmed success, retryable rejection and an uncertain external outcome. Harness exit does not send a second notification for Session work.
Private execution state changes also flow through DynamoDB Streams and EventBridge for operational consumers. Stream and notification failures have bounded retries and retained failure queues. These mechanisms do not constitute public Session history.
Authority#
Actor attribution, resource ownership, input source, output destination and credential subject remain distinct. Provider authentication is checked before payload parsing. Repository URLs use HTTPS and an allowlisted host. A notification connection does not grant the Agent access to that provider.
Execution admits a fixed capability envelope. Agent configuration, declared tools, IAM, network policy, provider scopes and connection grants constrain it. Host brokers check operation and resource authority before reading a credential. There is no pending human-approval state: an unexpected approval-shaped Codex request fails closed. See security and capability boundaries.
Rat Things is an engineering preview. See the API guide and capabilities page for supported behavior and operational limits.
Persistent worker isolation#
Dedicated ARM64 EC2 workers are available through enable_ec2_worker for Sessions
that must retain a live harness beyond the Lambda MicroVM lifetime. Each Session
gets one instance with a pinned AMI and container image, encrypted disk, a private
subnet and no inbound security-group rules. The root supervisor receives commands
through the encrypted AWS storage mailbox and forwards fixed operations to its
loopback control listener. A conditional claim precedes execution; an ambiguous
command is never automatically replayed.
The trusted runner reads credentials and commits Session state as root. It starts the selected Codex or Pi Durable process and repository commands as UID 10001. That identity cannot reach the control listener or EC2 instance metadata, and cannot read the root supervisor's process environment. The EC2 harness has no absolute execution timer; Session closure, execution authority loss or host loss ends it. Conditional heartbeats renew private Run retention while the harness remains active. MicroVM workers retain the AWS maximum lifetime and remain available during the backend transition.