@remnic/core 10.0.185 → 10.0.187
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/access-admin-ops-surface.js +97 -96
- package/dist/access-audit.js +2 -2
- package/dist/access-cli.js +97 -96
- package/dist/access-cli.js.map +1 -1
- package/dist/access-coding-context-resolution.js +6 -6
- package/dist/access-extraction-force-flush-preempt.js +97 -96
- package/dist/access-extraction-force-flush.js +97 -96
- package/dist/access-http-briefing.js +97 -96
- package/dist/access-http-query.js +97 -96
- package/dist/access-http.js +97 -96
- package/dist/access-identity-continuity-surface.js +97 -96
- package/dist/access-lcm-surface.js +97 -96
- package/dist/access-mcp.js +97 -96
- package/dist/access-observe-write-category.js +6 -6
- package/dist/access-observe-write-surface.js +97 -96
- package/dist/access-offline-manifest.js +5 -5
- package/dist/access-operations-batch.js +97 -96
- package/dist/access-operations.js +97 -96
- package/dist/access-recall-concurrency.js +97 -96
- package/dist/access-recall-response.js +97 -96
- package/dist/access-recall-surface.js +97 -96
- package/dist/access-schema.js +5 -5
- package/dist/access-service.js +97 -96
- package/dist/active-recall.js +10 -10
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/{auto-sync-OOEY2FSA.js → auto-sync-BJUAGKI5.js} +4 -4
- package/dist/briefing.js +7 -7
- package/dist/buffer.js +6 -5
- package/dist/calibration.js +1 -1
- package/dist/causal-consolidation.js +8 -8
- package/dist/{chunk-3N7I53KR.js → chunk-2QQCCUXF.js} +2 -2
- package/dist/{chunk-FYHFM64A.js → chunk-2RAVHJCD.js} +2 -2
- package/dist/{chunk-XYZR3NBU.js → chunk-2ZS7CB5H.js} +2 -2
- package/dist/{chunk-4TPU36X4.js → chunk-4N33L4HY.js} +2 -2
- package/dist/{chunk-BFPF5N3H.js → chunk-4RASUAN3.js} +4 -4
- package/dist/{chunk-CKTKATXL.js → chunk-4VFEN3WT.js} +19 -15
- package/dist/chunk-4VFEN3WT.js.map +1 -0
- package/dist/{chunk-R3UQIS3F.js → chunk-5AFBFAFX.js} +4 -4
- package/dist/{chunk-PY5XP7GR.js → chunk-6TIQLG7I.js} +2 -2
- package/dist/{chunk-JK5YFQQT.js → chunk-76KL37ON.js} +2 -2
- package/dist/{chunk-L7MVHAMS.js → chunk-7EPEZYX3.js} +2 -2
- package/dist/{chunk-A3HLZMHD.js → chunk-7KTORRIK.js} +2 -2
- package/dist/{chunk-PZ4OA7CP.js → chunk-7UTCETGK.js} +2 -2
- package/dist/{chunk-2LXROA34.js → chunk-AXSQGJSG.js} +2 -2
- package/dist/{chunk-5ITPOAKW.js → chunk-BANMPRSC.js} +2 -2
- package/dist/{chunk-FDXLO6CX.js → chunk-CRS2NY44.js} +2 -2
- package/dist/{chunk-SSKIXUR5.js → chunk-CTWWMEGR.js} +2 -2
- package/dist/{chunk-ZNHLUYIT.js → chunk-D7HOJFDS.js} +4 -4
- package/dist/{chunk-ZX5N5D6M.js → chunk-DAOMWGO2.js} +4 -4
- package/dist/{chunk-VN3RYYMS.js → chunk-DR4TYD56.js} +2 -2
- package/dist/{chunk-7DFJ4JX2.js → chunk-DTTDMK7Q.js} +7 -7
- package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
- package/dist/{chunk-QJBULLKG.js → chunk-F2MVWUNF.js} +2 -2
- package/dist/{chunk-N33M4NWM.js → chunk-FKLSIQBF.js} +3 -3
- package/dist/{chunk-5BESLEU7.js → chunk-FQE5QN5Q.js} +2 -2
- package/dist/{chunk-VFJ3PBZI.js → chunk-FXDQO7VX.js} +2 -2
- package/dist/{chunk-BAMF6J4W.js → chunk-GCHM5BYL.js} +4 -4
- package/dist/{chunk-6SROXED4.js → chunk-GRX5BE73.js} +2 -2
- package/dist/{chunk-UMGO4LEZ.js → chunk-HHCLV572.js} +2 -2
- package/dist/{chunk-CIC3WZVO.js → chunk-I233SAGS.js} +2 -2
- package/dist/{chunk-FBNR3JI5.js → chunk-IMT7NTFV.js} +2 -2
- package/dist/{chunk-63FIQIER.js → chunk-JJ42IDJU.js} +2 -2
- package/dist/{chunk-CJERJ724.js → chunk-JRHOL6B5.js} +2 -2
- package/dist/{chunk-ENKXMLE3.js → chunk-K5RGHUX7.js} +2 -2
- package/dist/{chunk-VAQIBC2L.js → chunk-KQIOW3TG.js} +2 -2
- package/dist/{chunk-H4HBQRGI.js → chunk-KVM3BS5K.js} +2 -2
- package/dist/{chunk-QJG6PEAM.js → chunk-KZJEKKK6.js} +3 -3
- package/dist/{chunk-TCSY74IN.js → chunk-L2DYRQQH.js} +181 -140
- package/dist/chunk-L2DYRQQH.js.map +1 -0
- package/dist/{chunk-N2PXVLV3.js → chunk-LANV6I63.js} +7 -7
- package/dist/{chunk-U7VEZ2XS.js → chunk-LPYGM6RE.js} +2 -2
- package/dist/{chunk-WCXWCAUC.js → chunk-MDXZIU5X.js} +2 -2
- package/dist/{chunk-VUC3DLQ5.js → chunk-MOWLANEJ.js} +2 -2
- package/dist/{chunk-IK7NPYYU.js → chunk-NFQKIZK3.js} +2 -2
- package/dist/{chunk-RXAWE76Y.js → chunk-O6QSBI3U.js} +2 -2
- package/dist/{chunk-5RBHL5TF.js → chunk-OA7YDB6A.js} +2 -2
- package/dist/{chunk-CXGD3N2Y.js → chunk-OVJAQWHO.js} +2 -2
- package/dist/{chunk-EWLOIHAZ.js → chunk-P5FF44G3.js} +5 -5
- package/dist/{chunk-5RWIZISF.js → chunk-PSUSA5SM.js} +3 -3
- package/dist/{chunk-DYZDFOBX.js → chunk-Q6S67LHR.js} +2 -2
- package/dist/{chunk-KYPFQO43.js → chunk-QPD7EYGI.js} +2 -2
- package/dist/{chunk-FE43YKNJ.js → chunk-RBPC4XGU.js} +31 -8
- package/dist/chunk-RBPC4XGU.js.map +1 -0
- package/dist/{chunk-G6V32Q4F.js → chunk-SFWQZBPN.js} +2 -2
- package/dist/{chunk-DNXQVCIC.js → chunk-SUI75NTN.js} +8 -8
- package/dist/{chunk-FDLPNFKE.js → chunk-T7R42MWB.js} +2 -2
- package/dist/chunk-TK6EBBKG.js +13 -0
- package/dist/chunk-TK6EBBKG.js.map +1 -0
- package/dist/{chunk-J7BAJ6BF.js → chunk-UCCXPMTP.js} +2 -2
- package/dist/{chunk-PDXO4LIH.js → chunk-UWKHLWUE.js} +13 -9
- package/dist/chunk-UWKHLWUE.js.map +1 -0
- package/dist/{chunk-L4TYD52M.js → chunk-VZBKCRU7.js} +2 -2
- package/dist/{chunk-T4MKFTJF.js → chunk-XHDS6HIX.js} +5 -5
- package/dist/{chunk-TKWIUL3D.js → chunk-YDGQYG4L.js} +7 -7
- package/dist/{chunk-4KUK3KGI.js → chunk-YJZDRM33.js} +3 -3
- package/dist/{chunk-NU5JRN3A.js → chunk-ZDLVHGIC.js} +2 -2
- package/dist/{chunk-OJXK5C6Z.js → chunk-ZG4GNPRE.js} +7 -7
- package/dist/{chunk-IJKO5RVJ.js → chunk-ZNYDDZVW.js} +3 -3
- package/dist/cli.js +97 -96
- package/dist/coding/export-okf-codegraph.js +13 -13
- package/dist/compounding/engine.js +8 -8
- package/dist/config.js +10 -10
- package/dist/connectors/codex-materialize-runner.js +7 -7
- package/dist/connectors/index.js +7 -7
- package/dist/convergence-refresh.js +9 -9
- package/dist/corpus-watermark.js +9 -9
- package/dist/dashboard-runtime.js +2 -2
- package/dist/deep-recall-http-glue.js +6 -6
- package/dist/deep-recall.js +2 -2
- package/dist/entity-retrieval.js +7 -7
- package/dist/explicit-capture.js +97 -96
- package/dist/extraction-entities-source.d.ts +11 -0
- package/dist/extraction-entities-source.d.ts.map +1 -0
- package/dist/extraction-entities-source.js +8 -0
- package/dist/extraction-entities-source.js.map +1 -0
- package/dist/extraction-judge.js +2 -2
- package/dist/extraction-normalization.js +2 -2
- package/dist/extraction-prompt.d.ts +19 -2
- package/dist/extraction-prompt.d.ts.map +1 -1
- package/dist/extraction-prompt.js +5 -1
- package/dist/extraction.d.ts +2 -1
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +15 -14
- package/dist/{first-start-migration-TCPK2I7J.js → first-start-migration-CCZ5SM3V.js} +4 -4
- package/dist/harmonic-retrieval.js +7 -7
- package/dist/index.js +117 -116
- package/dist/lcm/engine.js +3 -3
- package/dist/lcm/index.js +8 -8
- package/dist/location/index.js +8 -8
- package/dist/maintenance/memory-governance.js +7 -7
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -7
- package/dist/maintenance/rebuild-memory-projection-runner.js +9 -9
- package/dist/maintenance/rebuild-memory-projection.js +8 -8
- package/dist/memory-browse.js +5 -5
- package/dist/namespaces/migrate.js +8 -8
- package/dist/namespaces/search.js +4 -4
- package/dist/namespaces/storage.js +7 -7
- package/dist/offline-sync-changeset-generations.js +3 -3
- package/dist/offline-sync-embedding-generation.js +2 -2
- package/dist/offline-sync-snapshot-stream.js +5 -5
- package/dist/offline-sync.js +6 -6
- package/dist/operator-doctor-corpus.js +10 -10
- package/dist/operator-toolkit.js +17 -17
- package/dist/orchestration/backlog-scheduler.js +98 -97
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +98 -97
- package/dist/orchestration/extraction-queue-coordinator.d.ts +20 -0
- package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
- package/dist/orchestration/extraction-run-helpers.d.ts +2 -1
- package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
- package/dist/orchestration/extraction-run.d.ts.map +1 -1
- package/dist/orchestration/maintenance.js +15 -15
- package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
- package/dist/orchestrator.js +99 -98
- package/dist/qmd.js +2 -2
- package/dist/recall-navigation.js +97 -96
- package/dist/recall-state-view-admission.js +5 -5
- package/dist/recall-why-service.js +5 -5
- package/dist/resume-bundles.js +13 -13
- package/dist/search/factory.js +3 -3
- package/dist/search/index.js +3 -3
- package/dist/semantic-consolidation.js +8 -8
- package/dist/semantic-rule-promotion.js +7 -7
- package/dist/semantic-rule-verifier.js +7 -7
- package/dist/source-agent-qualifier.js +11 -10
- package/dist/standup/build.js +7 -7
- package/dist/storage.js +6 -6
- package/dist/transcript.js +2 -2
- package/dist/transfer/export-okf.js +7 -7
- package/dist/verified-recall.js +7 -7
- package/dist/who-knows-cli.js +8 -8
- package/dist/who-knows.js +7 -7
- package/package.json +2 -2
- package/src/extraction-carry-forward.test.ts +147 -0
- package/src/extraction-entities-source.ts +19 -0
- package/src/extraction-prompt.ts +60 -9
- package/src/extraction.ts +11 -8
- package/src/orchestration/extraction-queue-coordinator.ts +71 -4
- package/src/orchestration/extraction-queue-lane-bias.test.ts +220 -0
- package/src/orchestration/extraction-run-helpers.ts +11 -4
- package/src/orchestration/extraction-run.test.ts +23 -12
- package/src/orchestration/extraction-run.ts +6 -5
- package/src/orchestration/turn-ingestion.ts +7 -1
- package/dist/chunk-CKTKATXL.js.map +0 -1
- package/dist/chunk-FE43YKNJ.js.map +0 -1
- package/dist/chunk-PDXO4LIH.js.map +0 -1
- package/dist/chunk-TCSY74IN.js.map +0 -1
- /package/dist/{auto-sync-OOEY2FSA.js.map → auto-sync-BJUAGKI5.js.map} +0 -0
- /package/dist/{chunk-3N7I53KR.js.map → chunk-2QQCCUXF.js.map} +0 -0
- /package/dist/{chunk-FYHFM64A.js.map → chunk-2RAVHJCD.js.map} +0 -0
- /package/dist/{chunk-XYZR3NBU.js.map → chunk-2ZS7CB5H.js.map} +0 -0
- /package/dist/{chunk-4TPU36X4.js.map → chunk-4N33L4HY.js.map} +0 -0
- /package/dist/{chunk-BFPF5N3H.js.map → chunk-4RASUAN3.js.map} +0 -0
- /package/dist/{chunk-R3UQIS3F.js.map → chunk-5AFBFAFX.js.map} +0 -0
- /package/dist/{chunk-PY5XP7GR.js.map → chunk-6TIQLG7I.js.map} +0 -0
- /package/dist/{chunk-JK5YFQQT.js.map → chunk-76KL37ON.js.map} +0 -0
- /package/dist/{chunk-L7MVHAMS.js.map → chunk-7EPEZYX3.js.map} +0 -0
- /package/dist/{chunk-A3HLZMHD.js.map → chunk-7KTORRIK.js.map} +0 -0
- /package/dist/{chunk-PZ4OA7CP.js.map → chunk-7UTCETGK.js.map} +0 -0
- /package/dist/{chunk-2LXROA34.js.map → chunk-AXSQGJSG.js.map} +0 -0
- /package/dist/{chunk-5ITPOAKW.js.map → chunk-BANMPRSC.js.map} +0 -0
- /package/dist/{chunk-FDXLO6CX.js.map → chunk-CRS2NY44.js.map} +0 -0
- /package/dist/{chunk-SSKIXUR5.js.map → chunk-CTWWMEGR.js.map} +0 -0
- /package/dist/{chunk-ZNHLUYIT.js.map → chunk-D7HOJFDS.js.map} +0 -0
- /package/dist/{chunk-ZX5N5D6M.js.map → chunk-DAOMWGO2.js.map} +0 -0
- /package/dist/{chunk-VN3RYYMS.js.map → chunk-DR4TYD56.js.map} +0 -0
- /package/dist/{chunk-7DFJ4JX2.js.map → chunk-DTTDMK7Q.js.map} +0 -0
- /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
- /package/dist/{chunk-QJBULLKG.js.map → chunk-F2MVWUNF.js.map} +0 -0
- /package/dist/{chunk-N33M4NWM.js.map → chunk-FKLSIQBF.js.map} +0 -0
- /package/dist/{chunk-5BESLEU7.js.map → chunk-FQE5QN5Q.js.map} +0 -0
- /package/dist/{chunk-VFJ3PBZI.js.map → chunk-FXDQO7VX.js.map} +0 -0
- /package/dist/{chunk-BAMF6J4W.js.map → chunk-GCHM5BYL.js.map} +0 -0
- /package/dist/{chunk-6SROXED4.js.map → chunk-GRX5BE73.js.map} +0 -0
- /package/dist/{chunk-UMGO4LEZ.js.map → chunk-HHCLV572.js.map} +0 -0
- /package/dist/{chunk-CIC3WZVO.js.map → chunk-I233SAGS.js.map} +0 -0
- /package/dist/{chunk-FBNR3JI5.js.map → chunk-IMT7NTFV.js.map} +0 -0
- /package/dist/{chunk-63FIQIER.js.map → chunk-JJ42IDJU.js.map} +0 -0
- /package/dist/{chunk-CJERJ724.js.map → chunk-JRHOL6B5.js.map} +0 -0
- /package/dist/{chunk-ENKXMLE3.js.map → chunk-K5RGHUX7.js.map} +0 -0
- /package/dist/{chunk-VAQIBC2L.js.map → chunk-KQIOW3TG.js.map} +0 -0
- /package/dist/{chunk-H4HBQRGI.js.map → chunk-KVM3BS5K.js.map} +0 -0
- /package/dist/{chunk-QJG6PEAM.js.map → chunk-KZJEKKK6.js.map} +0 -0
- /package/dist/{chunk-N2PXVLV3.js.map → chunk-LANV6I63.js.map} +0 -0
- /package/dist/{chunk-U7VEZ2XS.js.map → chunk-LPYGM6RE.js.map} +0 -0
- /package/dist/{chunk-WCXWCAUC.js.map → chunk-MDXZIU5X.js.map} +0 -0
- /package/dist/{chunk-VUC3DLQ5.js.map → chunk-MOWLANEJ.js.map} +0 -0
- /package/dist/{chunk-IK7NPYYU.js.map → chunk-NFQKIZK3.js.map} +0 -0
- /package/dist/{chunk-RXAWE76Y.js.map → chunk-O6QSBI3U.js.map} +0 -0
- /package/dist/{chunk-5RBHL5TF.js.map → chunk-OA7YDB6A.js.map} +0 -0
- /package/dist/{chunk-CXGD3N2Y.js.map → chunk-OVJAQWHO.js.map} +0 -0
- /package/dist/{chunk-EWLOIHAZ.js.map → chunk-P5FF44G3.js.map} +0 -0
- /package/dist/{chunk-5RWIZISF.js.map → chunk-PSUSA5SM.js.map} +0 -0
- /package/dist/{chunk-DYZDFOBX.js.map → chunk-Q6S67LHR.js.map} +0 -0
- /package/dist/{chunk-KYPFQO43.js.map → chunk-QPD7EYGI.js.map} +0 -0
- /package/dist/{chunk-G6V32Q4F.js.map → chunk-SFWQZBPN.js.map} +0 -0
- /package/dist/{chunk-DNXQVCIC.js.map → chunk-SUI75NTN.js.map} +0 -0
- /package/dist/{chunk-FDLPNFKE.js.map → chunk-T7R42MWB.js.map} +0 -0
- /package/dist/{chunk-J7BAJ6BF.js.map → chunk-UCCXPMTP.js.map} +0 -0
- /package/dist/{chunk-L4TYD52M.js.map → chunk-VZBKCRU7.js.map} +0 -0
- /package/dist/{chunk-T4MKFTJF.js.map → chunk-XHDS6HIX.js.map} +0 -0
- /package/dist/{chunk-TKWIUL3D.js.map → chunk-YDGQYG4L.js.map} +0 -0
- /package/dist/{chunk-4KUK3KGI.js.map → chunk-YJZDRM33.js.map} +0 -0
- /package/dist/{chunk-NU5JRN3A.js.map → chunk-ZDLVHGIC.js.map} +0 -0
- /package/dist/{chunk-OJXK5C6Z.js.map → chunk-ZG4GNPRE.js.map} +0 -0
- /package/dist/{chunk-IJKO5RVJ.js.map → chunk-ZNYDDZVW.js.map} +0 -0
- /package/dist/{first-start-migration-TCPK2I7J.js.map → first-start-migration-CCZ5SM3V.js.map} +0 -0
package/src/extraction-prompt.ts
CHANGED
|
@@ -110,18 +110,74 @@ Span mode (numbered-message offsets):
|
|
|
110
110
|
- Invalid spans fall back to the frame, so keep the frame informative.`;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Char budget for the KNOWN ENTITIES block on gateway/direct extraction
|
|
115
|
+
* prompts. Mature stores hold thousands of entities; the unbounded list ran
|
|
116
|
+
* to ~200k chars on one production store — wider than the model's context —
|
|
117
|
+
* so the carry-forward is capped, keeping conversation-mentioned names first.
|
|
118
|
+
*/
|
|
119
|
+
export const KNOWN_ENTITIES_PROMPT_BUDGET_CHARS = 2000;
|
|
120
|
+
|
|
121
|
+
/** The rendered KNOWN ENTITIES block's fixed framing, kept in one place so
|
|
122
|
+
* the selector's budget reserve matches the render exactly. */
|
|
123
|
+
const KNOWN_ENTITIES_HEADING =
|
|
124
|
+
"\nKNOWN ENTITIES (use these exact names when referencing existing things):\n";
|
|
125
|
+
const KNOWN_ENTITIES_TRAILER =
|
|
126
|
+
"\n\nWhen you see something that matches a known entity, use THAT name exactly. Only create a NEW entity if nothing in this list represents it.\n";
|
|
127
|
+
const KNOWN_ENTITIES_FRAMING_CHARS =
|
|
128
|
+
KNOWN_ENTITIES_HEADING.length + KNOWN_ENTITIES_TRAILER.length;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Select the entity names worth carrying into an extraction prompt: every
|
|
132
|
+
* name the conversation mentions (hyphen/space/case-folded match), then the
|
|
133
|
+
* remaining names in store order until the char budget is spent. Names the
|
|
134
|
+
* conversation does not touch cannot be referenced by this extraction, so
|
|
135
|
+
* dropping them past the budget never loses a canonical-name hint.
|
|
136
|
+
*/
|
|
137
|
+
export function selectKnownEntitiesForPrompt(
|
|
138
|
+
entities: readonly string[],
|
|
139
|
+
conversation: string,
|
|
140
|
+
budgetChars = KNOWN_ENTITIES_PROMPT_BUDGET_CHARS,
|
|
141
|
+
): string[] {
|
|
142
|
+
if (entities.length === 0) return [];
|
|
143
|
+
if (entities.join(", ").length + KNOWN_ENTITIES_FRAMING_CHARS <= budgetChars) return [...entities];
|
|
144
|
+
const fold = (value: string): string => value.toLowerCase().replace(/[-_]+/g, " ");
|
|
145
|
+
const foldedConversation = fold(conversation);
|
|
146
|
+
const mentioned: string[] = [];
|
|
147
|
+
const rest: string[] = [];
|
|
148
|
+
for (const name of entities) {
|
|
149
|
+
(foldedConversation.includes(fold(name)) ? mentioned : rest).push(name);
|
|
150
|
+
}
|
|
151
|
+
const selected: string[] = [];
|
|
152
|
+
let used = 0;
|
|
153
|
+
for (const name of [...mentioned, ...rest]) {
|
|
154
|
+
const cost = (selected.length > 0 ? 2 : 0) + name.length;
|
|
155
|
+
// Skip a single oversized name instead of aborting the fill — smaller
|
|
156
|
+
// names behind it still deserve the budget.
|
|
157
|
+
if (cost > budgetChars - KNOWN_ENTITIES_FRAMING_CHARS) continue;
|
|
158
|
+
if (used + cost > budgetChars - KNOWN_ENTITIES_FRAMING_CHARS) break;
|
|
159
|
+
selected.push(name);
|
|
160
|
+
used += cost;
|
|
161
|
+
}
|
|
162
|
+
return selected;
|
|
163
|
+
}
|
|
164
|
+
|
|
113
165
|
/**
|
|
114
166
|
* Build extraction instructions shared between local and cloud LLM.
|
|
115
167
|
*
|
|
116
168
|
* `ambientCapture` marks input from an always-on recorder, which may carry
|
|
117
|
-
* speech the user never authored (issue #2294).
|
|
169
|
+
* speech the user never authored (issue #2294). `conversation` ranks the
|
|
170
|
+
* KNOWN ENTITIES carry-forward mention-first under the char budget; callers
|
|
171
|
+
* that omit it keep store order under the same budget.
|
|
118
172
|
*/
|
|
119
173
|
export function buildExtractionInstructions(
|
|
120
174
|
config: PluginConfig,
|
|
121
175
|
existingEntities?: string[],
|
|
122
|
-
ambientCapture = false
|
|
176
|
+
ambientCapture = false,
|
|
177
|
+
conversation = ""
|
|
123
178
|
): string {
|
|
124
179
|
const lifecycleCaps = resolveMemoryLifecycleCapabilities(config);
|
|
180
|
+
const knownEntities = selectKnownEntitiesForPrompt(existingEntities ?? [], conversation);
|
|
125
181
|
return `You are a memory extraction system. Analyze the following conversation and extract durable, reusable memories.
|
|
126
182
|
|
|
127
183
|
Memory categories:
|
|
@@ -195,13 +251,8 @@ Entity creation rules (STRICT):
|
|
|
195
251
|
- The entity list should be SHORT — think "things that would have their own Wikipedia page" not "things mentioned in passing"
|
|
196
252
|
|
|
197
253
|
${
|
|
198
|
-
|
|
199
|
-
?
|
|
200
|
-
KNOWN ENTITIES (use these exact names when referencing existing things):
|
|
201
|
-
${existingEntities.join(", ")}
|
|
202
|
-
|
|
203
|
-
When you see something that matches a known entity, use THAT name exactly. Only create a NEW entity if nothing in this list represents it.
|
|
204
|
-
`
|
|
254
|
+
knownEntities.length > 0
|
|
255
|
+
? KNOWN_ENTITIES_HEADING + knownEntities.join(", ") + KNOWN_ENTITIES_TRAILER
|
|
205
256
|
: ""
|
|
206
257
|
}
|
|
207
258
|
${eventTimePromptInstruction(config)}${spanModePromptSection(config.extraction?.spanMode ?? "off")}
|
package/src/extraction.ts
CHANGED
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
import { containsExtractionPlaceholder, extractionAttributes, extractionCueAnchors, extractionText, isPlainRecord } from "./extraction-normalization.js";
|
|
57
57
|
import { applyExtractionSpanMaterialization, bindLocalExtractionPrompt, buildSpanMaterializeTurns, stripUntrustedFactSpans, truncateLocalExtractionConversation, type SpanMaterializeTurn } from "./extraction-span-materialize.js";
|
|
58
58
|
import { extractionProviderJsonSchema, extractionProviderResponseFormat } from "./extraction-span-wire.js";
|
|
59
|
+
import { memoizeExistingEntities, type ExistingEntitiesSource } from "./extraction-entities-source.js";
|
|
59
60
|
import { resolveLocalLlmCapabilities, resolveMemoryLifecycleCapabilities, resolvePipelineProcessingCapabilities, resolveRecallAuxiliaryCapabilities } from "./capabilities.js";
|
|
60
61
|
type ExtractionQuestion = ExtractionResult["questions"][number];
|
|
61
62
|
type ExtractedFactResult = ExtractionResult["facts"][number];
|
|
@@ -1067,10 +1068,13 @@ export class ExtractionEngine {
|
|
|
1067
1068
|
|
|
1068
1069
|
async extract(
|
|
1069
1070
|
turns: BufferTurn[],
|
|
1070
|
-
existingEntities?:
|
|
1071
|
+
existingEntities?: ExistingEntitiesSource,
|
|
1071
1072
|
signal?: AbortSignal,
|
|
1072
1073
|
): Promise<ExtractionResult> {
|
|
1073
1074
|
const lifecycleCaps = resolveMemoryLifecycleCapabilities(this.config);
|
|
1075
|
+
// Resolved only when a gateway/direct prompt needs it; the local path
|
|
1076
|
+
// (every call on local-first deployments) never reads the list.
|
|
1077
|
+
const resolveEntities = memoizeExistingEntities(existingEntities);
|
|
1074
1078
|
|
|
1075
1079
|
// Guard: skip if buffer is empty or all turns are whitespace-only
|
|
1076
1080
|
const substantiveTurns = turns.filter((t) => t.content.trim().length > 0);
|
|
@@ -1188,7 +1192,7 @@ export class ExtractionEngine {
|
|
|
1188
1192
|
this.profiler.startSpan("local-llm", extractionTraceId);
|
|
1189
1193
|
primaryExtractorAttempted = true;
|
|
1190
1194
|
try {
|
|
1191
|
-
const localResult = await this.extractWithLocalLlm(conversation,
|
|
1195
|
+
const localResult = await this.extractWithLocalLlm(conversation, signal, ambientCapture);
|
|
1192
1196
|
throwIfExtractionAborted(signal);
|
|
1193
1197
|
if (localResult) {
|
|
1194
1198
|
const durationMs = Date.now() - startTime;
|
|
@@ -1247,7 +1251,7 @@ export class ExtractionEngine {
|
|
|
1247
1251
|
this.profiler.startSpan("direct-client", extractionTraceId);
|
|
1248
1252
|
primaryExtractorAttempted = true;
|
|
1249
1253
|
try {
|
|
1250
|
-
const directResult = await this.extractWithDirectClient(conversation,
|
|
1254
|
+
const directResult = await this.extractWithDirectClient(conversation, resolveEntities, signal, ambientCapture);
|
|
1251
1255
|
if (directResult) {
|
|
1252
1256
|
const durationMs = Date.now() - startTime;
|
|
1253
1257
|
this.profiler.endSpan("direct-client", extractionTraceId);
|
|
@@ -1317,7 +1321,7 @@ export class ExtractionEngine {
|
|
|
1317
1321
|
{
|
|
1318
1322
|
role: "system" as const,
|
|
1319
1323
|
content:
|
|
1320
|
-
buildExtractionInstructions(this.config,
|
|
1324
|
+
buildExtractionInstructions(this.config, await resolveEntities(), ambientCapture, conversation) +
|
|
1321
1325
|
`\n\nReturn only valid JSON matching this shape. Placeholder text describes field shape only and is never source evidence:\n${extractionResponseShape(this.config.extraction?.spanMode ?? "off")}`,
|
|
1322
1326
|
},
|
|
1323
1327
|
{ role: "user" as const, content: conversation },
|
|
@@ -1429,7 +1433,6 @@ export class ExtractionEngine {
|
|
|
1429
1433
|
*/
|
|
1430
1434
|
private async extractWithLocalLlm(
|
|
1431
1435
|
conversation: string,
|
|
1432
|
-
existingEntities?: string[],
|
|
1433
1436
|
signal?: AbortSignal,
|
|
1434
1437
|
ambientCapture = false,
|
|
1435
1438
|
): Promise<ExtractionResult | null> {
|
|
@@ -1557,7 +1560,7 @@ ${truncatedConversation}`;
|
|
|
1557
1560
|
*/
|
|
1558
1561
|
private async extractWithDirectClient(
|
|
1559
1562
|
conversation: string,
|
|
1560
|
-
|
|
1563
|
+
resolveEntities: () => Promise<string[]>,
|
|
1561
1564
|
signal?: AbortSignal,
|
|
1562
1565
|
ambientCapture = false,
|
|
1563
1566
|
): Promise<ExtractionResult | null> {
|
|
@@ -1575,10 +1578,10 @@ ${truncatedConversation}`;
|
|
|
1575
1578
|
{
|
|
1576
1579
|
role: "system",
|
|
1577
1580
|
content:
|
|
1578
|
-
buildExtractionInstructions(this.config,
|
|
1581
|
+
buildExtractionInstructions(this.config, await resolveEntities(), ambientCapture, conversation) +
|
|
1579
1582
|
`\n\nReturn only valid JSON matching this shape. Placeholder text describes field shape only and is never source evidence:\n${extractionResponseShape(this.config.extraction?.spanMode ?? "off")}`,
|
|
1580
1583
|
},
|
|
1581
|
-
{ role: "user", content: conversation },
|
|
1584
|
+
{ role: "user" as const, content: conversation },
|
|
1582
1585
|
],
|
|
1583
1586
|
...tokenParams,
|
|
1584
1587
|
},
|
|
@@ -50,15 +50,28 @@ export interface ExtractionQueueEnqueueOptions {
|
|
|
50
50
|
front?: boolean;
|
|
51
51
|
/** Buffer/session key. Tasks sharing a key never run concurrently. */
|
|
52
52
|
key?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Backlog/drain task: preferred up to `concurrency - FOREGROUND_FLOOR`
|
|
55
|
+
* concurrent slots whenever foreground work is also queued, so large
|
|
56
|
+
* claimed backlogs fill each call's prompt budget while live sessions
|
|
57
|
+
* keep a guaranteed floor share. The last slot is kept open for a
|
|
58
|
+
* fail-closed flush: a backlog task never fills it even with no
|
|
59
|
+
* foreground work queued.
|
|
60
|
+
*/
|
|
61
|
+
backlog?: boolean;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
interface QueueEntry {
|
|
56
65
|
run: ExtractionQueueTask;
|
|
57
66
|
key?: string;
|
|
67
|
+
backlog?: boolean;
|
|
68
|
+
/** Set by enqueue({ front: true }): jumps the queue ahead of lane bias. */
|
|
69
|
+
front?: boolean;
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
interface PreemptSlot {
|
|
61
73
|
key?: string;
|
|
74
|
+
backlog?: boolean;
|
|
62
75
|
armed?: { abort: () => void; seq: number };
|
|
63
76
|
}
|
|
64
77
|
|
|
@@ -89,6 +102,15 @@ export class ExtractionQueueCoordinator {
|
|
|
89
102
|
/** Preempt slots of the currently running tasks, keyed by slot identity. */
|
|
90
103
|
private readonly preemptSlots = new Map<object, PreemptSlot>();
|
|
91
104
|
private preemptSeq = 0;
|
|
105
|
+
/** Running tasks per lane — the backlog share and the foreground floor. */
|
|
106
|
+
private activeBacklog = 0;
|
|
107
|
+
private activeForeground = 0;
|
|
108
|
+
/**
|
|
109
|
+
* Slots kept available for foreground (non-backlog) tasks while backlog
|
|
110
|
+
* work also waits. A floor of one keeps live sessions extracting even at
|
|
111
|
+
* full backlog pressure; backlog tasks fill the rest.
|
|
112
|
+
*/
|
|
113
|
+
private static readonly FOREGROUND_FLOOR = 1;
|
|
92
114
|
/** Resolves the processor's park while a new task arrives mid-drain. */
|
|
93
115
|
private wake?: () => void;
|
|
94
116
|
|
|
@@ -120,9 +142,15 @@ export class ExtractionQueueCoordinator {
|
|
|
120
142
|
enqueue(task: ExtractionQueueTask, options?: ExtractionQueueEnqueueOptions): boolean {
|
|
121
143
|
if (!this.accepting) return false;
|
|
122
144
|
const key = options?.key;
|
|
123
|
-
const entry: QueueEntry = { run: task, key };
|
|
145
|
+
const entry: QueueEntry = { run: task, key, backlog: options?.backlog, front: options?.front };
|
|
124
146
|
if (options?.front) {
|
|
125
|
-
|
|
147
|
+
const sameKeyArmed =
|
|
148
|
+
key !== undefined &&
|
|
149
|
+
Array.from(this.preemptSlots.values()).some((slot) => slot.key === key && slot.armed !== undefined);
|
|
150
|
+
if (sameKeyArmed || this.preemptSlots.size >= this.concurrency) {
|
|
151
|
+
this.preemptRunning(options.key);
|
|
152
|
+
}
|
|
153
|
+
entry.front = true;
|
|
126
154
|
this.queue.unshift(entry);
|
|
127
155
|
} else {
|
|
128
156
|
this.queue.push(entry);
|
|
@@ -184,9 +212,13 @@ export class ExtractionQueueCoordinator {
|
|
|
184
212
|
const armed = Array.from(this.preemptSlots.values()).filter((slot) => slot.armed !== undefined);
|
|
185
213
|
if (armed.length === 0) return;
|
|
186
214
|
const preferred = preferredKey !== undefined ? armed.find((slot) => slot.key === preferredKey) : undefined;
|
|
215
|
+
// Lane-aware victim choice: with no same-key slot to abort, a flush takes
|
|
216
|
+
// a foreground slot before a backlog one, so drain chunk calls survive
|
|
217
|
+
// routine force-flush preemption while the flush still always wins a slot.
|
|
218
|
+
const victims = armed.some((slot) => slot.backlog !== true) ? armed.filter((slot) => slot.backlog !== true) : armed;
|
|
187
219
|
const chosen =
|
|
188
220
|
preferred ??
|
|
189
|
-
|
|
221
|
+
victims.reduce((a, b) => ((b.armed?.seq ?? -1) > (a.armed?.seq ?? -1) ? b : a));
|
|
190
222
|
const abort = chosen.armed?.abort;
|
|
191
223
|
chosen.armed = undefined;
|
|
192
224
|
abort?.();
|
|
@@ -291,11 +323,44 @@ export class ExtractionQueueCoordinator {
|
|
|
291
323
|
|
|
292
324
|
/** Take the next queue entry whose key is not already running or reserved (FIFO within a key). */
|
|
293
325
|
private takeRunnable(): QueueEntry | undefined {
|
|
326
|
+
// Front tasks jump the queue ahead of lane bias: a fail-closed force
|
|
327
|
+
// flush must start before any queued backlog work, even when the
|
|
328
|
+
// foreground floor is open. Same-key and reserved-key checks stay in
|
|
329
|
+
// takeFirstMatching, so a front flush still waits for its own running
|
|
330
|
+
// call rather than preempting it from the selection pass.
|
|
331
|
+
if (this.queue[0]?.front === true) {
|
|
332
|
+
const front = this.takeFirstMatching((entry) => entry.front === true);
|
|
333
|
+
if (front) return front;
|
|
334
|
+
}
|
|
335
|
+
// Lane bias: foreground keeps a floor of FOREGROUND_FLOOR slots while
|
|
336
|
+
// backlog work also waits, so a claimed backlog can never crowd live
|
|
337
|
+
// sessions out entirely; backlog tasks then fill every remaining slot.
|
|
338
|
+
// Backlog never holds the last slot, so a fail-closed flush always
|
|
339
|
+
// finds either a free slot or a foreground victim and never preempts an
|
|
340
|
+
// armed drain call. (A pick-time-only cap leaks: backlog armed to the
|
|
341
|
+
// full count stays armed when the foreground task finishes.) Either
|
|
342
|
+
// lane may still use all slots when the other has work to fill them.
|
|
343
|
+
if (this.activeForeground < ExtractionQueueCoordinator.FOREGROUND_FLOOR) {
|
|
344
|
+
const foreground = this.takeFirstMatching((entry) => entry.backlog !== true);
|
|
345
|
+
if (foreground) return foreground;
|
|
346
|
+
}
|
|
347
|
+
if (this.activeBacklog < Math.max(this.concurrency - 1, 1)) {
|
|
348
|
+
const backlog = this.takeFirstMatching((entry) => entry.backlog === true);
|
|
349
|
+
if (backlog) return backlog;
|
|
350
|
+
}
|
|
351
|
+
return this.takeFirstMatching((entry) => entry.backlog !== true);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** First queue entry satisfying `match` whose key is free to run. */
|
|
355
|
+
private takeFirstMatching(match: (entry: QueueEntry) => boolean): QueueEntry | undefined {
|
|
294
356
|
for (let index = 0; index < this.queue.length; index += 1) {
|
|
295
357
|
const entry = this.queue[index];
|
|
358
|
+
if (!match(entry)) continue;
|
|
296
359
|
if (entry.key !== undefined && (this.activeKeys.has(entry.key) || this.reservedKeys.has(entry.key))) continue;
|
|
297
360
|
this.queue.splice(index, 1);
|
|
298
361
|
if (entry.key !== undefined) this.activeKeys.add(entry.key);
|
|
362
|
+
if (entry.backlog === true) this.activeBacklog += 1;
|
|
363
|
+
else this.activeForeground += 1;
|
|
299
364
|
return entry;
|
|
300
365
|
}
|
|
301
366
|
return undefined;
|
|
@@ -304,13 +369,15 @@ export class ExtractionQueueCoordinator {
|
|
|
304
369
|
/** Run one entry with its own preempt slot; failures are classified + logged. */
|
|
305
370
|
private async runEntry(entry: QueueEntry): Promise<void> {
|
|
306
371
|
const slot: PreemptSlot = {};
|
|
307
|
-
this.preemptSlots.set(slot, { key: entry.key });
|
|
372
|
+
this.preemptSlots.set(slot, { key: entry.key, backlog: entry.backlog });
|
|
308
373
|
try {
|
|
309
374
|
await entry.run(this.createPreemptHandle(slot));
|
|
310
375
|
} catch (err) {
|
|
311
376
|
this.logExtractionQueueFailure(err, "task");
|
|
312
377
|
} finally {
|
|
313
378
|
this.preemptSlots.delete(slot);
|
|
379
|
+
if (entry.backlog === true) this.activeBacklog -= 1;
|
|
380
|
+
else this.activeForeground -= 1;
|
|
314
381
|
if (entry.key !== undefined) this.activeKeys.delete(entry.key);
|
|
315
382
|
}
|
|
316
383
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { ExtractionQueueCoordinator } from "./extraction-queue-coordinator.js";
|
|
5
|
+
|
|
6
|
+
const tick = () => new Promise<void>((resolve) => setImmediate(resolve));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lane bias (backlog priority + foreground floor): claimed-backlog drain
|
|
10
|
+
* tasks fill every slot past the foreground floor whenever both lanes wait,
|
|
11
|
+
* while live foreground work can never be fully crowded out.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** One blocked task per enqueue; `started` records which lane began. */
|
|
15
|
+
function harness(concurrency: number) {
|
|
16
|
+
const queue = new ExtractionQueueCoordinator(concurrency);
|
|
17
|
+
const started: string[] = [];
|
|
18
|
+
const resolvers = new Map<string, () => void>();
|
|
19
|
+
const enqueue = (lane: "fg" | "bg", tag: string) =>
|
|
20
|
+
queue.enqueue(async () => {
|
|
21
|
+
started.push(tag);
|
|
22
|
+
await new Promise<void>((resolve) => resolvers.set(tag, resolve));
|
|
23
|
+
}, { backlog: lane === "bg" });
|
|
24
|
+
const release = (tag: string) => {
|
|
25
|
+
resolvers.get(tag)?.();
|
|
26
|
+
resolvers.delete(tag);
|
|
27
|
+
};
|
|
28
|
+
const releaseAll = () => {
|
|
29
|
+
for (const tag of [...resolvers.keys()]) release(tag);
|
|
30
|
+
};
|
|
31
|
+
return { queue, started, enqueue, release, releaseAll };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test("backlog fills every slot past the one-slot foreground floor", async () => {
|
|
35
|
+
const h = harness(4);
|
|
36
|
+
// Interleave lanes on enqueue: selection order, not arrival order, decides.
|
|
37
|
+
h.enqueue("fg", "f1");
|
|
38
|
+
h.enqueue("bg", "b1");
|
|
39
|
+
h.enqueue("fg", "f2");
|
|
40
|
+
h.enqueue("bg", "b2");
|
|
41
|
+
h.enqueue("bg", "b3");
|
|
42
|
+
h.enqueue("bg", "b4");
|
|
43
|
+
h.enqueue("fg", "f3");
|
|
44
|
+
h.enqueue("bg", "b5");
|
|
45
|
+
await tick();
|
|
46
|
+
assert.deepEqual(h.started.sort(), ["b1", "b2", "b3", "f1"],
|
|
47
|
+
"3 backlog + 1 foreground: the floor holds under full backlog pressure");
|
|
48
|
+
// A settling backlog slot refills with backlog, not the waiting foreground.
|
|
49
|
+
h.releaseAll();
|
|
50
|
+
for (let i = 0; i < 20 && h.started.length < 8; i += 1) await tick();
|
|
51
|
+
assert.deepEqual(h.started.sort(), ["b1", "b2", "b3", "b4", "b5", "f1", "f2", "f3"],
|
|
52
|
+
"every queued task settles once released — the bias delays, never drops");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("the foreground floor applies per slot at any concurrency", async () => {
|
|
56
|
+
const h = harness(2);
|
|
57
|
+
h.enqueue("bg", "b1");
|
|
58
|
+
h.enqueue("bg", "b2");
|
|
59
|
+
h.enqueue("bg", "b3");
|
|
60
|
+
h.enqueue("fg", "f1");
|
|
61
|
+
h.enqueue("fg", "f2");
|
|
62
|
+
await tick();
|
|
63
|
+
assert.deepEqual(h.started.sort(), ["b1", "f1"],
|
|
64
|
+
"concurrency 2: one slot to each lane while both wait");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("backlog alone leaves the last slot free for a flush", async () => {
|
|
68
|
+
const h = harness(4);
|
|
69
|
+
h.enqueue("bg", "b1");
|
|
70
|
+
h.enqueue("bg", "b2");
|
|
71
|
+
h.enqueue("bg", "b3");
|
|
72
|
+
h.enqueue("bg", "b4");
|
|
73
|
+
await tick();
|
|
74
|
+
assert.deepEqual(h.started, ["b1", "b2", "b3"],
|
|
75
|
+
"one slot stays open so a fail-closed flush need not preempt");
|
|
76
|
+
// A foreground (flush-path) arrival takes the free slot, not a victim.
|
|
77
|
+
h.enqueue("fg", "f1");
|
|
78
|
+
await tick();
|
|
79
|
+
assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"]);
|
|
80
|
+
// While any foreground runs, backlog may again fill every other slot.
|
|
81
|
+
h.enqueue("bg", "b5");
|
|
82
|
+
await tick();
|
|
83
|
+
assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"],
|
|
84
|
+
"no free slot while all four are armed");
|
|
85
|
+
// Releasing the foreground task must NOT let queued backlog take the
|
|
86
|
+
// freed last slot — the reserve survives foreground completion.
|
|
87
|
+
h.release("f1");
|
|
88
|
+
await tick();
|
|
89
|
+
assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"],
|
|
90
|
+
"the fourth slot stays open after foreground settles");
|
|
91
|
+
h.releaseAll();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("force-flush preemption takes a foreground victim before a backlog one", async () => {
|
|
95
|
+
const queue = new ExtractionQueueCoordinator(2);
|
|
96
|
+
const aborted: string[] = [];
|
|
97
|
+
const enqueue = (lane: "fg" | "bg", tag: string) =>
|
|
98
|
+
queue.enqueue(async (preempt) => {
|
|
99
|
+
preempt?.arm(() => aborted.push(tag));
|
|
100
|
+
await new Promise<void>(() => {}); // never settles
|
|
101
|
+
}, { backlog: lane === "bg" });
|
|
102
|
+
enqueue("bg", "b1");
|
|
103
|
+
enqueue("fg", "f1");
|
|
104
|
+
await tick();
|
|
105
|
+
// Both slots armed: the flush has no same-key match and must pick a victim.
|
|
106
|
+
queue.preemptRunning("unrelated-key");
|
|
107
|
+
await tick();
|
|
108
|
+
assert.deepEqual(aborted, ["f1"],
|
|
109
|
+
"the foreground slot dies first — backlog chunk calls survive routine flushes");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a same-key armed backlog slot still loses to the flush", async () => {
|
|
113
|
+
const queue = new ExtractionQueueCoordinator(2);
|
|
114
|
+
const aborted: string[] = [];
|
|
115
|
+
queue.enqueue(async (preempt) => {
|
|
116
|
+
preempt?.arm(() => aborted.push("bg"));
|
|
117
|
+
await new Promise<void>(() => {});
|
|
118
|
+
}, { backlog: true, key: "k1" });
|
|
119
|
+
await tick();
|
|
120
|
+
queue.preemptRunning("k1");
|
|
121
|
+
await tick();
|
|
122
|
+
assert.deepEqual(aborted, ["bg"],
|
|
123
|
+
"same-key correctness beats the lane preference");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("foreground keeps all slots when no backlog work is queued", async () => {
|
|
127
|
+
const h = harness(4);
|
|
128
|
+
h.enqueue("fg", "f1");
|
|
129
|
+
h.enqueue("fg", "f2");
|
|
130
|
+
h.enqueue("fg", "f3");
|
|
131
|
+
await tick();
|
|
132
|
+
assert.deepEqual(h.started, ["f1", "f2", "f3"],
|
|
133
|
+
"foreground-only traffic is unaffected by the lane tag");
|
|
134
|
+
h.releaseAll();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("a front flush starts before queued backlog work", async () => {
|
|
138
|
+
const queue = new ExtractionQueueCoordinator(2);
|
|
139
|
+
const started: string[] = [];
|
|
140
|
+
const resolvers = new Map<string, () => void>();
|
|
141
|
+
const enqueue = (tag: string, options?: { backlog?: boolean; front?: boolean; key?: string }) =>
|
|
142
|
+
queue.enqueue(async () => {
|
|
143
|
+
started.push(tag);
|
|
144
|
+
await new Promise<void>((resolve) => resolvers.set(tag, resolve));
|
|
145
|
+
}, options);
|
|
146
|
+
const release = (tag: string) => resolvers.get(tag)?.();
|
|
147
|
+
enqueue("fg", { key: "fg" });
|
|
148
|
+
enqueue("hold", { key: "hold" });
|
|
149
|
+
await tick();
|
|
150
|
+
enqueue("bl", { backlog: true, key: "bl" });
|
|
151
|
+
enqueue("flush", { front: true, key: "flush" });
|
|
152
|
+
// Both slots are full until hold ends. Releasing it is what lets the
|
|
153
|
+
// front flush start; the queued backlog must not take that slot.
|
|
154
|
+
release("hold");
|
|
155
|
+
await tick();
|
|
156
|
+
assert.deepEqual(started, ["fg", "hold", "flush"],
|
|
157
|
+
"front flush must run before queued backlog: actual " + started.join(","));
|
|
158
|
+
for (const tag of [...resolvers.keys()]) release(tag);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("a front flush starts before queued backlog work (CodeRabbit Major, pure-backlog)", async () => {
|
|
162
|
+
const queue = new ExtractionQueueCoordinator(2);
|
|
163
|
+
const started: string[] = [];
|
|
164
|
+
const resolvers = new Map<string, () => void>();
|
|
165
|
+
const enqueue = (tag: string, options?: { backlog?: boolean; front?: boolean; key?: string }) =>
|
|
166
|
+
queue.enqueue(async () => {
|
|
167
|
+
started.push(tag);
|
|
168
|
+
await new Promise<void>((resolve) => resolvers.set(tag, resolve));
|
|
169
|
+
}, options);
|
|
170
|
+
const release = (tag: string) => resolvers.get(tag)?.();
|
|
171
|
+
enqueue("bl", { backlog: true, key: "bl" });
|
|
172
|
+
enqueue("bl2", { backlog: true, key: "bl2" });
|
|
173
|
+
enqueue("bl3", { backlog: true, key: "bl3" });
|
|
174
|
+
await tick();
|
|
175
|
+
// The fail-closed flush lands at the head after the backlog is queued.
|
|
176
|
+
enqueue("flush", { front: true, key: "flush" });
|
|
177
|
+
await tick();
|
|
178
|
+
// The flush must start before queued backlog work even with the foreground
|
|
179
|
+
// floor open (the lane check previously denied the front flag).
|
|
180
|
+
assert.deepEqual(started, ["bl", "flush"],
|
|
181
|
+
"front flush starts ahead of queued backlog work");
|
|
182
|
+
release("bl");
|
|
183
|
+
release("bl2");
|
|
184
|
+
release("flush");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("a front flush takes the free slot instead of killing armed backlog", async () => {
|
|
188
|
+
const queue = new ExtractionQueueCoordinator(4);
|
|
189
|
+
const aborted: string[] = [];
|
|
190
|
+
const started: string[] = [];
|
|
191
|
+
for (const tag of ["b1", "b2", "b3"]) {
|
|
192
|
+
queue.enqueue(async (preempt) => {
|
|
193
|
+
started.push(tag);
|
|
194
|
+
preempt?.arm(() => aborted.push(tag));
|
|
195
|
+
await new Promise<void>(() => {}); // never settles
|
|
196
|
+
}, { backlog: true });
|
|
197
|
+
}
|
|
198
|
+
await tick();
|
|
199
|
+
assert.deepEqual(started, ["b1", "b2", "b3"]);
|
|
200
|
+
// The invariant reserve leaves one slot free; the flush must use it
|
|
201
|
+
// rather than aborting an armed backlog task.
|
|
202
|
+
queue.enqueue(async () => { started.push("flush"); }, { front: true });
|
|
203
|
+
for (let i = 0; i < 10 && !started.includes("flush"); i += 1) await tick();
|
|
204
|
+
assert.deepEqual(aborted, [], "no victim while a free slot exists");
|
|
205
|
+
assert.deepEqual(started, ["b1", "b2", "b3", "flush"], "the flush ran in the reserved slot");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("a front flush beats queued backlog when the foreground floor is met", async () => {
|
|
209
|
+
const h = harness(2);
|
|
210
|
+
h.enqueue("fg", "f1");
|
|
211
|
+
await tick();
|
|
212
|
+
assert.deepEqual(h.started, ["f1"]);
|
|
213
|
+
// Backlog queued first, then a force flush jumps the queue: front
|
|
214
|
+
// priority outranks the backlog preference for ordinary queued tasks.
|
|
215
|
+
h.enqueue("bg", "b1");
|
|
216
|
+
h.queue.enqueue(async () => { h.started.push("flush"); }, { front: true });
|
|
217
|
+
for (let i = 0; i < 10 && !h.started.includes("flush"); i += 1) await tick();
|
|
218
|
+
assert.deepEqual(h.started.slice(0, 2), ["f1", "flush"],
|
|
219
|
+
"the flush wins the second slot over the queued backlog task");
|
|
220
|
+
});
|
|
@@ -4,6 +4,7 @@ import { resolveMemoryLifecycleCapabilities, resolveRecallEnhancementCapabilitie
|
|
|
4
4
|
import { log } from "../logger.js";
|
|
5
5
|
import type { ExtractionRunResult } from "./extraction-run.js";
|
|
6
6
|
import type { ExtractionEngine } from "../extraction.js";
|
|
7
|
+
import { memoizeExistingEntities, type ExistingEntitiesSource } from "../extraction-entities-source.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Count of durable outputs an extraction result asks persistence to write
|
|
@@ -411,7 +412,7 @@ export async function extractChunkedExtraction(
|
|
|
411
412
|
engine: Pick<ExtractionEngine, "extract">,
|
|
412
413
|
config: PluginConfig,
|
|
413
414
|
turns: BufferTurn[],
|
|
414
|
-
existingEntities:
|
|
415
|
+
existingEntities: ExistingEntitiesSource,
|
|
415
416
|
signal?: AbortSignal,
|
|
416
417
|
): Promise<ExtractionResult> {
|
|
417
418
|
const budget = config.extractionPromptMaxChars;
|
|
@@ -438,11 +439,17 @@ export async function extractChunkedExtraction(
|
|
|
438
439
|
entities: [],
|
|
439
440
|
questions: [],
|
|
440
441
|
};
|
|
441
|
-
|
|
442
|
+
// Carry-forward names found in earlier chunks flow into every later
|
|
443
|
+
// fallback call: the base listing resolves once (memoized), while
|
|
444
|
+
// `foundNames` re-spreads on each call so names found after a first
|
|
445
|
+
// fallback still reach subsequent fallback chunks.
|
|
446
|
+
const foundNames: string[] = [];
|
|
447
|
+
const baseEntities = memoizeExistingEntities(existingEntities);
|
|
448
|
+
const carryForward = async () => [...(await baseEntities()), ...foundNames];
|
|
442
449
|
let skippedReason: ExtractionResult["extractionSkippedReason"];
|
|
443
450
|
let providerCalls = 0;
|
|
444
451
|
for (const chunk of chunks) {
|
|
445
|
-
const part = await engine.extract(chunk,
|
|
452
|
+
const part = await engine.extract(chunk, carryForward, signal);
|
|
446
453
|
// A provider failure keeps the single-call surface so the run stays
|
|
447
454
|
// retryable under the no-drop contract; a per-chunk prefilter skip is
|
|
448
455
|
// not a failure — later chunks can still carry real facts.
|
|
@@ -463,7 +470,7 @@ export async function extractChunkedExtraction(
|
|
|
463
470
|
merged.episodeTitle ??= part.episodeTitle;
|
|
464
471
|
// Entity names found in earlier chunks flow into later calls so the
|
|
465
472
|
// LLM reuses them instead of inventing variants.
|
|
466
|
-
|
|
473
|
+
foundNames.push(...part.entities.map((entity) => entity.name));
|
|
467
474
|
}
|
|
468
475
|
// The connector must derive from the whole claim, not the first chunk —
|
|
469
476
|
// a mixed claim resolves to no connector, same as one call over the set.
|
|
@@ -362,18 +362,6 @@ test("runExtraction bounds storage preparation by its deadline", async () => {
|
|
|
362
362
|
};
|
|
363
363
|
},
|
|
364
364
|
},
|
|
365
|
-
{
|
|
366
|
-
name: "listEntityNames",
|
|
367
|
-
stage: "during_list_entity_names",
|
|
368
|
-
configure: async (harness: Harness) => {
|
|
369
|
-
const storage = await harness.storageForNs("default");
|
|
370
|
-
const listEntityNames = storage.listEntityNames.bind(storage);
|
|
371
|
-
storage.listEntityNames = async () => {
|
|
372
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
373
|
-
return listEntityNames();
|
|
374
|
-
};
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
365
|
] as const;
|
|
378
366
|
|
|
379
367
|
for (const scenario of scenarios) {
|
|
@@ -439,6 +427,29 @@ test("runExtraction force flush reports a late deadline after clearing committed
|
|
|
439
427
|
}
|
|
440
428
|
});
|
|
441
429
|
|
|
430
|
+
test("runExtraction does not list entity names on the local extraction path", async () => {
|
|
431
|
+
const harness = await makeHarness();
|
|
432
|
+
try {
|
|
433
|
+
const storage = await harness.storageForNs("default");
|
|
434
|
+
let listCalls = 0;
|
|
435
|
+
storage.listEntityNames = async () => {
|
|
436
|
+
listCalls += 1;
|
|
437
|
+
return new Promise<string[]>(() => {});
|
|
438
|
+
};
|
|
439
|
+
harness.setRespond(() => successResult());
|
|
440
|
+
const result = await harness.newCoordinator().runExtraction(makeTurns("lazy-entities"), {
|
|
441
|
+
skipCharThreshold: true,
|
|
442
|
+
skipUserTurnThreshold: true,
|
|
443
|
+
clearBufferAfterExtraction: false,
|
|
444
|
+
bufferKey: "lazy-entities",
|
|
445
|
+
});
|
|
446
|
+
assert.equal(listCalls, 0, "local-path extraction must not list the entity store");
|
|
447
|
+
assert.equal(result.status, "completed");
|
|
448
|
+
} finally {
|
|
449
|
+
await harness.cleanup();
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
442
453
|
test("runExtraction bounds threading pre-persist work by its deadline", async () => {
|
|
443
454
|
const harness = await makeHarness({ threadingEnabled: true });
|
|
444
455
|
try {
|
|
@@ -847,14 +847,15 @@ export class ExtractionRunCoordinator {
|
|
|
847
847
|
log.warn("runExtraction: extraction retry gate check failed; proceeding (fail-open)", err);
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
//
|
|
850
|
+
// Lazy entity list. A half-open probe lists first so a slow store cannot
|
|
851
|
+
// reopen the breaker. false keeps the deadline if extract() absorbs the error.
|
|
851
852
|
// The probe owner must release on ANY pre-persistence exit too (codex P1):
|
|
852
853
|
// the big try below only covers from the extract call onward.
|
|
853
854
|
try {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
"during_list_entity_names",
|
|
857
|
-
);
|
|
855
|
+
let entityNamesPromise: Promise<string[]> | undefined;
|
|
856
|
+
const existingEntities = (): Promise<string[]> =>
|
|
857
|
+
(entityNamesPromise ??= runDeadlineAware(() => storage.listEntityNames(), "during_list_entity_names", false));
|
|
858
|
+
if (extractionProbeOwned) await existingEntities();
|
|
858
859
|
let result: ExtractionResult;
|
|
859
860
|
// The half-open probe is bounded: one that gets no answer in time counts as
|
|
860
861
|
// a provider failure (re-opens the breaker) instead of holding every other
|
|
@@ -1013,7 +1013,13 @@ export class TurnIngestionCoordinator {
|
|
|
1013
1013
|
if (sharingNode) this.snapshotSharing.release(sharingNode);
|
|
1014
1014
|
exit.report();
|
|
1015
1015
|
}
|
|
1016
|
-
}, {
|
|
1016
|
+
}, {
|
|
1017
|
+
front: options.preemptRunning === true,
|
|
1018
|
+
key: bufferKey,
|
|
1019
|
+
// Claim/drain tasks (options.execution carries the claim-backed buffer)
|
|
1020
|
+
// take the backlog lane: biased to fill all-but-foreground-floor slots.
|
|
1021
|
+
backlog: options.execution !== undefined,
|
|
1022
|
+
});
|
|
1017
1023
|
if (!accepted) {
|
|
1018
1024
|
if (sharingNode) this.snapshotSharing.release(sharingNode);
|
|
1019
1025
|
settleTask(new Error("extraction queue is stopped"));
|