@agent-native/core 0.84.67 → 0.85.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +20 -0
- package/corpus/core/docs/content/locales/ar-SA/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/de-DE/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/es-ES/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/fr-FR/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/hi-IN/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/ja-JP/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/ko-KR/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/pt-BR/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/zh-CN/tracking.mdx +55 -0
- package/corpus/core/docs/content/locales/zh-TW/tracking.mdx +55 -0
- package/corpus/core/docs/content/tracking.mdx +2 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/action-continuation-guidance.ts +1 -1
- package/corpus/core/src/agent/production-agent.ts +222 -38
- package/corpus/core/src/agent/run-manager.ts +79 -0
- package/corpus/core/src/agent/run-store.ts +122 -8
- package/corpus/core/src/agent/types.ts +13 -0
- package/corpus/core/src/client/RunStuckBanner.tsx +14 -0
- package/corpus/core/src/client/agent-chat-adapter.ts +475 -0
- package/corpus/core/src/client/analytics.ts +2 -0
- package/corpus/core/src/client/error-format.ts +4 -0
- package/corpus/core/src/client/extensions/ExtensionsSidebarSection.tsx +1 -1
- package/corpus/core/src/client/session-replay.ts +774 -2
- package/corpus/core/src/client/sse-event-processor.ts +65 -9
- package/corpus/core/src/client/use-run-stuck-detection.ts +31 -7
- package/corpus/core/src/db/runtime-diagnostics.ts +331 -0
- package/corpus/core/src/server/agent-chat-plugin.ts +115 -2
- package/corpus/core/src/server/core-routes-plugin.ts +91 -4
- package/corpus/core/src/server/http-response-telemetry.ts +189 -0
- package/corpus/core/src/server/self-dispatch.ts +29 -0
- package/corpus/templates/analytics/.agents/skills/session-replay/SKILL.md +53 -1
- package/corpus/templates/analytics/AGENTS.md +13 -0
- package/corpus/templates/analytics/actions/view-screen.ts +25 -0
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +20 -0
- package/corpus/templates/analytics/app/global.css +55 -0
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +100 -1
- package/corpus/templates/analytics/app/i18n-data.ts +1226 -0
- package/corpus/templates/analytics/app/pages/Settings.tsx +3 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/EmailReportDialog.tsx +182 -144
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +11 -18
- package/corpus/templates/analytics/app/pages/analyses/AnalysisDetail.tsx +11 -18
- package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +49 -1
- package/corpus/templates/analytics/app/pages/sessions/SessionDevToolsPanel.tsx +557 -0
- package/corpus/templates/analytics/app/pages/sessions/session-replay-devtools.ts +274 -0
- package/corpus/templates/analytics/app/pages/settings/AlertRulesSettingsCard.tsx +974 -0
- package/corpus/templates/analytics/changelog/2026-07-02-alert-rules-can-now-be-viewed-and-managed-from-settings.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-02-recent-ask-chats-show-a-loading-placeholder-while-your-chat-.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-02-session-replays-now-capture-console-logs-and-network-request.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-02-sharing-status-labels-use-neutral-icons-instead-of-colored-d.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-02-the-session-replay-viewer-has-a-dev-tools-panel-with-console.md +6 -0
- package/corpus/templates/analytics/server/db/schema.ts +3 -0
- package/corpus/templates/analytics/server/jobs/analytics-alerts.ts +4 -0
- package/corpus/templates/analytics/server/lib/analytics-alerts.ts +142 -1
- package/corpus/templates/analytics/server/lib/session-replay-agent-context.ts +369 -8
- package/corpus/templates/analytics/server/lib/session-replay.ts +76 -2
- package/corpus/templates/analytics/server/routes/api/session-replay/agent-diagnostics.json.get.ts +101 -0
- package/corpus/templates/analytics/shared/session-replay-diagnostics.ts +78 -0
- package/corpus/templates/design/app/pages/DesignEditor.tsx +24 -12
- package/corpus/templates/design/changelog/2026-07-02-the-temporary-code-tab-is-hidden-from-the-design-editor-side.md +6 -0
- package/corpus/templates/plan/actions/create-visual-recap.ts +1 -1
- package/corpus/templates/plan/actions/update-local-plan-folder.ts +3 -1
- package/corpus/templates/plan/actions/update-visual-plan.ts +1 -1
- package/corpus/templates/plan/changelog/2026-07-02-trying-to-edit-a-recap-or-plan-you-can-only-view-now-explain.md +6 -0
- package/corpus/templates/plan/server/plans.ts +26 -9
- package/dist/agent/action-continuation-guidance.js +1 -1
- package/dist/agent/action-continuation-guidance.js.map +1 -1
- package/dist/agent/production-agent.d.ts +9 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +168 -34
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +29 -0
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +73 -0
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +41 -0
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +105 -7
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/types.d.ts +13 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/client/RunStuckBanner.d.ts.map +1 -1
- package/dist/client/RunStuckBanner.js +13 -0
- package/dist/client/RunStuckBanner.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +410 -0
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/analytics.d.ts +1 -1
- package/dist/client/analytics.d.ts.map +1 -1
- package/dist/client/analytics.js.map +1 -1
- package/dist/client/error-format.d.ts.map +1 -1
- package/dist/client/error-format.js +2 -0
- package/dist/client/error-format.js.map +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
- package/dist/client/session-replay.d.ts +36 -0
- package/dist/client/session-replay.d.ts.map +1 -1
- package/dist/client/session-replay.js +579 -1
- package/dist/client/session-replay.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +20 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +42 -11
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/client/use-run-stuck-detection.d.ts +14 -4
- package/dist/client/use-run-stuck-detection.d.ts.map +1 -1
- package/dist/client/use-run-stuck-detection.js +18 -4
- package/dist/client/use-run-stuck-detection.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +2 -2
- package/dist/db/runtime-diagnostics.d.ts +52 -0
- package/dist/db/runtime-diagnostics.d.ts.map +1 -0
- package/dist/db/runtime-diagnostics.js +250 -0
- package/dist/db/runtime-diagnostics.js.map +1 -0
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +3 -3
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/secrets/routes.d.ts +3 -3
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +101 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts +17 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +65 -5
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/http-response-telemetry.d.ts +4 -0
- package/dist/server/http-response-telemetry.d.ts.map +1 -0
- package/dist/server/http-response-telemetry.js +174 -0
- package/dist/server/http-response-telemetry.js.map +1 -0
- package/dist/server/self-dispatch.d.ts +17 -0
- package/dist/server/self-dispatch.d.ts.map +1 -1
- package/dist/server/self-dispatch.js +11 -0
- package/dist/server/self-dispatch.js.map +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/docs/content/locales/ar-SA/tracking.mdx +55 -0
- package/docs/content/locales/de-DE/tracking.mdx +55 -0
- package/docs/content/locales/es-ES/tracking.mdx +55 -0
- package/docs/content/locales/fr-FR/tracking.mdx +55 -0
- package/docs/content/locales/hi-IN/tracking.mdx +55 -0
- package/docs/content/locales/ja-JP/tracking.mdx +55 -0
- package/docs/content/locales/ko-KR/tracking.mdx +55 -0
- package/docs/content/locales/pt-BR/tracking.mdx +55 -0
- package/docs/content/locales/zh-CN/tracking.mdx +55 -0
- package/docs/content/locales/zh-TW/tracking.mdx +55 -0
- package/docs/content/tracking.mdx +2 -0
- package/package.json +1 -1
|
@@ -94,6 +94,13 @@ export declare function readLedgerEntry(threadId: string, toolKey: string): Prom
|
|
|
94
94
|
export declare function clearLedgerForThread(threadId: string): Promise<void>;
|
|
95
95
|
export declare function insertRun(id: string, threadId: string, turnId?: string, options?: {
|
|
96
96
|
dispatchMode?: "foreground" | "background";
|
|
97
|
+
/**
|
|
98
|
+
* JSON-serialized request body for a background dispatch. Persisted on the
|
|
99
|
+
* run row so the self-POST to the background function carries only the
|
|
100
|
+
* tiny `__backgroundRun` marker (Netlify caps background-function request
|
|
101
|
+
* bodies at 256KB); the worker rehydrates the body from this column.
|
|
102
|
+
*/
|
|
103
|
+
dispatchPayload?: string;
|
|
97
104
|
}): Promise<void>;
|
|
98
105
|
/**
|
|
99
106
|
* Atomically claim a background-dispatched run for processing. The foreground
|
|
@@ -125,6 +132,40 @@ export declare function readBackgroundRunClaim(runId: string): Promise<{
|
|
|
125
132
|
workerStage: string | null;
|
|
126
133
|
lastLivenessAt: number | null;
|
|
127
134
|
} | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Read the persisted dispatch payload for a background-dispatched run. The
|
|
137
|
+
* worker rehydrates its request body from this column when the dispatch marker
|
|
138
|
+
* carries `payloadRef: true` (the self-POST itself stays under Netlify's 256KB
|
|
139
|
+
* background-function body cap). Returns null when the row is missing or the
|
|
140
|
+
* payload was already cleared (terminal run).
|
|
141
|
+
*/
|
|
142
|
+
export declare function readRunDispatchPayload(runId: string): Promise<string | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Clear a run's persisted dispatch payload once the worker has claimed and
|
|
145
|
+
* rehydrated it — the payload can be large (full chat history) and has no use
|
|
146
|
+
* after the handoff. Best-effort; terminal status writes also clear it.
|
|
147
|
+
*/
|
|
148
|
+
export declare function clearRunDispatchPayload(runId: string): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* List background-dispatched runs that were never claimed by a worker within
|
|
151
|
+
* the unclaimed grace window. These are handoffs that were lost in flight —
|
|
152
|
+
* the async 202 (or the dispatching worker) died before any worker reached
|
|
153
|
+
* `claimBackgroundRun`. The periodic sweeper reaps them via
|
|
154
|
+
* `reapUnclaimedBackgroundRun` so a lost handoff becomes a loud, attributable
|
|
155
|
+
* error instead of a silent forever-hang. The foreground circuit-breaker
|
|
156
|
+
* already covers initial dispatches while the client is connected; this sweep
|
|
157
|
+
* exists for server-chained continuation handoffs, which have no foreground
|
|
158
|
+
* watching them.
|
|
159
|
+
*/
|
|
160
|
+
export declare function listUnclaimedBackgroundRunIds(): Promise<string[]>;
|
|
161
|
+
/**
|
|
162
|
+
* Count how many runs (chunks) a logical turn has consumed so far. This is the
|
|
163
|
+
* durable per-turn recovery ledger: unlike the in-marker `continuationCount`
|
|
164
|
+
* (which resets whenever a fresh client POST starts a new chain for the same
|
|
165
|
+
* turn), the SQL count survives every recovery path, so it bounds pathological
|
|
166
|
+
* turn loops regardless of which layer initiated each chunk.
|
|
167
|
+
*/
|
|
168
|
+
export declare function countRunsForTurn(threadId: string, turnId: string): Promise<number>;
|
|
128
169
|
/**
|
|
129
170
|
* Resolve the authenticated owner email for a run by joining it to its chat
|
|
130
171
|
* thread. The durable background worker's self-dispatch is cookieless
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-store.d.ts","sourceRoot":"","sources":["../../src/agent/run-store.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,eAAO,MAAM,qBAAqB;aAChC,IAAI,EAAE,OAAO;aACb,KAAK,EACH,qHAAqH;aACvH,SAAS,EAAE,WAAW;aACtB,WAAW;aACX,OAAO,EACL,gIAAgI;CAC1H,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,oCAAoC;aAC/C,IAAI,EAAE,OAAO;aACb,KAAK,EACH,gHAAgH;aAClH,SAAS,EAAE,iCAAiC;aAC5C,WAAW;aACX,OAAO,EACL,oNAAoN;CAC9M,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,4CAA4C;aACvD,IAAI,EAAE,OAAO;aACb,KAAK,EACH,oHAAoH;aACtH,SAAS,EAAE,0BAA0B;aACrC,WAAW;aACX,OAAO,EACL,yGAAyG;CACnG,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iCAAiC,QAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"run-store.d.ts","sourceRoot":"","sources":["../../src/agent/run-store.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,eAAO,MAAM,qBAAqB;aAChC,IAAI,EAAE,OAAO;aACb,KAAK,EACH,qHAAqH;aACvH,SAAS,EAAE,WAAW;aACtB,WAAW;aACX,OAAO,E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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,IAAI,CAAC,CAEf"}
|
package/dist/agent/run-store.js
CHANGED
|
@@ -105,7 +105,8 @@ async function ensureRunTables() {
|
|
|
105
105
|
error_detail TEXT,
|
|
106
106
|
terminal_reason TEXT,
|
|
107
107
|
dispatch_mode TEXT,
|
|
108
|
-
diag_stage TEXT
|
|
108
|
+
diag_stage TEXT,
|
|
109
|
+
dispatch_payload TEXT
|
|
109
110
|
)
|
|
110
111
|
`;
|
|
111
112
|
const agentRunEventsCreateSql = `
|
|
@@ -179,6 +180,13 @@ async function ensureRunTables() {
|
|
|
179
180
|
["dispatch_mode", "TEXT"],
|
|
180
181
|
["diag_stage", "TEXT"],
|
|
181
182
|
["worker_stage", "TEXT"],
|
|
183
|
+
// dispatch_payload holds the JSON request body for a background
|
|
184
|
+
// dispatch so the self-POST to the Netlify background function can
|
|
185
|
+
// stay tiny (Netlify caps background-function request bodies at
|
|
186
|
+
// 256KB — a large chat history silently exceeded it). The worker
|
|
187
|
+
// rehydrates the body from this column via the marker's payloadRef.
|
|
188
|
+
// Cleared on terminal status writes.
|
|
189
|
+
["dispatch_payload", "TEXT"],
|
|
182
190
|
]) {
|
|
183
191
|
await ensureColumnExists("agent_runs", col, `ALTER TABLE agent_runs ADD COLUMN IF NOT EXISTS ${col} ${colType}`);
|
|
184
192
|
}
|
|
@@ -251,6 +259,7 @@ async function ensureRunTables() {
|
|
|
251
259
|
"dispatch_mode",
|
|
252
260
|
"diag_stage",
|
|
253
261
|
"worker_stage",
|
|
262
|
+
"dispatch_payload",
|
|
254
263
|
]) {
|
|
255
264
|
try {
|
|
256
265
|
await client.execute(`ALTER TABLE agent_runs ADD COLUMN ${col} TEXT`);
|
|
@@ -372,7 +381,7 @@ export async function insertRun(id, threadId, turnId, options) {
|
|
|
372
381
|
const client = getDbExec();
|
|
373
382
|
const now = Date.now();
|
|
374
383
|
await client.execute({
|
|
375
|
-
sql: `INSERT INTO agent_runs (id, thread_id, status, started_at, heartbeat_at, last_progress_at, turn_id, dispatch_mode) VALUES (?, ?, 'running', ?, ?, ?, ?, ?)`,
|
|
384
|
+
sql: `INSERT INTO agent_runs (id, thread_id, status, started_at, heartbeat_at, last_progress_at, turn_id, dispatch_mode, dispatch_payload) VALUES (?, ?, 'running', ?, ?, ?, ?, ?, ?)`,
|
|
376
385
|
args: [
|
|
377
386
|
id,
|
|
378
387
|
threadId,
|
|
@@ -381,6 +390,7 @@ export async function insertRun(id, threadId, turnId, options) {
|
|
|
381
390
|
now,
|
|
382
391
|
turnId ?? id,
|
|
383
392
|
options?.dispatchMode ?? null,
|
|
393
|
+
options?.dispatchPayload ?? null,
|
|
384
394
|
],
|
|
385
395
|
});
|
|
386
396
|
}
|
|
@@ -493,6 +503,88 @@ export async function readBackgroundRunClaim(runId) {
|
|
|
493
503
|
lastLivenessAt: row.heartbeat_at ?? row.started_at ?? null,
|
|
494
504
|
};
|
|
495
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Read the persisted dispatch payload for a background-dispatched run. The
|
|
508
|
+
* worker rehydrates its request body from this column when the dispatch marker
|
|
509
|
+
* carries `payloadRef: true` (the self-POST itself stays under Netlify's 256KB
|
|
510
|
+
* background-function body cap). Returns null when the row is missing or the
|
|
511
|
+
* payload was already cleared (terminal run).
|
|
512
|
+
*/
|
|
513
|
+
export async function readRunDispatchPayload(runId) {
|
|
514
|
+
await ensureRunTables();
|
|
515
|
+
const client = getDbExec();
|
|
516
|
+
const { rows } = await client.execute({
|
|
517
|
+
sql: `SELECT dispatch_payload FROM agent_runs WHERE id = ? LIMIT 1`,
|
|
518
|
+
args: [runId],
|
|
519
|
+
});
|
|
520
|
+
const row = rows?.[0];
|
|
521
|
+
if (!row)
|
|
522
|
+
return null;
|
|
523
|
+
const payload = row.dispatch_payload;
|
|
524
|
+
return typeof payload === "string" && payload.length > 0 ? payload : null;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Clear a run's persisted dispatch payload once the worker has claimed and
|
|
528
|
+
* rehydrated it — the payload can be large (full chat history) and has no use
|
|
529
|
+
* after the handoff. Best-effort; terminal status writes also clear it.
|
|
530
|
+
*/
|
|
531
|
+
export async function clearRunDispatchPayload(runId) {
|
|
532
|
+
await ensureRunTables();
|
|
533
|
+
const client = getDbExec();
|
|
534
|
+
await client.execute({
|
|
535
|
+
sql: `UPDATE agent_runs SET dispatch_payload = NULL WHERE id = ?`,
|
|
536
|
+
args: [runId],
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* List background-dispatched runs that were never claimed by a worker within
|
|
541
|
+
* the unclaimed grace window. These are handoffs that were lost in flight —
|
|
542
|
+
* the async 202 (or the dispatching worker) died before any worker reached
|
|
543
|
+
* `claimBackgroundRun`. The periodic sweeper reaps them via
|
|
544
|
+
* `reapUnclaimedBackgroundRun` so a lost handoff becomes a loud, attributable
|
|
545
|
+
* error instead of a silent forever-hang. The foreground circuit-breaker
|
|
546
|
+
* already covers initial dispatches while the client is connected; this sweep
|
|
547
|
+
* exists for server-chained continuation handoffs, which have no foreground
|
|
548
|
+
* watching them.
|
|
549
|
+
*/
|
|
550
|
+
export async function listUnclaimedBackgroundRunIds() {
|
|
551
|
+
await ensureRunTables();
|
|
552
|
+
const client = getDbExec();
|
|
553
|
+
const { rows } = await client.execute({
|
|
554
|
+
// CAST keeps the ms-epoch param 64-bit on Postgres (see
|
|
555
|
+
// backgroundAwareStaleCutoffSql for the int4-inference failure mode).
|
|
556
|
+
sql: `SELECT id FROM agent_runs
|
|
557
|
+
WHERE status = 'running'
|
|
558
|
+
AND dispatch_mode = 'background'
|
|
559
|
+
AND COALESCE(heartbeat_at, started_at) < (CAST(? AS BIGINT) - ${UNCLAIMED_BACKGROUND_RUN_GRACE_MS})`,
|
|
560
|
+
args: [Date.now()],
|
|
561
|
+
});
|
|
562
|
+
const ids = [];
|
|
563
|
+
for (const row of rows ?? []) {
|
|
564
|
+
const id = row.id;
|
|
565
|
+
if (typeof id === "string" && id)
|
|
566
|
+
ids.push(id);
|
|
567
|
+
}
|
|
568
|
+
return ids;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Count how many runs (chunks) a logical turn has consumed so far. This is the
|
|
572
|
+
* durable per-turn recovery ledger: unlike the in-marker `continuationCount`
|
|
573
|
+
* (which resets whenever a fresh client POST starts a new chain for the same
|
|
574
|
+
* turn), the SQL count survives every recovery path, so it bounds pathological
|
|
575
|
+
* turn loops regardless of which layer initiated each chunk.
|
|
576
|
+
*/
|
|
577
|
+
export async function countRunsForTurn(threadId, turnId) {
|
|
578
|
+
await ensureRunTables();
|
|
579
|
+
const client = getDbExec();
|
|
580
|
+
const { rows } = await client.execute({
|
|
581
|
+
sql: `SELECT COUNT(*) AS run_count FROM agent_runs WHERE thread_id = ? AND turn_id = ?`,
|
|
582
|
+
args: [threadId, turnId],
|
|
583
|
+
});
|
|
584
|
+
const raw = rows?.[0]?.run_count;
|
|
585
|
+
const count = Number(raw);
|
|
586
|
+
return Number.isFinite(count) ? count : 0;
|
|
587
|
+
}
|
|
496
588
|
/**
|
|
497
589
|
* Resolve the authenticated owner email for a run by joining it to its chat
|
|
498
590
|
* thread. The durable background worker's self-dispatch is cookieless
|
|
@@ -912,7 +1004,9 @@ export async function updateRunStatus(runId, status) {
|
|
|
912
1004
|
await ensureRunTables();
|
|
913
1005
|
const client = getDbExec();
|
|
914
1006
|
await client.execute({
|
|
915
|
-
|
|
1007
|
+
// Terminal writes also drop the (potentially large) dispatch payload —
|
|
1008
|
+
// it only exists to rehydrate a not-yet-claimed background worker.
|
|
1009
|
+
sql: `UPDATE agent_runs SET status = ?, completed_at = ?, dispatch_payload = NULL WHERE id = ?`,
|
|
916
1010
|
args: [status, Date.now(), runId],
|
|
917
1011
|
});
|
|
918
1012
|
}
|
|
@@ -928,7 +1022,9 @@ export async function updateRunStatusIfRunning(runId, status) {
|
|
|
928
1022
|
await ensureRunTables();
|
|
929
1023
|
const client = getDbExec();
|
|
930
1024
|
const { rowsAffected } = await client.execute({
|
|
931
|
-
|
|
1025
|
+
// Terminal writes also drop the (potentially large) dispatch payload —
|
|
1026
|
+
// it only exists to rehydrate a not-yet-claimed background worker.
|
|
1027
|
+
sql: `UPDATE agent_runs SET status = ?, completed_at = ?, dispatch_payload = NULL WHERE id = ? AND status = 'running'`,
|
|
932
1028
|
args: [status, Date.now(), runId],
|
|
933
1029
|
});
|
|
934
1030
|
return (rowsAffected ?? 0) > 0;
|
|
@@ -948,11 +1044,13 @@ export async function getRunStatus(runId) {
|
|
|
948
1044
|
export async function markRunAborted(runId, reason) {
|
|
949
1045
|
await ensureRunTables();
|
|
950
1046
|
const client = getDbExec();
|
|
951
|
-
await client.execute({
|
|
952
|
-
sql: `UPDATE agent_runs SET status = 'aborted', abort_reason = ?, completed_at = ?, terminal_reason = ? WHERE id =
|
|
1047
|
+
const { rowsAffected } = await client.execute({
|
|
1048
|
+
sql: `UPDATE agent_runs SET status = 'aborted', abort_reason = ?, completed_at = ?, terminal_reason = ? WHERE id = ? AND status = 'running'`,
|
|
953
1049
|
args: [reason ?? "user", Date.now(), `aborted:${reason ?? "user"}`, runId],
|
|
954
1050
|
});
|
|
955
|
-
|
|
1051
|
+
if ((rowsAffected ?? 0) > 0) {
|
|
1052
|
+
await safeAppendTerminalRunEvent(runId, { type: "done" }, "mark-aborted");
|
|
1053
|
+
}
|
|
956
1054
|
}
|
|
957
1055
|
export async function isRunAborted(runId) {
|
|
958
1056
|
return (await getRunAbortState(runId)).aborted;
|