Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): read copy updatedAt from published rows

Alfredo Lopezd22967eba6f6
diff --git a/gfs-controller/src/api/serve.test.ts b/gfs-controller/src/api/serve.test.ts
index b0c9ab9ba..05a86cadc 100644
--- a/gfs-controller/src/api/serve.test.ts
+++ b/gfs-controller/src/api/serve.test.ts
@@ -466,9 +466,10 @@ describe("GfsReadServer.tryHandle — served reads", () => {
const res = new FakeRes();
await run(deps(), req(`/v1/resources/${RID}`, { auth: "Bearer t" }), res);
expect(res.statusCode).toBe(200);
- const data = (res.json as { ok: boolean; data: { gfsUri: string; name: string } }).data;
+ const data = (res.json as { ok: boolean; data: { gfsUri: string; name: string; updatedAt: string } }).data;
expect(data.name).toBe("report.pdf");
expect(data.gfsUri).toBe(`gfs://main/${RID}`);
+ expect(data.updatedAt).toBe("2026-01-01T00:00:00.000Z");
});
it("200 children returns the paged items", async () => {
@@ -541,6 +542,7 @@ describe("GfsReadServer.tryHandle — served reads", () => {
path: FILE.pathCache,
version: FILE.version,
bytes: FILE.bytes,
+ updatedAt: FILE.updatedAt,
permissions: ["read", "write"],
sources: ["grant"],
coversDescendants: true,
@@ -550,10 +552,11 @@ describe("GfsReadServer.tryHandle — served reads", () => {
});
await run(deps({ listAccessible }), req("/v1/accessible?limit=20", { auth: "Bearer t" }), res);
expect(res.statusCode).toBe(200);
- const data = (res.json as { data: { items: Array<{ gfsUri: string; permissions: string[] }> } })
+ const data = (res.json as { data: { items: Array<{ gfsUri: string; permissions: string[]; updatedAt?: string }> } })
.data;
expect(data.items[0]?.gfsUri).toBe(`gfs://main/${RID}`);
expect(data.items[0]?.permissions).toContain("write");
+ expect(data.items[0]?.updatedAt).toBe("2026-01-01T00:00:00.000Z");
});
it("403 accessible requires a read scope even if the store would return rows", async () => {
diff --git a/gfs-controller/src/db/copyPublication.failures.test.ts b/gfs-controller/src/db/copyPublication.failures.test.ts
index dd5b58a62..43bbacc47 100644
--- a/gfs-controller/src/db/copyPublication.failures.test.ts
+++ b/gfs-controller/src/db/copyPublication.failures.test.ts
@@ -86,7 +86,10 @@ describe("copy rollback and ambiguous commit outcomes", () => {
it("treats an exact fully published ambiguous commit as success after the request is aborted", async () => {
const fixture = copyFixture({ ambiguity: "full", abortOnAmbiguity: true });
- await expect(fixture.writes.copy(fixture.input)).resolves.toMatchObject({ objectCount: 4 });
+ await expect(fixture.writes.copy(fixture.input)).resolves.toMatchObject({
+ objectCount: 4,
+ root: { updatedAt: "2026-01-01T00:00:00.000Z" },
+ });
expect(fixture.input.signal?.aborted).toBe(true);
expect(fixture.db.manifests.size).toBe(0);
expect(fixture.blobs.deletes).toEqual([]);
diff --git a/gfs-controller/src/db/copyPublication.test.ts b/gfs-controller/src/db/copyPublication.test.ts
index 554d671a7..183cf1b39 100644
--- a/gfs-controller/src/db/copyPublication.test.ts
+++ b/gfs-controller/src/db/copyPublication.test.ts
@@ -7,7 +7,13 @@ describe("transactional recursive copy publication", () => {
const before = new Map(db.resources);
const copied = await writes.copy(input);
expect(copied).toMatchObject({ requestId: input.requestId, objectCount: 4, fileCount: 2, folderCount: 2, totalBytes: 10n });
- expect(copied.root).toMatchObject({ parentResourceId: DEST, name: "source", pathCache: "/archive/source", version: 0 });
+ expect(copied.root).toMatchObject({
+ parentResourceId: DEST,
+ name: "source",
+ pathCache: "/archive/source",
+ version: 0,
+ updatedAt: "2026-01-01T00:00:00.000Z",
+ });
const added = [...db.resources.values()].filter(row => !before.has(String(row.resource_id)));
expect(added).toHaveLength(4);
expect(new Set(added.map(row => row.resource_id)).size).toBe(4);
diff --git a/gfs-controller/src/db/copyPublication.ts b/gfs-controller/src/db/copyPublication.ts
index 1abb2923e..0d3d1d698 100644
--- a/gfs-controller/src/db/copyPublication.ts
+++ b/gfs-controller/src/db/copyPublication.ts
@@ -275,21 +275,33 @@ async function auditFailure(input: CopyInput, error: unknown): Promise<void> {
);
}
+type AmbiguousInspection =
+ | { outcome: "full"; updatedAt: string }
+ | { outcome: "zero" }
+ | { outcome: "unsafe" };
+
async function inspectAmbiguous(
deps: Dependencies,
input: CopyInput,
reserved: ReservedNode[],
budget: DeadlineBudget
-): Promise<"full" | "zero" | "unsafe"> {
+): Promise<AmbiguousInspection> {
try {
const published = await deps.manifests.resolvePublishedTree(input.drive, reserved, budget);
- if (published !== null) return "full";
+ if (published !== null) {
+ const root = reserved[0];
+ if (!root) return { outcome: "unsafe" };
+ const rootRow = published.find(row => String(row.resource_id) === root.resourceId);
+ return { outcome: "full", updatedAt: toIsoTimestamp(rootRow?.updated_at) };
+ }
return await deps.tx.transaction(async client => {
const rows = await client.query(`SELECT resource_id FROM gfs_resources WHERE drive = $1 AND resource_id = ANY($2::uuid[])`, [input.drive, reserved.map(node => node.resourceId)]);
- if (rows.rows.length === 0) return "zero";
- return "unsafe";
+ if (rows.rows.length === 0) return { outcome: "zero" };
+ return { outcome: "unsafe" };
}, budget);
- } catch { return "unsafe"; }
+ } catch {
+ return { outcome: "unsafe" };
+ }
}
export async function publishCopy(deps: Dependencies, input: CopyInput): Promise<CopyPublicationResult> {
@@ -328,6 +340,7 @@ export async function publishCopy(deps: Dependencies, input: CopyInput): Promise
stagedKeys.push(staged.blobKey);
}
const root = reserved[0];
+ if (!root) throw new Error("copy reserved an empty tree");
let publishedUpdatedAt: string | undefined;
await deps.tx.transaction(async client => {
await revalidate(client, input);
@@ -350,7 +363,7 @@ export async function publishCopy(deps: Dependencies, input: CopyInput): Promise
await deps.manifests.removeCommittedMany(input.requestId, stagedKeys, {
deadlineAtMs: input.deadlineAtMs, signal: input.signal, now: input.now,
}).catch(() => undefined);
- return result(input, root, publishedUpdatedAt ?? new Date().toISOString());
+ return result(input, root, toIsoTimestamp(publishedUpdatedAt));
} catch (error) {
if ((error as Error).name === "CommitOutcomeUnknownError") {
// COMMIT uncertainty is resolved with a fresh, short budget. The request
@@ -358,15 +371,24 @@ export async function publishCopy(deps: Dependencies, input: CopyInput): Promise
// cannot safely gate the independent read-back.
const recoveryBudget = ambiguousCommitBudget();
const outcome = await inspectAmbiguous(deps, input, reserved, recoveryBudget);
- if (outcome === "full") {
- await deps.manifests.removeCommittedMany(input.requestId, stagedKeys, ambiguousCommitBudget()).catch(() => undefined);
- return result(input, reserved[0], new Date().toISOString());
- }
- if (outcome === "zero") {
- await cleanup(deps, ambiguousCommitBudget(), stagedKeys);
- await auditFailure(input, error);
+ switch (outcome.outcome) {
+ case "full": {
+ const recoveredRoot = reserved[0];
+ if (!recoveredRoot) throw error as CommitOutcomeUnknownError;
+ await deps.manifests.removeCommittedMany(input.requestId, stagedKeys, ambiguousCommitBudget()).catch(() => undefined);
+ return result(input, recoveredRoot, outcome.updatedAt);
+ }
+ case "zero":
+ await cleanup(deps, ambiguousCommitBudget(), stagedKeys);
+ await auditFailure(input, error);
+ throw error as CommitOutcomeUnknownError;
+ case "unsafe":
+ throw error as CommitOutcomeUnknownError;
+ default: {
+ const _exhaustive: never = outcome;
+ throw _exhaustive;
+ }
}
- throw error as CommitOutcomeUnknownError;
}
await cleanup(deps, inputBudget(input), stagedKeys);
await auditFailure(input, error);
diff --git a/gfs-controller/test/copyPublicationTestKit.ts b/gfs-controller/test/copyPublicationTestKit.ts
index c7f6040d0..72df2edec 100644
--- a/gfs-controller/test/copyPublicationTestKit.ts
+++ b/gfs-controller/test/copyPublicationTestKit.ts
@@ -41,7 +41,8 @@ export const destination = (): CopyDestinationSnapshot => ({
function dbRow(value: CopySnapshotNode): Record<string, unknown> {
return { resource_id: value.resourceId, drive: value.drive, parent_resource_id: value.parentResourceId,
name: value.name, kind: value.kind, path_cache: value.pathCache, version: value.version,
- bytes: value.bytes.toString(), blob_key: value.blobKey, content_sha256: value.contentSha256, deleted_at: value.deletedAt };
+ bytes: value.bytes.toString(), blob_key: value.blobKey, content_sha256: value.contentSha256, deleted_at: value.deletedAt,
+ updated_at: new Date("2026-01-01T00:00:00.000Z") };
}
export class CopyDb implements TxClient {