mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
Fix remote-only workspace base refs and pre-adapter retry loops (#11892)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Execution workspaces give each run an isolated directory and a selected base ref > - A remote-only base ref can fail before `git worktree add` when the ref is not local > - A setup failure before adapter dispatch must block the run without an agent-only retry > - This pull request resolves both remote-tracking ref forms and bounds recovery for the same unresolved ref > - The benefit is correct workspace setup and no repeated pre-adapter recovery loop ## Linked Issues or Issue Description This PR has no existing public issue. It addresses a workspace setup bug. **What happened?** A remote-only base ref could fail before `git worktree add`. A setup failure before adapter dispatch could also queue an agent-only missing-comment retry. **Expected behavior** Paperclip must resolve `fix/foo` and `origin/fix/foo` before it creates a worktree. An unresolved ref must create a human-owned configuration blocker. Paperclip must not queue an agent-only retry when the adapter never starts. **Steps to reproduce** 1. Configure an execution workspace with a base ref that exists only on the remote. 2. Start a run that creates a fresh worktree. 3. Repeat the run with the same unresolved ref. 4. Observe one configuration blocker and no repeated agent-only recovery action. **Paperclip version or commit** `7664e323189bc219d8cbe00433b2e82b682b0504` **Deployment mode** Built from source with `pnpm dev`. **Agent adapter(s) involved** Not adapter-specific. The failure occurs before adapter dispatch. **Database mode** Not database-related. **Access context** Both board and agent execution paths can use execution workspaces. Related public pull request: `Refs #11123`. ## What Changed - Resolve remote-only base refs with the authenticated fetch helper before `git worktree add`. - Support both unqualified refs and remote-tracking refs. - Raise a `configuration_incomplete` blocker when the requested ref remains unresolved. - Suppress missing-comment retries when setup fails before adapter dispatch. - Add the requested ref to the recovery fingerprint to bound identical recovery actions. - Add focused tests and update the execution semantics document. ## Verification - `tsc --noEmit` passed for the changed server code. - Focused Vitest suites passed, including four base-ref tests, fingerprint deduplication, and pre-adapter retry suppression. - GitHub Actions must run the full pull request gate. ## Risks Low risk. The change affects workspace setup before adapter dispatch. Existing worktree reuse remains unchanged. An unresolved ref now creates a clear configuration blocker instead of starting an adapter run. ## Model Used OpenAI GPT-5; exact model ID `gpt-5`; agentic tool use and repository review. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
adfbe2d4b9
commit
69590890d4
10 files changed
+673
-47
No files matched your search
@@ -36,6 +36,7 @@ import {
|
||||
realizeExecutionWorkspace,
|
||||
refreshRemoteTrackingBaseRef,
|
||||
releaseRuntimeServicesForRun,
|
||||
UnresolvedWorkspaceBaseRefError,
|
||||
resetRuntimeServicesForTests,
|
||||
resolveRuntimeProvisionCommand,
|
||||
resolveWorkspaceRuntimeReadinessTimeoutSec,
|
||||
@@ -251,6 +252,26 @@ async function advanceRemoteMaster(sourceRepo: string, remotePath: string, fileN
|
||||
return readGit(sourceRepo, ["rev-parse", "master"]);
|
||||
}
|
||||
|
||||
// Push a branch to the bare remote without leaving a local ref or a
|
||||
// remote-tracking ref in `repoRoot`. This reproduces a remote-only feature
|
||||
// branch: the clone was made before the push, so `repoRoot` learns the branch
|
||||
// only after an authenticated fetch of `origin/<branch>`.
|
||||
async function pushRemoteOnlyBranch(
|
||||
sourceRepo: string,
|
||||
remotePath: string,
|
||||
branch: string,
|
||||
fileName: string,
|
||||
) {
|
||||
await runGit(sourceRepo, ["checkout", "-B", branch]);
|
||||
await fs.writeFile(path.join(sourceRepo, fileName), `${fileName}\n`, "utf8");
|
||||
await runGit(sourceRepo, ["add", fileName]);
|
||||
await runGit(sourceRepo, ["commit", "-m", `Add ${fileName}`]);
|
||||
await runGit(sourceRepo, ["push", remotePath, branch]);
|
||||
const sha = await readGit(sourceRepo, ["rev-parse", branch]);
|
||||
await runGit(sourceRepo, ["checkout", "master"]);
|
||||
return sha;
|
||||
}
|
||||
|
||||
function realizeWorktreeForTest(repoRoot: string, repoRef: string | null) {
|
||||
return realizeExecutionWorkspace({
|
||||
base: {
|
||||
@@ -1018,6 +1039,111 @@ describe("realizeExecutionWorkspace", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("bases a fresh worktree on a remote-only branch supplied as fix/foo", async () => {
|
||||
const { sourceRepo, remotePath, repoRoot } = await createClonedRepoWithRemote();
|
||||
const remoteSha = await pushRemoteOnlyBranch(sourceRepo, remotePath, "fix/foo", "remote-only.txt");
|
||||
|
||||
// The clone never learned the branch: no local ref and no remote-tracking ref.
|
||||
await expect(readGit(repoRoot, ["rev-parse", "--verify", "fix/foo"])).rejects.toThrow();
|
||||
await expect(readGit(repoRoot, ["rev-parse", "--verify", "origin/fix/foo"])).rejects.toThrow();
|
||||
|
||||
const workspace = await realizeWorktreeForTest(repoRoot, "fix/foo");
|
||||
|
||||
expect(workspace.created).toBe(true);
|
||||
expect(workspace.repoRef).toBe("origin/fix/foo");
|
||||
expect(workspace.baseRefSha).toBe(remoteSha);
|
||||
expect(await readGit(workspace.cwd, ["rev-parse", "HEAD"])).toBe(remoteSha);
|
||||
});
|
||||
|
||||
it("bases a fresh worktree on a remote-only branch supplied as origin/fix/foo", async () => {
|
||||
const { sourceRepo, remotePath, repoRoot } = await createClonedRepoWithRemote();
|
||||
const remoteSha = await pushRemoteOnlyBranch(sourceRepo, remotePath, "fix/bar", "remote-only.txt");
|
||||
|
||||
await expect(readGit(repoRoot, ["rev-parse", "--verify", "origin/fix/bar"])).rejects.toThrow();
|
||||
|
||||
const workspace = await realizeWorktreeForTest(repoRoot, "origin/fix/bar");
|
||||
|
||||
expect(workspace.created).toBe(true);
|
||||
expect(workspace.repoRef).toBe("origin/fix/bar");
|
||||
expect(workspace.baseRefSha).toBe(remoteSha);
|
||||
expect(await readGit(workspace.cwd, ["rev-parse", "HEAD"])).toBe(remoteSha);
|
||||
});
|
||||
|
||||
it("stops before git worktree add when the base ref is absent on origin", async () => {
|
||||
const { repoRoot } = await createClonedRepoWithRemote();
|
||||
|
||||
const error = await realizeWorktreeForTest(repoRoot, "fix/does-not-exist").then(
|
||||
() => null,
|
||||
(caught: unknown) => caught,
|
||||
);
|
||||
|
||||
expect(error).toBeInstanceOf(UnresolvedWorkspaceBaseRefError);
|
||||
const unresolved = error as UnresolvedWorkspaceBaseRefError;
|
||||
expect(unresolved.requestedRef).toBe("fix/does-not-exist");
|
||||
expect(unresolved.recoveryIdentityRef).toBe("origin/fix/does-not-exist");
|
||||
expect(unresolved.attemptedRefs).toEqual(["origin/fix/does-not-exist"]);
|
||||
// No worktree directory was created for the fresh-create path.
|
||||
await expect(
|
||||
fs.stat(path.join(repoRoot, ".paperclip", "worktrees", "PAP-447-add-worktree-support")),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("gives equivalent spellings of one absent remote ref the same recovery identity", async () => {
|
||||
const { repoRoot } = await createClonedRepoWithRemote();
|
||||
|
||||
// The unqualified form and the remote-tracking form name the same remote
|
||||
// branch. Both must map to one `recoveryIdentityRef`, so recovery does not
|
||||
// treat a spelling change as a new blocker.
|
||||
const unqualified = await realizeWorktreeForTest(repoRoot, "fix/absent").then(
|
||||
() => null,
|
||||
(caught: unknown) => caught,
|
||||
);
|
||||
const remoteTracking = await realizeWorktreeForTest(repoRoot, "origin/fix/absent").then(
|
||||
() => null,
|
||||
(caught: unknown) => caught,
|
||||
);
|
||||
// The full remote-tracking spelling names the same branch as well. It must
|
||||
// map to the same canonical recovery identity, not to its raw spelling.
|
||||
const fullRemoteTracking = await realizeWorktreeForTest(repoRoot, "refs/remotes/origin/fix/absent").then(
|
||||
() => null,
|
||||
(caught: unknown) => caught,
|
||||
);
|
||||
|
||||
expect(unqualified).toBeInstanceOf(UnresolvedWorkspaceBaseRefError);
|
||||
expect(remoteTracking).toBeInstanceOf(UnresolvedWorkspaceBaseRefError);
|
||||
expect(fullRemoteTracking).toBeInstanceOf(UnresolvedWorkspaceBaseRefError);
|
||||
const unqualifiedError = unqualified as UnresolvedWorkspaceBaseRefError;
|
||||
const remoteTrackingError = remoteTracking as UnresolvedWorkspaceBaseRefError;
|
||||
const fullRemoteTrackingError = fullRemoteTracking as UnresolvedWorkspaceBaseRefError;
|
||||
// Each error keeps its own operator spelling for the human notice.
|
||||
expect(unqualifiedError.requestedRef).toBe("fix/absent");
|
||||
expect(remoteTrackingError.requestedRef).toBe("origin/fix/absent");
|
||||
expect(fullRemoteTrackingError.requestedRef).toBe("refs/remotes/origin/fix/absent");
|
||||
// All three share one canonical recovery identity.
|
||||
expect(unqualifiedError.recoveryIdentityRef).toBe("origin/fix/absent");
|
||||
expect(remoteTrackingError.recoveryIdentityRef).toBe("origin/fix/absent");
|
||||
expect(fullRemoteTrackingError.recoveryIdentityRef).toBe("origin/fix/absent");
|
||||
});
|
||||
|
||||
it("surfaces an authenticated fetch failure as an unresolved base ref, not a crash", async () => {
|
||||
const { repoRoot } = await createClonedRepoWithRemote();
|
||||
// Point origin at a path that no repository backs. The authenticated fetch
|
||||
// fails, so the ref never resolves and the resolver reports the fetch error.
|
||||
await runGit(repoRoot, ["remote", "set-url", "origin", path.join(os.tmpdir(), "paperclip-missing-remote.git")]);
|
||||
|
||||
const error = await realizeWorktreeForTest(repoRoot, "fix/unreachable").then(
|
||||
() => null,
|
||||
(caught: unknown) => caught,
|
||||
);
|
||||
|
||||
expect(error).toBeInstanceOf(UnresolvedWorkspaceBaseRefError);
|
||||
const unresolved = error as UnresolvedWorkspaceBaseRefError;
|
||||
expect(unresolved.requestedRef).toBe("fix/unreachable");
|
||||
expect(unresolved.fetchError).toEqual(
|
||||
expect.stringContaining("Could not refresh base ref origin/fix/unreachable"),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects reusing an empty directory that only looks like a worktree because it sits inside the repo", async () => {
|
||||
const repoRoot = await createTempRepo();
|
||||
const branchName = "PAP-447-add-worktree-support";
|
||||
@@ -7477,14 +7603,26 @@ describeEmbeddedPostgres("workspace runtime startup reconciliation", () => {
|
||||
process.env.PAPERCLIP_HOME = paperclipHome;
|
||||
process.env.PAPERCLIP_INSTANCE_ID = `runtime-pnpm-reconcile-${randomUUID()}`;
|
||||
|
||||
const portProbe = net.createServer();
|
||||
await new Promise<void>((resolve) => portProbe.listen(0, "127.0.0.1", resolve));
|
||||
const address = portProbe.address();
|
||||
const port = typeof address === "object" && address ? address.port : null;
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
portProbe.close((error) => error ? reject(error) : resolve());
|
||||
});
|
||||
if (!port) throw new Error("Failed to reserve pnpm reconciliation test port");
|
||||
// Reserve a port outside the runtime exposure app-port range (42000-42999).
|
||||
// The reconciler stores this port on the row. A port inside that range makes
|
||||
// the reconciler treat the row as an exposure reservation and report drift,
|
||||
// so the live service never reaches the adoption path this test verifies.
|
||||
const reservePort = async () => {
|
||||
for (let attempt = 0; attempt < 100; attempt += 1) {
|
||||
const probe = net.createServer();
|
||||
await new Promise<void>((resolve) => probe.listen(0, "127.0.0.1", resolve));
|
||||
const address = probe.address();
|
||||
const candidate = typeof address === "object" && address ? address.port : null;
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
probe.close((error) => error ? reject(error) : resolve());
|
||||
});
|
||||
if (candidate && candidate <= 55_535 && (candidate < 42_000 || candidate > 42_999)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw new Error("Failed to reserve pnpm reconciliation test port outside the broker range");
|
||||
};
|
||||
const port = await reservePort();
|
||||
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
|
||||
Reference in new issue
Block a user