Files
AgentCompany/src/shared/provider-request-domain.ts
T
ZacharyZhang-NY 1f89ea7089 Stop shipping megabytes of skill prompts in every snapshot refresh
The whole app turned to molasses because snapshot.load() shipped the
entire skill_runtime_snapshots table - unbounded, compiled_prompt
included - over IPC on every refresh. A real profile carried 142 rows
totaling 144MB (1.1MB each from the pre-cap CEO compile-all era), so
every coalesced refresh serialized ~144MB of JSON. The forced-humanizer
rework made it worse by adding a row per run for every agent.

- Drop skillRuntimeSnapshots, skillRevisions, skillTests, and
  skillBindings from the renderer snapshot: no renderer surface reads
  them; skill internals are main-process state. Only the lightweight
  skillDefinitions catalogue still ships.
- Project provider_requests without raw_response_json (4.1MB across the
  newest 100 rows; RunsPage only reads responseText)
- Migration 051 purges the bug-era compiled prompts from existing DBs
- resolveRuntimeSnapshot is now idempotent per run: a run re-queued by
  startup recovery reuses its frozen snapshot instead of dying on the
  uniqueness guard and burning real retry budget
- Regression test pins the contract: a 2MB database row must not add
  bytes to the snapshot (payload asserted under 400KB)
2026-07-08 23:20:56 -04:00

52 lines
1.4 KiB
TypeScript

import type { ProviderExecutionMode } from "./provider-policy-domain";
export const PROVIDER_REQUEST_STATE = {
PENDING: "pending",
STREAMING: "streaming",
SUCCEEDED: "succeeded",
FAILED: "failed",
CANCELLED: "cancelled",
} as const;
export type ProviderRequestState = typeof PROVIDER_REQUEST_STATE[keyof typeof PROVIDER_REQUEST_STATE];
/**
* Snapshot projection of a provider request. The raw provider response body
* stays in the database (task_runs diagnostics read it there) — shipping it
* to the renderer ballooned every snapshot by megabytes for nothing.
*/
export interface ProviderRequestRecord {
id: string;
orgId: string;
providerId: string;
providerKey: string;
workspaceId: string | null;
model: string;
promptSha256: string;
responseText: string | null;
state: ProviderRequestState;
errorMessage: string | null;
inputCharCount: number;
outputCharCount: number;
executionMode: ProviderExecutionMode;
policyDecision: string;
externalResponseId: string | null;
streamEventCount: number;
cancelledAt: string | null;
createdAt: string;
completedAt: string | null;
}
export interface ProviderStreamRendererEvent {
requestId: string;
providerId: string;
providerKey: string;
model: string;
streamEventType: "message_start" | "text_delta" | "message_stop" | "error";
textDelta: string | null;
responseText: string;
providerResponseId: string | null;
rawEventJson: string;
streamEventCount: number;
}