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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- On macOS and Windows, reading bridge records started one process per record. Before a record is read, prodex removes a temporary hard link that an interrupted record write can leave beside it, and where the store has no descriptor directory to work through (macOS and Windows), that cleanup runs in a child process, which was started for every record read whether or not there was anything to clean. Found 2026-11-09 with the descriptor path switched off on Linux, as on macOS: listing 200 receipts took 1956 ms against 264 ms with it, and the follow-up budget check every follow-up runs (`--continue`, MCP `pro_consult` with `continue_task` or `continue_thread`) 1929 ms against 273 ms. The child process is now started only when the record has a second link, so reads start none and a record write still costs one.
- On Windows, replacing a bridge record failed with `EPERM` while another prodex process was reading it. Records are replaced by renaming a new file over them, and Windows refuses that rename while another handle has the old file open: found on CI 2026-11-09, a session rewritten while another store listed sessions failed this way, and the test for that race was then skipped on Windows. The rename is now tried again for up to 2 seconds while Windows reports the file in use (`EPERM`, `EACCES` or `EBUSY`), with the checks before it repeated, and then fails with the rename's own error. Other platforms are unchanged. The race test runs on Windows again.
- A record that could not be read was not named. With a task record at mode 000, `prodex tasks list` failed as `EACCES: permission denied, open '/proc/self/fd/20/task_...json'`, a descriptor path, and with a hard-linked record as "Target path is hard linked and cannot be used through safe file operations", naming no file. Found 2026-11-09. They now say `Task record is not readable: .bridge/tasks/<id>.json (EACCES)` and `Task record is hard linked: .bridge/tasks/<id>.json has another name on disk`, with what to do (give your user access to it, or remove the other name, or move it aside, then retry), the same for results, sessions and receipts. The path is the repo path, so MCP clients are not given the machine's absolute path.
- One untrusted result hid every other result from `prodex results show latest`, `prodex results artifact latest` and MCP `bridge_list_results`. Found 2026-11-09: with two finished tasks and the older one's `task_completed` receipt moved away, all three failed with "Result record is untrusted: .bridge/results/<older task>.json has no trusted task_completed receipt", while `prodex results show <newer task>` worked. `latest` now resolves to the newest trusted result, stepping past untrusted ones as `prodex pro latest` does, and fails with the untrusted record's reason only when no result is trusted. `bridge_list_results` lists the trusted results and adds `untrusted_skipped` (how many were left out) and `untrusted` (each one's task id and reason, with repo-relative paths). Showing or fetching an untrusted result by its task id still refuses it.
- `prodex pro blockers --cwd <repo>` reported a repo with one corrupt `.bridge/results/*.json` as having no consults at all. Found 2026-11-09: a repo reported as "3 of 3 consults" printed "No consults recorded in this repo." with rc=0 once the corrupt file was added, and `--json` said `"roots": 0`. The record's error was swallowed. The command now fails with "Result record is corrupt: .bridge/results/<file>.json. Move it aside or fix the JSON, then retry." Without `--cwd`, the other bridge roots are still reported and the one skipped is named on stderr with the same message.
- `prodex sessions cancel <id>` made the cancelled session the latest one. Cancelling stamped the session as just used: found 2026-11-09, after cancelling an older session by id, `prodex sessions show latest` showed that cancelled session, and `prodex sessions cancel latest` failed with "already blocked; it was cancelled before" while the newer session was still running. Cancelling now leaves the session's last-used time alone, so `latest` and the order of `sessions list` stay as they were; sending through a session still makes it the latest.
- `prodex pro blockers --since 2026-02-30` was read as 2026-03-02. A day the month does not have rolled over into the next month (found 2026-11-09). Such a date is now refused with "--since 2026-02-30 names a day that does not exist"; real dates, including 29 February in a leap year, dates with a time, and ages like `7d` or `24h` work as before.

## 0.40.51

Expand Down
2 changes: 2 additions & 0 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ prodex results reseal <task-id> --confirm-current-result

This writes a new local `task_completed` receipt for the current result payload. Prefer the explicit task id you just reviewed; `latest` is accepted for convenience but resolves from the current raw result list at execution time. It does not reseal unsigned receipts, forged receipts, or receipts that already point at a different result digest.

An untrusted result does not hide the others: `results show latest` and `results artifact latest` resolve to the newest trusted result, as `pro latest` does, and MCP `bridge_list_results` lists the trusted results with `untrusted_skipped` (how many were left out) and `untrusted` (each one's task id and reason). Naming an untrusted result by its task id still refuses it.

Receipts are HMAC-signed with a local key in `.bridge/receipt-key.local`. If you suspect the key was exposed, rotate it:

```bash
Expand Down
21 changes: 15 additions & 6 deletions src/cli-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,19 @@ export async function latestRawResultTaskId(store: BridgeStore): Promise<string>
}

export async function latestResultTaskId(store: BridgeStore, options: { readOnly?: boolean } = {}): Promise<string> {
const results = options.readOnly ? await listResultsForInspection(store) : await store.listResults();
const result = results.at(-1);
if (!result) throw new Error("No results found");
return result.task_id;
if (!options.readOnly) {
const result = (await store.listResults()).at(-1);
if (!result) throw new Error("No results found");
return result.task_id;
}
// The newest trusted result, stepping past untrusted ones the way `pro
// latest` does; with none trusted, the newest untrusted one's reason.
const { trusted, untrusted } = await listResultsForInspection(store);
const result = trusted.at(-1);
if (result) return result.task_id;
const newestUntrusted = untrusted.at(-1);
if (newestUntrusted) throw newestUntrusted;
throw new Error("No results found");
}

export async function latestTask(
Expand Down Expand Up @@ -402,8 +411,8 @@ export async function listTasksForInspection(
return store.listTasksReadOnly(status);
}

export async function listResultsForInspection(store: BridgeStore): Promise<Awaited<ReturnType<BridgeStore["listResults"]>>> {
return store.listFinalizedResultsReadOnly();
export async function listResultsForInspection(store: BridgeStore): Promise<Awaited<ReturnType<BridgeStore["listResultsByTrustReadOnly"]>>> {
return store.listResultsByTrustReadOnly();
}

export async function listRawResultsForInspection(store: BridgeStore): Promise<Awaited<ReturnType<BridgeStore["listResults"]>>> {
Expand Down
19 changes: 16 additions & 3 deletions src/cli-pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,14 @@ export async function runProCommand(rest: string[], io: CliIO, runCliFn: RunCliF
...(result.blocker ? { blocker: reclassifyRecordedBlocker(result.blocker) } : {})
});
}
} catch {
// A root that has been deleted or is unreadable is not a failure of
// the report; it just has nothing to contribute.
} catch (error) {
// A bare catch here turned one corrupt record into "No consults
// recorded in this repo." with rc=0 (found 2026-11-09). A deleted
// root does not get here: it reads as empty or is not listed. The
// repo asked for fails with the record's own advice; across every
// root, the rest are still reported and this one is named.
if (scopedToOneRepo) throw error;
io.stderr(`blockers_warning: skipped ${root}: ${errorMessage(error)}`);
}
}
const report = buildBlockerReport({
Expand Down Expand Up @@ -3485,6 +3490,14 @@ export function readSinceFlag(args: string[]): string | undefined {
if (!Number.isFinite(parsed)) {
throw new Error(`--since expects a date or an age like 7d or 24h, not "${raw}".`);
}
// Date.parse rolls a day the month lacks into the next month: 2026-02-30
// was read as 2026-03-02 (found 2026-11-09).
const [year, month, day] = raw.trim().slice(0, 10).split("-").map(Number) as [number, number, number];
const calendarDay = new Date(0);
calendarDay.setUTCFullYear(year, month - 1, day);
if (calendarDay.getUTCFullYear() !== year || calendarDay.getUTCMonth() !== month - 1 || calendarDay.getUTCDate() !== day) {
throw new Error(`--since ${raw} names a day that does not exist; use a date like 2026-01-01 or an age like 7d or 24h.`);
}
return new Date(parsed).toISOString();
}

Expand Down
17 changes: 16 additions & 1 deletion src/mcp-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,22 @@ export function createMcpToolHandlers(context: McpToolContext) {
},

async bridge_list_results() {
return { results: (await store.listFinalizedResultsReadOnly()).map(redactResultForMcp) };
// An untrusted record is left out and named, as `prodex pro list` does,
// instead of failing the list for every trusted result beside it.
const { trusted, untrusted } = await store.listResultsByTrustReadOnly();
return {
results: trusted.map(redactResultForMcp),
...(untrusted.length > 0
? {
untrusted_skipped: untrusted.length,
untrusted: untrusted.map((error) => ({
task_id: error.taskId,
status: "untrusted" as const,
summary: redactContextText(error.message, [context.cwd])
}))
}
: {})
};
},

async bridge_fetch_result(input: { task_id: string }) {
Expand Down
3 changes: 2 additions & 1 deletion src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export function createServer(cwd = process.cwd(), options: CreateMcpServerOption
server.registerTool(
"bridge_list_results",
{
description: "List completed or blocked bridge results.",
description:
"List completed or blocked bridge results. A result without a trusted completion receipt is left out; `untrusted_skipped` counts those and `untrusted` gives each one's reason.",
inputSchema: {}
},
async () => asText(await handlers.bridge_list_results())
Expand Down
63 changes: 46 additions & 17 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export interface ResealResultOutput {
receipt: Receipt;
}

/** A result refused for want of a trusted task_completed receipt. */
export type UntrustedResultError = Error & { code: "EUNTRUSTED_RESULT"; taskId: string };


// A bridge root has to be a real directory in a real filesystem. Field report
// (macOS): an agent harness started `prodex mcp` with a working directory of
Expand Down Expand Up @@ -402,11 +405,24 @@ export class BridgeStore {
);
}

async listFinalizedResultsReadOnly(): Promise<Result[]> {
/**
* Every result, split into those a trusted task_completed receipt finalizes
* and the untrusted ones, each with the error that refuses it.
*
* This used to throw on the first untrusted result, so one old record whose
* receipt was moved away failed `results show latest` and MCP
* `bridge_list_results` for every newer result too (found 2026-11-09).
* Callers decide what to do with the untrusted ones; fetching one by id
* still refuses it.
*/
async listResultsByTrustReadOnly(): Promise<{ trusted: Result[]; untrusted: UntrustedResultError[] }> {
const results = await this.listResultsReadOnly();
if (results.length === 0) return results;
if (results.length === 0) return { trusted: [], untrusted: [] };
if (!(await this.hasReadyStorageDirReadOnly("receipts"))) {
throw untrustedResultError(this.root, results[0].task_id, "has no trusted task_completed receipt");
return {
trusted: [],
untrusted: results.map((result) => untrustedResultError(this.root, result.task_id, "has no trusted task_completed receipt"))
};
}
// Read receipts ONCE and index them by task_id instead of re-reading and
// re-parsing the whole receipts directory for every result, which was
Expand All @@ -418,10 +434,18 @@ export class BridgeStore {
if (existing) existing.push(receipt);
else completionReceiptsByTask.set(receipt.task_id, [receipt]);
}
const trusted: Result[] = [];
const untrusted: UntrustedResultError[] = [];
for (const result of results) {
await this.assertReceiptsTrustCompletion(result.task_id, result, completionReceiptsByTask.get(result.task_id) ?? []);
try {
await this.assertReceiptsTrustCompletion(result.task_id, result, completionReceiptsByTask.get(result.task_id) ?? []);
trusted.push(result);
} catch (error) {
if (!isUntrustedResultErrorCode(error)) throw error;
untrusted.push(error);
}
}
return results;
return { trusted, untrusted };
}

async getResult(taskId: string): Promise<Result> {
Expand Down Expand Up @@ -628,18 +652,19 @@ export class BridgeStore {
const why = existing.blocker?.code === "cancelled" ? "it was cancelled before" : "its outcome is recorded";
throw new Error(`Session ${existing.id} is already ${existing.status}; ${why}, so there is nothing to cancel.`);
}
return this.writeSession({
id: existing.id,
direction: existing.direction,
backend: existing.backend,
session_key: existing.session_key,
project: existing.project,
thread: existing.thread,
task_id: existing.task_id,
// Written directly rather than through writeSession, which stamps
// last_used_at: cancelling is not using the session, and an older one
// cancelled by id became "latest", so `sessions cancel latest` then
// refused it while a newer session kept running (found 2026-11-09).
await this.ensure();
const session = SessionSchema.parse({
...existing,
schema_version: SCHEMA_VERSION,
status: "blocked",
blocker: { code: "cancelled", message: "Session cancelled via CLI.", retryable: false },
warnings: existing.warnings
blocker: { code: "cancelled", message: "Session cancelled via CLI.", retryable: false }
});
await this.writeRecordJson("sessions", existing.id, session);
return session;
}

async getSessionReadOnly(sessionId: string): Promise<Session> {
Expand Down Expand Up @@ -1686,15 +1711,19 @@ function recordUnusableError(kind: BridgeRecordKind, id: string, filePath: strin
return undefined;
}

function untrustedResultError(root: string, taskId: string, reason: string): Error {
function untrustedResultError(root: string, taskId: string, reason: string): UntrustedResultError {
const error = new Error(
`Result record is untrusted: ${formatRecordPath(root, path.join(root, ".bridge", "results", `${taskId}.json`))} ${reason}. If this is a locally signed legacy completion receipt, review .bridge/results/${taskId}.json, then run \`prodex results reseal ${taskId} --confirm-current-result\`. Retry the completion path or move the result record aside, then retry.`
) as Error & { code: "EUNTRUSTED_RESULT"; taskId: string };
) as UntrustedResultError;
error.code = "EUNTRUSTED_RESULT";
error.taskId = taskId;
return error;
}

function isUntrustedResultErrorCode(error: unknown): error is UntrustedResultError {
return error instanceof Error && (error as { code?: unknown }).code === "EUNTRUSTED_RESULT";
}

function formatRecordPath(root: string, filePath: string): string {
const relative = path.relative(root, filePath);
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return filePath;
Expand Down
Loading
Loading