Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugins/pardes-pi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ retained for later inspection rather than declared safe. Use baseline branch
overrides only intentionally. Worker reports are stored under the owning
manager's `reports/` directory; concise summaries wake the manager.

Clean completion audits lead with bounded worker-branch non-merge change
candidates from cooperative first-parent evidence; topology does not prove
authorship or feature semantics. They label merge first-parent diffs separately
as integration context, retain the total branch-point delta, first-parent commit
count, and latest-commit evidence, and do not infer exact conflict-resolution
ownership from parent diffs. The routine-compatible total safety diff is also
subject to explicit Git timeout/output bounds (the provenance defaults, with
independent service overrides); if it cannot complete within them, Pardes
reports the total as unavailable and retains only explicitly known live paths.
Dirty, unsupported, or over-bound histories likewise degrade explicitly instead
of claiming attribution.

`pull_request_create` publishes a clean committed worker state as a
user-controlled review gate. After the exact pushed SHA is verified as the
hosted head, Pardes makes the retained local worker branch track the managed
Expand Down
12 changes: 8 additions & 4 deletions plugins/pardes-pi/extensions/pardes/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export {
RemoteBaselineBranchSchema,
type RepoState,
RepoStateSchema,
type WorktreeCommitProvenance,
type WorktreeCommitProvenanceBounds,
WorktreeCommitProvenanceBoundsSchema,
WorktreeCommitProvenanceSchema,
type WorktreeCommitProvenanceUnavailableReason,
WorktreeCommitProvenanceUnavailableReasonSchema,
type WorktreeLatestCommitDelta,
WorktreeLatestCommitDeltaSchema,
type WorktreeLease,
WorktreeLeaseSchema,
} from './schemas.ts';
Expand Down Expand Up @@ -50,10 +58,6 @@ export {
WORKTREE_PROVENANCE_GIT_TIMEOUT_MS,
WORKTREE_PROVENANCE_MAX_FIRST_PARENT_COMMITS,
WORKTREE_PROVENANCE_MAX_PATHS,
type WorktreeCommitProvenance,
type WorktreeCommitProvenanceBounds,
type WorktreeCommitProvenanceUnavailableReason,
type WorktreeInspection,
type WorktreeLatestCommitDelta,
type WorktreeServiceError,
} from './worktrees.ts';
83 changes: 83 additions & 0 deletions plugins/pardes-pi/extensions/pardes/git/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,89 @@ export const WorktreeLeaseSchema = Schema.Struct({
});
export type WorktreeLease = typeof WorktreeLeaseSchema.Type;

const FullCommitShaSchema = Schema.String.check(Schema.isPattern(/^[0-9a-f]{40,64}$/));
const NonNegativeIntegerSchema = Schema.Number.check(
Schema.isInt(),
Schema.isGreaterThanOrEqualTo(0),
);

export const WorktreeLatestCommitDeltaSchema = Schema.Struct({
changedPaths: Schema.Array(NonEmptyString),
commitSha: FullCommitShaSchema,
kind: Schema.Literals(['first_parent_non_merge', 'merge_commit']),
});
export type WorktreeLatestCommitDelta = typeof WorktreeLatestCommitDeltaSchema.Type;

export const WorktreeCommitProvenanceBoundsSchema = Schema.Struct({
maxFirstParentCommits: NonNegativeIntegerSchema,
maxPaths: NonNegativeIntegerSchema,
});
export type WorktreeCommitProvenanceBounds = typeof WorktreeCommitProvenanceBoundsSchema.Type;

export const WorktreeCommitProvenanceUnavailableReasonSchema = Schema.Literals([
'dirty_worktree',
'worktree_not_registered',
'branch_mismatch',
'baseline_not_ancestor',
'unsupported_graph',
'bounds_exceeded',
'total_diff_unavailable',
'inspection_failed',
]);
export type WorktreeCommitProvenanceUnavailableReason =
typeof WorktreeCommitProvenanceUnavailableReasonSchema.Type;

/** Bounded cooperative first-parent evidence; merge-parent diffs are context, not authorship proof. */
export const WorktreeCommitProvenanceSchema = Schema.Union([
Schema.Struct({
attribution: Schema.Literal('cooperative_first_parent'),
bounds: WorktreeCommitProvenanceBoundsSchema,
branchPointSha: FullCommitShaSchema,
firstParentNonMergeCommitCount: NonNegativeIntegerSchema,
firstParentNonMergePaths: Schema.Array(NonEmptyString),
headSha: FullCommitShaSchema,
latestDelta: Schema.optionalKey(WorktreeLatestCommitDeltaSchema),
mergeCommitCount: NonNegativeIntegerSchema,
mergePaths: Schema.Array(NonEmptyString),
status: Schema.Literal('available'),
totalBranchCommitCount: NonNegativeIntegerSchema,
totalBranchDeltaPaths: Schema.Array(NonEmptyString),
}),
Schema.Struct({
bounds: WorktreeCommitProvenanceBoundsSchema,
dirtyPaths: Schema.Array(NonEmptyString),
observedBranch: Schema.optionalKey(NonEmptyString),
reason: WorktreeCommitProvenanceUnavailableReasonSchema,
status: Schema.Literal('unavailable'),
}),
]).check(
Schema.makeFilter((provenance) => {
if (provenance.status === 'unavailable')
return provenance.dirtyPaths.length <= provenance.bounds.maxPaths
? undefined
: 'dirtyPaths exceeds its declared provenance bound';
if (
provenance.firstParentNonMergePaths.length > provenance.bounds.maxPaths ||
provenance.mergePaths.length > provenance.bounds.maxPaths ||
provenance.totalBranchDeltaPaths.length > provenance.bounds.maxPaths ||
(provenance.latestDelta?.changedPaths.length ?? 0) > provenance.bounds.maxPaths
)
return 'available path evidence exceeds its declared provenance bound';
if (provenance.totalBranchCommitCount > provenance.bounds.maxFirstParentCommits)
return 'totalBranchCommitCount exceeds its declared provenance bound';
if (
provenance.firstParentNonMergeCommitCount + provenance.mergeCommitCount !==
provenance.totalBranchCommitCount
)
return 'first-parent commit categories do not sum to totalBranchCommitCount';
return provenance.latestDelta === undefined ||
provenance.latestDelta.commitSha === provenance.headSha
? undefined
: 'latestDelta.commitSha must match headSha';
}),
);
export type WorktreeCommitProvenance = typeof WorktreeCommitProvenanceSchema.Type;

/** Persisted detached review checkout pinned to one immutable worker head. */
export const DetachedReviewCheckoutLeaseSchema = Schema.Struct({
createdAt: NonEmptyString,
Expand Down
118 changes: 113 additions & 5 deletions plugins/pardes-pi/extensions/pardes/git/worktrees.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
chmodSync,
existsSync,
mkdirSync,
mkdtempSync,
Expand All @@ -8,7 +9,7 @@ import {
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { delimiter, join } from 'node:path';
import { Effect } from 'effect';
import { afterEach, describe, expect, test } from 'vitest';
import {
Expand Down Expand Up @@ -39,6 +40,19 @@ function git(cwd: string, ...args: string[]): string {
return runGitFixture(cwd, ...args);
}

function executableOnPath(name: string): string {
const executable = (process.env.PATH ?? '')
.split(delimiter)
.map((directory) => join(directory, name))
.find(existsSync);
if (!executable) throw new Error(`Could not resolve ${name} on PATH`);
return realpathSync(executable);
}

function shellQuote(value: string): string {
return `'${value.replaceAll("'", "'\\''")}'`;
}

const worktreeGit = (
cwd: string,
args: ReadonlyArray<string>,
Expand Down Expand Up @@ -590,7 +604,7 @@ describe('managed worktree service', () => {
});
});

test('refuses stable provenance for dirty worktrees while returning complete dirty paths', async () => {
test('refuses stable provenance for dirty worktrees while retaining total safety-audit paths', async () => {
const primary = fixtureRepository();
const repo = await Effect.runPromise(discoverRepository(primary));
const branchPointSha = git(primary, 'rev-parse', 'HEAD');
Expand All @@ -608,13 +622,48 @@ describe('managed worktree service', () => {
);

expect(inspection).toMatchObject({
changedPaths: ['dirty.txt'],
changedPaths: ['dirty.txt', 'worker.txt'],
dirty: true,
provenance: { dirtyPaths: ['dirty.txt'], reason: 'dirty_worktree', status: 'unavailable' },
});
});

test('returns dirty refusal before committed-range output can exceed the audit circuit breaker', async () => {
test('degrades over-bound dirty provenance without dropping the routine safety-audit path set', async () => {
const primary = fixtureRepository();
const repo = await Effect.runPromise(discoverRepository(primary));
const branchPointSha = git(primary, 'rev-parse', 'HEAD');
const service = makeManagedWorktreeService({ provenanceMaxPaths: 1 });
const lease = await Effect.runPromise(
service.create({
agentId: 'agent-dirty-path-bound',
branchPointSha,
managerId: 'manager-1',
repo,
}),
);
writeFileSync(join(lease.path, 'committed.txt'), 'committed\n');
git(lease.path, 'add', 'committed.txt');
git(lease.path, 'commit', '-m', 'committed fixture');
writeFileSync(join(lease.path, 'dirty-a.txt'), 'dirty a\n');
writeFileSync(join(lease.path, 'dirty-b.txt'), 'dirty b\n');

expect(
await Effect.runPromise(
inspectProvenance(service, owner(repo, 'manager-1', 'agent-dirty-path-bound'), lease),
),
).toMatchObject({
changedPaths: ['committed.txt', 'dirty-a.txt', 'dirty-b.txt'],
dirty: true,
provenance: {
bounds: { maxPaths: 1 },
dirtyPaths: [],
reason: 'bounds_exceeded',
status: 'unavailable',
},
});
});

test('degrades honestly when the bounded total safety diff exceeds its output limit', async () => {
const primary = fixtureRepository();
const repo = await Effect.runPromise(discoverRepository(primary));
const branchPointSha = git(primary, 'rev-parse', 'HEAD');
Expand All @@ -638,7 +687,65 @@ describe('managed worktree service', () => {
inspectProvenance(service, owner(repo, 'manager-1', 'agent-dirty-bound'), lease),
),
).toMatchObject({
provenance: { dirtyPaths: ['dirty.txt'], reason: 'dirty_worktree', status: 'unavailable' },
changedPaths: ['dirty.txt'],
dirty: true,
provenance: {
dirtyPaths: ['dirty.txt'],
reason: 'total_diff_unavailable',
status: 'unavailable',
},
});
});

test('degrades deterministically when the bounded total safety diff exceeds its timeout', async () => {
const primary = fixtureRepository();
const repo = await Effect.runPromise(discoverRepository(primary));
const branchPointSha = git(primary, 'rev-parse', 'HEAD');
const service = makeManagedWorktreeService({ provenanceTotalDiffGitTimeoutMs: 100 });
const lease = await Effect.runPromise(
service.create({
agentId: 'agent-diff-timeout',
branchPointSha,
managerId: 'manager-1',
repo,
}),
);
writeFileSync(join(lease.path, 'changed.txt'), 'changed\n');
git(lease.path, 'add', 'changed.txt');
git(lease.path, 'commit', '-m', 'timeout fixture');

const wrapperRoot = mkdtempSync(join(tmpdir(), 'pardes-slow-git-'));
temporaryDirectories.push(wrapperRoot);
const wrapper = join(wrapperRoot, 'git');
const marker = join(wrapperRoot, 'diff-started');
const realGit = executableOnPath('git');
writeFileSync(
wrapper,
`#!/bin/sh\nif [ "$1" = "diff" ]; then\n : > ${shellQuote(marker)}\n sleep 1\nfi\nexec ${shellQuote(realGit)} "$@"\n`,
);
chmodSync(wrapper, 0o755);
const originalPath = process.env.PATH;
const inspection = await (async () => {
try {
process.env.PATH = `${wrapperRoot}${delimiter}${originalPath ?? ''}`;
return await Effect.runPromise(
inspectProvenance(service, owner(repo, 'manager-1', 'agent-diff-timeout'), lease),
);
} finally {
if (originalPath === undefined) delete process.env.PATH;
else process.env.PATH = originalPath;
}
})();

expect(existsSync(marker)).toBe(true);
expect(inspection).toMatchObject({
changedPaths: [],
dirty: false,
provenance: {
dirtyPaths: [],
reason: 'total_diff_unavailable',
status: 'unavailable',
},
});
});

Expand Down Expand Up @@ -821,6 +928,7 @@ describe('managed worktree service', () => {
inspectProvenance(service, owner(repo, 'manager-1', 'agent-commit-bounds'), lease),
),
).toMatchObject({
changedPaths: ['first.txt', 'second.txt'],
provenance: {
bounds: { maxFirstParentCommits: 1 },
dirtyPaths: [],
Expand Down
Loading
Loading