@opengeni/worker-bundle 2.0.3-canary.36079201993001 → 2.0.3
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/dist/activities/context-compaction.d.ts +2 -10
- package/dist/{activities-turn-AJHDYNZU.js → activities-turn-EZEDZTEZ.js} +26 -73
- package/dist/activities-turn-EZEDZTEZ.js.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +19 -19
- package/src/activities/agent-turn/compaction-prep.ts +16 -52
- package/src/activities/context-compaction.ts +14 -49
- package/dist/activities-turn-AJHDYNZU.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -790,7 +790,7 @@ function temporalWorkflowExecutionNotFound(error) {
|
|
|
790
790
|
return isGrpcServiceError(error) && error.code === 5;
|
|
791
791
|
}
|
|
792
792
|
async function createDefaultWorkerActivities(role, dependencies = {}) {
|
|
793
|
-
return role === "control" ? (await import("./activities-control-IVTL723D.js")).createControlActivities(dependencies) : (await import("./activities-turn-
|
|
793
|
+
return role === "control" ? (await import("./activities-control-IVTL723D.js")).createControlActivities(dependencies) : (await import("./activities-turn-EZEDZTEZ.js")).createTurnActivities(dependencies);
|
|
794
794
|
}
|
|
795
795
|
function resolveOpenGeniWorkflowDefinition(moduleUrl = import.meta.url) {
|
|
796
796
|
const modulePath = fileURLToPath(moduleUrl).replaceAll("\\", "/");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/worker-bundle",
|
|
3
|
-
"version": "2.0.3
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "OpenGeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -54,24 +54,24 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@llamaindex/liteparse": "2.14.2",
|
|
57
|
-
"@opengeni/agent-proto": "^0.6.0
|
|
58
|
-
"@opengeni/capabilities": "^0.3.4
|
|
59
|
-
"@opengeni/codemode": "^0.6.2
|
|
60
|
-
"@opengeni/codex": "^0.2.26
|
|
61
|
-
"@opengeni/config": "^2.1.1
|
|
62
|
-
"@opengeni/contracts": "^5.1.1
|
|
63
|
-
"@opengeni/core": "^4.0.3
|
|
64
|
-
"@opengeni/db": "^6.0.3
|
|
65
|
-
"@opengeni/documents": "^0.8.34
|
|
66
|
-
"@opengeni/events": "^0.4.32
|
|
67
|
-
"@opengeni/github": "^0.7.16
|
|
68
|
-
"@opengeni/network": "^0.3.1
|
|
69
|
-
"@opengeni/observability": "^0.8.32
|
|
70
|
-
"@opengeni/runtime": "^4.0.3
|
|
71
|
-
"@opengeni/sdk": "^7.1.1
|
|
72
|
-
"@opengeni/storage": "^0.2.133
|
|
73
|
-
"@opengeni/tool-gateway": "^0.1.13
|
|
74
|
-
"@opengeni/xai-subscription": "^0.1.4
|
|
57
|
+
"@opengeni/agent-proto": "^0.6.0",
|
|
58
|
+
"@opengeni/capabilities": "^0.3.4",
|
|
59
|
+
"@opengeni/codemode": "^0.6.2",
|
|
60
|
+
"@opengeni/codex": "^0.2.26",
|
|
61
|
+
"@opengeni/config": "^2.1.1",
|
|
62
|
+
"@opengeni/contracts": "^5.1.1",
|
|
63
|
+
"@opengeni/core": "^4.0.3",
|
|
64
|
+
"@opengeni/db": "^6.0.3",
|
|
65
|
+
"@opengeni/documents": "^0.8.34",
|
|
66
|
+
"@opengeni/events": "^0.4.32",
|
|
67
|
+
"@opengeni/github": "^0.7.16",
|
|
68
|
+
"@opengeni/network": "^0.3.1",
|
|
69
|
+
"@opengeni/observability": "^0.8.32",
|
|
70
|
+
"@opengeni/runtime": "^4.0.3",
|
|
71
|
+
"@opengeni/sdk": "^7.1.1",
|
|
72
|
+
"@opengeni/storage": "^0.2.133",
|
|
73
|
+
"@opengeni/tool-gateway": "^0.1.13",
|
|
74
|
+
"@opengeni/xai-subscription": "^0.1.4",
|
|
75
75
|
"@temporalio/activity": "^1.17.0",
|
|
76
76
|
"@temporalio/client": "^1.17.0",
|
|
77
77
|
"@temporalio/worker": "^1.17.0",
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
compactionThresholdTokens,
|
|
12
12
|
CompactionNeededError,
|
|
13
13
|
compactionProviderRejection,
|
|
14
|
-
|
|
15
|
-
compactionSummaryOutputTokens,
|
|
14
|
+
SUMMARY_BUFFER_TOKENS,
|
|
16
15
|
type ModelResponseUsage,
|
|
17
16
|
} from "@opengeni/runtime";
|
|
18
17
|
import { type Settings } from "@opengeni/config";
|
|
@@ -169,13 +168,6 @@ export async function prepareCompaction(deps: CompactionPrepDeps): Promise<Compa
|
|
|
169
168
|
const remotePrefix: RemoteCompactionPrefix = {
|
|
170
169
|
agent: null,
|
|
171
170
|
};
|
|
172
|
-
const portableResponsesNeedsAgentPrefix =
|
|
173
|
-
resolvedModel?.provider.api === "responses" &&
|
|
174
|
-
!(billingState.isCodexTurn && session.codexCompactionMode === "remote_v2");
|
|
175
|
-
const preparedPortableRequest = () => {
|
|
176
|
-
if (!remotePrefix.agent) throw new Error("Compaction agent is unavailable");
|
|
177
|
-
return preparedCompactionRequest(remotePrefix.agent);
|
|
178
|
-
};
|
|
179
171
|
|
|
180
172
|
const promptCacheKey = acceptsPromptCacheKeyForTurn(resolvedModel) ? input.sessionId : undefined;
|
|
181
173
|
const compactionUsageState = createCompactionModelUsageEventState(claimedModelUsageSourceKeys);
|
|
@@ -208,8 +200,8 @@ export async function prepareCompaction(deps: CompactionPrepDeps): Promise<Compa
|
|
|
208
200
|
contextContributions: eventing.companyBrainContextContributions,
|
|
209
201
|
});
|
|
210
202
|
};
|
|
211
|
-
const compactionSummarizerFor = (systemInstructions?: string)
|
|
212
|
-
|
|
203
|
+
const compactionSummarizerFor = (systemInstructions?: string) =>
|
|
204
|
+
resolvedModel
|
|
213
205
|
? (s: Settings, m: Array<Record<string, unknown>>) =>
|
|
214
206
|
withProviderRequestContext(() =>
|
|
215
207
|
summarizeContextForCompaction(s, m, {
|
|
@@ -217,37 +209,20 @@ export async function prepareCompaction(deps: CompactionPrepDeps): Promise<Compa
|
|
|
217
209
|
provider: resolvedModel.provider,
|
|
218
210
|
api: resolvedModel.provider.api,
|
|
219
211
|
model: turnExecutionPolicy.upstreamModelId,
|
|
220
|
-
maxOutputTokens:
|
|
221
|
-
...(cancellationSignal ? { signal: cancellationSignal } : {}),
|
|
212
|
+
maxOutputTokens: SUMMARY_BUFFER_TOKENS,
|
|
222
213
|
onUsage: recordCompactionUsage,
|
|
223
214
|
...(systemInstructions ? { systemInstructions } : {}),
|
|
224
215
|
...(promptCacheKey ? { promptCacheKey } : {}),
|
|
225
|
-
...(portableResponsesNeedsAgentPrefix
|
|
226
|
-
? { preparedRequest: preparedPortableRequest() }
|
|
227
|
-
: {}),
|
|
228
216
|
}),
|
|
229
217
|
)
|
|
230
218
|
: (s: Settings, m: Array<Record<string, unknown>>) =>
|
|
231
219
|
summarizeContextForCompaction(s, m, {
|
|
232
220
|
model: turnExecutionPolicy.upstreamModelId,
|
|
233
|
-
maxOutputTokens:
|
|
234
|
-
...(cancellationSignal ? { signal: cancellationSignal } : {}),
|
|
221
|
+
maxOutputTokens: SUMMARY_BUFFER_TOKENS,
|
|
235
222
|
onUsage: recordCompactionUsage,
|
|
236
223
|
...(systemInstructions ? { systemInstructions } : {}),
|
|
237
224
|
...(promptCacheKey ? { promptCacheKey } : {}),
|
|
238
225
|
});
|
|
239
|
-
summarize.estimatePrefixTokens = () => {
|
|
240
|
-
if (resolvedModel?.provider.api === "chat") {
|
|
241
|
-
return estimateSerializedValueTokens(systemInstructions ?? "");
|
|
242
|
-
}
|
|
243
|
-
const prepared = portableResponsesNeedsAgentPrefix ? preparedPortableRequest() : null;
|
|
244
|
-
return (
|
|
245
|
-
estimateSerializedValueTokens(prepared?.systemInstructions ?? systemInstructions ?? "") +
|
|
246
|
-
(prepared ? estimateSerializedValueTokens(prepared.tools) : 0)
|
|
247
|
-
);
|
|
248
|
-
};
|
|
249
|
-
return summarize;
|
|
250
|
-
};
|
|
251
226
|
// Prompt-cache prefix for remote_v2 MUST match ordinary turns:
|
|
252
227
|
// tools → instructions → history. Filled after buildAgent for every
|
|
253
228
|
// compact path (including operator /compact, which now builds the agent
|
|
@@ -290,9 +265,13 @@ export async function prepareCompaction(deps: CompactionPrepDeps): Promise<Compa
|
|
|
290
265
|
...(remoteCompactionRequester ? { requestRemoteCompactionV2: remoteCompactionRequester } : {}),
|
|
291
266
|
} as const;
|
|
292
267
|
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
//
|
|
268
|
+
// Operator /compact:
|
|
269
|
+
// - portable (incl. Codex portable): early maintenance path — no
|
|
270
|
+
// prepareTools/sandbox; summarizer only needs composed instructions.
|
|
271
|
+
// - remote_v2: fall through to prepareTools/buildAgent so the compact
|
|
272
|
+
// request reuses the ordinary tools→instructions cache prefix, then
|
|
273
|
+
// settle without inference. (Requester is also wired for Codex portable
|
|
274
|
+
// turns but unused there — gate on the frozen session mode.)
|
|
296
275
|
const compactionOnlyTurn = turn.source === "compaction";
|
|
297
276
|
const remoteV2CompactionNeedsAgentPrefix =
|
|
298
277
|
Boolean(remoteCompactionRequester) && session.codexCompactionMode === "remote_v2";
|
|
@@ -329,11 +308,7 @@ export async function prepareCompaction(deps: CompactionPrepDeps): Promise<Compa
|
|
|
329
308
|
control.activityStatus = "idle";
|
|
330
309
|
return claimedResult({ status: "idle" });
|
|
331
310
|
};
|
|
332
|
-
if (
|
|
333
|
-
compactionOnlyTurn &&
|
|
334
|
-
!remoteV2CompactionNeedsAgentPrefix &&
|
|
335
|
-
!portableResponsesNeedsAgentPrefix
|
|
336
|
-
) {
|
|
311
|
+
if (compactionOnlyTurn && !remoteV2CompactionNeedsAgentPrefix) {
|
|
337
312
|
const compactionInstructions = appendWorkspaceMemory(
|
|
338
313
|
appendSessionInstructions(
|
|
339
314
|
appendWorkspaceGovernance(
|
|
@@ -491,7 +466,6 @@ export async function runPostAgentCompaction(
|
|
|
491
466
|
claimedResult,
|
|
492
467
|
turn,
|
|
493
468
|
session,
|
|
494
|
-
resolvedModel,
|
|
495
469
|
remotePrefix,
|
|
496
470
|
remoteCompactionRequester,
|
|
497
471
|
publishCompactionLiveEvents,
|
|
@@ -506,13 +480,10 @@ export async function runPostAgentCompaction(
|
|
|
506
480
|
} = deps;
|
|
507
481
|
|
|
508
482
|
const agentInstructions = typeof agent.instructions === "string" ? agent.instructions : "";
|
|
509
|
-
const preparedPortable =
|
|
510
|
-
resolvedModel?.provider.api === "responses" &&
|
|
511
|
-
!(remoteCompactionRequester && session.codexCompactionMode === "remote_v2");
|
|
512
483
|
const compactSummarizer = compactionSummarizerFor(
|
|
513
484
|
agentInstructions.trim() ? agentInstructions : undefined,
|
|
514
485
|
);
|
|
515
|
-
if (remoteCompactionRequester
|
|
486
|
+
if (remoteCompactionRequester) {
|
|
516
487
|
// The prefix is captured only after this agent passes normal SDK preparation.
|
|
517
488
|
remotePrefix.agent = agent;
|
|
518
489
|
}
|
|
@@ -520,11 +491,7 @@ export async function runPostAgentCompaction(
|
|
|
520
491
|
if (compactionOnlyTurn) {
|
|
521
492
|
const requested = await isSessionCompactionRequested(db, input.workspaceId, input.sessionId);
|
|
522
493
|
let outcome: Awaited<ReturnType<typeof maybeCompactContext>> | null = null;
|
|
523
|
-
if (
|
|
524
|
-
requested &&
|
|
525
|
-
(preparedPortable ||
|
|
526
|
-
(remoteCompactionRequester && session.codexCompactionMode === "remote_v2"))
|
|
527
|
-
) {
|
|
494
|
+
if (requested && remoteCompactionRequester && session.codexCompactionMode === "remote_v2") {
|
|
528
495
|
queuePreparedCompaction(
|
|
529
496
|
agent,
|
|
530
497
|
new CompactionNeededError({
|
|
@@ -643,10 +610,7 @@ export async function runPostAgentCompaction(
|
|
|
643
610
|
return { exit: claimedResult({ status: "idle" }) };
|
|
644
611
|
}
|
|
645
612
|
|
|
646
|
-
if (
|
|
647
|
-
preparedPortable ||
|
|
648
|
-
(remoteCompactionRequester && session.codexCompactionMode === "remote_v2")
|
|
649
|
-
) {
|
|
613
|
+
if (remoteCompactionRequester && session.codexCompactionMode === "remote_v2") {
|
|
650
614
|
const forced = await isSessionCompactionRequested(db, input.workspaceId, input.sessionId);
|
|
651
615
|
const thresholdTokens = compactionThresholdTokens(eventing.modelRunSettings);
|
|
652
616
|
if (
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
EmptyCompactionSummaryError,
|
|
11
11
|
REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
12
|
-
|
|
13
|
-
buildSummaryItem,
|
|
12
|
+
SUMMARY_BUFFER_TOKENS,
|
|
14
13
|
buildCompactionReplacementHistory,
|
|
15
14
|
buildRemoteV2ReplacementHistory,
|
|
16
15
|
compactionThresholdTokens,
|
|
@@ -59,13 +58,7 @@ export type MaybeCompactResult =
|
|
|
59
58
|
* Codex, call Codex `/codex/responses` with `compaction_trigger` and persist the
|
|
60
59
|
* opaque compaction item. Fail closed — never silently fall back to portable.
|
|
61
60
|
*/
|
|
62
|
-
export type CompactionSummarizer = (
|
|
63
|
-
settings: Settings,
|
|
64
|
-
input: CompactionItem[],
|
|
65
|
-
) => Promise<string>) & {
|
|
66
|
-
/** Model-visible instructions and tool schemas outside the history estimate. */
|
|
67
|
-
estimatePrefixTokens?: () => number;
|
|
68
|
-
};
|
|
61
|
+
export type CompactionSummarizer = (settings: Settings, input: CompactionItem[]) => Promise<string>;
|
|
69
62
|
|
|
70
63
|
/** Returns the opaque Codex remote compaction v2 item. */
|
|
71
64
|
export type RemoteCompactionV2Requester = (
|
|
@@ -88,7 +81,7 @@ export async function maybeCompactContext(
|
|
|
88
81
|
// Injectable for tests; defaults to the real provider-aware model call.
|
|
89
82
|
summarize: CompactionSummarizer = (s, m) =>
|
|
90
83
|
summarizeForCompaction(s, m, {
|
|
91
|
-
maxOutputTokens:
|
|
84
|
+
maxOutputTokens: SUMMARY_BUFFER_TOKENS,
|
|
92
85
|
}),
|
|
93
86
|
// Operator-forced (the /compact command): bypass the budget trigger and
|
|
94
87
|
// compact now if there is anything to summarize. Structural guards still hold.
|
|
@@ -307,7 +300,6 @@ async function settleSkippedAfterStart(
|
|
|
307
300
|
reason:
|
|
308
301
|
| "no_history"
|
|
309
302
|
| "replacement_not_smaller"
|
|
310
|
-
| "replacement_exceeds_model_budget"
|
|
311
303
|
| "replacement_unchanged"
|
|
312
304
|
| "summarization_failed",
|
|
313
305
|
): Promise<Extract<MaybeCompactResult, { compacted: false }>> {
|
|
@@ -463,23 +455,12 @@ async function compactContextPortable(
|
|
|
463
455
|
const summarized = await summarizeWithCodexOverflowTrimming(summarize, settings, items);
|
|
464
456
|
const summaryBody = summarized.summaryBody;
|
|
465
457
|
const retainedTokens = await retentionTokenCounts(canonicalItems, projectForWire);
|
|
466
|
-
const outputReserve = compactionSummaryOutputTokens(settings.contextWindowTokens);
|
|
467
|
-
const structuralBudget = Math.min(
|
|
468
|
-
contextInputBudgetTokens(settings) || settings.contextWindowTokens - outputReserve,
|
|
469
|
-
settings.contextWindowTokens - outputReserve,
|
|
470
|
-
);
|
|
471
|
-
const prefixTokens = Math.max(0, Math.ceil(summarize.estimatePrefixTokens?.() ?? 0));
|
|
472
|
-
const summaryTokens = estimateTokens([buildSummaryItem(summaryBody)]);
|
|
473
458
|
const replacementHistory = buildCompactionReplacementHistory(
|
|
474
459
|
canonicalItems,
|
|
475
460
|
summaryBody,
|
|
476
461
|
(item) => retainedTokens.get(item) ?? estimateTokens([item]),
|
|
477
|
-
Math.min(outputReserve, Math.max(0, structuralBudget - prefixTokens - summaryTokens)),
|
|
478
462
|
);
|
|
479
463
|
const estimatedTokensAfter = estimateTokens(await projectForWire(replacementHistory));
|
|
480
|
-
if (estimatedTokensAfter + prefixTokens > structuralBudget) {
|
|
481
|
-
return await settleSkippedAfterStart(db, scope, options, "replacement_exceeds_model_budget");
|
|
482
|
-
}
|
|
483
464
|
const replacementFingerprint = compactionReplacementFingerprint(replacementHistory);
|
|
484
465
|
const previousReplacementFingerprint = latestCompactionReplacementFingerprint(canonicalItems);
|
|
485
466
|
const summaryIndex =
|
|
@@ -539,7 +520,7 @@ async function compactContextPortable(
|
|
|
539
520
|
};
|
|
540
521
|
}
|
|
541
522
|
|
|
542
|
-
|
|
523
|
+
async function summarizeWithCodexOverflowTrimming(
|
|
543
524
|
summarize: CompactionSummarizer,
|
|
544
525
|
settings: Settings,
|
|
545
526
|
activeHistory: CompactionItem[],
|
|
@@ -550,32 +531,17 @@ export async function summarizeWithCodexOverflowTrimming(
|
|
|
550
531
|
}> {
|
|
551
532
|
// Codex's estimator is intentionally coarse. Keep the explicit checkpoint
|
|
552
533
|
// request below both the effective input window and the raw window minus the
|
|
553
|
-
// requested summary
|
|
554
|
-
//
|
|
555
|
-
//
|
|
556
|
-
const summaryAwareBudget = Math.max(
|
|
557
|
-
0,
|
|
558
|
-
settings.contextWindowTokens - compactionSummaryOutputTokens(settings.contextWindowTokens),
|
|
559
|
-
);
|
|
534
|
+
// requested summary, then leave 15% estimator headroom. This changes only the
|
|
535
|
+
// temporary summarizer input; durable active history remains untouched until
|
|
536
|
+
// applyContextCompaction succeeds under the attempt fence.
|
|
537
|
+
const summaryAwareBudget = Math.max(0, settings.contextWindowTokens - SUMMARY_BUFFER_TOKENS);
|
|
560
538
|
const configuredInputBudget = contextInputBudgetTokens(settings);
|
|
561
539
|
const structuralBudget = Math.min(
|
|
562
540
|
configuredInputBudget > 0 ? configuredInputBudget : summaryAwareBudget,
|
|
563
541
|
summaryAwareBudget,
|
|
564
542
|
);
|
|
565
|
-
const
|
|
566
|
-
const initialBudget = Math.max(0, structuralBudget - prefixTokens);
|
|
543
|
+
const initialBudget = Math.floor(structuralBudget * 0.85);
|
|
567
544
|
let preparation = prepareCompactionPromptInput(activeHistory, initialBudget);
|
|
568
|
-
// A checkpoint prompt without source history cannot summarize that history.
|
|
569
|
-
// Do not let a plausible-sounding reply replace durable active context.
|
|
570
|
-
const requireHistory = () => {
|
|
571
|
-
if (activeHistory.length > 0 && preparation.input.length === 1) {
|
|
572
|
-
throw new EmptyCompactionSummaryError({
|
|
573
|
-
stage: "portable_input_budget",
|
|
574
|
-
reason: "no_history_fit",
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
requireHistory();
|
|
579
545
|
try {
|
|
580
546
|
return {
|
|
581
547
|
summaryBody: await summarize(settings, preparation.input),
|
|
@@ -585,16 +551,15 @@ export async function summarizeWithCodexOverflowTrimming(
|
|
|
585
551
|
} catch (error) {
|
|
586
552
|
if (!isContextWindowExceeded(error)) throw error;
|
|
587
553
|
// The provider is more authoritative than the byte/4 estimate. Refit once
|
|
588
|
-
// to
|
|
554
|
+
// to 70% of both the configured target and the actual prepared estimate;
|
|
589
555
|
// then fail terminally with prior history intact. Never issue one failing
|
|
590
|
-
// request per oldest item. The
|
|
591
|
-
// provider can count slightly more than twice the byte/4 estimate
|
|
592
|
-
//
|
|
556
|
+
// request per oldest item. The production incident proved that the
|
|
557
|
+
// provider can count slightly more than twice the byte/4 estimate, so a
|
|
558
|
+
// half-size retry is the smallest honest bound for that observed skew.
|
|
593
559
|
const retryBudget = Math.floor(
|
|
594
|
-
Math.min(initialBudget * 0.
|
|
560
|
+
Math.min(initialBudget * 0.5, preparation.estimatedInputTokens * 0.5),
|
|
595
561
|
);
|
|
596
562
|
preparation = prepareCompactionPromptInput(activeHistory, retryBudget);
|
|
597
|
-
requireHistory();
|
|
598
563
|
return {
|
|
599
564
|
summaryBody: await summarize(settings, preparation.input),
|
|
600
565
|
preparation,
|