mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 12:50:37 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The restart chaos TTFT driver measures time to first token, but only with a tiny fixture workspace and only locally > - Dotta asked whether speed is good with a workspace like the paperclip repository itself, and that had never been measured > - This pull request lets the driver run in a real repository workspace, measure the first follow-up after an idle restart, run on Daytona (per-turn or warm reusable sandboxes), and report each run's workspace operations > - The benefit is a repeatable large-workspace speed measurement; its first run found a full workspace re-upload on every remote turn ## Linked Issues or Issue Description **What happened?** The TTFT driver seeded only a tiny fixture repository, created tasks outside any project, ran only locally, and could not show workspace operation durations. So large-workspace speed (worktree creation, provision, remote upload) was never measured. **Steps to reproduce** 1. Run `ttft-baseline.ts` with any options. 2. Every task runs without a project workspace and on the local host. 3. Nothing in the report shows worktree, provision or sync cost. **Expected behavior** The driver can measure a real repository workspace, locally and on Daytona, and names the workspace operations each run waited on. ## What Changed - `--workspace-repo <path>`: the seed uses that repository as the project's primary workspace (git_worktree isolation), and tasks are created in the project. - A `postfault` phase: K1 while idle, then a follow-up on each task; reported in its own table. - `--env daytona`, `--daytona-image`, `--daytona-cpu`, `--daytona-warm` (the reusable warm Daytona fixture). The Daytona controller preparation moved to `daytona-controller.ts`, and every sandbox is cleaned up at the end; incomplete cleanup fails the run. - Each run's workspace operations (`/api/heartbeat-runs/:id/workspace-operations`) are saved, and printed ranked by duration. ## Verification - `tsc -p tests/restart-chaos`: no errors in harness files. - Used for the large-workspace measurement, a fresh paperclip clone on local and Daytona (per-turn and warm). First turn / follow-up: local 31–34 s / 7 s; Daytona per-turn 58–63 s / 30 s; Daytona warm 45–51 s / 8–10 s. Every Daytona sandbox was cleaned up (environment deleted, none remaining). ## Risks - Test harness only; no product code. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with tool use (shell, file editing, test execution, Daytona measurements). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
3.3 KiB
TypeScript
52 lines
3.3 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { writeFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { assertControllerMatchesImage, defaultDaytonaImageCacheRoot, prepareDaytonaImageArtifacts } from "./daytona-image.js";
|
|
import { PLUGIN_BUILD_STAMP, pluginBuildState } from "./plugin-build.js";
|
|
import type { Timeline } from "./timeline.js";
|
|
|
|
function run(command: string, args: string[], cwd: string, label: string) {
|
|
const result = spawnSync(command, args, { cwd, stdio: "inherit" });
|
|
if (result.status !== 0) throw new Error(`${label} failed (${command} ${args.join(" ")})`);
|
|
}
|
|
|
|
/**
|
|
* Mirrors restart-chaos main.ts's Daytona preparation for the TTFT driver.
|
|
* The bundled Daytona plugin is outside the root workspace; prepare it as CI
|
|
* does, and rebuild it whenever its sources (or the plugin SDK's) changed since
|
|
* the last build, so a worktree that moved to a new master tests that master's
|
|
* plugin rather than an older build.
|
|
*/
|
|
export function ensureDaytonaPlugin(repositoryRoot: string, timeline: Timeline) {
|
|
const root = path.join(repositoryRoot, "packages/plugins/sandbox-providers/daytona");
|
|
// Inputs outside the plugin directory: the linked plugin SDK and the tsconfig chain both packages extend.
|
|
const extraInputs = [
|
|
...["src", "package.json", "tsconfig.json"].map(file => path.join(repositoryRoot, "packages/plugins/sdk", file)),
|
|
...["tsconfig.json", "tsconfig.base.json"].map(file => path.join(repositoryRoot, file)),
|
|
];
|
|
const state = pluginBuildState(root, extraInputs);
|
|
timeline.add("daytona_plugin_build_state", { reason: state.reason, inputHash: state.inputHash });
|
|
if (!state.needsBuild) return;
|
|
run("pnpm", ["install", "--ignore-workspace", "--frozen-lockfile", "--ignore-scripts"], root, "Daytona plugin install");
|
|
run(process.execPath, [path.join(repositoryRoot, "scripts/link-plugin-dev-sdk.mjs")], repositoryRoot, "Plugin SDK link");
|
|
run("pnpm", ["--dir", root, "build"], repositoryRoot, "Daytona plugin build");
|
|
writeFileSync(path.join(root, PLUGIN_BUILD_STAMP), `${state.inputHash}\n`);
|
|
timeline.add("daytona_plugin_built", { inputHash: state.inputHash });
|
|
}
|
|
|
|
/**
|
|
* Controller environment for `--env daytona`: extract the image's Linux runnerd
|
|
* and provider pack (cached per image digest, no Docker), refuse a controller
|
|
* whose runner source differs from the image, and build the Daytona plugin.
|
|
*/
|
|
export async function prepareDaytonaController(input: { image: string; repositoryRoot: string; timeline: Timeline }):
|
|
Promise<Record<string, string>> {
|
|
const artifacts = await prepareDaytonaImageArtifacts({ image: input.image, cacheRoot: defaultDaytonaImageCacheRoot(),
|
|
log: line => console.info(`[daytona-image] ${line}`) });
|
|
const { localContentId } = await assertControllerMatchesImage(artifacts, input.repositoryRoot);
|
|
input.timeline.add("daytona_image_matched", { image: input.image, contentId: artifacts.contentId, localContentId, sourceRevision: artifacts.sourceRevision,
|
|
runnerdSha256: artifacts.runnerdSha256, providerPackDigest: artifacts.providerPackDigest, platformManifestDigest: artifacts.platformManifestDigest });
|
|
ensureDaytonaPlugin(input.repositoryRoot, input.timeline);
|
|
return { PAPERCLIP_RUNNER_REMOTE_BINARY_PATH: artifacts.runnerdPath, PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH: artifacts.providerPackPath };
|
|
}
|