@volter/world-core 3.0.155 → 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.
Files changed (150) hide show
  1. package/attach.cjs +2 -0
  2. package/capability-decision.cjs +6 -4
  3. package/dist/attach.cjs +2 -0
  4. package/dist/capability-decision.cjs +6 -4
  5. package/dist/generated/pack-facts.json +204 -4
  6. package/dist/inject.cjs +150 -86
  7. package/dist/network-policy.cjs +11 -1
  8. package/dist/network-policy.d.cts +1 -0
  9. package/dist/pack-facts.d.cts +3 -0
  10. package/dist/required-credential-transport.cjs +29 -0
  11. package/dist/required-credential-transport.d.cts +3 -0
  12. package/dist/src/actions.d.ts +15 -0
  13. package/dist/src/actions.js +82 -21
  14. package/dist/src/ancestry.d.ts +5 -4
  15. package/dist/src/ancestry.js +53 -28
  16. package/dist/src/blob-store.d.ts +16 -0
  17. package/dist/src/blob-store.js +76 -1
  18. package/dist/src/changeset.js +1 -1
  19. package/dist/src/clickhouse/compression.d.ts +28 -0
  20. package/dist/src/clickhouse/compression.js +281 -0
  21. package/dist/src/clickhouse/index.d.ts +1 -0
  22. package/dist/src/clickhouse/index.js +1 -0
  23. package/dist/src/derived-core.d.ts +84 -7
  24. package/dist/src/derived-core.js +336 -61
  25. package/dist/src/derived-real.js +97 -15
  26. package/dist/src/derived.d.ts +5 -0
  27. package/dist/src/derived.js +3 -0
  28. package/dist/src/executor.d.ts +7 -0
  29. package/dist/src/executor.js +15 -1
  30. package/dist/src/fork.js +1 -1
  31. package/dist/src/git/lfs.d.ts +13 -3
  32. package/dist/src/git/lfs.js +41 -9
  33. package/dist/src/grpc-wire.js +2 -1
  34. package/dist/src/h2.js +63 -10
  35. package/dist/src/head.d.ts +5 -0
  36. package/dist/src/head.js +15 -0
  37. package/dist/src/history.d.ts +1 -1
  38. package/dist/src/history.js +7 -7
  39. package/dist/src/index.d.ts +5 -1
  40. package/dist/src/index.js +6 -1
  41. package/dist/src/live/ingest.js +9 -13
  42. package/dist/src/live/rtmp.js +7 -5
  43. package/dist/src/live/segmenter.js +7 -1
  44. package/dist/src/log.d.ts +23 -3
  45. package/dist/src/log.js +160 -37
  46. package/dist/src/machines.js +5 -1
  47. package/dist/src/managed-go-programs.d.ts +55 -0
  48. package/dist/src/managed-go-programs.js +133 -0
  49. package/dist/src/managed-original-inputs.d.ts +101 -0
  50. package/dist/src/managed-original-inputs.js +125 -0
  51. package/dist/src/mongodb/client.d.ts +8 -0
  52. package/dist/src/mongodb/client.js +27 -0
  53. package/dist/src/mongodb/index.d.ts +2 -0
  54. package/dist/src/mongodb/index.js +5 -0
  55. package/dist/src/mongodb/stream.d.ts +97 -0
  56. package/dist/src/mongodb/stream.js +206 -0
  57. package/dist/src/observe.js +1 -1
  58. package/dist/src/pack-fetch.d.ts +6 -1
  59. package/dist/src/pack-fetch.js +69 -14
  60. package/dist/src/pack-paths.d.ts +2 -1
  61. package/dist/src/pack-paths.js +6 -1
  62. package/dist/src/packRegistry.d.ts +10 -14
  63. package/dist/src/packRegistry.js +2 -13
  64. package/dist/src/protocol.d.ts +13 -0
  65. package/dist/src/protocol.js +13 -0
  66. package/dist/src/redis/engine.d.ts +10 -4
  67. package/dist/src/redis/engine.js +103 -32
  68. package/dist/src/redis/member-storage.js +20 -8
  69. package/dist/src/redis/service-times.d.ts +25 -0
  70. package/dist/src/redis/service-times.js +87 -0
  71. package/dist/src/redis/stream.d.ts +2 -1
  72. package/dist/src/redis/stream.js +109 -20
  73. package/dist/src/resource-blob.d.ts +4 -0
  74. package/dist/src/resource-blob.js +8 -1
  75. package/dist/src/runtime-state.d.ts +11 -0
  76. package/dist/src/runtime-state.js +13 -0
  77. package/dist/src/runtime.d.ts +7 -5
  78. package/dist/src/runtime.js +7 -4
  79. package/dist/src/serve-http.d.ts +2 -0
  80. package/dist/src/serve-http.js +73 -6
  81. package/dist/src/serve.d.ts +10 -0
  82. package/dist/src/serve.js +43 -3
  83. package/dist/src/sockets.d.ts +4 -1
  84. package/dist/src/sockets.js +59 -6
  85. package/dist/src/storage.d.ts +2 -1
  86. package/dist/src/storage.js +6 -3
  87. package/dist/src/vendor-call.js +58 -0
  88. package/dist/src/world-boot.d.ts +1 -0
  89. package/dist/src/world-boot.js +6 -0
  90. package/dist/src/world-clock.js +6 -2
  91. package/dist/src/world-store.d.ts +122 -7
  92. package/dist/src/world-store.js +959 -103
  93. package/dist/src/xml.d.ts +30 -0
  94. package/dist/src/xml.js +74 -0
  95. package/generated/pack-facts.json +204 -4
  96. package/inject.cjs +150 -86
  97. package/network-policy.cjs +11 -1
  98. package/network-policy.d.cts +1 -0
  99. package/pack-facts.d.cts +3 -0
  100. package/package.json +27 -1
  101. package/required-credential-transport.cjs +29 -0
  102. package/required-credential-transport.d.cts +3 -0
  103. package/src/actions.ts +78 -21
  104. package/src/ancestry.ts +46 -24
  105. package/src/blob-store.ts +59 -1
  106. package/src/changeset.ts +1 -1
  107. package/src/clickhouse/compression.ts +172 -0
  108. package/src/clickhouse/index.ts +2 -0
  109. package/src/derived-core.ts +356 -61
  110. package/src/derived-real.ts +80 -14
  111. package/src/derived.ts +9 -1
  112. package/src/executor.ts +17 -3
  113. package/src/fork.ts +1 -1
  114. package/src/git/lfs.ts +40 -9
  115. package/src/grpc-wire.ts +2 -1
  116. package/src/h2.ts +46 -5
  117. package/src/head.ts +15 -0
  118. package/src/history.ts +7 -7
  119. package/src/index.ts +7 -1
  120. package/src/live/ingest.ts +7 -3
  121. package/src/live/rtmp.ts +7 -5
  122. package/src/live/segmenter.ts +7 -1
  123. package/src/log.ts +147 -32
  124. package/src/machines.ts +5 -1
  125. package/src/managed-go-programs.ts +146 -0
  126. package/src/managed-original-inputs.ts +163 -0
  127. package/src/mongodb/client.ts +27 -0
  128. package/src/mongodb/index.ts +5 -0
  129. package/src/mongodb/stream.ts +223 -0
  130. package/src/observe.ts +1 -1
  131. package/src/pack-fetch.ts +66 -16
  132. package/src/pack-paths.ts +5 -1
  133. package/src/packRegistry.ts +3 -15
  134. package/src/protocol.ts +13 -0
  135. package/src/redis/engine.ts +100 -57
  136. package/src/redis/member-storage.ts +17 -9
  137. package/src/redis/service-times.ts +81 -0
  138. package/src/redis/stream.ts +66 -14
  139. package/src/resource-blob.ts +9 -1
  140. package/src/runtime-state.ts +14 -0
  141. package/src/runtime.ts +10 -3
  142. package/src/serve-http.ts +65 -6
  143. package/src/serve.ts +45 -3
  144. package/src/sockets.ts +39 -8
  145. package/src/storage.ts +5 -3
  146. package/src/vendor-call.ts +54 -0
  147. package/src/world-boot.ts +6 -0
  148. package/src/world-clock.ts +6 -2
  149. package/src/world-store.ts +768 -91
  150. package/src/xml.ts +71 -0
@@ -7,6 +7,31 @@ export type WorldStat = {
7
7
  isDirectory: boolean;
8
8
  isSymbolicLink?: boolean;
9
9
  };
10
+ /** Diagnostic context only; it does not change lock acquisition or stale-owner policy. */
11
+ export type WorldLockOptions = {
12
+ retainLiveOwner?: boolean;
13
+ operation?: string;
14
+ caller?: string;
15
+ };
16
+ /**
17
+ * Capture at the outermost lock helper, then carry the same caller through nested helpers.
18
+ * LIMIT THE CAPTURE TO THE FRAMES READ (browser-substrate S2 R44, AC-LC3): V8's third frame supplies the caller,
19
+ * while new Error().stack normally collects up to Error.stackTraceLimit frames (ten by default).
20
+ * Retained browser-substrate LibreChat World-realm warm-up profiles 73/74 from runs 36c6d279 and 991f63e7e
21
+ * attributed about 10-57 ms self/inclusive to storageLockScope over each full 13.3-13.4 second profile window.
22
+ * Samples are about 5 ms apart. Those totals include this helper's capture, string and regex work; they are
23
+ * neither isolated capture time nor the credential doors' share. The co-located host serves doors on one loop.
24
+ * Original profiles are under /Users/aaronclaw/heavy-lead/librechat/logs-kept/:
25
+ * librechat-sn-36c6d279-e9e2632a-004051/cpuprofile/ (SHA256 prefixes 04dfc4fe, 77df6e8e) and
26
+ * librechat-sn-991f63e7e/cpuprofile/ (be6c6a93, 2fe80e7c), realms 73 and 74 respectively.
27
+ * The limit is lowered to three only for Error's own writable numeric data property above three, and restored
28
+ * only when lowered. Absent, accessor, non-writable and lower limits receive no writes. Existing constructor
29
+ * and user stack-formatter failure paths remain; this diagnostic optimization changes no lock ownership rule.
30
+ */
31
+ export declare function storageLockScope(options?: WorldLockOptions): WorldLockOptions & {
32
+ operation: string;
33
+ caller: string;
34
+ };
10
35
  /**
11
36
  * The synchronous persistence seam. Every path is an ABSOLUTE key the caller already
12
37
  * computed (via `worldPaths`/`worldStateRoot`); the store treats it as an opaque key,
@@ -51,13 +76,57 @@ export interface WorldStore {
51
76
  readRange?(path: string, start: number): string | null;
52
77
  /** Resolve filesystem aliases for durable ownership; absent on opaque-key stores. */
53
78
  canonicalPath?(path: string): string;
79
+ /** `read`, for a small file every operation needs and few change (a branch's pointer, the World's clock): the text
80
+ * kept from the last read while the path's own facts stand, so an unchanged file costs one check and no read.
81
+ * Optional: a store without it is read. */
82
+ readKept?(path: string): string | null;
83
+ /** The facts of the generation kept beside a tree's files in `dirPath` (TREE_FILES): one string that differs after
84
+ * any write of one of them through a store, by this process or another; `null` where the directory has none yet,
85
+ * which says nothing. Optional: a store without it is asked for each file's own facts. */
86
+ generation?(dirPath: string): string | null;
87
+ /** The generation in `dirPath` now, when exactly one write of a tree's file through a store has moved it since
88
+ * `before` (a generation this store answered for it); `null` when it cannot say so. A writer that read `before` just
89
+ * ahead of its own write, holding the directory's history lock, learns that its write was the only one (log.ts
90
+ * appendToBranchLog). Optional, beside `generation`. */
91
+ generationAfterOwnWrite?(dirPath: string, before: string): string | null;
54
92
  /** Run `fn` holding an exclusive lock on `lockPath`, releasing it afterwards. The fs
55
93
  * backend uses the historical cross-process reclaimable file lock; an in-memory,
56
94
  * single-instance backend is a synchronous pass-through. */
57
- withLock<T>(lockPath: string, fn: () => T, options?: {
58
- retainLiveOwner?: boolean;
59
- }): T;
95
+ withLock<T>(lockPath: string, fn: () => T, options?: WorldLockOptions): T;
60
96
  }
97
+ /** The files a service's tree is folded from, by name in its state directory (log.ts: the parent log, the branch log,
98
+ * the branch's pointer), and the generation a store keeps beside them. */
99
+ export declare const TREE_FILES: {
100
+ readonly parent: "events.jsonl";
101
+ readonly branch: "actions.jsonl";
102
+ readonly pointer: "branch.json";
103
+ };
104
+ export declare const TREE_GENERATION = "tree.generation";
105
+ /**
106
+ * A WORLD'S CARRIED LOCKS, REMOVED AT ITS OPEN (S2 K4). A World booted over its kept state (`up --keep-state`, a
107
+ * tab's restored archive) carries whatever lock files its last life left in its services' state directories. One whose
108
+ * holder record cannot be read is no holder's once its taker has gone, and a restore gives it the restore's file time,
109
+ * so the empty-record grace and the 60 s age ran from the restore: every waiter waited them, or gave up at 10 s (Twenty
110
+ * e946aa4c run 2: anthropic's projection.lock, "holder record unreadable", 10,086 ms, then its credentials 500 and the
111
+ * server 10 s late). A carried `.recovery` that is not empty and does not parse was never ended by R13's rule at all.
112
+ *
113
+ * A file is carried only when all of these hold: it is a world-core lock or its reclaim record (`*.lock`,
114
+ * `*.lock.recovery`) in a service's state directory (`<root>/<service>/<stateDir>/world`, never a yarn.lock or any
115
+ * project file); its text is empty or a holder record's beginning (`{"pid"`) that does not parse; and its file time is
116
+ * before `before`, the start of this boot's claim. A restore sets the time before the claim; a taker that is live now
117
+ * (a CLI's changeset rebase, a branch World keeping this one as its parent's storage, a two-call taker between its
118
+ * create and its record) made its file after it. Each removal is still a reclaimer's: a lock's under its `.recovery`,
119
+ * taken with its record (createRecorded), a held `.recovery` skipped; the file read again, renamed aside, the aside copy
120
+ * read again and linked back where it now holds a record (EEXIST there is the path taken since, left to its holder).
121
+ * A record that parses is kept, under its rules (a dead holder's, our own pid's, the 60 s age, which a restore resets:
122
+ * not this rule's). Answers the paths removed.
123
+ */
124
+ export declare function removeCarriedLocks(roots: readonly string[], options: {
125
+ stateDir: string;
126
+ before: number;
127
+ }): string[];
128
+ /** Name a bookkeeping phase within an existing acquisition; never acquire another lock. */
129
+ export declare function withStorageLockOperation<T>(path: string, operation: string, fn: () => T): T;
61
130
  /**
62
131
  * The default store: a thin, faithful pass-through to `node:fs`. Every method preserves
63
132
  * the exact behavior the kernel had before the seam existed — the durable append
@@ -66,6 +135,51 @@ export interface WorldStore {
66
135
  */
67
136
  export declare class FsWorldStore implements WorldStore {
68
137
  read(path: string): string | null;
138
+ /**
139
+ * A small file's text, kept while its own facts stand. THE GUARANTEE: the key is the path's own lstat (device,
140
+ * inode, size, modification and change times); this process's own writes through the store drop what is kept at
141
+ * once; another process's write is seen when any of those facts moves. That is the guarantee a tree's stamp
142
+ * already rests on for its logs (their size and modification time), with the inode and change time added: a
143
+ * replaced file (writeAtomic) is another inode, a file written in place has another time. What it cannot see is a
144
+ * rewrite to the same size on the same or a reused inode within one tick of the file system's clock, with no check
145
+ * between; the logs' stamp has the same limit. A link is read through, and not kept.
146
+ * A text read after a write that came between the lstat and the read is kept under the OLDER key, so the next
147
+ * check finds the facts moved and reads again: what is kept is never newer than its key, and never served past it.
148
+ */
149
+ private readonly kept;
150
+ readKept(path: string): string | null;
151
+ /**
152
+ * A TREE'S GENERATION: one file beside a tree's three files, a byte longer after every write of any of them, so a
153
+ * reader that has the tree's stamp asks ONE question to know it still stands (log.ts treeFacts), where it asked
154
+ * three, two of them of files a World with no parent does not have.
155
+ *
156
+ * WHAT MAKES IT SOUND. A writer appends a byte BEFORE its write and another AFTER it; a reader takes the
157
+ * generation's facts BEFORE it reads the files' own. The file only grows, so its size never repeats on one inode,
158
+ * and a replaced or removed file is another inode or none. So for any write W and any reader that kept a stamp S
159
+ * under generation G: if W's first byte is after G was read, the kept G is behind and S is not served; if it is
160
+ * before, then either W itself was before S's own reads (S holds it), or W's second byte is after G was read, and
161
+ * again G is behind. An append is one call the system orders among all writers: each byte is one append of its
162
+ * own, whole or not at all, on a POSIX filesystem and in a tab's one kernel (browser-substrate
163
+ * packages/node/src/kernel-virtual-filesystem.ts appendFileSync, an O_APPEND open and writeAll, which sends a write
164
+ * of at most DATA_BYTES as one SYS_write request the kernel serves whole; or, by a file step, its table's own
165
+ * O_APPEND open and write of the one byte, filesystem.ts appendFileBytes). The proof rests on that; log.ts
166
+ * appendToBranchLog's (`generationAfterOwnWrite`: one write is exactly two bytes) as well.
167
+ *
168
+ * WHERE THAT STOPS. (1) A writer that dies between its write and its second byte, with a reader's whole check
169
+ * between its first byte and its write: that reader keeps the older stamp until the next write of the tree. (2) A
170
+ * writer of these files that does not come through a store of this version (an older package, a copy made over a
171
+ * live directory by another program): the generation does not move. A directory made or removed whole has no
172
+ * generation or another's, which serves nothing kept. (3) A stamp that names files outside its own directory (a
173
+ * World with a parent: its view and its ancestors' logs) is never kept under a generation (log.ts).
174
+ */
175
+ generation(dirPath: string): string | null;
176
+ /** One write is `moved` twice, a byte each: the same file, those two bytes longer. */
177
+ generationAfterOwnWrite(dirPath: string, before: string): string | null;
178
+ /** One more byte on the generation beside `path`, where `path` is one of a tree's files. A directory that is not
179
+ * there has no reader to tell: the write that makes it is followed by the byte that makes its generation. */
180
+ private moved;
181
+ /** A write of `path`, with the generation beside it moved before and after where it is one of a tree's files. */
182
+ private writing;
69
183
  readLines(path: string): string[];
70
184
  readRange(path: string, start: number): string | null;
71
185
  append(path: string, data: string): void;
@@ -79,17 +193,18 @@ export declare class FsWorldStore implements WorldStore {
79
193
  remove(path: string): void;
80
194
  mkdir(dirPath: string): void;
81
195
  list(dirPath: string): string[];
196
+ /** The real path of each path already resolved: a state directory's does not move under a running process, and
197
+ * every history lock asked for it again. A path that does not exist yet is not kept. */
198
+ private readonly canonical;
82
199
  canonicalPath(path: string): string;
83
200
  stat(path: string): WorldStat | null;
84
201
  /** Run `fn` holding an exclusive cross-process file lock. The lockfile records
85
- * `{pid, hostname, at}`; a contender that finds a stale lock (dead pid or age >
202
+ * identity, operation, caller and any nested wait; a contender that finds a stale lock (dead pid or age >
86
203
  * LOCK_STALE_MS) reclaims it by atomically renaming it aside — so a crashed holder
87
204
  * can't wedge the world forever. Reclaim is race-safe: only the process that wins
88
205
  * the rename clears the stale inode, and the exclusive `wx` create still decides the
89
206
  * winner. (Moved verbatim from storage.ts `withFileLock`.) */
90
- withLock<T>(lockPath: string, fn: () => T, options?: {
91
- retainLiveOwner?: boolean;
92
- }): T;
207
+ withLock<T>(lockPath: string, fn: () => T, options?: WorldLockOptions): T;
93
208
  }
94
209
  /**
95
210
  * An in-memory store. Files are entries in a `Map<path, string>`; directories are