Diffinery

homeflare/celldpublic

feat(bindings): version_metadata binding, and features in --version

Jason Schwarzenberger authored 1 parent 2477acdcommit 5234aa998452a40eef879578e7d5e01d3a64ed4cBrowse files
11 files changed+159−3
Files (11)
modifiedHOMEFLARE.md+2−0View file
@@ -24,6 +24,8 @@
2424 | `node:url` (all but the legacy `parse` / `resolve`) | celld had no `node:url`; Fedify's WebFinger handler calls `domainToASCII` and `domainToUnicode`. Both run Node's own steps (the input set as a `ws://x` hostname) through new host ops on the `url` crate. |
2525 | `node:process` as the global `process` | The module was the throwing stub while `globalThis.process` existed, so Fedify's User-Agent (`Node.js/${process.versions.node}`, taken when the global has a Node version) threw on every outgoing request. Found by listing palm's bundle imports. |
2626 | `media` binding (Media Transformations) | palm makes video thumbnails with `env.MEDIA_TRANSFORMS.input(stream).transform(...).output({ mode: "frame" })`. The Wrangler `media` key becomes a binding (config → manifest → `WorkerConfig::with_media` → `__makeMediaBinding`) that reads the input and posts it, with both option objects in the `x-media-transform` header, to `CELLD_MEDIA_URL/transform`: Homeflare's `homeflare-media` (ffmpeg). Its answers and `{code, message}` errors (as `MediaError`) are the binding's. Without `CELLD_MEDIA_URL` a result rejects with code 9500. |
27+| `version_metadata` binding | Upstream celld had none, so Homeflare passed the version ID as a plain string. The binding is now Cloudflare's frozen `{ id, tag, timestamp }`. The config may set all three (Homeflare passes its own version ID, tag and time, so they match its Dashboard and `wrangler versions`); otherwise the id is the deployment's version, the tag is empty and the timestamp is the deploy time. |
28+| `homeflare:` line in `celld --version` | Lists what this build adds (`HOMEFLARE_FEATURES` in `lib.rs`), so Homeflare sends a config key only to a celld that accepts it. Add a feature there with each patch. |
2729
2830 ## Building
2931
modifiedcrates/celld/deploy.rs+64−1View file
@@ -58,6 +58,7 @@
5858 "r2_buckets",
5959 "worker_loaders",
6060 "media",
61+ "version_metadata",
6162 "containers",
6263 "no_bundle",
6364 "define",
@@ -552,6 +553,14 @@
552553 format!("env.{name} (Media)"),
553554 "Media Transformations".to_string(),
554555 )),
556+ Some("version_metadata") => Some((
557+ format!("env.{name} (Version metadata)"),
558+ binding
559+ .get("id")
560+ .and_then(Value::as_str)
561+ .unwrap_or("this deployment's version")
562+ .to_string(),
563+ )),
555564 Some("plain_text") => Some((
556565 format!("env.{name} (Text)"),
557566 "Environment Variable".to_string(),
@@ -1905,6 +1914,59 @@
19051914 }
19061915 Some(_) => bail!("config `media` must be an object with a `binding` name"),
19071916 };
1917+ // `version_metadata` (Homeflare patch): Cloudflare's {id, tag, timestamp}
1918+ // for the running version. A platform deploying through celld can set
1919+ // all three (Homeflare passes its own version ID, tag and time, so they
1920+ // match its Dashboard and `wrangler versions`); otherwise the id is the
1921+ // deployment's version, the tag is empty and the timestamp is now.
1922+ let version_metadata = match object.get("version_metadata") {
1923+ None => None,
1924+ Some(Value::Object(metadata)) => {
1925+ let binding = match metadata.get("binding") {
1926+ Some(Value::String(binding)) => binding.as_str(),
1927+ Some(_) => bail!("version_metadata `binding` must be a string"),
1928+ None => bail!("version_metadata has no `binding` name"),
1929+ };
1930+ if !valid_binding(binding) {
1931+ bail!("invalid version_metadata binding name: {binding:?}");
1932+ }
1933+ let field = |key: &str| -> anyhow::Result<Option<String>> {
1934+ match metadata.get(key) {
1935+ None | Some(Value::Null) => Ok(None),
1936+ Some(Value::String(value)) => Ok(Some(value.clone())),
1937+ Some(_) => bail!("version_metadata `{key}` must be a string"),
1938+ }
1939+ };
1940+ let id = field("id")?;
1941+ let tag = field("tag")?.unwrap_or_default();
1942+ let timestamp = match field("timestamp")? {
1943+ Some(timestamp) => {
1944+ chrono::DateTime::parse_from_rfc3339(&timestamp).map_err(|_| {
1945+ anyhow!(
1946+ "version_metadata `timestamp` must be an RFC 3339 time: {timestamp:?}"
1947+ )
1948+ })?;
1949+ timestamp
1950+ }
1951+ None => chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
1952+ };
1953+ if let Some(key) = metadata
1954+ .keys()
1955+ .find(|key| !matches!(key.as_str(), "binding" | "id" | "tag" | "timestamp"))
1956+ {
1957+ bail!("version_metadata sets `{key}`, which celld does not support");
1958+ }
1959+ bindings.push(json!({
1960+ "type": "version_metadata",
1961+ "name": binding,
1962+ "id": id,
1963+ "tag": tag,
1964+ "timestamp": timestamp,
1965+ }));
1966+ Some(binding)
1967+ }
1968+ Some(_) => bail!("config `version_metadata` must be an object with a `binding` name"),
1969+ };
19081970 let mut vars = BTreeMap::new();
19091971 match object.get("vars") {
19101972 None => {}
@@ -1971,7 +2033,8 @@
19712033 || declared_vars
19722034 || !r2_binding_names.is_empty()
19732035 || !worker_loaders.is_empty()
1974- || media_binding.is_some())
2036+ || media_binding.is_some()
2037+ || version_metadata.is_some())
19752038 {
19762039 bail!("an asset-only project cannot declare Worker bindings");
19772040 }
modifiedcrates/celld/fleet.rs+24−0View file
@@ -900,6 +900,26 @@
900900 let media_bindings = bindings(&manifest, "media")
901901 .filter_map(|binding| binding.get("name")?.as_str().map(str::to_string))
902902 .collect();
903+ // `version_metadata` (Homeflare patch): its `env` name and the frozen
904+ // {id, tag, timestamp}; the id defaults to this deployment's version.
905+ let version_metadata = bindings(&manifest, "version_metadata")
906+ .next()
907+ .and_then(|binding| {
908+ let name = binding.get("name")?.as_str()?.to_string();
909+ let id = binding
910+ .get("id")
911+ .and_then(serde_json::Value::as_str)
912+ .unwrap_or(&manifest.version)
913+ .to_string();
914+ Some((
915+ name,
916+ serde_json::json!({
917+ "id": id,
918+ "tag": binding.get("tag").and_then(serde_json::Value::as_str).unwrap_or(""),
919+ "timestamp": binding.get("timestamp").and_then(serde_json::Value::as_str).unwrap_or(""),
920+ }),
921+ ))
922+ });
903923 let services = service_bindings(&manifest);
904924 let vars = worker_vars(&manifest);
905925 let compat = crate::worker_compat(&manifest.raw_metadata);
@@ -957,6 +977,7 @@
957977 asset_binding,
958978 loader_bindings,
959979 media_bindings,
980+ version_metadata,
960981 assets,
961982 services,
962983 crons,
@@ -978,6 +999,9 @@
978999 /// `env` names of this script's Media Transformations bindings (Homeflare
9791000 /// patch).
9801001 pub media_bindings: Vec<String>,
1002+ /// The `version_metadata` binding's `env` name and its {id, tag,
1003+ /// timestamp} (Homeflare patch).
1004+ pub version_metadata: Option<(String, serde_json::Value)>,
9811005 pub assets: Option<crate::assets::AssetResolver>,
9821006 pub services: Vec<(String, String, Option<String>)>,
9831007 /// `triggers.crons` from the manifest, driving the reserved cron cell.
modifiedcrates/celld/generation.rs+2−0View file
@@ -555,6 +555,7 @@
555555 asset_binding,
556556 loader_bindings,
557557 media_bindings,
558+ version_metadata,
558559 assets: resolver,
559560 services,
560561 crons,
@@ -574,6 +575,7 @@
574575 .with_asset_binding(asset_binding)
575576 .with_loaders(loader_bindings)
576577 .with_media(media_bindings)
578+ .with_version_metadata(version_metadata)
577579 .with_queue_consumers(queue_catalog.clone())
578580 .with_crons(if is_primary { crons } else { Vec::new() })
579581 .with_containers(containers)
modifiedcrates/celld/js.rs+10−0View file
@@ -1920,6 +1920,8 @@
19201920 loader_bindings: Vec<String>,
19211921 /// `env` names of Media Transformations bindings (Homeflare patch).
19221922 media_bindings: Vec<String>,
1923+ /// The `version_metadata` binding and its value (Homeflare patch).
1924+ version_metadata: Option<(String, serde_json::Value)>,
19231925 /// Ambient outbound authority. Loaded workers may be denied.
19241926 egress: EgressPolicy,
19251927 /// Structured-clone values and host-minted service routes that a loaded
@@ -2067,6 +2069,7 @@
20672069 asset_binding: None,
20682070 loader_bindings: Vec::new(),
20692071 media_bindings: Vec::new(),
2072+ version_metadata: None,
20702073 egress: EgressPolicy::Allow,
20712074 loader_env: None,
20722075 resource_limits: None,
@@ -2151,6 +2154,13 @@
21512154 self
21522155 }
21532156
2157+ /// Give this Worker a `version_metadata` binding: an `env` name and its
2158+ /// {id, tag, timestamp} (Homeflare patch).
2159+ pub fn with_version_metadata(mut self, binding: Option<(String, serde_json::Value)>) -> Self {
2160+ self.version_metadata = binding;
2161+ self
2162+ }
2163+
21542164 /// Set this Worker's ambient outbound authority (loaded workers only).
21552165 fn with_egress(mut self, egress: EgressPolicy) -> Self {
21562166 self.egress = egress;
modifiedcrates/celld/js/bootstrap.rs+5−0View file
@@ -683,6 +683,11 @@
683683 for name in &config.loader_bindings {
684684 lines.push_str(&format!("e[{:?}] = __celld.__makeLoader();\n", name));
685685 }
686+ // Version metadata (Homeflare patch): a frozen {id, tag, timestamp},
687+ // as on Cloudflare.
688+ if let Some((name, value)) = &config.version_metadata {
689+ lines.push_str(&format!("e[{:?}] = Object.freeze({});\n", name, value));
690+ }
686691 // Media Transformations (Homeflare patch): the binding posts to the
687692 // node's media service, or says it has none.
688693 if !config.media_bindings.is_empty() {
modifiedcrates/celld/lib.rs+13−0View file
@@ -311,3 +311,16 @@
311311 queue_json_messages: switch("queue_json_messages", "queue_v8_messages", "2024-03-18"),
312312 }
313313 }
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.
318+pub 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+];
modifiedcrates/celld/main.rs+9−2View file
@@ -3548,8 +3548,14 @@
35483548 } else {
35493549 ""
35503550 };
3551- celld::cli_output::Output::new(celld::cli_output::Format::Text)
3552- .line(format_args!("celld {}{profile}", env!("CARGO_PKG_VERSION")))?;
3551+ // The second line lists what this build adds to upstream celld
3552+ // (Homeflare patch), so a platform deploying through it knows
3553+ // which config it accepts.
3554+ celld::cli_output::Output::new(celld::cli_output::Format::Text).line(format_args!(
3555+ "celld {}{profile}\nhomeflare: {}",
3556+ env!("CARGO_PKG_VERSION"),
3557+ celld::HOMEFLARE_FEATURES.join(" ")
3558+ ))?;
35533559 return Ok(());
35543560 }
35553561 Action::Diagnose {
@@ -4054,6 +4060,7 @@
40544060 .map(str::to_string)
40554061 .collect(),
40564062 media_bindings: Vec::new(),
4063+ version_metadata: None,
40574064 assets: None,
40584065 services: Vec::new(),
40594066 crons,
modifieddocs/cloudflare-compat.md+1−0View file
@@ -27,6 +27,7 @@
2727 | [D1](services/d1.md) | **Yes** |
2828 | [Workflows](services/workflows.md) | **Yes** |
2929 | [R2](services/r2.md) | **Yes** |
30+| Version metadata (`version_metadata` binding) | **Yes** — `{ id, tag, timestamp }`; a platform can set all three in the config (Homeflare patch) |
3031 | Media Transformations (`media` binding) | **Partial** — needs a media service at `CELLD_MEDIA_URL`, such as Homeflare's `homeflare-media` (Homeflare patch) |
3132 | Workers AI | **No** |
3233 | Vectorize | **No** |
addedhomeflare/smoke/version-metadata/index.js+17−0View file
@@ -1,0 +1,17 @@
1+// Smoke test for the version_metadata binding: Cloudflare's frozen
2+// { id, tag, timestamp } with the values the config set.
3+const expectEqual = (name, got, want) => ({ name, ok: JSON.stringify(got) === JSON.stringify(want), got });
4+
5+export default {
6+ async fetch(request, env) {
7+ const vm = env.CF_VERSION_METADATA;
8+ const checks = [
9+ expectEqual("is an object", typeof vm, "object"),
10+ expectEqual("fields", { ...vm }, { id: "7b2f4b49-9d0a-4d0e-8a2b-1f3c5d6e7f80", tag: "v1.2.3", timestamp: "2026-12-05T08:00:00.000Z" }),
11+ expectEqual("frozen", Object.isFrozen(vm), true),
12+ expectEqual("timestamp parses", new Date(vm.timestamp).toISOString(), vm.timestamp),
13+ ];
14+ const failed = checks.filter((c) => !c.ok);
15+ return Response.json({ ok: failed.length === 0, failed, checks }, { status: failed.length ? 500 : 200 });
16+ },
17+};
addedhomeflare/smoke/version-metadata/wrangler.jsonc+12−0View file
@@ -1,0 +1,12 @@
1+{
2+ "name": "version-metadata",
3+ "main": "index.js",
4+ "compatibility_date": "2026-01-01",
5+ // As Homeflare deploys it: its own version ID, tag and time.
6+ "version_metadata": {
7+ "binding": "CF_VERSION_METADATA",
8+ "id": "7b2f4b49-9d0a-4d0e-8a2b-1f3c5d6e7f80",
9+ "tag": "v1.2.3",
10+ "timestamp": "2026-12-05T08:00:00.000Z"
11+ }
12+}