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
7 changes: 7 additions & 0 deletions .changeset/bounded-agent-team-waits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@agent-native/core": patch
---

Allow bounded, abortable waits for agent task status and results, and keep volatile read-only task checks fresh throughout an agent turn.

Save sub-agent results within their active task transaction while retaining execution lease checks and atomic rollback.
1 change: 1 addition & 0 deletions packages/core/src/a2a/task-store-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const dbExec: DbExec = {

vi.mock("../db/client.js", () => ({
getDbExec: () => dbExec,
getScopedTransactionDbExec: () => undefined,
isProductionServerlessFunctionRuntime: () => false,
}));

Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/agent/execution-fence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AsyncLocalStorage } from "node:async_hooks";

import { getDbExec, type DbExec } from "../db/client.js";
import {
getDbExec,
getScopedTransactionDbExec,
type DbExec,
} from "../db/client.js";

export interface ExecutionFence {
threadId: string;
Expand Down Expand Up @@ -161,6 +165,10 @@ export async function withFencedExecutionWrite<T>(
if (!scopedFence) {
throw new StaleExecutionFenceError(fence);
}
if (getScopedTransactionDbExec() === client) {
await lockAndAssertCurrentExecutionFences(client);
return write(client);
}
if (!client.transaction) {
throw new Error("Fenced execution writes require transaction support");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { mockEvent } from "h3";
import { beforeAll, describe, expect, it, vi } from "vitest";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";

import { closeDbExec } from "../db/client.js";
import { withMigrationRuntime } from "../db/migration-runtime.js";
import { SCHEMA_SNAPSHOT } from "../db/schema-snapshot.generated.js";
import { __setSchemaSnapshotForTests } from "../db/store-registry.js";
import { runWithRequestContext } from "../server/request-context.js";
import type {
AgentEngine,
Expand All @@ -25,7 +32,36 @@ vi.mock("./tool-approval-store.js", async (importOriginal) => ({
const { createProductionAgentHandler, toolCallCacheKey } =
await import("./production-agent.js");

beforeAll(() => withMigrationRuntime(ensureRunTables));
const previousDatabaseUrl = process.env.DATABASE_URL;
let databaseDirectory: string;

beforeAll(async () => {
await closeDbExec();
databaseDirectory = fs.mkdtempSync(
path.join(os.tmpdir(), "approved-tool-gone-"),
);
process.env.DATABASE_URL = `pglite:${databaseDirectory}`;
// Retain release-owned inbox schema while leaving the thread store cold.
__setSchemaSnapshotForTests({
...SCHEMA_SNAPSHOT,
statements: SCHEMA_SNAPSHOT.statements.filter(
(statement) => !/\bchat_threads\b/.test(statement),
),
tables: SCHEMA_SNAPSHOT.tables.filter((table) => table !== "chat_threads"),
migrations: SCHEMA_SNAPSHOT.migrations.filter(
([storeId]) => storeId !== "chat_threads",
),
});
await withMigrationRuntime(ensureRunTables);
});
afterAll(async () => {
__setSchemaSnapshotForTests(undefined);
await closeDbExec();
if (previousDatabaseUrl === undefined) delete process.env.DATABASE_URL;
else process.env.DATABASE_URL = previousDatabaseUrl;
if (databaseDirectory)
fs.rmSync(databaseDirectory, { recursive: true, force: true });
});

const EMAIL = { to: "customer@example.com", body: "Your refund is approved." };

Expand Down
Loading
Loading