@volter/world-core 3.0.156 → 3.0.157
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/attach.cjs +2 -0
- package/capability-decision.cjs +6 -4
- package/dist/attach.cjs +2 -0
- package/dist/capability-decision.cjs +6 -4
- package/dist/generated/pack-facts.json +77 -8
- package/dist/network-policy.cjs +11 -1
- package/dist/network-policy.d.cts +1 -0
- package/dist/pack-facts.d.cts +3 -0
- package/dist/required-credential-transport.cjs +29 -0
- package/dist/required-credential-transport.d.cts +3 -0
- package/dist/src/blob-store.d.ts +16 -0
- package/dist/src/blob-store.js +76 -1
- package/dist/src/derived-core.d.ts +72 -6
- package/dist/src/derived-core.js +192 -51
- package/dist/src/derived-real.js +97 -15
- package/dist/src/derived.d.ts +5 -0
- package/dist/src/executor.d.ts +7 -0
- package/dist/src/executor.js +15 -1
- package/dist/src/git/lfs.d.ts +13 -3
- package/dist/src/git/lfs.js +41 -9
- package/dist/src/head.d.ts +2 -0
- package/dist/src/head.js +6 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/live/ingest.js +9 -13
- package/dist/src/live/rtmp.js +7 -5
- package/dist/src/live/segmenter.js +7 -1
- package/dist/src/machines.js +5 -1
- package/dist/src/managed-go-programs.d.ts +55 -0
- package/dist/src/managed-go-programs.js +133 -0
- package/dist/src/mongodb/stream.d.ts +23 -0
- package/dist/src/pack-fetch.d.ts +6 -1
- package/dist/src/pack-fetch.js +49 -6
- package/dist/src/pack-paths.d.ts +2 -1
- package/dist/src/pack-paths.js +6 -1
- package/dist/src/resource-blob.d.ts +4 -0
- package/dist/src/resource-blob.js +8 -1
- package/dist/src/runtime.d.ts +3 -3
- package/dist/src/runtime.js +2 -2
- package/dist/src/serve-http.js +53 -3
- package/dist/src/sockets.d.ts +4 -1
- package/dist/src/sockets.js +59 -6
- package/dist/src/vendor-call.js +58 -0
- package/dist/src/world-store.d.ts +15 -1
- package/dist/src/world-store.js +78 -2
- package/generated/pack-facts.json +77 -8
- package/network-policy.cjs +11 -1
- package/network-policy.d.cts +1 -0
- package/pack-facts.d.cts +3 -0
- package/package.json +8 -1
- package/required-credential-transport.cjs +29 -0
- package/required-credential-transport.d.cts +3 -0
- package/src/blob-store.ts +59 -1
- package/src/derived-core.ts +215 -51
- package/src/derived-real.ts +80 -14
- package/src/derived.ts +6 -1
- package/src/executor.ts +17 -3
- package/src/git/lfs.ts +40 -9
- package/src/head.ts +6 -0
- package/src/index.ts +1 -0
- package/src/live/ingest.ts +7 -3
- package/src/live/rtmp.ts +7 -5
- package/src/live/segmenter.ts +7 -1
- package/src/machines.ts +5 -1
- package/src/managed-go-programs.ts +146 -0
- package/src/mongodb/stream.ts +10 -0
- package/src/pack-fetch.ts +46 -8
- package/src/pack-paths.ts +5 -1
- package/src/resource-blob.ts +9 -1
- package/src/runtime.ts +4 -2
- package/src/serve-http.ts +43 -3
- package/src/sockets.ts +39 -8
- package/src/vendor-call.ts +54 -0
- package/src/world-store.ts +66 -2
package/src/world-store.ts
CHANGED
|
@@ -52,6 +52,40 @@ import { randomUUID } from 'node:crypto';
|
|
|
52
52
|
import { refuseReadOnlyWrite } from './request-scope.ts';
|
|
53
53
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
54
54
|
|
|
55
|
+
// WHAT A LOCK HOLD ASKS (architecture, "What a hold asks is counted"): the file
|
|
56
|
+
// store's questions counted inside an outermost lock hold and outside one, said at each outermost release where
|
|
57
|
+
// VOLTER_TWIN_LOG=1 (storage.ts twinLog's gate and line), and not counted otherwise. Each counter counts the calls of
|
|
58
|
+
// its own method: a readKept that misses its kept text, or meets a link, also counts the read it makes. A hold's
|
|
59
|
+
// `heldMs` is the time of the hold's body, run once the lock is taken and before it is released, as the lock's release
|
|
60
|
+
// line times its hold; the wait before the take is the wait line's `waitedMs`.
|
|
61
|
+
const QUESTION_KINDS = ['generation', 'read', 'readKept', 'stat', 'exists', 'list', 'append'] as const;
|
|
62
|
+
type QuestionCounts = Record<(typeof QUESTION_KINDS)[number], number>;
|
|
63
|
+
// Read once, where a process is: a realm with none counts nothing.
|
|
64
|
+
const questionsCounted = typeof process !== 'undefined' && process.env?.VOLTER_TWIN_LOG === '1';
|
|
65
|
+
const noQuestions = (): QuestionCounts => ({ generation: 0, read: 0, readKept: 0, stat: 0, exists: 0, list: 0, append: 0 });
|
|
66
|
+
let lockHoldDepth = 0;
|
|
67
|
+
let questionsHeld = noQuestions();
|
|
68
|
+
let questionsUnheld = noQuestions();
|
|
69
|
+
function asked(kind: (typeof QUESTION_KINDS)[number]): void {
|
|
70
|
+
if (questionsCounted) (lockHoldDepth > 0 ? questionsHeld : questionsUnheld)[kind] += 1;
|
|
71
|
+
}
|
|
72
|
+
function countedHold<T>(operation: string, fn: () => T): () => T {
|
|
73
|
+
if (!questionsCounted) return fn;
|
|
74
|
+
return () => {
|
|
75
|
+
const began = Date.now();
|
|
76
|
+
lockHoldDepth += 1;
|
|
77
|
+
try { return fn(); }
|
|
78
|
+
finally {
|
|
79
|
+
lockHoldDepth -= 1;
|
|
80
|
+
if (lockHoldDepth === 0) {
|
|
81
|
+
const held = questionsHeld, before = questionsUnheld;
|
|
82
|
+
questionsHeld = noQuestions(); questionsUnheld = noQuestions();
|
|
83
|
+
try { console.error('[twin:store-lock]', JSON.stringify({ operation, heldMs: Date.now() - began, held, before })); } catch { /* an instrument */ }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
55
89
|
/** Metadata a caller needs about a stored path. `isDirectory` distinguishes a JSON
|
|
56
90
|
* sidecar from a per-service subdir (validate/scrub walk on it); `size`+`mtimeMs`
|
|
57
91
|
* drive the append-dedupe index's cache-validity check in storage.ts. */
|
|
@@ -60,9 +94,31 @@ export type WorldStat = { size: number; mtimeMs: number; isDirectory: boolean; i
|
|
|
60
94
|
/** Diagnostic context only; it does not change lock acquisition or stale-owner policy. */
|
|
61
95
|
export type WorldLockOptions = { retainLiveOwner?: boolean; operation?: string; caller?: string };
|
|
62
96
|
|
|
63
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Capture at the outermost lock helper, then carry the same caller through nested helpers.
|
|
99
|
+
* LIMIT THE CAPTURE TO THE FRAMES READ (browser-substrate S2 R44, AC-LC3): V8's third frame supplies the caller,
|
|
100
|
+
* while new Error().stack normally collects up to Error.stackTraceLimit frames (ten by default).
|
|
101
|
+
* Retained browser-substrate LibreChat World-realm warm-up profiles 73/74 from runs 36c6d279 and 991f63e7e
|
|
102
|
+
* attributed about 10-57 ms self/inclusive to storageLockScope over each full 13.3-13.4 second profile window.
|
|
103
|
+
* Samples are about 5 ms apart. Those totals include this helper's capture, string and regex work; they are
|
|
104
|
+
* neither isolated capture time nor the credential doors' share. The co-located host serves doors on one loop.
|
|
105
|
+
* Original profiles are under /Users/aaronclaw/heavy-lead/librechat/logs-kept/:
|
|
106
|
+
* librechat-sn-36c6d279-e9e2632a-004051/cpuprofile/ (SHA256 prefixes 04dfc4fe, 77df6e8e) and
|
|
107
|
+
* librechat-sn-991f63e7e/cpuprofile/ (be6c6a93, 2fe80e7c), realms 73 and 74 respectively.
|
|
108
|
+
* The limit is lowered to three only for Error's own writable numeric data property above three, and restored
|
|
109
|
+
* only when lowered. Absent, accessor, non-writable and lower limits receive no writes. Existing constructor
|
|
110
|
+
* and user stack-formatter failure paths remain; this diagnostic optimization changes no lock ownership rule.
|
|
111
|
+
*/
|
|
64
112
|
export function storageLockScope(options: WorldLockOptions = {}): WorldLockOptions & { operation: string; caller: string } {
|
|
65
|
-
|
|
113
|
+
let frame: string | undefined;
|
|
114
|
+
if (!options.caller) {
|
|
115
|
+
const held = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
|
|
116
|
+
const lowered = held !== undefined && 'value' in held && held.writable === true
|
|
117
|
+
&& typeof held.value === 'number' && held.value > 3;
|
|
118
|
+
if (lowered) Error.stackTraceLimit = 3;
|
|
119
|
+
try { frame = new Error().stack?.split('\n')[3]; }
|
|
120
|
+
finally { if (lowered) Error.stackTraceLimit = held!.value as number; }
|
|
121
|
+
}
|
|
66
122
|
const location = frame?.slice(frame.lastIndexOf('(') + 1).trim().replace(/^at\s+/, '');
|
|
67
123
|
const site = location?.match(/^(.*):(\d+):\d+\)?$/);
|
|
68
124
|
const caller = options.caller ?? (site ? `${site[1]!.replace(/^file:\/\//, '')}:${site[2]}` : 'unknown:0');
|
|
@@ -555,6 +611,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
555
611
|
// pays a kernel exchange for each, and a tree's stamp is a handful of these on every operation: Twenty's Redis twin
|
|
556
612
|
// spent 54 s of 136 in `existsSync` and `statSync` under `treeStamp`, and its server's requests waited on it.
|
|
557
613
|
read(path: string): string | null {
|
|
614
|
+
asked('read');
|
|
558
615
|
try { return readFileSync(path, 'utf8'); }
|
|
559
616
|
catch (error) { if (absent(error)) return null; throw error; }
|
|
560
617
|
}
|
|
@@ -572,6 +629,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
572
629
|
*/
|
|
573
630
|
private readonly kept = new Map<string, { key: string; text: string }>();
|
|
574
631
|
readKept(path: string): string | null {
|
|
632
|
+
asked('readKept');
|
|
575
633
|
// A missing file is asked for without an error being made of it: a World with no parent has no branch.json, and
|
|
576
634
|
// every stamp asks.
|
|
577
635
|
let own: Stats | undefined;
|
|
@@ -613,6 +671,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
613
671
|
* World with a parent: its view and its ancestors' logs) is never kept under a generation (log.ts).
|
|
614
672
|
*/
|
|
615
673
|
generation(dirPath: string): string | null {
|
|
674
|
+
asked('generation');
|
|
616
675
|
let own: Stats | undefined;
|
|
617
676
|
try { own = lstatSync(join(dirPath, TREE_GENERATION), { throwIfNoEntry: false }); }
|
|
618
677
|
catch (error) { if (!absent(error)) throw error; }
|
|
@@ -661,6 +720,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
661
720
|
}
|
|
662
721
|
|
|
663
722
|
append(path: string, data: string): void {
|
|
723
|
+
asked('append');
|
|
664
724
|
refuseReadOnlyWrite('the World'); // a read-only request writes nothing, whatever path it takes to the store
|
|
665
725
|
this.kept.delete(path);
|
|
666
726
|
// A tree's file in a tab: the generation's byte, the append and the byte again as one request of the kernel
|
|
@@ -712,6 +772,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
712
772
|
}
|
|
713
773
|
|
|
714
774
|
exists(path: string): boolean {
|
|
775
|
+
asked('exists');
|
|
715
776
|
return existsSync(path);
|
|
716
777
|
}
|
|
717
778
|
|
|
@@ -726,6 +787,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
726
787
|
}
|
|
727
788
|
|
|
728
789
|
list(dirPath: string): string[] {
|
|
790
|
+
asked('list');
|
|
729
791
|
try { return readdirSync(dirPath); }
|
|
730
792
|
catch (error) {
|
|
731
793
|
// No such directory is an empty one, as before; a path that IS there and is not a directory still fails.
|
|
@@ -750,6 +812,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
750
812
|
}
|
|
751
813
|
|
|
752
814
|
stat(path: string): WorldStat | null {
|
|
815
|
+
asked('stat');
|
|
753
816
|
// The path itself first: where it is no link, that is the whole answer. A link is followed by a second call,
|
|
754
817
|
// and one that leads nowhere is absent, as it was.
|
|
755
818
|
// Asked without an error being made of a missing path (a tree's parent log is absent in a World with no parent).
|
|
@@ -771,6 +834,7 @@ export class FsWorldStore implements WorldStore {
|
|
|
771
834
|
withLock<T>(lockPath: string, fn: () => T, options: WorldLockOptions = {}): T {
|
|
772
835
|
const started = Date.now();
|
|
773
836
|
const scope = storageLockScope(options);
|
|
837
|
+
fn = countedHold(scope.operation, fn);
|
|
774
838
|
let fd: number | null = null;
|
|
775
839
|
// A kernel's file step takes the lock with its record in one request and keeps no descriptor (fileSteps).
|
|
776
840
|
const steps = fileSteps();
|