@agent-native/core 0.78.5 → 0.78.7
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/core/CHANGELOG.md +12 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/production-agent.ts +74 -13
- package/corpus/templates/assets/actions/_helpers.ts +15 -2
- package/corpus/templates/assets/actions/get-library.ts +2 -2
- package/corpus/templates/assets/actions/view-screen.ts +98 -36
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +50 -8
- package/dist/agent/production-agent.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 +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/package.json +1 -1
package/corpus/core/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @agent-native/core
|
|
2
2
|
|
|
3
|
+
## 0.78.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 61b078a: Preserve resolved user and org context when agent tool calls run actions.
|
|
8
|
+
|
|
9
|
+
## 0.78.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 81a7f90: diag(agent): add awaited `post_model_awaited` and `pre_claim` probes in the durable background worker. `worker_stage` stalls at `model_done` even though the code right after is trivial sync; these awaited (withDbTimeout-bounded) writes distinguish a hung bg-fn DB connection right after model resolution (probe never lands) from a later main-flow stall (probe lands, then the stall is downstream).
|
|
14
|
+
|
|
3
15
|
## 0.78.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/corpus/core/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.7",
|
|
4
4
|
"description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/agent-native#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,8 +33,10 @@ import { readBody } from "../server/h3-helpers.js";
|
|
|
33
33
|
import {
|
|
34
34
|
getRequestRunContext,
|
|
35
35
|
ensureRequestRunContext,
|
|
36
|
+
getRequestContext,
|
|
36
37
|
getRequestOrgId,
|
|
37
38
|
getRequestUserEmail,
|
|
39
|
+
runWithRequestContext,
|
|
38
40
|
} from "../server/request-context.js";
|
|
39
41
|
import { fireInternalDispatch } from "../server/self-dispatch.js";
|
|
40
42
|
import {
|
|
@@ -3431,23 +3433,40 @@ export async function runAgentLoop(opts: {
|
|
|
3431
3433
|
| undefined;
|
|
3432
3434
|
try {
|
|
3433
3435
|
const timeoutSignal = AbortSignal.timeout(toolTimeoutMs);
|
|
3436
|
+
const actionUserEmail = opts.ownerEmail ?? getRequestUserEmail();
|
|
3437
|
+
const actionOrgId = opts.orgId ?? getRequestOrgId() ?? null;
|
|
3438
|
+
const actionContext = {
|
|
3439
|
+
send,
|
|
3440
|
+
userEmail: actionUserEmail ?? undefined,
|
|
3441
|
+
orgId: actionOrgId,
|
|
3442
|
+
caller: "tool" as const,
|
|
3443
|
+
attachments: opts.attachments,
|
|
3444
|
+
signal,
|
|
3445
|
+
// Audit attribution: the action name + the agent thread/turn that
|
|
3446
|
+
// triggered this call, so a mutation can be traced to its run.
|
|
3447
|
+
actionName: toolCall.name,
|
|
3448
|
+
...(opts.threadId ? { threadId: opts.threadId } : {}),
|
|
3449
|
+
...(opts.turnId ? { turnId: opts.turnId } : {}),
|
|
3450
|
+
};
|
|
3451
|
+
const requestContext = getRequestContext();
|
|
3452
|
+
const invokeAction = () =>
|
|
3453
|
+
actionEntry.run(
|
|
3454
|
+
toolCall.input as Record<string, string>,
|
|
3455
|
+
actionContext,
|
|
3456
|
+
);
|
|
3434
3457
|
// Keep a reference to the action promise so we can attach a zombie-
|
|
3435
3458
|
// detection continuation AFTER Promise.race abandons it on run abort.
|
|
3436
3459
|
// The promise itself is not awaited here — Promise.race owns the await.
|
|
3437
3460
|
const actionPromise = Promise.resolve(
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
actionName: toolCall.name,
|
|
3448
|
-
...(opts.threadId ? { threadId: opts.threadId } : {}),
|
|
3449
|
-
...(opts.turnId ? { turnId: opts.turnId } : {}),
|
|
3450
|
-
}),
|
|
3461
|
+
runWithRequestContext(
|
|
3462
|
+
{
|
|
3463
|
+
...(requestContext ?? {}),
|
|
3464
|
+
...(actionUserEmail ? { userEmail: actionUserEmail } : {}),
|
|
3465
|
+
...(actionOrgId ? { orgId: actionOrgId } : {}),
|
|
3466
|
+
...(requestContext?.run ? { run: requestContext.run } : {}),
|
|
3467
|
+
},
|
|
3468
|
+
invokeAction,
|
|
3469
|
+
),
|
|
3451
3470
|
);
|
|
3452
3471
|
|
|
3453
3472
|
// When the run is aborted (soft-timeout / user cancel) while this tool
|
|
@@ -4184,6 +4203,28 @@ export function createProductionAgentHandler(
|
|
|
4184
4203
|
// hang right after model resolution (DB connection); if it's
|
|
4185
4204
|
// `engine_resolved`/`systemprompt_enter`, the stall is in the named step.
|
|
4186
4205
|
workerStep("engine_resolved");
|
|
4206
|
+
// DIAGNOSTIC-ONLY: AWAITED probe (bg worker only). worker_stage stalls at
|
|
4207
|
+
// `model_done` even though the code right after is trivial sync — this
|
|
4208
|
+
// distinguishes the two causes: if `post_model_awaited` lands, DB writes
|
|
4209
|
+
// still work after model_done and the stall is later in the main flow; if it
|
|
4210
|
+
// never lands (stays `model_done`), the bg-fn DB connection itself is hung
|
|
4211
|
+
// right after model resolution. `recordRunDiagnostic` is `withDbTimeout`-
|
|
4212
|
+
// bounded, so a hung write rejects (caught) rather than blocking forever.
|
|
4213
|
+
if (isBackgroundWorker && bgRunId) {
|
|
4214
|
+
const probeStart = Date.now();
|
|
4215
|
+
try {
|
|
4216
|
+
await recordRunDiagnostic(
|
|
4217
|
+
bgRunId,
|
|
4218
|
+
RUN_DIAG_STAGE.workerSetupStep,
|
|
4219
|
+
"post_model_awaited",
|
|
4220
|
+
);
|
|
4221
|
+
workerStep(`post_model_ok=${Date.now() - probeStart}ms`);
|
|
4222
|
+
} catch (e) {
|
|
4223
|
+
workerStep(
|
|
4224
|
+
`post_model_threw=${Date.now() - probeStart}ms:${String((e as Error)?.message ?? e).slice(0, 80)}`,
|
|
4225
|
+
);
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4187
4228
|
|
|
4188
4229
|
// One-line per-turn resolution log so it's obvious in dev which engine
|
|
4189
4230
|
// is actually handling the request. `requestEngine` is what the client
|
|
@@ -5106,6 +5147,26 @@ export function createProductionAgentHandler(
|
|
|
5106
5147
|
// DIAGNOSTIC-ONLY: last stage before startRun fires. A worker that reaches
|
|
5107
5148
|
// prestart but never workerStarted is hanging inside startRun itself.
|
|
5108
5149
|
workerStep("prestart");
|
|
5150
|
+
// DIAGNOSTIC-ONLY: AWAITED probe right before startRun (bg worker only). If
|
|
5151
|
+
// worker_stage reaches `pre_claim_ok` but the run never flips to
|
|
5152
|
+
// `worker_started`, the stall is inside startRun's claim itself; if it never
|
|
5153
|
+
// reaches `pre_claim_*`, the stall is somewhere in the setup between
|
|
5154
|
+
// post_model and here.
|
|
5155
|
+
if (isBackgroundWorker && bgRunId) {
|
|
5156
|
+
const claimProbeStart = Date.now();
|
|
5157
|
+
try {
|
|
5158
|
+
await recordRunDiagnostic(
|
|
5159
|
+
bgRunId,
|
|
5160
|
+
RUN_DIAG_STAGE.workerSetupStep,
|
|
5161
|
+
"pre_claim",
|
|
5162
|
+
);
|
|
5163
|
+
workerStep(`pre_claim_ok=${Date.now() - claimProbeStart}ms`);
|
|
5164
|
+
} catch (e) {
|
|
5165
|
+
workerStep(
|
|
5166
|
+
`pre_claim_threw=${Date.now() - claimProbeStart}ms:${String((e as Error)?.message ?? e).slice(0, 80)}`,
|
|
5167
|
+
);
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5109
5170
|
// DIAGNOSTIC-ONLY: peak-ish RSS (MB) + assembled system-prompt size (KB) at
|
|
5110
5171
|
// prestart. The analytics bg worker dies right after model_done; if the
|
|
5111
5172
|
// FOREGROUND (identical build, writes land) is already near the ~1024MB
|
|
@@ -12,8 +12,21 @@ import type {
|
|
|
12
12
|
StyleBrief,
|
|
13
13
|
} from "../shared/api.js";
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
type AccessCtx = {
|
|
16
|
+
userEmail?: string;
|
|
17
|
+
orgId?: string | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function accessContext(ctx?: AccessCtx) {
|
|
21
|
+
if (!ctx) return undefined;
|
|
22
|
+
return {
|
|
23
|
+
userEmail: ctx.userEmail,
|
|
24
|
+
orgId: ctx.orgId ?? undefined,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function requireLibrary(id: string, ctx?: AccessCtx) {
|
|
29
|
+
const access = await resolveAccess("asset-library", id, accessContext(ctx));
|
|
17
30
|
if (!access) throw new Error("Asset library not found or not accessible.");
|
|
18
31
|
return access.resource;
|
|
19
32
|
}
|
|
@@ -18,8 +18,8 @@ export default defineAction({
|
|
|
18
18
|
}),
|
|
19
19
|
http: { method: "GET" },
|
|
20
20
|
readOnly: true,
|
|
21
|
-
run: async ({ id }) => {
|
|
22
|
-
const library = await requireLibrary(id);
|
|
21
|
+
run: async ({ id }, ctx) => {
|
|
22
|
+
const library = await requireLibrary(id, ctx);
|
|
23
23
|
const db = getDb();
|
|
24
24
|
const [collections, folders, assets, runs] = await Promise.all([
|
|
25
25
|
db
|
|
@@ -15,13 +15,17 @@ import listGenerationPresets from "./list-generation-presets.js";
|
|
|
15
15
|
import listGenerationSessions from "./list-generation-sessions.js";
|
|
16
16
|
import listLibraries from "./list-libraries.js";
|
|
17
17
|
|
|
18
|
+
function screenError(error: unknown): string {
|
|
19
|
+
return error instanceof Error ? error.message : String(error);
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
export default defineAction({
|
|
19
23
|
description:
|
|
20
24
|
"See what the user is currently looking at in Assets, including current library/asset context and pending generation variants.",
|
|
21
25
|
schema: z.object({}),
|
|
22
26
|
http: false,
|
|
23
27
|
readOnly: true,
|
|
24
|
-
run: async () => {
|
|
28
|
+
run: async (_args, ctx) => {
|
|
25
29
|
const [navigation, variants, legacyVariants] = await Promise.all([
|
|
26
30
|
readAppStateForCurrentTab("navigation"),
|
|
27
31
|
readAppState("asset-variants"),
|
|
@@ -32,56 +36,114 @@ export default defineAction({
|
|
|
32
36
|
variants: variants ?? legacyVariants,
|
|
33
37
|
};
|
|
34
38
|
const nav = navigation as any;
|
|
39
|
+
const errors: Record<string, string> = {};
|
|
40
|
+
const readPart = async <T>(
|
|
41
|
+
key: string,
|
|
42
|
+
task: () => T | Promise<T>,
|
|
43
|
+
): Promise<T | null> => {
|
|
44
|
+
try {
|
|
45
|
+
const value = await task();
|
|
46
|
+
screen[key] = value;
|
|
47
|
+
return value;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
errors[key] = screenError(error);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
35
54
|
if (nav?.libraryId) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
const library = await readPart("library", () =>
|
|
56
|
+
getLibrary.run({ id: nav.libraryId }, ctx),
|
|
57
|
+
);
|
|
58
|
+
if (library) {
|
|
59
|
+
await Promise.all([
|
|
60
|
+
readPart("generationPresets", () =>
|
|
61
|
+
listGenerationPresets.run(
|
|
62
|
+
{
|
|
63
|
+
libraryId: nav.libraryId,
|
|
64
|
+
},
|
|
65
|
+
ctx,
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
readPart("generationSessions", () =>
|
|
69
|
+
listGenerationSessions.run(
|
|
70
|
+
{
|
|
71
|
+
libraryId: nav.libraryId,
|
|
72
|
+
limit: 20,
|
|
73
|
+
},
|
|
74
|
+
ctx,
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
44
79
|
}
|
|
45
80
|
if (nav?.assetId) {
|
|
46
|
-
|
|
81
|
+
await readPart("asset", () => getAsset.run({ id: nav.assetId }, ctx));
|
|
47
82
|
}
|
|
48
83
|
if (nav?.sessionId) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
await readPart("generationSession", () =>
|
|
85
|
+
getGenerationSession.run(
|
|
86
|
+
{
|
|
87
|
+
id: nav.sessionId,
|
|
88
|
+
},
|
|
89
|
+
ctx,
|
|
90
|
+
),
|
|
91
|
+
);
|
|
52
92
|
}
|
|
53
93
|
if (nav?.runId) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
94
|
+
await readPart("generationRun", () =>
|
|
95
|
+
getGenerationRun.run(
|
|
96
|
+
{
|
|
97
|
+
runId: nav.runId,
|
|
98
|
+
},
|
|
99
|
+
ctx,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
57
102
|
}
|
|
58
103
|
if (nav?.view === "picker") {
|
|
59
|
-
|
|
104
|
+
await readPart("libraries", () =>
|
|
105
|
+
listLibraries.run({ compact: true }, ctx),
|
|
106
|
+
);
|
|
60
107
|
if (nav.libraryId) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
108
|
+
await readPart("assets", () =>
|
|
109
|
+
listAssets.run(
|
|
110
|
+
{
|
|
111
|
+
libraryId: nav.libraryId,
|
|
112
|
+
mediaType:
|
|
113
|
+
nav.mediaType === "image" || nav.mediaType === "video"
|
|
114
|
+
? nav.mediaType
|
|
115
|
+
: undefined,
|
|
116
|
+
query:
|
|
117
|
+
typeof nav.query === "string" && nav.query.trim()
|
|
118
|
+
? nav.query
|
|
119
|
+
: undefined,
|
|
120
|
+
},
|
|
121
|
+
ctx,
|
|
122
|
+
),
|
|
123
|
+
);
|
|
72
124
|
}
|
|
73
125
|
}
|
|
74
126
|
if (nav?.view === "library" && nav?.selection === "all") {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
127
|
+
await Promise.all([
|
|
128
|
+
readPart("libraries", () => listLibraries.run({ compact: false }, ctx)),
|
|
129
|
+
readPart("assets", () =>
|
|
130
|
+
listAssets.run(
|
|
131
|
+
{
|
|
132
|
+
query:
|
|
133
|
+
typeof nav.search === "string" && nav.search.trim()
|
|
134
|
+
? nav.search
|
|
135
|
+
: undefined,
|
|
136
|
+
},
|
|
137
|
+
ctx,
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
]);
|
|
82
141
|
}
|
|
83
142
|
if (nav?.view === "audit") {
|
|
84
|
-
|
|
143
|
+
await readPart("audit", () => listAuditRuns.run({ limit: 20 }, ctx));
|
|
144
|
+
}
|
|
145
|
+
if (Object.keys(errors).length) {
|
|
146
|
+
screen.errors = errors;
|
|
85
147
|
}
|
|
86
148
|
return screen;
|
|
87
149
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AAkCzD,OAAO,EAGL,KAAK,eAAe,E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AAG,IAAI,CAAC;IACtB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACpC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7D;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B,GAAG,OAAO,CAAC,cAAc,CAAC,CAuvC1B;AA4CD;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,KAAK,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE;IACtD,kBAAkB,EAAE,OAAO,CAAC;IAC5B,GAAG,EAAE,SAAS,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;CAC3B,GAAG,OAAO,CAOV;AA+BD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAouDhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
|
|
@@ -13,7 +13,7 @@ import { completeRun as completeProgressRun, startRun as startProgressRun, updat
|
|
|
13
13
|
import { getFrontmatterValue, parseFrontmatter, } from "../resources/metadata.js";
|
|
14
14
|
import { isDeployCredentialFallbackAllowed, readDeployCredentialEnv, } from "../server/credential-provider.js";
|
|
15
15
|
import { readBody } from "../server/h3-helpers.js";
|
|
16
|
-
import { getRequestRunContext, ensureRequestRunContext, getRequestOrgId, getRequestUserEmail, } from "../server/request-context.js";
|
|
16
|
+
import { getRequestRunContext, ensureRequestRunContext, getRequestContext, getRequestOrgId, getRequestUserEmail, runWithRequestContext, } from "../server/request-context.js";
|
|
17
17
|
import { fireInternalDispatch } from "../server/self-dispatch.js";
|
|
18
18
|
import { isReasoningEffort, normalizeReasoningEffortForModel, } from "../shared/reasoning-effort.js";
|
|
19
19
|
import { applyContextDirectives } from "./context-xray/apply-directives.js";
|
|
@@ -2537,13 +2537,12 @@ export async function runAgentLoop(opts) {
|
|
|
2537
2537
|
let mcpApp;
|
|
2538
2538
|
try {
|
|
2539
2539
|
const timeoutSignal = AbortSignal.timeout(toolTimeoutMs);
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
const actionPromise = Promise.resolve(actionEntry.run(toolCall.input, {
|
|
2540
|
+
const actionUserEmail = opts.ownerEmail ?? getRequestUserEmail();
|
|
2541
|
+
const actionOrgId = opts.orgId ?? getRequestOrgId() ?? null;
|
|
2542
|
+
const actionContext = {
|
|
2544
2543
|
send,
|
|
2545
|
-
userEmail:
|
|
2546
|
-
orgId:
|
|
2544
|
+
userEmail: actionUserEmail ?? undefined,
|
|
2545
|
+
orgId: actionOrgId,
|
|
2547
2546
|
caller: "tool",
|
|
2548
2547
|
attachments: opts.attachments,
|
|
2549
2548
|
signal,
|
|
@@ -2552,7 +2551,18 @@ export async function runAgentLoop(opts) {
|
|
|
2552
2551
|
actionName: toolCall.name,
|
|
2553
2552
|
...(opts.threadId ? { threadId: opts.threadId } : {}),
|
|
2554
2553
|
...(opts.turnId ? { turnId: opts.turnId } : {}),
|
|
2555
|
-
}
|
|
2554
|
+
};
|
|
2555
|
+
const requestContext = getRequestContext();
|
|
2556
|
+
const invokeAction = () => actionEntry.run(toolCall.input, actionContext);
|
|
2557
|
+
// Keep a reference to the action promise so we can attach a zombie-
|
|
2558
|
+
// detection continuation AFTER Promise.race abandons it on run abort.
|
|
2559
|
+
// The promise itself is not awaited here — Promise.race owns the await.
|
|
2560
|
+
const actionPromise = Promise.resolve(runWithRequestContext({
|
|
2561
|
+
...(requestContext ?? {}),
|
|
2562
|
+
...(actionUserEmail ? { userEmail: actionUserEmail } : {}),
|
|
2563
|
+
...(actionOrgId ? { orgId: actionOrgId } : {}),
|
|
2564
|
+
...(requestContext?.run ? { run: requestContext.run } : {}),
|
|
2565
|
+
}, invokeAction));
|
|
2556
2566
|
// When the run is aborted (soft-timeout / user cancel) while this tool
|
|
2557
2567
|
// call is in flight, Promise.race below will throw "Run aborted" and the
|
|
2558
2568
|
// action's promise becomes a zombie — it keeps running but its result is
|
|
@@ -3177,6 +3187,23 @@ export function createProductionAgentHandler(options) {
|
|
|
3177
3187
|
// hang right after model resolution (DB connection); if it's
|
|
3178
3188
|
// `engine_resolved`/`systemprompt_enter`, the stall is in the named step.
|
|
3179
3189
|
workerStep("engine_resolved");
|
|
3190
|
+
// DIAGNOSTIC-ONLY: AWAITED probe (bg worker only). worker_stage stalls at
|
|
3191
|
+
// `model_done` even though the code right after is trivial sync — this
|
|
3192
|
+
// distinguishes the two causes: if `post_model_awaited` lands, DB writes
|
|
3193
|
+
// still work after model_done and the stall is later in the main flow; if it
|
|
3194
|
+
// never lands (stays `model_done`), the bg-fn DB connection itself is hung
|
|
3195
|
+
// right after model resolution. `recordRunDiagnostic` is `withDbTimeout`-
|
|
3196
|
+
// bounded, so a hung write rejects (caught) rather than blocking forever.
|
|
3197
|
+
if (isBackgroundWorker && bgRunId) {
|
|
3198
|
+
const probeStart = Date.now();
|
|
3199
|
+
try {
|
|
3200
|
+
await recordRunDiagnostic(bgRunId, RUN_DIAG_STAGE.workerSetupStep, "post_model_awaited");
|
|
3201
|
+
workerStep(`post_model_ok=${Date.now() - probeStart}ms`);
|
|
3202
|
+
}
|
|
3203
|
+
catch (e) {
|
|
3204
|
+
workerStep(`post_model_threw=${Date.now() - probeStart}ms:${String(e?.message ?? e).slice(0, 80)}`);
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3180
3207
|
// One-line per-turn resolution log so it's obvious in dev which engine
|
|
3181
3208
|
// is actually handling the request. `requestEngine` is what the client
|
|
3182
3209
|
// sent from the model picker; `engine.name` is what resolveEngine picked.
|
|
@@ -3937,6 +3964,21 @@ export function createProductionAgentHandler(options) {
|
|
|
3937
3964
|
// DIAGNOSTIC-ONLY: last stage before startRun fires. A worker that reaches
|
|
3938
3965
|
// prestart but never workerStarted is hanging inside startRun itself.
|
|
3939
3966
|
workerStep("prestart");
|
|
3967
|
+
// DIAGNOSTIC-ONLY: AWAITED probe right before startRun (bg worker only). If
|
|
3968
|
+
// worker_stage reaches `pre_claim_ok` but the run never flips to
|
|
3969
|
+
// `worker_started`, the stall is inside startRun's claim itself; if it never
|
|
3970
|
+
// reaches `pre_claim_*`, the stall is somewhere in the setup between
|
|
3971
|
+
// post_model and here.
|
|
3972
|
+
if (isBackgroundWorker && bgRunId) {
|
|
3973
|
+
const claimProbeStart = Date.now();
|
|
3974
|
+
try {
|
|
3975
|
+
await recordRunDiagnostic(bgRunId, RUN_DIAG_STAGE.workerSetupStep, "pre_claim");
|
|
3976
|
+
workerStep(`pre_claim_ok=${Date.now() - claimProbeStart}ms`);
|
|
3977
|
+
}
|
|
3978
|
+
catch (e) {
|
|
3979
|
+
workerStep(`pre_claim_threw=${Date.now() - claimProbeStart}ms:${String(e?.message ?? e).slice(0, 80)}`);
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3940
3982
|
// DIAGNOSTIC-ONLY: peak-ish RSS (MB) + assembled system-prompt size (KB) at
|
|
3941
3983
|
// prestart. The analytics bg worker dies right after model_done; if the
|
|
3942
3984
|
// FOREGROUND (identical build, writes land) is already near the ~1024MB
|