Diffinery

homeflare/celldpublic

330 lines · 9.7 KBRaw History
1// Copyright 2026 Deno Land Inc. Apache-2.0 license.
2
3#![warn(clippy::disallowed_methods, clippy::disallowed_types)]
4
5//! Effect adapters for the clean-sheet core.
6//!
7//! The executable owns one serial actor which is the only caller of
8//! `celld_logic::on_event`. Adapter futures never borrow core state; they send
9//! versioned completion events back through its mailbox.
10
11mod tokio_select;
12#[doc(hidden)]
13pub use tokio_select::__asyncrt_select_support;
14
15pub mod actor;
16#[cfg(all(test, celld_internal_tests))]
17mod conformance_core_loop_tests {
18 include!(env!("CELLD_CONFORMANCE_CORE_LOOP_TESTS"));
19}
20#[cfg(all(test, celld_internal_tests))]
21mod conformance_facet_failure_tests {
22 include!(env!("CELLD_CONFORMANCE_FACET_FAILURE_TESTS"));
23}
24pub mod assets;
25#[cfg(not(celld_internal_tests))]
26pub mod asyncrt;
27// The internal test flag alone selects the simulated asyncrt, so an external
28// test harness built with the flag sees the same simulated world the
29// in-crate suites see. `test` must not be part of the gate:
30// a dependency never has it, and the harness binary builds unflagged,
31// so the shipped and harness builds keep the real asyncrt.
32#[cfg(celld_internal_tests)]
33#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
34pub mod asyncrt {
35 include!(env!("CELLD_INTERNAL_ASYNCRT"));
36}
37#[cfg(all(test, celld_internal_tests))]
38mod asyncrt_contract_tests {
39 include!(env!("CELLD_INTERNAL_ASYNCRT_TESTS"));
40}
41pub mod bucket;
42pub mod cell_cli;
43pub mod cell_dispatch;
44mod cell_host;
45pub mod cell_runtime;
46pub mod clean_reload;
47pub mod cli_options;
48pub mod cli_output;
49pub mod container;
50pub mod control_plane;
51pub mod d1_cli;
52pub mod dead_node_gc;
53pub mod deploy;
54pub mod dev;
55pub mod docker;
56pub mod drain_token;
57pub mod engine_api;
58pub mod env_vars;
59#[cfg(celld_internal_tests)]
60#[allow(clippy::disallowed_methods)]
61#[doc(hidden)]
62pub mod fault {
63 include!(env!("CELLD_INTERNAL_SQLITE_FAULT"));
64}
65pub(crate) mod facet_streams;
66pub mod fleet;
67pub mod generation;
68pub mod host_channels;
69pub mod host_services;
70pub mod http_streams;
71pub mod js;
72pub mod kv_blob;
73pub mod kv_cli;
74pub(crate) mod local_store;
75pub mod ltx_repl;
76pub mod ltx_replication;
77pub mod machine;
78pub mod memory;
79pub mod node_log;
80pub(crate) mod operator_cell;
81#[doc(hidden)]
82pub mod otlp;
83pub mod ownership_store;
84pub mod peer_auth;
85pub mod peer_probe;
86pub mod pool;
87pub mod protocol;
88pub(crate) mod queue_batching;
89pub mod queue_cli;
90pub mod queue_policy;
91pub mod r2_cli;
92pub(crate) mod r2_store;
93pub mod replication;
94pub mod runtime;
95pub mod startup;
96pub mod storage;
97pub mod telemetry;
98pub mod wake;
99pub mod wake_entry;
100pub mod wake_format;
101pub mod ws_client;
102pub mod ws_registry;
103
104#[cfg(all(test, celld_internal_tests))]
105mod composed_simulation {
106 include!(env!("CELLD_INTERNAL_COMPOSED_SIMULATION"));
107}
108
109#[cfg(all(test, celld_internal_tests))]
110mod simulation_reproduction {
111 include!(env!("CELLD_INTERNAL_SIMULATION_REPRODUCTION"));
112}
113
114#[cfg(all(test, celld_internal_tests))]
115mod token_lifecycle_tests {
116 include!(env!("CELLD_INTERNAL_TOKEN_PROBE"));
117}
118
119#[cfg(all(test, celld_internal_tests))]
120mod conformance_world_tests {
121 include!(env!("CELLD_CONFORMANCE_WORLD_TESTS"));
122}
123
124#[cfg(all(test, celld_internal_tests))]
125#[allow(clippy::disallowed_methods)]
126mod conformance_world_s2_tests {
127 include!(env!("CELLD_CONFORMANCE_WORLD_S2_TESTS"));
128}
129
130#[cfg(all(test, celld_internal_tests))]
131#[allow(clippy::disallowed_methods)]
132mod conformance_o3_oracle {
133 include!(env!("CELLD_CONFORMANCE_O3_ORACLE_TESTS"));
134}
135
136#[cfg(all(test, celld_internal_tests))]
137#[allow(clippy::disallowed_methods)]
138mod conformance_world_s5a_tests {
139 include!(env!("CELLD_CONFORMANCE_WORLD_S5A_TESTS"));
140}
141
142#[cfg(all(test, celld_internal_tests))]
143#[allow(clippy::disallowed_methods)]
144mod conformance_world_s5c_tests {
145 include!(env!("CELLD_CONFORMANCE_WORLD_S5C_TESTS"));
146}
147
148#[cfg(celld_internal_tests)]
149#[allow(clippy::disallowed_methods)]
150#[doc(hidden)]
151pub mod conformance_sim_store {
152 include!(env!("CELLD_CONFORMANCE_SIM_STORE_TESTS"));
153}
154
155#[cfg(celld_internal_tests)]
156#[allow(clippy::disallowed_methods)]
157#[doc(hidden)]
158pub mod conformance_sim_cell_host {
159 include!(env!("CELLD_CONFORMANCE_SIM_CELL_HOST_TESTS"));
160}
161
162#[cfg(all(test, celld_internal_tests))]
163#[allow(clippy::disallowed_methods)]
164pub(crate) mod conformance_world_s1_tests {
165 include!(env!("CELLD_CONFORMANCE_WORLD_S1_TESTS"));
166}
167
168#[cfg(all(test, celld_internal_tests))]
169#[allow(clippy::disallowed_methods)]
170pub(crate) mod conformance_world_coverage {
171 include!(env!("CELLD_CONFORMANCE_WORLD_COVERAGE_TESTS"));
172}
173
174#[cfg(all(test, celld_internal_tests))]
175#[allow(clippy::disallowed_methods)]
176mod conformance_world_s3_tests {
177 include!(env!("CELLD_CONFORMANCE_WORLD_S3_TESTS"));
178}
179
180#[cfg(all(test, celld_internal_tests))]
181#[allow(clippy::disallowed_methods)]
182mod conformance_world_s5b_tests {
183 include!(env!("CELLD_CONFORMANCE_WORLD_S5B_TESTS"));
184}
185
186/// Completion token for a resident-isolate reservation made by the decision
187/// core. Dropping the queued/running job reports that the cell is idle again;
188/// the token contains no selection or lifecycle policy of its own.
189pub struct CellActivityGuard {
190 finish: Option<Box<dyn FnOnce() + Send>>,
191}
192
193impl CellActivityGuard {
194 pub fn new(finish: impl FnOnce() + Send + 'static) -> Self {
195 Self {
196 finish: Some(Box::new(finish)),
197 }
198 }
199}
200
201impl Drop for CellActivityGuard {
202 fn drop(&mut self) {
203 if let Some(finish) = self.finish.take() {
204 finish();
205 }
206 }
207}
208
209/// A stateless entrypoint selected for one fetch request.
210#[derive(Clone, Debug, PartialEq)]
211pub struct WorkerFetchEntrypoint {
212 pub name: String,
213 /// The caller's `ctx.props` as V8 structured-clone bytes. An empty vector
214 /// represents an omitted or `undefined` props value.
215 pub props: Vec<u8>,
216}
217
218/// Resource limits selected by a Worker Loader stub for one invocation.
219#[doc(hidden)]
220#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Deserialize)]
221#[serde(rename_all = "camelCase", deny_unknown_fields)]
222pub struct WorkerInvocationLimits {
223 pub cpu_ms: Option<u32>,
224 pub sub_requests: Option<u32>,
225}
226
227/// One operation on a Worker entrypoint. A property read has no arguments,
228/// while a call owns its complete receiver path and structured-clone payload.
229pub enum WorkerRpcOperation {
230 Get { path: Vec<String> },
231 Call { path: Vec<String>, args: Vec<u8> },
232}
233
234pub enum WorkerJob {
235 Fetch {
236 queued_at: std::time::Instant,
237 /// An entrypoint dispatcher target, or the direct default export when
238 /// absent.
239 entrypoint: Option<WorkerFetchEntrypoint>,
240 invocation_limits: Option<WorkerInvocationLimits>,
241 url: String,
242 method: String,
243 body: js::RequestBody,
244 headers: Vec<(String, String)>,
245 request_id: Option<js::RequestId>,
246 /// Receives one completed invocation report for Dynamic Worker tails.
247 /// Ordinary fetches leave this empty.
248 tail_report: Option<tokio::sync::oneshot::Sender<String>>,
249 reply: tokio::sync::oneshot::Sender<anyhow::Result<js::HttpResponse>>,
250 },
251 Rpc {
252 entrypoint: String,
253 operation: WorkerRpcOperation,
254 /// The caller's `ctx.props` as V8 structured-clone bytes, the same
255 /// encoding as `args`. It is empty when the caller sent none, which no
256 /// encoded value can be. A Worker Loader entrypoint or a transferred
257 /// Service Binding can set it.
258 props: Vec<u8>,
259 invocation_limits: Option<WorkerInvocationLimits>,
260 reply: tokio::sync::oneshot::Sender<anyhow::Result<Vec<u8>>>,
261 },
262 Queue {
263 queued_at: std::time::Instant,
264 batch: js::QueueBatch,
265 reply: tokio::sync::oneshot::Sender<anyhow::Result<js::QueueDispatchResult>>,
266 },
267}
268
269/// Temporary host seam required by the verbatim JS adapter. The runtime
270/// adapter will construct the real shared Worker queue; lifecycle policy does
271/// not move into this type.
272/// Compatibility switches copied with the JS adapter. These are runtime
273/// semantics, not lifecycle decisions.
274pub fn worker_compat(metadata: &serde_json::Value) -> js::Compat {
275 let flags = metadata
276 .get("compatibility_flags")
277 .and_then(serde_json::Value::as_array);
278 let has_flag = |name: &str| {
279 flags.is_some_and(|flags| {
280 flags
281 .iter()
282 .any(|flag| flag.as_str().is_some_and(|flag| flag == name))
283 })
284 };
285 let date = metadata
286 .get("compatibility_date")
287 .and_then(serde_json::Value::as_str);
288 let switch = |enable: &str, disable: &str, since: &str| {
289 if has_flag(enable) {
290 return true;
291 }
292 if has_flag(disable) {
293 return false;
294 }
295 date.is_some_and(|date| date >= since)
296 };
297 js::Compat {
298 delete_all_deletes_alarm: switch(
299 "delete_all_deletes_alarm",
300 "delete_all_preserves_alarm",
301 "2026-02-24",
302 ),
303 js_rpc: has_flag("js_rpc"),
304 fetcher_get_put_delete: !switch(
305 "fetcher_no_get_put_delete",
306 "fetcher_has_get_put_delete",
307 "2024-03-26",
308 ),
309 sqlite_vec: has_flag("sqlite_vec"),
310 websocket_standard_binary_type: has_flag("websocket_standard_binary_type"),
311 queue_json_messages: switch("queue_json_messages", "queue_v8_messages", "2024-03-18"),
312 }
313}
314
315/// What this build adds to upstream celld (Homeflare patches), as printed by
316/// `celld --version` on its `homeflare:` line. Platforms deploying through
317/// celld read it to know which config keys it accepts.
318pub const HOMEFLARE_FEATURES: &[&str] = &[
319 "node-net",
320 "node-dns",
321 "node-url",
322 "node-process",
323 "response-clone-stream",
324 "media",
325 "version-metadata",
326 "ratelimits",
327 "send-email",
328 "container-memory-budget",
329 "privileged-containers",
330];