docs/MASTRA-HARNESS.md
Mastra and the RS game harness
Coordinator update: see AGENT-COORDINATOR.md and COORDINATOR-ADAPTERS.md for the new durable multi-agent jobs. Older single-handoff descriptions below describe the retained legacy flow, not the complete current agent directory. Live release pilots and unrestricted code/test execution remain unverified.
Updated 2026-10-26. This document distinguishes implemented runtime behavior from proposed integrations.
What is running
- The assistant uses the existing signed-in Codex app-server for inference, model discovery and its agent loop. Default remains
gpt-6.1-sol, high. It is not the OpenAI Agents SDK and does not copy ChatGPT credentials into that SDK. - Mastra
createWorkflowcoordinates research turns. Native Mastra Code Mode now exposesrs_computeto Codex. It can orchestrate onlyexternal_rs_research, using QuickJS WebAssembly isolation inside a separate worker so CPU-bound calculations cannot block the world-feed event loop. No filesystem, shell, direct network, credentials, mission approval or game dispatch is exposed in the interpreter. - The existing gameplay executor remains a separate headless Playwright daemon with signed mission policies, exact account grants, leases, protection checks, cancellation and receipts. No new SDK runner runtime was introduced.
- Command now manages this daemon through Gameplay harness setup → Start & pair local runtime. It starts the bundled daemon on an assigned loopback port and performs pairing server-side. It does not execute code from the selected codebase and never auto-connects accounts.
Operator flow
- Open
#missions, then Gameplay harness setup. - Review the existing RS-SDK directory and choose Start & pair local runtime. The encrypted credential vault is bound to this codebase; a different codebase uses a separately managed daemon/manual pairing.
- Enroll the exact account with a relative credential-file reference, allowed capabilities, expiry and explicit controller-handoff review. The file's username must match the selected player. Credentials never enter the browser.
- Expand that enrolled account and explicitly confirm its previous controller is stopped before choosing Connect. This is the first step that opens a game session.
- Inspect method availability and record an actual completed capability pilot with an operator and receipt reference. Certification does not manufacture missing client signals or missing methods.
- Select Live execution, prepare a bounded mission, review it, approve it, then run through the existing Command flow. Assistant drafts do not bypass this sequence.
- Use Stop all for missions; inspect receipts for verified cessation versus unknown. Re-enable dispatch explicitly after a stop. Revoke grants or reconcile quarantined accounts only after inspecting their actual state.
The local runtime stops with the app (including managed stdin closure after parent exit). Restarting never reconnects bots. Persisted grant/mission records survive; stale observations do not become fresh, and unresolved outcomes remain quarantined. Manual external pairing is blocked while the managed runtime is running to avoid showing one daemon's account state while administering another.
Implementation map
| File | Responsibility |
|---|---|
server/assistant/code-mode.ts | Mastra Code Mode + QuickJS, 32 MiB heap, 15-second execution limit, 16 KB code and 45 KB output bounds |
server/assistant/code-mode-transport.ts, code-mode-worker.ts | Per-computation worker lifecycle, tool-message bridge and hard deadline |
server/assistant/service.ts | Codex dynamic tools, shared six-read budget, maximum three calculations per turn, source/report persistence and cancellation |
server/harness/local-runtime.ts | Fixed child-process launcher and operator API bridge; tokens stay server-side |
scripts/harness.ts | CLI and managed daemon lifecycle |
server/missions/routes.ts | Same-origin, HttpOnly session and CSRF checks before operator mutations |
src/coordination/LocalRuntimeSetup.tsx | Start/stop, account connection, pilot evidence, grant revocation and reconciliation |
src/coordination/HarnessSetup.tsx | Enrollment and optional external daemon pairing |
server/harness/engine.ts, playwright-port.ts | Existing deterministic gameplay policy and actual client operations |
Operator endpoints: GET /api/harness/local; POST /api/harness/local/{start,stop,enroll,connect,certify,revoke,reconcile,reenable}. All POSTs require the same Command session/CSRF/origin checks as mission mutations. Administrative schemas remain owned by the daemon. Never expose a generic shell/admin-action forwarding route.
Code Mode uses the same research operations as direct assistant reads. Each nested read counts toward the six-read budget, carries source URLs and coverage, and creates the same report when supported. A nested read cannot call mission mutation endpoints. Generated output is a calculation, not new evidence of game execution.
Current upstream verification
Context.dev retrieved official documentation for SDK Agents, A2A, Code Mode, AgentController and the current CLI on 2026-10-26. Registry versions verified and pinned in this app: @mastra/core 1.79.0, @mastra/quickjs 0.1.4. create-mastra is 1.35.0. Upstream repository HEAD observed: 5bb592a862869d529d8d6ca48772cd0e1863f224 (a point-in-time observation, not a production dependency).
Ran npm create mastra@latest with --empty --no-install --no-git --no-skills in a temporary reference directory outside the repository. Its generated Mastra entrypoint and core dependency were inspected. The CLI requires a project name, not an absolute path argument. No scaffold replaced the existing app.
- SDK Agents: current wrappers are
@mastra/claude,@mastra/cursor, and@mastra/openai. Each provider retains its runtime and tools. They are not installed or connected in this app. OpenAI Agents SDK requires its own provider credentials; it is not Codex app-server authentication. - A2A: agent-card discovery and task-oriented delegation, with v0.3 and v1.0 documented. No A2A endpoint is exposed or remote peer linked here. Existing Tincan remains an explicitly reviewed planning handoff. A future A2A adapter should retain that review/receipt behavior and never turn remote text into gameplay permission.
- Code Mode: implemented with QuickJS rather than host-privileged
LocalSandbox. - AgentController: the canonical newer runtime for sessions/modes/steering;
@mastra/core/harnessis a deprecated compatibility entrypoint. This app has not migrated its Codex agent loop to AgentController. Existing SQLite tasks/transcripts and deterministic mission state remain authoritative. Do not report this as a full native Mastra durable-agent migration.
Live pilot still required
No live account was selected for this change. Verification uses fake GamePorts and zero-account runtime startup. A selected bot with its existing controller stopped is required for the first real pilot. The current adapter still requires genuine client evidence for idle/follow/defeat; rsHarnessSignals must not be replaced with invented constants. Missing signals remain Unknown. A passing simulator or a recorded certification does not prove live combat, farming, or verified stop behavior.
Focused tests: bun test server/harness server/assistant. Complete app check: pnpm run check. The validation record is under reports/palantir-validation/mastra-harness-20261026 in the repository root.