vayrm 0.1.0__py3-none-any.whl

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 (986) hide show
  1. acr/__init__.py +29 -0
  2. acr/api/__init__.py +0 -0
  3. acr/api/root_api.py +87 -0
  4. acr/api/server.py +70 -0
  5. acr/cache/__init__.py +20 -0
  6. acr/cache/manager.py +394 -0
  7. acr/cache/policy.py +187 -0
  8. acr/checkpoint/__init__.py +30 -0
  9. acr/checkpoint/delta.py +209 -0
  10. acr/checkpoint/manager.py +764 -0
  11. acr/checkpoint/manifest.py +174 -0
  12. acr/checkpoint/policy.py +181 -0
  13. acr/checkpoint/provider.py +44 -0
  14. acr/cli.py +74 -0
  15. acr/cluster/__init__.py +20 -0
  16. acr/cluster/eligibility.py +71 -0
  17. acr/cluster/federation.py +77 -0
  18. acr/cluster/knowledge.py +285 -0
  19. acr/cluster/node_entry.py +103 -0
  20. acr/cluster/root_brain.py +1090 -0
  21. acr/cluster/state_aggregator.py +340 -0
  22. acr/cluster/subroot_agent.py +234 -0
  23. acr/communication/__init__.py +0 -0
  24. acr/communication/checkpoint_transfer.py +237 -0
  25. acr/communication/framing.py +182 -0
  26. acr/communication/inmemory.py +274 -0
  27. acr/communication/interfaces.py +173 -0
  28. acr/communication/local_channel.py +68 -0
  29. acr/communication/network.py +193 -0
  30. acr/communication/paladin_adapter.py +1003 -0
  31. acr/communication/priority.py +45 -0
  32. acr/communication/propagation.py +98 -0
  33. acr/communication/protocol.py +1349 -0
  34. acr/communication/tcp.py +917 -0
  35. acr/communication/transport.py +286 -0
  36. acr/core/__init__.py +3 -0
  37. acr/core/config.py +134 -0
  38. acr/core/enums.py +87 -0
  39. acr/core/errors.py +15 -0
  40. acr/core/identity.py +63 -0
  41. acr/core/types.py +6 -0
  42. acr/entrypoint.py +691 -0
  43. acr/events.py +600 -0
  44. acr/execution/__init__.py +5 -0
  45. acr/execution/dispatcher.py +63 -0
  46. acr/execution/feedback.py +79 -0
  47. acr/execution/manager.py +126 -0
  48. acr/execution/models.py +102 -0
  49. acr/execution/safe_worker.py +145 -0
  50. acr/facade.py +142 -0
  51. acr/history/__init__.py +3 -0
  52. acr/history/execution.py +85 -0
  53. acr/integration/__init__.py +0 -0
  54. acr/integration/paladin_import.py +72 -0
  55. acr/logging.py +78 -0
  56. acr/migration/__init__.py +3 -0
  57. acr/migration/manager.py +110 -0
  58. acr/network/__init__.py +0 -0
  59. acr/network/paladin_adapter.py +359 -0
  60. acr/node/__init__.py +72 -0
  61. acr/node/agent.py +483 -0
  62. acr/node/assessment.py +388 -0
  63. acr/node/brain.py +812 -0
  64. acr/node/history.py +95 -0
  65. acr/node/knowledge.py +680 -0
  66. acr/node/peer_view.py +226 -0
  67. acr/node/resource_snapshot.py +294 -0
  68. acr/node/self_model.py +542 -0
  69. acr/node/state_buffer.py +145 -0
  70. acr/node/state_machine.py +384 -0
  71. acr/node/state_publisher.py +245 -0
  72. acr/node/temporal.py +399 -0
  73. acr/peers/__init__.py +36 -0
  74. acr/peers/interfaces.py +65 -0
  75. acr/peers/knowledge.py +212 -0
  76. acr/peers/manager.py +186 -0
  77. acr/peers/merge.py +94 -0
  78. acr/peers/models.py +227 -0
  79. acr/platforms/__init__.py +8 -0
  80. acr/platforms/linux/__init__.py +12 -0
  81. acr/platforms/linux/provider.py +10 -0
  82. acr/platforms/linux/runtime.py +85 -0
  83. acr/platforms/linux/workloads.py +22 -0
  84. acr/platforms/macos/__init__.py +12 -0
  85. acr/platforms/macos/provider.py +10 -0
  86. acr/platforms/macos/runtime.py +28 -0
  87. acr/platforms/macos/workloads.py +24 -0
  88. acr/platforms/windows/__init__.py +12 -0
  89. acr/platforms/windows/provider.py +10 -0
  90. acr/platforms/windows/runtime.py +28 -0
  91. acr/platforms/windows/workloads.py +20 -0
  92. acr/registry/__init__.py +20 -0
  93. acr/registry/backend.py +63 -0
  94. acr/registry/cluster_registry.py +105 -0
  95. acr/registry/node_registry.py +41 -0
  96. acr/registry/resource_registry.py +395 -0
  97. acr/registry/root_registry.py +57 -0
  98. acr/registry/session_registry.py +74 -0
  99. acr/registry/subroot_registry.py +162 -0
  100. acr/resource_fabric/__init__.py +55 -0
  101. acr/resource_fabric/capacity_model.py +165 -0
  102. acr/resource_fabric/cooldown.py +133 -0
  103. acr/resource_fabric/criticality.py +57 -0
  104. acr/resource_fabric/decision_engine.py +476 -0
  105. acr/resource_fabric/filtering.py +220 -0
  106. acr/resource_fabric/hardware.py +182 -0
  107. acr/resource_fabric/hierarchy.py +229 -0
  108. acr/resource_fabric/manager.py +505 -0
  109. acr/resource_fabric/normalization.py +70 -0
  110. acr/resource_fabric/preemption.py +393 -0
  111. acr/resource_fabric/quota.py +132 -0
  112. acr/resource_fabric/reconciliation.py +160 -0
  113. acr/resource_fabric/resource_claim.py +184 -0
  114. acr/resource_fabric/resource_health.py +75 -0
  115. acr/resource_fabric/resource_lease.py +147 -0
  116. acr/resource_fabric/resource_offer.py +126 -0
  117. acr/resource_fabric/resource_policy.py +164 -0
  118. acr/resource_fabric/resource_pool.py +375 -0
  119. acr/resource_fabric/scoring.py +329 -0
  120. acr/resources/__init__.py +3 -0
  121. acr/resources/capabilities.py +111 -0
  122. acr/resources/cluster_state.py +101 -0
  123. acr/resources/metric.py +15 -0
  124. acr/resources/node_context.py +250 -0
  125. acr/resources/pressure.py +47 -0
  126. acr/resources/snapshot.py +173 -0
  127. acr/resources/state.py +139 -0
  128. acr/runtime/__init__.py +0 -0
  129. acr/runtime/aggregate_state.py +102 -0
  130. acr/runtime/continuous_sampler.py +103 -0
  131. acr/runtime/discovery.py +199 -0
  132. acr/runtime/endpoint.py +81 -0
  133. acr/runtime/master_root.py +154 -0
  134. acr/runtime/monitoring.py +205 -0
  135. acr/runtime/monte_carlo.py +139 -0
  136. acr/runtime/node.py +74 -0
  137. acr/runtime/node_brain.py +242 -0
  138. acr/runtime/node_model.py +104 -0
  139. acr/runtime/policy.py +179 -0
  140. acr/runtime/root.py +44 -0
  141. acr/runtime/root_controller.py +250 -0
  142. acr/runtime/safety.py +81 -0
  143. acr/runtime/scheduling_view.py +325 -0
  144. acr/runtime/trajectory.py +67 -0
  145. acr/runtime/workload_brain.py +136 -0
  146. acr/schedulers/__init__.py +54 -0
  147. acr/schedulers/adaptive.py +333 -0
  148. acr/schedulers/adaptive_common.py +44 -0
  149. acr/schedulers/adaptive_v2.py +94 -0
  150. acr/schedulers/adaptive_v3.py +387 -0
  151. acr/schedulers/admission.py +76 -0
  152. acr/schedulers/base.py +83 -0
  153. acr/schedulers/context.py +44 -0
  154. acr/schedulers/decision.py +85 -0
  155. acr/schedulers/estimation.py +141 -0
  156. acr/schedulers/explainable.py +129 -0
  157. acr/schedulers/heterogeneity.py +251 -0
  158. acr/schedulers/heterogeneity_aware.py +316 -0
  159. acr/schedulers/least_loaded.py +182 -0
  160. acr/schedulers/monte_carlo.py +123 -0
  161. acr/schedulers/queue.py +132 -0
  162. acr/schedulers/reasons.py +68 -0
  163. acr/schedulers/replay.py +41 -0
  164. acr/schedulers/resource_aware.py +547 -0
  165. acr/schedulers/round_robin.py +77 -0
  166. acr/schedulers/state_aware.py +144 -0
  167. acr/schedulers/strategy.py +310 -0
  168. acr/schedulers/task_weights.py +87 -0
  169. acr/schedulers/trace.py +284 -0
  170. acr/schedulers/weights.py +79 -0
  171. acr/scripts/__init__.py +0 -0
  172. acr/scripts/live_validator.py +0 -0
  173. acr/simulation/__init__.py +8 -0
  174. acr/simulation/decentralized.py +294 -0
  175. acr/simulation/failure_injector.py +0 -0
  176. acr/state/__init__.py +45 -0
  177. acr/state/catalog.py +284 -0
  178. acr/state/chunk.py +186 -0
  179. acr/state/manifest.py +239 -0
  180. acr/state/object.py +252 -0
  181. acr/state/residency.py +282 -0
  182. acr/storage/__init__.py +19 -0
  183. acr/storage/backend.py +115 -0
  184. acr/storage/filesystem.py +127 -0
  185. acr/storage/memory.py +78 -0
  186. acr/subroot/__init__.py +7 -0
  187. acr/subroot/local_fabric.py +180 -0
  188. acr/subroot/runtime.py +225 -0
  189. acr/telemetry/__init__.py +3 -0
  190. acr/telemetry/__main__.py +93 -0
  191. acr/telemetry/base.py +25 -0
  192. acr/telemetry/collector.py +94 -0
  193. acr/telemetry/detector.py +45 -0
  194. acr/telemetry/platforms/__init__.py +3 -0
  195. acr/telemetry/platforms/linux/__init__.py +3 -0
  196. acr/telemetry/platforms/linux/cpu.py +184 -0
  197. acr/telemetry/platforms/linux/gpu.py +161 -0
  198. acr/telemetry/platforms/linux/memory.py +149 -0
  199. acr/telemetry/platforms/linux/network.py +170 -0
  200. acr/telemetry/platforms/linux/power.py +52 -0
  201. acr/telemetry/platforms/linux/provider.py +133 -0
  202. acr/telemetry/platforms/linux/storage.py +98 -0
  203. acr/telemetry/platforms/linux/system.py +30 -0
  204. acr/telemetry/platforms/linux/thermal.py +106 -0
  205. acr/telemetry/platforms/macos/__init__.py +3 -0
  206. acr/telemetry/platforms/macos/cpu.py +85 -0
  207. acr/telemetry/platforms/macos/gpu.py +208 -0
  208. acr/telemetry/platforms/macos/memory.py +61 -0
  209. acr/telemetry/platforms/macos/network.py +32 -0
  210. acr/telemetry/platforms/macos/power.py +44 -0
  211. acr/telemetry/platforms/macos/provider.py +75 -0
  212. acr/telemetry/platforms/macos/storage.py +33 -0
  213. acr/telemetry/platforms/macos/system.py +16 -0
  214. acr/telemetry/platforms/macos/thermal.py +59 -0
  215. acr/telemetry/platforms/windows/__init__.py +3 -0
  216. acr/telemetry/platforms/windows/cpu.py +86 -0
  217. acr/telemetry/platforms/windows/gpu.py +449 -0
  218. acr/telemetry/platforms/windows/memory.py +69 -0
  219. acr/telemetry/platforms/windows/network.py +86 -0
  220. acr/telemetry/platforms/windows/power.py +68 -0
  221. acr/telemetry/platforms/windows/provider.py +74 -0
  222. acr/telemetry/platforms/windows/storage.py +62 -0
  223. acr/telemetry/platforms/windows/system.py +13 -0
  224. acr/telemetry/platforms/windows/thermal.py +139 -0
  225. acr/telemetry/record.py +232 -0
  226. acr/telemetry/root_telemetry_tracker.py +422 -0
  227. acr/telemetry/validate.py +98 -0
  228. acr/test_bug.py +6 -0
  229. acr/test_migration.py +81 -0
  230. acr/test_node.py +6 -0
  231. acr/test_provider.py +10 -0
  232. acr/training/__init__.py +0 -0
  233. acr/training/backend.py +87 -0
  234. acr/training/worker.py +48 -0
  235. acr/transfer/__init__.py +51 -0
  236. acr/transfer/backend.py +154 -0
  237. acr/transfer/backends/__init__.py +3 -0
  238. acr/transfer/backends/memory.py +239 -0
  239. acr/transfer/backends/tcp.py +396 -0
  240. acr/transfer/chunking.py +268 -0
  241. acr/transfer/diff.py +283 -0
  242. acr/transfer/manager.py +336 -0
  243. acr/transfer/plan.py +307 -0
  244. acr/ui/__init__.py +0 -0
  245. acr/ui/resource_dashboard.py +0 -0
  246. acr/ui/root_dashboard.py +1144 -0
  247. acr/utils/__init__.py +0 -0
  248. acr/utils/profiling.py +80 -0
  249. acr/workloads/__init__.py +15 -0
  250. acr/workloads/characteristics.py +36 -0
  251. acr/workloads/cpu_worker.py +60 -0
  252. acr/workloads/identity.py +36 -0
  253. acr/workloads/io_worker.py +86 -0
  254. acr/workloads/knowledge.py +36 -0
  255. acr/workloads/memory_worker.py +68 -0
  256. acr/workloads/mixed_worker.py +80 -0
  257. acr/workloads/profile.py +44 -0
  258. acr/workloads/pytorch/__init__.py +0 -0
  259. acr/workloads/pytorch/adapter.py +37 -0
  260. acr/workloads/pytorch/checkpoint.py +33 -0
  261. acr/workloads/pytorch/runtime.py +229 -0
  262. acr/workloads/requirements.py +155 -0
  263. acr/workloads/spec.py +39 -0
  264. acr/workloads/state_needs.py +32 -0
  265. acr/workloads/virtual.py +146 -0
  266. acr/workloads/windows_workloads.py +79 -0
  267. acr/workloads/worker.py +83 -0
  268. acr/workloads/workload.py +126 -0
  269. ai/__init__.py +0 -0
  270. ai/agents/__init__.py +0 -0
  271. ai/agents/agents.py +0 -0
  272. ai/checkpoints/__init__.py +0 -0
  273. ai/checkpoints/checkpoints.py +0 -0
  274. ai/datasets/__init__.py +0 -0
  275. ai/datasets/datasets.py +0 -0
  276. ai/fusion/__init__.py +0 -0
  277. ai/fusion/fusion.py +0 -0
  278. ai/inference/__init__.py +0 -0
  279. ai/inference/inference.py +0 -0
  280. ai/model_loader/__init__.py +0 -0
  281. ai/model_loader/model_loader.py +0 -0
  282. ai/model_registry/__init__.py +0 -0
  283. ai/model_registry/model_registry.py +0 -0
  284. ai/orchestration/__init__.py +0 -0
  285. ai/orchestration/orchestration.py +0 -0
  286. ai/plugins/__init__.py +0 -0
  287. ai/plugins/coding/__init__.py +0 -0
  288. ai/plugins/coding/coding.py +0 -0
  289. ai/plugins/embedding/__init__.py +0 -0
  290. ai/plugins/embedding/embedding.py +0 -0
  291. ai/plugins/llm/__init__.py +0 -0
  292. ai/plugins/llm/llm.py +0 -0
  293. ai/plugins/memory/__init__.py +0 -0
  294. ai/plugins/memory/memory.py +0 -0
  295. ai/plugins/ocr/__init__.py +0 -0
  296. ai/plugins/ocr/ocr.py +0 -0
  297. ai/plugins/planning/__init__.py +0 -0
  298. ai/plugins/planning/planning.py +0 -0
  299. ai/plugins/reranker/__init__.py +0 -0
  300. ai/plugins/reranker/reranker.py +0 -0
  301. ai/plugins/slm/__init__.py +0 -0
  302. ai/plugins/slm/slm.py +0 -0
  303. ai/plugins/speech/__init__.py +0 -0
  304. ai/plugins/speech/speech.py +0 -0
  305. ai/plugins/trm/__init__.py +0 -0
  306. ai/plugins/trm/trm.py +0 -0
  307. ai/plugins/vision/__init__.py +0 -0
  308. ai/plugins/vision/vision.py +0 -0
  309. ai/runtime/__init__.py +0 -0
  310. ai/runtime/runtime.py +0 -0
  311. ai/tensors/__init__.py +0 -0
  312. ai/tensors/tensors.py +0 -0
  313. ai/training/__init__.py +0 -0
  314. ai/training/training.py +0 -0
  315. ai/workflows/__init__.py +0 -0
  316. ai/workflows/workflows.py +0 -0
  317. apps/__init__.py +0 -0
  318. apps/cli/__init__.py +0 -0
  319. apps/cli/main.py +517 -0
  320. apps/node/__init__.py +0 -0
  321. apps/node/api.py +140 -0
  322. apps/node/main.py +634 -0
  323. apps/node/peers.py +224 -0
  324. apps/root/__init__.py +0 -0
  325. apps/root/api/__init__.py +0 -0
  326. apps/root/api/server.py +244 -0
  327. apps/root/main.py +809 -0
  328. cluster/__init__.py +0 -0
  329. cluster/allocation/__init__.py +0 -0
  330. cluster/allocation/allocation.py +0 -0
  331. cluster/autoscaling/__init__.py +0 -0
  332. cluster/autoscaling/autoscaling.py +0 -0
  333. cluster/balancer/__init__.py +0 -0
  334. cluster/balancer/balancer.py +0 -0
  335. cluster/failover/__init__.py +0 -0
  336. cluster/failover/failover.py +0 -0
  337. cluster/global_state/__init__.py +0 -0
  338. cluster/global_state/global_state.py +0 -0
  339. cluster/health/__init__.py +0 -0
  340. cluster/health/health.py +0 -0
  341. cluster/leader/__init__.py +0 -0
  342. cluster/leader/leader.py +0 -0
  343. cluster/membership/__init__.py +0 -0
  344. cluster/membership/membership.py +0 -0
  345. cluster/node_manager/__init__.py +0 -0
  346. cluster/node_manager/node_manager.py +0 -0
  347. cluster/placement/__init__.py +0 -0
  348. cluster/placement/placement.py +0 -0
  349. cluster/recovery/__init__.py +0 -0
  350. cluster/recovery/recovery.py +0 -0
  351. cluster/registry/__init__.py +0 -0
  352. cluster/registry/registry.py +0 -0
  353. cluster/replication/__init__.py +0 -0
  354. cluster/replication/replication.py +0 -0
  355. cluster/resource_manager/__init__.py +0 -0
  356. cluster/resource_manager/resource_manager.py +0 -0
  357. cluster/routing/__init__.py +0 -0
  358. cluster/routing/routing.py +0 -0
  359. cluster/scheduler/__init__.py +0 -0
  360. cluster/scheduler/scheduler.py +0 -0
  361. cluster/topology/__init__.py +0 -0
  362. cluster/topology/topology.py +0 -0
  363. core/__init__.py +0 -0
  364. core/ai/__init__.py +0 -0
  365. core/ai/agent.py +8 -0
  366. core/ai/cognition.py +9 -0
  367. core/ai/context.py +8 -0
  368. core/ai/dataset_security/__init__.py +9 -0
  369. core/ai/dataset_security/dataset.py +26 -0
  370. core/ai/execution.py +8 -0
  371. core/ai/registry/__init__.py +9 -0
  372. core/ai/registry/registry.py +40 -0
  373. core/ai/scheduler.py +9 -0
  374. core/bootstrap/__init__.py +50 -0
  375. core/bootstrap/docker.py +209 -0
  376. core/bootstrap/environment.py +50 -0
  377. core/bootstrap/headscale.py +177 -0
  378. core/bootstrap/manager.py +260 -0
  379. core/bootstrap/metrics.py +40 -0
  380. core/bootstrap/platform/__init__.py +68 -0
  381. core/bootstrap/platform/base.py +164 -0
  382. core/bootstrap/platform/capabilities.py +166 -0
  383. core/bootstrap/platform/linux.py +168 -0
  384. core/bootstrap/platform/macos.py +131 -0
  385. core/bootstrap/platform/service_manager.py +226 -0
  386. core/bootstrap/platform/windows.py +162 -0
  387. core/bootstrap/policies.py +5 -0
  388. core/bootstrap/ports.py +141 -0
  389. core/bootstrap/processes.py +138 -0
  390. core/bootstrap/recovery.py +29 -0
  391. core/bootstrap/sources.py +5 -0
  392. core/bootstrap/state_machine.py +86 -0
  393. core/bootstrap/tailscale.py +175 -0
  394. core/bootstrap/validators.py +5 -0
  395. core/capabilities/__init__.py +0 -0
  396. core/capabilities/descriptor.py +12 -0
  397. core/capabilities/graph/__init__.py +0 -0
  398. core/capabilities/graph/dependencies.py +15 -0
  399. core/capabilities/graph/graph.py +14 -0
  400. core/capabilities/graph/query.py +10 -0
  401. core/capabilities/manager.py +8 -0
  402. core/capabilities/registry.py +8 -0
  403. core/cluster/__init__.py +0 -0
  404. core/cluster/consensus/__init__.py +9 -0
  405. core/cluster/consensus/consensus.py +44 -0
  406. core/cluster/events.py +10 -0
  407. core/cluster/health.py +8 -0
  408. core/cluster/lifecycle.py +6 -0
  409. core/cluster/manager.py +24 -0
  410. core/cluster/membership.py +16 -0
  411. core/cluster/state.py +11 -0
  412. core/communication/__init__.py +100 -0
  413. core/communication/cache/__init__.py +8 -0
  414. core/communication/cache/cache.py +72 -0
  415. core/communication/compression/__init__.py +12 -0
  416. core/communication/compression/compression.py +51 -0
  417. core/communication/connection/__init__.py +106 -0
  418. core/communication/discovery/__init__.py +214 -0
  419. core/communication/discovery/discovery.py +0 -0
  420. core/communication/encryption/__init__.py +68 -0
  421. core/communication/encryption/encryption.py +0 -0
  422. core/communication/errors/__init__.py +65 -0
  423. core/communication/events/__init__.py +130 -0
  424. core/communication/gateway/__init__.py +9 -0
  425. core/communication/gateway/gateway.py +156 -0
  426. core/communication/heartbeat/__init__.py +116 -0
  427. core/communication/heartbeat/heartbeat.py +0 -0
  428. core/communication/identity/__init__.py +180 -0
  429. core/communication/identity/identity.py +0 -0
  430. core/communication/interfaces/__init__.py +57 -0
  431. core/communication/interfaces/interfaces.py +193 -0
  432. core/communication/latency/__init__.py +8 -0
  433. core/communication/latency/latency.py +77 -0
  434. core/communication/layer.py +857 -0
  435. core/communication/messaging/__init__.py +95 -0
  436. core/communication/messaging/messaging.py +0 -0
  437. core/communication/messaging/secure_bus.py +144 -0
  438. core/communication/monitoring/__init__.py +8 -0
  439. core/communication/monitoring/monitor.py +64 -0
  440. core/communication/network/__init__.py +77 -0
  441. core/communication/network/context.py +59 -0
  442. core/communication/network/events.py +47 -0
  443. core/communication/network/monitor.py +140 -0
  444. core/communication/network/resolver.py +125 -0
  445. core/communication/network/transport.py +197 -0
  446. core/communication/network/tuner.py +94 -0
  447. core/communication/peer/__init__.py +188 -0
  448. core/communication/peer/peer.py +0 -0
  449. core/communication/plugins/__init__.py +76 -0
  450. core/communication/protocols/__init__.py +0 -0
  451. core/communication/protocols/protocol.py +0 -0
  452. core/communication/qos/__init__.py +8 -0
  453. core/communication/qos/qos.py +99 -0
  454. core/communication/registry.py +83 -0
  455. core/communication/relay/__init__.py +84 -0
  456. core/communication/reliability/__init__.py +8 -0
  457. core/communication/reliability/reliability.py +97 -0
  458. core/communication/routing/__init__.py +54 -0
  459. core/communication/routing/router.py +0 -0
  460. core/communication/security/__init__.py +100 -0
  461. core/communication/security/handshake.py +120 -0
  462. core/communication/security/security.py +110 -0
  463. core/communication/serialization/__init__.py +128 -0
  464. core/communication/serialization/serialization.py +0 -0
  465. core/communication/sessions/__init__.py +109 -0
  466. core/communication/sessions/session.py +0 -0
  467. core/communication/streaming/__init__.py +21 -0
  468. core/communication/streaming/bandwidth_optimizer/__init__.py +8 -0
  469. core/communication/streaming/bandwidth_optimizer/bandwidth_optimizer.py +68 -0
  470. core/communication/streaming/checkpoint_sync/__init__.py +8 -0
  471. core/communication/streaming/checkpoint_sync/checkpoint_sync.py +28 -0
  472. core/communication/streaming/checksum/__init__.py +8 -0
  473. core/communication/streaming/checksum/checksum.py +48 -0
  474. core/communication/streaming/chunk_manager/__init__.py +8 -0
  475. core/communication/streaming/chunk_manager/chunk_manager.py +100 -0
  476. core/communication/streaming/dataset_sync/__init__.py +8 -0
  477. core/communication/streaming/dataset_sync/dataset_sync.py +28 -0
  478. core/communication/streaming/file_transfer/__init__.py +8 -0
  479. core/communication/streaming/file_transfer/file_transfer.py +28 -0
  480. core/communication/streaming/media_stream/__init__.py +8 -0
  481. core/communication/streaming/media_stream/media_stream.py +28 -0
  482. core/communication/streaming/model_distribution/__init__.py +8 -0
  483. core/communication/streaming/model_distribution/model_distribution.py +28 -0
  484. core/communication/streaming/replication/__init__.py +8 -0
  485. core/communication/streaming/replication/replication.py +28 -0
  486. core/communication/streaming/resume_manager/__init__.py +8 -0
  487. core/communication/streaming/resume_manager/resume_manager.py +84 -0
  488. core/communication/streaming/scheduler/__init__.py +76 -0
  489. core/communication/streaming/secure_transfer.py +90 -0
  490. core/communication/streaming/synchronization/__init__.py +8 -0
  491. core/communication/streaming/synchronization/synchronization.py +28 -0
  492. core/communication/streaming/tensor_stream/__init__.py +8 -0
  493. core/communication/streaming/tensor_stream/tensor_stream.py +28 -0
  494. core/communication/streaming/transfer_manager/__init__.py +8 -0
  495. core/communication/streaming/transfer_manager/transfer_manager.py +212 -0
  496. core/communication/topology/__init__.py +74 -0
  497. core/communication/transport/__init__.py +1 -0
  498. core/communication/transport/future/__init__.py +0 -0
  499. core/communication/transport/future/transport.py +0 -0
  500. core/communication/transport/grpc/__init__.py +0 -0
  501. core/communication/transport/grpc/transport.py +0 -0
  502. core/communication/transport/quic/__init__.py +0 -0
  503. core/communication/transport/quic/client.py +0 -0
  504. core/communication/transport/quic/connection.py +0 -0
  505. core/communication/transport/quic/server.py +0 -0
  506. core/communication/transport/quic/transport.py +0 -0
  507. core/communication/transport/tcp/__init__.py +149 -0
  508. core/communication/transport/tcp/client.py +0 -0
  509. core/communication/transport/tcp/connection.py +0 -0
  510. core/communication/transport/tcp/server.py +0 -0
  511. core/communication/transport/tcp/transport.py +0 -0
  512. core/communication/transport/websocket/__init__.py +0 -0
  513. core/communication/transport/websocket/transport.py +0 -0
  514. core/communication/traversal/__init__.py +60 -0
  515. core/configuration/__init__.py +0 -0
  516. core/configuration/configuration.py +0 -0
  517. core/configuration/scopes.py +13 -0
  518. core/diagnostics/__init__.py +0 -0
  519. core/diagnostics/diagnostics.py +0 -0
  520. core/discovery/__init__.py +0 -0
  521. core/discovery/context.py +9 -0
  522. core/discovery/events.py +10 -0
  523. core/discovery/failure/__init__.py +0 -0
  524. core/discovery/failure/detector.py +6 -0
  525. core/discovery/failure/isolation.py +5 -0
  526. core/discovery/failure/suspicion.py +5 -0
  527. core/discovery/gossip/__init__.py +0 -0
  528. core/discovery/gossip/exchange.py +5 -0
  529. core/discovery/gossip/manager.py +6 -0
  530. core/discovery/gossip/protocol.py +9 -0
  531. core/discovery/gossip/state.py +9 -0
  532. core/discovery/heartbeat/__init__.py +0 -0
  533. core/discovery/heartbeat/manager.py +5 -0
  534. core/discovery/heartbeat/monitor.py +5 -0
  535. core/discovery/heartbeat/scheduler.py +6 -0
  536. core/discovery/manager.py +8 -0
  537. core/discovery/policies.py +9 -0
  538. core/discovery/registry.py +11 -0
  539. core/discovery/runtime.py +7 -0
  540. core/discovery/state.py +9 -0
  541. core/federation/__init__.py +0 -0
  542. core/federation/directory.py +5 -0
  543. core/federation/discovery.py +5 -0
  544. core/federation/manager.py +5 -0
  545. core/federation/policies.py +5 -0
  546. core/federation/registry.py +5 -0
  547. core/federation/remote.py +5 -0
  548. core/federation/routing.py +5 -0
  549. core/federation/trust.py +5 -0
  550. core/interfaces/__init__.py +325 -0
  551. core/interfaces/icluster.py +1 -0
  552. core/interfaces/icommunication.py +0 -0
  553. core/interfaces/idataset.py +0 -0
  554. core/interfaces/imodel.py +0 -0
  555. core/interfaces/iplugin.py +0 -0
  556. core/interfaces/iresource.py +0 -0
  557. core/interfaces/iruntime.py +0 -0
  558. core/interfaces/ischeduler.py +0 -0
  559. core/interfaces/isecurity.py +0 -0
  560. core/interfaces/istorage.py +0 -0
  561. core/interfaces/istreaming.py +0 -0
  562. core/interfaces/itelemetry.py +0 -0
  563. core/interfaces/itransport.py +0 -0
  564. core/kernel/__init__.py +0 -0
  565. core/kernel/context.py +19 -0
  566. core/kernel/diagnostics.py +15 -0
  567. core/kernel/events.py +13 -0
  568. core/kernel/health.py +19 -0
  569. core/kernel/kernel.py +23 -0
  570. core/kernel/lifecycle.py +35 -0
  571. core/kernel/manifest.py +29 -0
  572. core/kernel/runtimes/__init__.py +0 -0
  573. core/kernel/runtimes/descriptor.py +30 -0
  574. core/kernel/runtimes/registry.py +21 -0
  575. core/kernel/state.py +39 -0
  576. core/logging/__init__.py +0 -0
  577. core/logging/logging.py +0 -0
  578. core/logging_setup.py +98 -0
  579. core/network/__init__.py +0 -0
  580. core/network/bus.py +56 -0
  581. core/network/config.py +202 -0
  582. core/network/connection/__init__.py +0 -0
  583. core/network/connection/manager.py +57 -0
  584. core/network/connection/pool.py +43 -0
  585. core/network/connection/registry.py +19 -0
  586. core/network/connection/retry.py +30 -0
  587. core/network/connection/state.py +64 -0
  588. core/network/controlplane/__init__.py +0 -0
  589. core/network/controlplane/acl/__init__.py +0 -0
  590. core/network/controlplane/acl/acl_manager.py +69 -0
  591. core/network/controlplane/audit/__init__.py +0 -0
  592. core/network/controlplane/audit/logger.py +33 -0
  593. core/network/controlplane/authentication/__init__.py +0 -0
  594. core/network/controlplane/authentication/auth.py +64 -0
  595. core/network/controlplane/authorization/__init__.py +0 -0
  596. core/network/controlplane/authorization/authz.py +42 -0
  597. core/network/controlplane/cluster/__init__.py +0 -0
  598. core/network/controlplane/cluster/synchronizer.py +32 -0
  599. core/network/controlplane/configuration/__init__.py +0 -0
  600. core/network/controlplane/configuration/manager.py +37 -0
  601. core/network/controlplane/derp/__init__.py +0 -0
  602. core/network/controlplane/derp/derp_coordinator.py +31 -0
  603. core/network/controlplane/events.py +57 -0
  604. core/network/controlplane/exceptions.py +26 -0
  605. core/network/controlplane/identity/__init__.py +0 -0
  606. core/network/controlplane/identity/manager.py +92 -0
  607. core/network/controlplane/models.py +70 -0
  608. core/network/controlplane/monitoring/__init__.py +0 -0
  609. core/network/controlplane/monitoring/monitor.py +27 -0
  610. core/network/controlplane/nat/__init__.py +0 -0
  611. core/network/controlplane/nat/nat_coordinator.py +30 -0
  612. core/network/controlplane/peer_coordinator.py +40 -0
  613. core/network/controlplane/registry/__init__.py +0 -0
  614. core/network/controlplane/registry/registry.py +67 -0
  615. core/network/controlplane/routing/__init__.py +0 -0
  616. core/network/controlplane/routing/routing.py +32 -0
  617. core/network/controlplane/services/__init__.py +0 -0
  618. core/network/controlplane/services/identity_service.py +16 -0
  619. core/network/controlplane/topology/__init__.py +0 -0
  620. core/network/controlplane/topology/topology.py +54 -0
  621. core/network/discovery/__init__.py +0 -0
  622. core/network/discovery/cache.py +30 -0
  623. core/network/discovery/interfaces.py +43 -0
  624. core/network/discovery/manager.py +49 -0
  625. core/network/discovery/provider.py +331 -0
  626. core/network/discovery/synchronizer.py +75 -0
  627. core/network/events.py +136 -0
  628. core/network/exceptions.py +34 -0
  629. core/network/headscale/__init__.py +0 -0
  630. core/network/headscale/acl.py +11 -0
  631. core/network/headscale/api.py +132 -0
  632. core/network/headscale/client.py +163 -0
  633. core/network/headscale/headscale_state.py +107 -0
  634. core/network/headscale/headscale_sync_service.py +349 -0
  635. core/network/headscale/health.py +76 -0
  636. core/network/headscale/identity.py +8 -0
  637. core/network/headscale/models.py +28 -0
  638. core/network/headscale/registration.py +368 -0
  639. core/network/headscale/startup_check.py +651 -0
  640. core/network/headscale/sync.py +75 -0
  641. core/network/health/__init__.py +0 -0
  642. core/network/health/monitor.py +50 -0
  643. core/network/health/states.py +13 -0
  644. core/network/management/__init__.py +0 -0
  645. core/network/management/config.py +35 -0
  646. core/network/management/doctor.py +70 -0
  647. core/network/management/headscale.py +77 -0
  648. core/network/management/installer.py +44 -0
  649. core/network/management/logs.py +21 -0
  650. core/network/management/models.py +58 -0
  651. core/network/management/operator.py +37 -0
  652. core/network/management/provision.py +20 -0
  653. core/network/management/tailscale.py +125 -0
  654. core/network/manager.py +266 -0
  655. core/network/metrics/__init__.py +6 -0
  656. core/network/metrics/manager.py +77 -0
  657. core/network/orchestrator/__init__.py +0 -0
  658. core/network/orchestrator/orchestrator.py +125 -0
  659. core/network/orchestrator/route_evaluator.py +56 -0
  660. core/network/platform/__init__.py +17 -0
  661. core/network/platform/capabilities.py +237 -0
  662. core/network/scheduler/__init__.py +0 -0
  663. core/network/scheduler/network_scheduler.py +0 -0
  664. core/network/security/__init__.py +0 -0
  665. core/network/security/policy.py +0 -0
  666. core/network/services/__init__.py +0 -0
  667. core/network/services/heartbeat.py +149 -0
  668. core/network/session/__init__.py +0 -0
  669. core/network/session/manager.py +139 -0
  670. core/network/transfer/__init__.py +0 -0
  671. core/network/transfer/checksum.py +13 -0
  672. core/network/transfer/chunk_manager.py +17 -0
  673. core/network/transfer/compression.py +13 -0
  674. core/network/transfer/reassembly.py +27 -0
  675. core/network/transfer/resume.py +36 -0
  676. core/network/transfer/transfer_manager.py +103 -0
  677. core/network/transfer/verification.py +13 -0
  678. core/network/transport/__init__.py +0 -0
  679. core/network/transport/base.py +125 -0
  680. core/network/transport/factory.py +27 -0
  681. core/network/transport/interfaces.py +90 -0
  682. core/network/transport/manager.py +37 -0
  683. core/network/transport/mock_provider.py +60 -0
  684. core/network/transport/provider.py +62 -0
  685. core/network/transport/tcp_provider.py +45 -0
  686. core/network/wireguard/__init__.py +0 -0
  687. core/network/wireguard/health_monitor.py +30 -0
  688. core/network/wireguard/interface_manager.py +19 -0
  689. core/network/wireguard/key_manager.py +61 -0
  690. core/network/wireguard/peer_manager.py +33 -0
  691. core/network/wireguard/provider.py +41 -0
  692. core/network/wireguard/system_provider.py +85 -0
  693. core/network/wireguard/tunnel_manager.py +25 -0
  694. core/node/__init__.py +0 -0
  695. core/node/descriptor.py +10 -0
  696. core/node/events.py +9 -0
  697. core/node/health.py +6 -0
  698. core/node/identity.py +9 -0
  699. core/node/lifecycle.py +27 -0
  700. core/node/manager.py +10 -0
  701. core/node/state.py +15 -0
  702. core/platform/__init__.py +0 -0
  703. core/platform/common/__init__.py +0 -0
  704. core/platform/common/common.py +0 -0
  705. core/platform/drivers/__init__.py +0 -0
  706. core/platform/drivers/drivers.py +0 -0
  707. core/platform/linux/__init__.py +0 -0
  708. core/platform/linux/linux.py +0 -0
  709. core/platform/macos/__init__.py +0 -0
  710. core/platform/macos/macos.py +0 -0
  711. core/platform/windows/__init__.py +0 -0
  712. core/platform/windows/windows.py +0 -0
  713. core/plugins/__init__.py +0 -0
  714. core/plugins/manager.py +17 -0
  715. core/plugins/manifest.py +24 -0
  716. core/plugins/registry.py +11 -0
  717. core/research/__init__.py +9 -0
  718. core/resource_fabric/__init__.py +0 -0
  719. core/resource_fabric/admission_control/__init__.py +0 -0
  720. core/resource_fabric/admission_control/admission_control.py +0 -0
  721. core/resource_fabric/allocator/__init__.py +0 -0
  722. core/resource_fabric/allocator/allocator.py +0 -0
  723. core/resource_fabric/discovery/__init__.py +0 -0
  724. core/resource_fabric/discovery/discovery.py +0 -0
  725. core/resource_fabric/gpu_pool/__init__.py +0 -0
  726. core/resource_fabric/gpu_pool/gpu_pool.py +0 -0
  727. core/resource_fabric/inventory/__init__.py +0 -0
  728. core/resource_fabric/inventory/inventory.py +0 -0
  729. core/resource_fabric/memory_pool/__init__.py +0 -0
  730. core/resource_fabric/memory_pool/memory_pool.py +0 -0
  731. core/resource_fabric/network_pool/__init__.py +0 -0
  732. core/resource_fabric/network_pool/network_pool.py +0 -0
  733. core/resource_fabric/placement/__init__.py +0 -0
  734. core/resource_fabric/placement/placement.py +0 -0
  735. core/resource_fabric/quotas/__init__.py +0 -0
  736. core/resource_fabric/quotas/quotas.py +0 -0
  737. core/resource_fabric/storage_pool/__init__.py +0 -0
  738. core/resource_fabric/storage_pool/storage_pool.py +0 -0
  739. core/resources/__init__.py +0 -0
  740. core/resources/allocator/__init__.py +0 -0
  741. core/resources/allocator/allocator.py +0 -0
  742. core/resources/bandwidth/__init__.py +0 -0
  743. core/resources/bandwidth/bandwidth.py +0 -0
  744. core/resources/cpu/__init__.py +0 -0
  745. core/resources/cpu/cpu.py +0 -0
  746. core/resources/disk/__init__.py +0 -0
  747. core/resources/disk/disk.py +0 -0
  748. core/resources/gpu/__init__.py +0 -0
  749. core/resources/gpu/gpu.py +0 -0
  750. core/resources/manager.py +12 -0
  751. core/resources/memory/__init__.py +0 -0
  752. core/resources/memory/memory.py +0 -0
  753. core/resources/models.py +42 -0
  754. core/resources/network/__init__.py +0 -0
  755. core/resources/network/network.py +0 -0
  756. core/resources/npu/__init__.py +0 -0
  757. core/resources/npu/npu.py +0 -0
  758. core/resources/power/__init__.py +0 -0
  759. core/resources/power/power.py +0 -0
  760. core/resources/predictor/__init__.py +0 -0
  761. core/resources/predictor/predictor.py +0 -0
  762. core/resources/registry.py +11 -0
  763. core/resources/storage/__init__.py +0 -0
  764. core/resources/storage/storage.py +0 -0
  765. core/resources/telemetry/__init__.py +0 -0
  766. core/resources/telemetry/telemetry.py +0 -0
  767. core/resources/temperature/__init__.py +0 -0
  768. core/resources/temperature/temperature.py +0 -0
  769. core/runtime/__init__.py +0 -0
  770. core/runtime/event_bus/__init__.py +0 -0
  771. core/runtime/event_bus/event_bus.py +0 -0
  772. core/runtime/executor/__init__.py +0 -0
  773. core/runtime/executor/executor.py +0 -0
  774. core/runtime/job_dispatcher/__init__.py +0 -0
  775. core/runtime/job_dispatcher/job_dispatcher.py +0 -0
  776. core/runtime/lifecycle/__init__.py +0 -0
  777. core/runtime/lifecycle/lifecycle.py +0 -0
  778. core/runtime/plugin_manager/__init__.py +0 -0
  779. core/runtime/plugin_manager/plugin_manager.py +0 -0
  780. core/runtime/runtime_api/__init__.py +0 -0
  781. core/runtime/runtime_api/runtime_api.py +0 -0
  782. core/runtime/scheduler/__init__.py +0 -0
  783. core/runtime/scheduler/scheduler.py +0 -0
  784. core/runtime/service_manager/__init__.py +0 -0
  785. core/runtime/service_manager/service_manager.py +0 -0
  786. core/runtime/state_machine/__init__.py +0 -0
  787. core/runtime/state_machine/state_machine.py +0 -0
  788. core/runtime/task_manager/__init__.py +0 -0
  789. core/runtime/task_manager/task_manager.py +0 -0
  790. core/runtime/task_queue/__init__.py +0 -0
  791. core/runtime/task_queue/task_queue.py +0 -0
  792. core/runtime/worker_pool/__init__.py +0 -0
  793. core/runtime/worker_pool/worker_pool.py +0 -0
  794. core/scheduler/__init__.py +0 -0
  795. core/scheduler/execution_flow.py +8 -0
  796. core/scheduler/executor.py +8 -0
  797. core/scheduler/placement.py +7 -0
  798. core/scheduler/queue.py +7 -0
  799. core/scheduler/scheduler.py +8 -0
  800. core/security/__init__.py +1 -0
  801. core/security/audit/__init__.py +0 -0
  802. core/security/audit/journal.py +12 -0
  803. core/security/audit/logger.py +7 -0
  804. core/security/audit/retention.py +10 -0
  805. core/security/authentication/__init__.py +0 -0
  806. core/security/authentication/handshake.py +16 -0
  807. core/security/authentication/manager.py +17 -0
  808. core/security/authentication/policy.py +12 -0
  809. core/security/authorization/__init__.py +1 -0
  810. core/security/authorization/manager.py +21 -0
  811. core/security/authorization/policy.py +10 -0
  812. core/security/authorization/rbac.py +23 -0
  813. core/security/bus_integration.py +8 -0
  814. core/security/crypto/__init__.py +0 -0
  815. core/security/crypto/keys.py +18 -0
  816. core/security/crypto/provider.py +38 -0
  817. core/security/domains/__init__.py +0 -0
  818. core/security/domains/domain.py +29 -0
  819. core/security/hardware/__init__.py +0 -0
  820. core/security/hardware/provider.py +21 -0
  821. core/security/identity/__init__.py +0 -0
  822. core/security/identity/descriptor.py +13 -0
  823. core/security/identity/identity.py +36 -0
  824. core/security/identity/registry.py +17 -0
  825. core/security/identity/validator.py +13 -0
  826. core/security/identity_store.py +34 -0
  827. core/security/peer_registry.py +56 -0
  828. core/security/pki/__init__.py +3 -0
  829. core/security/pki/authority.py +12 -0
  830. core/security/pki/ca.py +118 -0
  831. core/security/pki/csr.py +10 -0
  832. core/security/pki/manager.py +14 -0
  833. core/security/pki/revocation.py +13 -0
  834. core/security/pki/store.py +20 -0
  835. core/security/pki/validator.py +16 -0
  836. core/security/policy/__init__.py +1 -0
  837. core/security/policy/policy.py +103 -0
  838. core/security/runtime/__init__.py +0 -0
  839. core/security/runtime/context.py +22 -0
  840. core/security/runtime/events.py +37 -0
  841. core/security/runtime/lifecycle.py +26 -0
  842. core/security/runtime/manager.py +49 -0
  843. core/security/secrets/__init__.py +1 -0
  844. core/security/secrets/manager.py +7 -0
  845. core/security/secrets/provider.py +9 -0
  846. core/security/secrets/rotation.py +6 -0
  847. core/security/secrets/store.py +14 -0
  848. core/security/secrets/vault.py +65 -0
  849. core/security/security.py +0 -0
  850. core/security/sessions/__init__.py +0 -0
  851. core/security/sessions/descriptor.py +11 -0
  852. core/security/sessions/lifecycle.py +12 -0
  853. core/security/sessions/manager.py +18 -0
  854. core/security/sessions/state.py +11 -0
  855. core/security/threats/__init__.py +0 -0
  856. core/security/threats/catalog.py +23 -0
  857. core/security/threats/classification.py +17 -0
  858. core/security/threats/mitigation.py +11 -0
  859. core/security/threats/severity.py +23 -0
  860. core/security/trust/__init__.py +1 -0
  861. core/security/trust/engine.py +16 -0
  862. core/security/trust/evaluator.py +6 -0
  863. core/security/trust/evidence.py +17 -0
  864. core/security/trust/graph.py +11 -0
  865. core/security/trust/manager.py +16 -0
  866. core/security/trust/policy.py +9 -0
  867. core/security/trust/reputation.py +3 -0
  868. core/security/trust/trust.py +62 -0
  869. core/services/__init__.py +0 -0
  870. core/services/authentication/__init__.py +0 -0
  871. core/services/authentication/service.py +0 -0
  872. core/services/cache/__init__.py +0 -0
  873. core/services/cache/service.py +0 -0
  874. core/services/descriptor.py +7 -0
  875. core/services/discovery/__init__.py +0 -0
  876. core/services/discovery/service.py +0 -0
  877. core/services/discovery.py +7 -0
  878. core/services/health/__init__.py +0 -0
  879. core/services/health/service.py +0 -0
  880. core/services/health.py +7 -0
  881. core/services/heartbeat/__init__.py +0 -0
  882. core/services/heartbeat/service.py +0 -0
  883. core/services/lifecycle.py +7 -0
  884. core/services/logging/__init__.py +0 -0
  885. core/services/logging/service.py +0 -0
  886. core/services/manager.py +7 -0
  887. core/services/manifest.py +7 -0
  888. core/services/metrics/__init__.py +0 -0
  889. core/services/metrics/service.py +0 -0
  890. core/services/notifications/__init__.py +0 -0
  891. core/services/notifications/service.py +0 -0
  892. core/services/registry.py +7 -0
  893. core/services/resolver.py +7 -0
  894. core/services/resource_monitor/__init__.py +0 -0
  895. core/services/resource_monitor/service.py +0 -0
  896. core/services/runtime.py +8 -0
  897. core/services/scheduler/__init__.py +0 -0
  898. core/services/scheduler/service.py +0 -0
  899. core/services/state.py +24 -0
  900. core/services/sync/__init__.py +0 -0
  901. core/services/sync/service.py +0 -0
  902. core/services/transfer/__init__.py +0 -0
  903. core/services/transfer/service.py +0 -0
  904. core/storage/__init__.py +0 -0
  905. core/storage/artifacts/__init__.py +0 -0
  906. core/storage/artifacts/artifacts.py +0 -0
  907. core/storage/cache/__init__.py +0 -0
  908. core/storage/cache/cache.py +0 -0
  909. core/storage/checkpoints/__init__.py +0 -0
  910. core/storage/checkpoints/checkpoints.py +0 -0
  911. core/storage/cleanup/__init__.py +0 -0
  912. core/storage/cleanup/cleanup.py +0 -0
  913. core/storage/datasets/__init__.py +0 -0
  914. core/storage/datasets/datasets.py +0 -0
  915. core/storage/distributed_store/__init__.py +0 -0
  916. core/storage/distributed_store/distributed_store.py +0 -0
  917. core/storage/logs/__init__.py +0 -0
  918. core/storage/logs/logs.py +0 -0
  919. core/storage/metadata/__init__.py +0 -0
  920. core/storage/metadata/metadata.py +0 -0
  921. core/storage/metadata/store.py +7 -0
  922. core/storage/models/__init__.py +0 -0
  923. core/storage/models/models.py +0 -0
  924. core/storage/object_store/__init__.py +0 -0
  925. core/storage/object_store/object_store.py +0 -0
  926. core/storage/replication/__init__.py +0 -0
  927. core/storage/replication/replication.py +0 -0
  928. core/storage/snapshots/__init__.py +0 -0
  929. core/storage/snapshots/snapshots.py +0 -0
  930. core/system/__init__.py +0 -0
  931. core/system/bus.py +15 -0
  932. core/system/commands.py +7 -0
  933. core/system/events.py +7 -0
  934. core/system/queries.py +7 -0
  935. core/system/subscriptions.py +7 -0
  936. core/telemetry/__init__.py +0 -0
  937. core/telemetry/alerts/__init__.py +0 -0
  938. core/telemetry/alerts/alerts.py +0 -0
  939. core/telemetry/analytics/__init__.py +0 -0
  940. core/telemetry/analytics/analytics.py +0 -0
  941. core/telemetry/dashboards/__init__.py +0 -0
  942. core/telemetry/dashboards/dashboards.py +0 -0
  943. core/telemetry/events/__init__.py +0 -0
  944. core/telemetry/events/events.py +0 -0
  945. core/telemetry/metrics/__init__.py +0 -0
  946. core/telemetry/metrics/metrics.py +0 -0
  947. core/telemetry/profiling/__init__.py +0 -0
  948. core/telemetry/profiling/profiling.py +0 -0
  949. core/telemetry/tracing/__init__.py +0 -0
  950. core/telemetry/tracing/tracing.py +0 -0
  951. core/time/__init__.py +0 -0
  952. core/time/clock.py +5 -0
  953. core/time/logical.py +5 -0
  954. core/time/synchronization.py +5 -0
  955. core/time/vector.py +5 -0
  956. core/topology/__init__.py +0 -0
  957. core/topology/graph.py +5 -0
  958. core/topology/manager.py +5 -0
  959. core/topology/snapshot.py +5 -0
  960. core/utilities/__init__.py +0 -0
  961. core/utilities/utilities.py +0 -0
  962. protocol/__init__.py +0 -0
  963. protocol/commands/__init__.py +0 -0
  964. protocol/commands/commands.py +0 -0
  965. protocol/errors/__init__.py +0 -0
  966. protocol/errors/errors.py +0 -0
  967. protocol/events/__init__.py +0 -0
  968. protocol/events/events.py +0 -0
  969. protocol/messages/__init__.py +0 -0
  970. protocol/messages/messages.py +0 -0
  971. protocol/protobuf/__init__.py +0 -0
  972. protocol/responses/__init__.py +0 -0
  973. protocol/responses/responses.py +0 -0
  974. protocol/schemas/__init__.py +416 -0
  975. protocol/versioning/__init__.py +0 -0
  976. protocol/versioning/versioning.py +0 -0
  977. protocol/wire/__init__.py +0 -0
  978. protocol/wire/common/__init__.py +0 -0
  979. protocol/wire/common/types.py +7 -0
  980. protocol/wire/evolution.py +10 -0
  981. vayrm/__init__.py +8 -0
  982. vayrm-0.1.0.dist-info/METADATA +166 -0
  983. vayrm-0.1.0.dist-info/RECORD +986 -0
  984. vayrm-0.1.0.dist-info/WHEEL +5 -0
  985. vayrm-0.1.0.dist-info/entry_points.txt +3 -0
  986. vayrm-0.1.0.dist-info/top_level.txt +7 -0
acr/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ """
2
+ Adaptive Computing Resource (ACR)
3
+ =================================
4
+
5
+ ACR is a platform-agnostic, distributed computing runtime for heterogeneous clusters.
6
+ It provides node intelligence, cluster knowledge exchange, adaptive scheduling,
7
+ and closed-loop execution feedback.
8
+ """
9
+
10
+ from acr.facade import ACRNode, ACRRoot
11
+ from acr.workloads import Workload
12
+ from acr.schedulers.adaptive import AdaptiveScheduler
13
+ from acr.schedulers.decision import SchedulingDecision
14
+ from acr.execution.manager import ExecutionManager
15
+ from acr.execution.models import ExecutionAttempt
16
+ from acr.communication.protocol import ExecutionObservationMessage as ExecutionObservation
17
+ from acr.resources.snapshot import NodeSnapshot
18
+
19
+ __all__ = [
20
+ "ACRNode",
21
+ "ACRRoot",
22
+ "Workload",
23
+ "AdaptiveScheduler",
24
+ "SchedulingDecision",
25
+ "ExecutionManager",
26
+ "ExecutionAttempt",
27
+ "ExecutionObservation",
28
+ "NodeSnapshot",
29
+ ]
acr/api/__init__.py ADDED
File without changes
acr/api/root_api.py ADDED
@@ -0,0 +1,87 @@
1
+ from dataclasses import dataclass
2
+ from typing import Dict, List, Optional
3
+ from acr.node.knowledge import NodeKnowledge
4
+
5
+ @dataclass
6
+ class WorkerRecord:
7
+ worker_key: str
8
+ endpoint: Optional[Dict]
9
+ paladin_node_id: str
10
+ session_id: Optional[str]
11
+ connection: str
12
+ connection_status: str
13
+ telemetry: Optional[dict]
14
+ knowledge: Optional[NodeKnowledge]
15
+
16
+ class RootDashboardAPI:
17
+ """
18
+ API for retrieving WorkerRecords for the dashboard.
19
+ """
20
+ def __init__(self, root_brain, control_plane):
21
+ self._brain = root_brain
22
+ self._cp = control_plane
23
+
24
+ def get_workers(self) -> List[WorkerRecord]:
25
+ workers = []
26
+ all_k = self._brain.all_node_knowledge()
27
+ tracker = getattr(self._cp, "telemetry_tracker", None)
28
+
29
+ # We also want to include nodes that the tracker knows about but have no knowledge yet
30
+ worker_keys = set(all_k.keys())
31
+ if tracker:
32
+ worker_keys.update(rec.node_id for rec in tracker.all_records())
33
+
34
+ for worker_key in worker_keys:
35
+ # worker_key is usually "{paladin_node_id}_{session_id}"
36
+ if "_" in worker_key:
37
+ paladin_node_id, session_id = worker_key.split("_", 1)
38
+ else:
39
+ paladin_node_id, session_id = worker_key, None
40
+
41
+ k = all_k.get(worker_key)
42
+ ep = None
43
+ conn_status = "UNKNOWN"
44
+ tel = None
45
+
46
+ if tracker:
47
+ rec = tracker.get_record(worker_key)
48
+ if rec:
49
+ tel = rec.__dict__
50
+ if rec.current_mesh_ip:
51
+ ep = {
52
+ "mesh_ip": rec.current_mesh_ip,
53
+ "service_port": rec.current_service_port
54
+ }
55
+ conn_status = rec.connection_status
56
+
57
+ if not ep and hasattr(self._cp, "get_node_endpoint"):
58
+ # fallback to paladin directly if tracker missed it
59
+ ep_data = self._cp.get_node_endpoint(paladin_node_id)
60
+ if ep_data:
61
+ ep = {
62
+ "mesh_ip": ep_data.get("mesh_ip"),
63
+ "service_port": ep_data.get("service_port")
64
+ }
65
+ if conn_status == "UNKNOWN":
66
+ conn_status = ep_data.get("connection_status", "UNKNOWN")
67
+
68
+ workers.append(WorkerRecord(
69
+ worker_key=worker_key,
70
+ endpoint=ep,
71
+ paladin_node_id=paladin_node_id,
72
+ session_id=session_id,
73
+ connection="PALADIN",
74
+ connection_status=conn_status,
75
+ telemetry=tel,
76
+ knowledge=k
77
+ ))
78
+
79
+ # Sort so order is stable
80
+ workers.sort(key=lambda w: w.worker_key)
81
+ return workers
82
+
83
+ def get_worker(self, worker_key: str) -> Optional[WorkerRecord]:
84
+ for w in self.get_workers():
85
+ if w.worker_key == worker_key:
86
+ return w
87
+ return None
acr/api/server.py ADDED
@@ -0,0 +1,70 @@
1
+ """
2
+ acr/api/server.py
3
+ FastAPI server exposing real-time state of the NodeBrain and WorkloadBrain.
4
+ """
5
+ from fastapi import FastAPI, HTTPException
6
+ import uuid
7
+ import threading
8
+
9
+ from acr.runtime.node_brain import NodeBrain
10
+ from acr.runtime.workload_brain import WorkloadBrain
11
+ from acr.runtime.monitoring import RuntimeMonitor
12
+ from acr.workloads.pytorch.adapter import PyTorchWorkloadAdapter
13
+ from acr.workloads.pytorch.checkpoint import PyTorchCheckpointer
14
+ from acr.workloads.pytorch.runtime import run_training
15
+
16
+ app = FastAPI(title="ACR Live Runtime API", version="1.0.0")
17
+
18
+ # Global instances for the runtime
19
+ run_id = str(uuid.uuid4())
20
+ node_brain = NodeBrain(node_id="macos_node_1")
21
+ workload_brain = WorkloadBrain(workload_id="pytorch_resnet_1")
22
+ monitor = RuntimeMonitor(node_brain, workload_brain, run_id=run_id, interval_s=1.0)
23
+ adapter = PyTorchWorkloadAdapter(workload_brain)
24
+ checkpointer = PyTorchCheckpointer(f"checkpoints/{run_id}")
25
+
26
+ training_thread = None
27
+
28
+ @app.on_event("startup")
29
+ def startup_event():
30
+ print("Starting Continuous Node Monitor...")
31
+ monitor.start()
32
+
33
+ @app.on_event("shutdown")
34
+ def shutdown_event():
35
+ print("Stopping runtime...")
36
+ monitor.stop()
37
+ adapter.stop()
38
+ if training_thread:
39
+ training_thread.join(timeout=2.0)
40
+
41
+ @app.get("/api/v1/node")
42
+ def get_node_state():
43
+ """Returns the current state and trends of the physical node."""
44
+ return node_brain.get_state_summary()
45
+
46
+ @app.get("/api/v1/workload")
47
+ def get_workload_state():
48
+ """Returns the current state and metrics of the running workload."""
49
+ return workload_brain.get_state_summary()
50
+
51
+ @app.post("/api/v1/workload/start")
52
+ def start_workload(device: str = "cpu", batch_size: int = 64):
53
+ """Start the real PyTorch workload in a background thread."""
54
+ global training_thread
55
+ if training_thread and training_thread.is_alive():
56
+ raise HTTPException(status_code=400, detail="Workload is already running")
57
+
58
+ training_thread = threading.Thread(
59
+ target=run_training,
60
+ args=(adapter, checkpointer, device, batch_size),
61
+ daemon=True
62
+ )
63
+ training_thread.start()
64
+ return {"status": "started", "device": device, "batch_size": batch_size}
65
+
66
+ @app.post("/api/v1/workload/stop")
67
+ def stop_workload():
68
+ """Stop the running PyTorch workload."""
69
+ adapter.running = False
70
+ return {"status": "stopping"}
acr/cache/__init__.py ADDED
@@ -0,0 +1,20 @@
1
+ """
2
+ acr/cache/__init__.py
3
+
4
+ Local state cache management for ACR nodes.
5
+ """
6
+ from acr.cache.policy import (
7
+ CacheEntry, EvictionPolicy, AdmissionPolicy,
8
+ LRUEvictionPolicy, LFUEvictionPolicy, SizeAwareEvictionPolicy,
9
+ AlwaysAdmitPolicy, SizeThresholdPolicy,
10
+ )
11
+ from acr.cache.manager import (
12
+ CacheTier, CacheEventType, CacheEvent, CacheStats, CacheManager,
13
+ )
14
+
15
+ __all__ = [
16
+ "CacheEntry", "EvictionPolicy", "AdmissionPolicy",
17
+ "LRUEvictionPolicy", "LFUEvictionPolicy", "SizeAwareEvictionPolicy",
18
+ "AlwaysAdmitPolicy", "SizeThresholdPolicy",
19
+ "CacheTier", "CacheEventType", "CacheEvent", "CacheStats", "CacheManager",
20
+ ]
acr/cache/manager.py ADDED
@@ -0,0 +1,394 @@
1
+ """
2
+ acr/cache/manager.py
3
+
4
+ CacheManager: local state cache for an ACR node.
5
+
6
+ The CacheManager sits between the storage backend and the scheduler.
7
+ It answers: "Is this chunk available locally? Can I serve it without a
8
+ remote transfer?"
9
+
10
+ Responsibilities
11
+ ----------------
12
+ - Admission: decide whether to accept a new chunk into the cache
13
+ - Eviction: free space when pressure requires it
14
+ - Promotion: move a chunk to a higher-priority tier
15
+ - Demotion: move a chunk to a lower-priority tier
16
+ - Prefetch: proactively fetch chunks expected to be needed soon
17
+ - Residency tracking: what chunks are cached and at what tier
18
+ - Hit/miss accounting: maintain statistics for scheduling decisions
19
+
20
+ Memory hierarchy (conceptual, represented as priority tiers)
21
+ -------------------------------------------------------------
22
+ Tier 0: GPU / accelerator memory (highest cost to reload)
23
+ Tier 1: RAM (system memory)
24
+ Tier 2: Local persistent storage
25
+ Tier 3: Remote (not cached — fetch required)
26
+
27
+ The CacheManager tracks tiers 0–2. Tier 3 means "not here".
28
+ The storage backend holds the actual bytes for tiers 1–2.
29
+ GPU residency is metadata-only (ACR does not manage GPU memory directly).
30
+
31
+ Design rules
32
+ ------------
33
+ - CacheManager depends on StorageBackend (injected).
34
+ - CacheManager depends on EvictionPolicy and AdmissionPolicy (injected).
35
+ - All operations produce structured CacheEvent records.
36
+ - Cache hits/misses are counted per chunk_id.
37
+ - capacity_bytes is a soft limit: eviction is triggered when exceeded.
38
+ - Eviction frees at least one slot; it may free more if under severe pressure.
39
+ """
40
+ from __future__ import annotations
41
+
42
+ import time
43
+ from dataclasses import dataclass, field
44
+ from enum import Enum
45
+
46
+ from acr.cache.policy import (
47
+ AdmissionPolicy, AlwaysAdmitPolicy, CacheEntry,
48
+ EvictionPolicy, LRUEvictionPolicy,
49
+ )
50
+ from acr.storage.backend import StorageBackend
51
+
52
+
53
+ class CacheTier(Enum):
54
+ """
55
+ Conceptual memory tier.
56
+
57
+ GPU : GPU / accelerator memory (fastest; metadata-only in ACR)
58
+ RAM : System RAM (fast; managed via storage backend)
59
+ STORAGE : Local persistent storage (slower; managed via storage backend)
60
+ REMOTE : Not locally cached
61
+ """
62
+ GPU = 0
63
+ RAM = 1
64
+ STORAGE = 2
65
+ REMOTE = 3
66
+
67
+
68
+ @dataclass
69
+ class CacheEventType(Enum):
70
+ HIT = "hit"
71
+ MISS = "miss"
72
+ ADMITTED = "admitted"
73
+ EVICTED = "evicted"
74
+ PROMOTED = "promoted"
75
+ DEMOTED = "demoted"
76
+ REJECTED = "rejected" # admission policy said no
77
+ PREFETCH = "prefetch"
78
+
79
+
80
+ @dataclass
81
+ class CacheEvent:
82
+ """A structured event emitted by the CacheManager for observability."""
83
+ event_type: CacheEventType
84
+ chunk_id: str
85
+ size_bytes: int | None
86
+ tier: CacheTier | None
87
+ timestamp: float = field(default_factory=time.monotonic)
88
+ reason: str = ""
89
+
90
+
91
+ @dataclass
92
+ class CacheStats:
93
+ """Accumulated hit/miss/eviction statistics."""
94
+ hits: int = 0
95
+ misses: int = 0
96
+ admissions: int = 0
97
+ evictions: int = 0
98
+ rejections: int = 0
99
+ promotions: int = 0
100
+ demotions: int = 0
101
+ bytes_evicted: int = 0
102
+ bytes_admitted: int = 0
103
+
104
+ @property
105
+ def hit_rate(self) -> float | None:
106
+ total = self.hits + self.misses
107
+ return self.hits / total if total > 0 else None
108
+
109
+ def to_dict(self) -> dict:
110
+ return {
111
+ "hits": self.hits, "misses": self.misses,
112
+ "admissions": self.admissions, "evictions": self.evictions,
113
+ "rejections": self.rejections,
114
+ "bytes_evicted": self.bytes_evicted,
115
+ "bytes_admitted": self.bytes_admitted,
116
+ "hit_rate": self.hit_rate,
117
+ }
118
+
119
+
120
+ class CacheManager:
121
+ """
122
+ Local state cache for one ACR node.
123
+
124
+ Parameters
125
+ ----------
126
+ storage : the storage backend that holds actual bytes
127
+ capacity_bytes: soft limit on total cache size; None = unlimited
128
+ eviction_policy : which entry to evict when over capacity
129
+ admission_policy : whether to admit a new entry
130
+ default_tier : which tier admitted entries land in (RAM or STORAGE)
131
+ max_events : how many CacheEvents to retain in the event log
132
+ """
133
+
134
+ def __init__(
135
+ self,
136
+ storage: StorageBackend,
137
+ capacity_bytes: int | None = None,
138
+ eviction_policy: EvictionPolicy | None = None,
139
+ admission_policy: AdmissionPolicy | None = None,
140
+ default_tier: CacheTier = CacheTier.RAM,
141
+ max_events: int = 1000,
142
+ ) -> None:
143
+ self._storage = storage
144
+ self.capacity_bytes = capacity_bytes
145
+ self._eviction = eviction_policy or LRUEvictionPolicy()
146
+ self._admission = admission_policy or AlwaysAdmitPolicy()
147
+ self._default_tier = default_tier
148
+ self._max_events = max_events
149
+
150
+ # chunk_id → CacheEntry
151
+ self._entries: dict[str, CacheEntry] = {}
152
+ # chunk_id → CacheTier
153
+ self._tiers: dict[str, CacheTier] = {}
154
+ # Accumulated stats
155
+ self._stats = CacheStats()
156
+ # Event log (bounded)
157
+ self._events: list[CacheEvent] = []
158
+
159
+ # ------------------------------------------------------------------
160
+ # Core operations
161
+ # ------------------------------------------------------------------
162
+
163
+ def put(self, chunk_id: str, data: bytes, priority: int = 0) -> bool:
164
+ """
165
+ Admit a chunk into the cache.
166
+
167
+ Returns True if admitted, False if rejected by admission policy.
168
+ If the cache is over capacity after admission, eviction is triggered.
169
+
170
+ The data is written to the storage backend on admission.
171
+ """
172
+ size = len(data)
173
+
174
+ # Admission check
175
+ if not self._admission.should_admit(chunk_id, size):
176
+ self._stats.rejections += 1
177
+ self._emit(CacheEventType.REJECTED, chunk_id, size, None, "admission_policy")
178
+ return False
179
+
180
+ # If already present, update data and refresh entry
181
+ now = time.monotonic()
182
+ if chunk_id in self._entries:
183
+ old_size = self._entries[chunk_id].size_bytes
184
+ self._entries[chunk_id].size_bytes = size
185
+ self._eviction.on_access(self._entries[chunk_id], now)
186
+ key = self._storage_key(chunk_id)
187
+ self._storage.write(key, data)
188
+ self._stats.bytes_admitted += size - old_size
189
+ return True
190
+
191
+ # Write to storage backend
192
+ key = self._storage_key(chunk_id)
193
+ self._storage.write(key, data)
194
+
195
+ entry = CacheEntry(
196
+ chunk_id=chunk_id, size_bytes=size,
197
+ priority=priority, inserted_at=now,
198
+ )
199
+ self._eviction.on_insert(entry, now)
200
+ self._entries[chunk_id] = entry
201
+ self._tiers[chunk_id] = self._default_tier
202
+
203
+ self._stats.admissions += 1
204
+ self._stats.bytes_admitted += size
205
+ self._emit(CacheEventType.ADMITTED, chunk_id, size, self._default_tier)
206
+
207
+ # Evict if over capacity
208
+ self._enforce_capacity()
209
+ return True
210
+
211
+ def get(self, chunk_id: str) -> bytes | None:
212
+ """
213
+ Retrieve cached chunk bytes.
214
+ Returns None on cache miss (does NOT raise).
215
+ Records hit or miss in stats.
216
+ """
217
+ if chunk_id not in self._entries:
218
+ self._stats.misses += 1
219
+ self._emit(CacheEventType.MISS, chunk_id, None, None)
220
+ return None
221
+
222
+ entry = self._entries[chunk_id]
223
+ now = time.monotonic()
224
+ self._eviction.on_access(entry, now)
225
+ self._stats.hits += 1
226
+ tier = self._tiers.get(chunk_id, self._default_tier)
227
+ self._emit(CacheEventType.HIT, chunk_id, entry.size_bytes, tier)
228
+
229
+ key = self._storage_key(chunk_id)
230
+ try:
231
+ return self._storage.read(key)
232
+ except KeyError:
233
+ # Metadata says cached but bytes gone — treat as miss, clean up
234
+ self._remove_entry(chunk_id)
235
+ self._stats.hits -= 1
236
+ self._stats.misses += 1
237
+ return None
238
+
239
+ def contains(self, chunk_id: str) -> bool:
240
+ """Return True if chunk_id is in the cache (metadata check only)."""
241
+ return chunk_id in self._entries
242
+
243
+ def evict(self, chunk_id: str) -> bool:
244
+ """
245
+ Explicitly evict a specific chunk.
246
+ Returns True if it was in the cache, False otherwise.
247
+ """
248
+ if chunk_id not in self._entries:
249
+ return False
250
+ size = self._entries[chunk_id].size_bytes
251
+ tier = self._tiers.get(chunk_id)
252
+ self._remove_entry(chunk_id)
253
+ self._stats.evictions += 1
254
+ self._stats.bytes_evicted += size
255
+ self._emit(CacheEventType.EVICTED, chunk_id, size, tier, "explicit_eviction")
256
+ return True
257
+
258
+ def promote(self, chunk_id: str, target_tier: CacheTier) -> bool:
259
+ """
260
+ Promote a chunk to a higher (lower-number) tier.
261
+ Returns False if chunk not in cache or already at target tier.
262
+ GPU promotions are metadata-only (bytes stay in storage).
263
+ """
264
+ if chunk_id not in self._entries:
265
+ return False
266
+ current = self._tiers.get(chunk_id, self._default_tier)
267
+ if target_tier.value >= current.value:
268
+ return False # not a promotion
269
+ self._tiers[chunk_id] = target_tier
270
+ self._stats.promotions += 1
271
+ size = self._entries[chunk_id].size_bytes
272
+ self._emit(CacheEventType.PROMOTED, chunk_id, size, target_tier,
273
+ f"{current.name}→{target_tier.name}")
274
+ return True
275
+
276
+ def demote(self, chunk_id: str, target_tier: CacheTier) -> bool:
277
+ """
278
+ Demote a chunk to a lower (higher-number) tier.
279
+ Returns False if chunk not in cache or already at/below target.
280
+ """
281
+ if chunk_id not in self._entries:
282
+ return False
283
+ current = self._tiers.get(chunk_id, self._default_tier)
284
+ if target_tier.value <= current.value:
285
+ return False # not a demotion
286
+ self._tiers[chunk_id] = target_tier
287
+ self._stats.demotions += 1
288
+ size = self._entries[chunk_id].size_bytes
289
+ self._emit(CacheEventType.DEMOTED, chunk_id, size, target_tier,
290
+ f"{current.name}→{target_tier.name}")
291
+ return True
292
+
293
+ def prefetch(self, chunk_id: str, data: bytes, priority: int = 1) -> bool:
294
+ """
295
+ Proactively admit a chunk with a standard priority boost.
296
+ Delegates to put() with a structured event.
297
+ """
298
+ result = self.put(chunk_id, data, priority=priority)
299
+ if result:
300
+ # Relabel last admitted event as prefetch
301
+ self._emit(CacheEventType.PREFETCH, chunk_id, len(data), self._default_tier)
302
+ return result
303
+
304
+ # ------------------------------------------------------------------
305
+ # Pressure and capacity
306
+ # ------------------------------------------------------------------
307
+
308
+ def current_bytes(self) -> int:
309
+ """Total bytes in cache (from entry metadata, not storage scan)."""
310
+ return sum(e.size_bytes for e in self._entries.values())
311
+
312
+ def pressure(self) -> float | None:
313
+ """
314
+ Cache pressure (0.0–1.0).
315
+ Returns None if no capacity limit is set.
316
+ """
317
+ if self.capacity_bytes is None:
318
+ return None
319
+ return min(1.0, self.current_bytes() / self.capacity_bytes)
320
+
321
+ def entry_count(self) -> int:
322
+ return len(self._entries)
323
+
324
+ def cached_chunk_ids(self) -> set[str]:
325
+ return set(self._entries.keys())
326
+
327
+ def chunks_at_tier(self, tier: CacheTier) -> list[str]:
328
+ return [cid for cid, t in self._tiers.items() if t == tier]
329
+
330
+ def get_tier(self, chunk_id: str) -> CacheTier:
331
+ """Return the tier of a cached chunk, or REMOTE if not cached."""
332
+ return self._tiers.get(chunk_id, CacheTier.REMOTE)
333
+
334
+ # ------------------------------------------------------------------
335
+ # Stats and observability
336
+ # ------------------------------------------------------------------
337
+
338
+ @property
339
+ def stats(self) -> CacheStats:
340
+ return self._stats
341
+
342
+ def recent_events(self, n: int = 50) -> list[CacheEvent]:
343
+ return self._events[-n:]
344
+
345
+ def reset_stats(self) -> None:
346
+ self._stats = CacheStats()
347
+
348
+ # ------------------------------------------------------------------
349
+ # Private helpers
350
+ # ------------------------------------------------------------------
351
+
352
+ def _storage_key(self, chunk_id: str) -> str:
353
+ return f"cache/{chunk_id}"
354
+
355
+ def _remove_entry(self, chunk_id: str) -> None:
356
+ """Remove entry metadata and backing storage."""
357
+ self._entries.pop(chunk_id, None)
358
+ self._tiers.pop(chunk_id, None)
359
+ key = self._storage_key(chunk_id)
360
+ self._storage.delete(key)
361
+
362
+ def _enforce_capacity(self) -> None:
363
+ """Evict entries until we are within capacity, or cache is empty."""
364
+ if self.capacity_bytes is None:
365
+ return
366
+ while self.current_bytes() > self.capacity_bytes and self._entries:
367
+ victim_id = self._eviction.choose_victim(self._entries)
368
+ if victim_id is None:
369
+ break
370
+ size = self._entries[victim_id].size_bytes
371
+ tier = self._tiers.get(victim_id)
372
+ self._remove_entry(victim_id)
373
+ self._stats.evictions += 1
374
+ self._stats.bytes_evicted += size
375
+ self._emit(CacheEventType.EVICTED, victim_id, size, tier, "capacity_pressure")
376
+
377
+ def _emit(
378
+ self,
379
+ event_type: CacheEventType,
380
+ chunk_id: str,
381
+ size_bytes: int | None,
382
+ tier: CacheTier | None,
383
+ reason: str = "",
384
+ ) -> None:
385
+ event = CacheEvent(
386
+ event_type=event_type,
387
+ chunk_id=chunk_id,
388
+ size_bytes=size_bytes,
389
+ tier=tier,
390
+ reason=reason,
391
+ )
392
+ self._events.append(event)
393
+ if len(self._events) > self._max_events:
394
+ self._events = self._events[-self._max_events:]