Repository navigation
feat(runtime): auto-record decision trajectories + emit ai-hist contract (Workstream B) - #207
Conversation
Wire the (previously unwired) agent-trajectories SDK into the runtime so
every persona run records its own decision trajectory (the WHY) and emits a
compacted, contract-shaped artifact for the ai-hist trajectory sync source.
- types: add TrajectoryContext (chapter/note/decide/error/done) on
WorkforceCtx, plus the locked CompactedTrajectoryContract shape.
- trajectory.ts: per-persona TrajectoryRecorder over TrajectoryClient. Opens a
trajectory per run, auto-finalizes on done, and writes the contract to
$TRAJECTORY_ROOT/<personaId>/compacted/<id>.json (decisions flattened to
{question,chosen,reasoning,alternatives[]}, retrospective subset, personaId/
projectId stamped). Recording activates only when recordTrajectories !== false
AND a trajectory root resolves (TRAJECTORY_ROOT or explicit) — never writes to
the process cwd. autoCompact{mechanical,markdown} enabled (best-effort).
- ctx: instantiate the recorder per persona, expose ctx.trajectory, reserve the
field against integration clobbering; honor opts.trajectoryRoot.
- runner: drive begin/complete/fail around the dispatch loop; recording is
best-effort and never breaks the run it observes.
- cloud-defaults: inject the ai-hist MCP (resolveAiHistFromEnv) into the harness
spec, gated on recordTrajectories. Keys off the SAME TRAJECTORY_ROOT the
recorder writes to, so the MCP reads back exactly what the runtime wrote.
A↔B contract is the frozen interface with ai-hist (codex-1); aggregate
`trail compact` output is deliberately NOT the interface.
Tests: 6 new (records a run, contract shape, auto-finalize, abandon-on-error,
done idempotency, disabled/no-root no-ops). Full runtime suite 80/80 green;
runtime+deploy+mcp-workforce+workload-router+cli all build.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
Warning Review limit reached
More reviews will be available in 8 minutes and 9 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces trajectory recording capabilities to the runtime, integrating the agent-trajectories dependency. It adds configuration resolution for the ai-hist MCP server, integrates a trajectory recorder into the context builder (buildCtx), manages the recorder's lifecycle during event dispatching, and defines corresponding TypeScript interfaces and tests. The review feedback highlights two key improvements: returning undefined from resolveAiHistFromEnv when both trajectoryRoot and dbPath are empty to prevent starting an unnecessary MCP server, and using the (string & {}) idiom in the CompactedTrajectoryContract status type to preserve IDE autocomplete.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return { | ||
| ...(trajectoryRoot ? { trajectoryRoot } : {}), | ||
| ...(dbPath ? { dbPath } : {}) | ||
| }; |
There was a problem hiding this comment.
If both trajectoryRoot and dbPath are empty or undefined, this function currently returns an empty object {}. This causes aiHist to be truthy, which injects an empty aiHist configuration into the harness spec and starts the "ai-hist" MCP server unnecessarily even when trajectory recording is completely inactive. Returning undefined when both are empty avoids starting the unnecessary MCP server.
if (!trajectoryRoot && !dbPath) return undefined;
return {
...(trajectoryRoot ? { trajectoryRoot } : {}),
...(dbPath ? { dbPath } : {})
};| personaId: string; | ||
| projectId: string | null; | ||
| task: { title: string; description: string | null }; | ||
| status: 'active' | 'completed' | 'abandoned' | string; |
There was a problem hiding this comment.
In TypeScript, unioning literal types with string causes the type to collapse into string, which loses IDE autocomplete/intellisense for the literal values. To preserve autocomplete for 'active' | 'completed' | 'abandoned' while still allowing any arbitrary string, use the (string & {}) idiom.
| status: 'active' | 'completed' | 'abandoned' | string; | |
| status: 'active' | 'completed' | 'abandoned' | (string & {}); |
… write+MCP) cloud-defaults computes the trajectory root ONCE and feeds the same value to both the recorder write-root (threaded into buildCtx by the runner) and the ai-hist MCP env, so write-root === MCP-root by construction. - resolveCloudTrajectoryRoot: env.TRAJECTORY_ROOT wins; otherwise defaults to <workspaceRoot>/.trajectories, but ONLY in a real cloud workspace (configured mount or accessible /workspace). Local/tests stay opt-in via env so the runtime never writes to a developer's cwd (loud-on-misconfig preserved). - CloudRuntimeDefaults.trajectoryRoot exposed; runner threads it into buildCtx. - resolveAiHistFromEnv takes the resolved root as its default so the injected ai-hist MCP reads exactly what the recorder writes. Cloud personas now record by default (satisfies "saved automatically") without breaking the write-root===MCP-root guarantee. Tests: +2 (explicit env wins; cloud-workspace default). Runtime suite 82/82. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
Fixed one PR breakage outside the changed-file set: the Local verification passed:
Note: the root |
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
✅ pr-reviewer applied fixes — committed and pushed Fixed one PR breakage outside the changed-file set: the Local verification passed:
Note: the root |
|
Updated the deploy e2e Notion essay smoke mock to satisfy the current Validated locally with:
No bot review artifacts were present in |
|
✅ pr-reviewer applied fixes — committed and pushed Updated the deploy e2e Notion essay smoke mock to satisfy the current Validated locally with:
No bot review artifacts were present in |
Workstream B — runtime trajectory recording (the WHY)
Wires the previously-unwired
agent-trajectoriesSDK into the runtime so every persona run records its own decision trajectory and emits a compacted, contract-shaped artifact for the ai-hist trajectory sync source (codex-1, Workstream A).What changed (
packages/runtimeonly)types.ts—TrajectoryContext(chapter/note/decide/error/done) onWorkforceCtx, plus the lockedCompactedTrajectoryContractshape.trajectory.ts(new) — per-personaTrajectoryRecorderoverTrajectoryClient. Opens a trajectory per run, auto-finalizes on completion, writes the contract to$TRAJECTORY_ROOT/<personaId>/compacted/<id>.json: decisions flattened to{question,chosen,reasoning,alternatives[]}, retrospective projected to its subset,personaId/projectIdstamped.autoCompact {mechanical,markdown}enabled (best-effort).ctx.ts— instantiate the recorder per persona, exposectx.trajectory, reserve it against integration clobbering, honoropts.trajectoryRoot.runner.ts— drivebegin/complete/failaround the dispatch loop. Recording is best-effort and never breaks the run it observes.cloud-defaults.ts— inject theai-histMCP (resolveAiHistFromEnv) into the harness spec, gated onrecordTrajectories. The lead's handoff piece.The two guarantees
TRAJECTORY_ROOTwith no implicit default → the MCP reads back exactly what the runtime wrote (or, with no root, the recorder writes nothing and there is nothing to mis-read).recordTrajectories !== falseand a trajectory root resolves — it never writes to the process cwd.Contract (frozen A↔B interface with ai-hist)
{ id, version, personaId, projectId, task:{title,description}, status, startedAt, completedAt, decisions:[{question,chosen,reasoning,alternatives[]}], retrospective:{summary,approach,learnings[],confidence} }— notype:"compacted"/sourceTrajectories[], so ai-hist's defensive filter keeps it. Aggregatetrail compactoutput is deliberately NOT the interface.Tests / verification
doneidempotency, disabled/no-root no-ops.runtime+deploy+mcp-workforce+workload-router+cliall build.🤖 Generated with Claude Code