mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 05:11:49 +01:00
perf(server): append ordinary run events in one statement (#16569)
Ordinary run events now validate their binding, allocate a sequence and insert the decoded receipt in one atomic PostgreSQL statement. Native replay and retry-exhaustion transactions keep their existing behavior. Verification: exact-head full CI/E2E, Superagent, legacy security and Apex 5/5 passed. PostgreSQL concurrency, rollback and payload controls pass. Controlled network-delay comparison reduced median event persistence from about192ms to48ms; no staging response-time claim is made before deployment. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
d75b3fc33f
commit
b294abb9eb
5 files changed
+217
-19
No files matched your search
@@ -66,6 +66,7 @@ import {
|
||||
NativeSessionProtocolIntegrityError,
|
||||
} from "../../vendor/paperclip-runner/index.js";
|
||||
import * as issueServiceModule from "../issues.js";
|
||||
import * as runEventWriter from "../heartbeat-run-events.js";
|
||||
import { NativePermissionDeclinedError } from "./native-permission-decline.js";
|
||||
import { resolvePaperclipRunnerNativeProviderInput } from "./provider-profile.js";
|
||||
import {
|
||||
@@ -9678,12 +9679,24 @@ describe("native process ownership", () => {
|
||||
startedAt: "2026-08-18T18:00:00.000Z",
|
||||
};
|
||||
const onSpawn = vi.fn(async () => undefined);
|
||||
const db = leaseDb(execution);
|
||||
const admissionWriter = vi.spyOn(runEventWriter, "appendHeartbeatRunEvent").mockResolvedValueOnce({
|
||||
row: {
|
||||
id: 1, companyId: execution.binding.companyId, runId: execution.binding.runId,
|
||||
agentId: execution.binding.agentId, seq: 1, eventType: "native.process_start_requested",
|
||||
stream: "system", level: "info", color: null, message: null, payload: null,
|
||||
sourceInstanceId: null, sourceEventId: null, sourceSeq: null,
|
||||
sourcePayloadSha256: null, protocolSchemaVersion: null, createdAt: new Date(),
|
||||
},
|
||||
disposition: "committed", highestContiguousSourceSeq: 0,
|
||||
});
|
||||
state.createBackend.mockClear();
|
||||
state.execute.mockReset().mockImplementation(async (options) => {
|
||||
await options.onSessionAdmission();
|
||||
expect(updates).toContainEqual({ table: heartbeatRunEvents, values: expect.objectContaining({
|
||||
expect(admissionWriter).toHaveBeenCalledWith(db, expect.objectContaining({
|
||||
eventType: "native.process_start_requested", runId: execution.binding.runId,
|
||||
}) });
|
||||
companyId: execution.binding.companyId, agentId: execution.binding.agentId,
|
||||
}));
|
||||
await options.backend.onSpawn(processMetadata);
|
||||
return {
|
||||
result: { summary: "completed" },
|
||||
@@ -9697,18 +9710,17 @@ describe("native process ownership", () => {
|
||||
highestContiguousSourceSeq: 1,
|
||||
};
|
||||
});
|
||||
const updates: Array<{ table: unknown; values: Record<string, unknown> }> = [];
|
||||
state.createBackend.mockImplementationOnce((_input, options) => {
|
||||
expect(updates.some(update => update.values.eventType === "native.process_start_requested")).toBe(false);
|
||||
expect(admissionWriter).not.toHaveBeenCalled();
|
||||
return { kind: "test", onSpawn: options.onSpawn };
|
||||
});
|
||||
|
||||
await executePaperclipNativeSession({
|
||||
db: leaseDb(execution, {}, {}, updates),
|
||||
execution,
|
||||
runnerInstanceId: "runner",
|
||||
onSpawn,
|
||||
});
|
||||
try {
|
||||
await executePaperclipNativeSession({ db, execution, runnerInstanceId: "runner", onSpawn });
|
||||
expect(admissionWriter).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
admissionWriter.mockRestore();
|
||||
}
|
||||
|
||||
expect(state.createBackend).toHaveBeenCalledWith(
|
||||
execution,
|
||||
|
||||
Reference in new issue
Block a user