worker: replace filesystem prompts with effective DCDL catalog

This commit is contained in:
2026-08-14 13:45:03 +09:00
parent 48ff977d06
commit 0ad7d6d210
45 changed files with 892 additions and 1895 deletions
@@ -24,6 +24,8 @@ pub struct ConfigBundle {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub declarations: Vec<ConfigDeclaration>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub prompt_catalog: Option<worker::EffectivePromptCatalog>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub profile_source_archive: Option<ProfileSourceArchive>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub profile_source_archive_handle: Option<BackendResourceHandle>,
@@ -69,6 +71,16 @@ impl ConfigBundle {
));
}
if let Some(prompt_catalog) = &self.prompt_catalog {
lines.push(format!(
"prompt_catalog\0{}\0{}\0{}\0{}",
prompt_catalog.config_revision,
prompt_catalog.schema_fingerprint,
prompt_catalog.toolchain_fingerprint,
prompt_catalog.catalog_digest
));
}
if let Some(archive) = &self.profile_source_archive {
lines.push(format!(
"profile_archive\0{}\0{}\0{}",
@@ -274,6 +286,12 @@ pub(crate) fn validate_config_bundle(bundle: &ConfigBundle) -> Result<(), Runtim
validate_declaration_reference(&bundle.metadata.id, declaration)?;
}
if let Some(prompt_catalog) = &bundle.prompt_catalog {
prompt_catalog.verify_digest().map_err(|error| {
RuntimeError::InvalidRequest(format!("invalid Prompt catalog projection: {error}"))
})?;
}
if let Some(archive) = &bundle.profile_source_archive {
validate_profile_source_archive_ref(&archive.reference).map_err(|err| {
RuntimeError::InvalidRequest(format!("invalid profile source archive: {err}"))
@@ -582,6 +600,7 @@ mod tests {
name: "credential".to_string(),
reference: reference.to_string(),
}],
prompt_catalog: None,
profile_source_archive: None,
profile_source_archive_handle: None,
}
@@ -615,6 +634,32 @@ mod tests {
validate_config_bundle(&bundle_with_declaration("vault:team.api-key")).unwrap();
}
#[test]
fn validates_immutable_prompt_catalog_projection() {
let mut bundle = bundle_with_declaration("secret:github-token");
bundle.prompt_catalog = Some(
worker::EffectivePromptCatalog::new(
std::collections::BTreeMap::from([("default".to_string(), "hello".to_string())]),
7,
"schema",
"toolchain",
)
.unwrap(),
);
bundle = bundle.with_computed_digest();
validate_config_bundle(&bundle).unwrap();
bundle
.prompt_catalog
.as_mut()
.unwrap()
.templates
.insert("default".into(), "tampered".into());
bundle = bundle.with_computed_digest();
let error = validate_config_bundle(&bundle).unwrap_err();
assert!(error.to_string().contains("catalog digest mismatch"));
}
#[test]
fn bundle_summary_redacts_runtime_internal_resource_handle() {
let mut bundle = bundle_with_declaration("secret:github-token");
+2
View File
@@ -1811,6 +1811,7 @@ mod tests {
label: Some("test".to_string()),
}],
declarations: Vec::new(),
prompt_catalog: None,
profile_source_archive: None,
profile_source_archive_handle: None,
}
@@ -2648,6 +2649,7 @@ mod ws_tests {
label: Some("ws".to_string()),
}],
declarations: Vec::new(),
prompt_catalog: None,
profile_source_archive: None,
profile_source_archive_handle: None,
}
+3 -3
View File
@@ -743,10 +743,10 @@ mod tests {
.load(Some("profiles/main.dcdl"), "./shared.dcdl")
.unwrap();
match loaded {
LoadedImport::Source(source) => {
assert_eq!(source.key, "profiles/shared.dcdl");
LoadedImport::Source { key, .. } => {
assert_eq!(key, "profiles/shared.dcdl");
}
LoadedImport::Value(_) => panic!("expected source import"),
LoadedImport::Value { .. } => panic!("expected source import"),
}
}
+1
View File
@@ -2832,6 +2832,7 @@ mod tests {
name: "read".to_string(),
reference: "capability:read".to_string(),
}],
prompt_catalog: None,
profile_source_archive: None,
profile_source_archive_handle: None,
}
+20 -5
View File
@@ -53,7 +53,7 @@ use worker::feature::builtin::{
#[cfg(feature = "ws-server")]
use worker::ipc::protocol_session::{live_log_entry_event, subscribe_worker_protocol_session};
use worker::{
PromptLoader, SegmentLogSink, WORKER_INPUT_SUBMISSION_EXTENSION_DOMAIN, Worker,
PromptCatalogSource, SegmentLogSink, WORKER_INPUT_SUBMISSION_EXTENSION_DOMAIN, Worker,
WorkerController, WorkerControllerTransport, WorkerError, WorkerFilesystemAuthority,
WorkerHandle, WorkerSharedState, WorkerWorkspaceContext, WorkspaceClient, WorkspaceId,
};
@@ -329,12 +329,12 @@ impl ProfileRuntimeWorkerFactory {
fn restore_fallback_manifest(
worker_name: &str,
) -> Result<(manifest::WorkerManifest, PromptLoader), String> {
) -> Result<(manifest::WorkerManifest, PromptCatalogSource), String> {
let mut config = manifest::WorkerManifestConfig::builtin_defaults();
config.worker.name = Some(worker_name.to_string());
let manifest = manifest::WorkerManifest::try_from(config)
.map_err(|err| format!("failed to build restore fallback manifest: {err}"))?;
Ok((manifest, PromptLoader::builtins_only()))
Ok((manifest, PromptCatalogSource::builtins_only()))
}
async fn resolve_profile_source_archive(
&self,
@@ -566,7 +566,7 @@ impl RuntimeWorkerFactory for ProfileRuntimeWorkerFactory {
let archive = self
.resolve_profile_source_archive(&request.request.profile_source)
.await?;
let (manifest, loader) = {
let (manifest, mut loader) = {
let manifest = archive
.resolve_profile(selector, &worker_root, &worker_name)
.map_err(|err| format!("failed to resolve profile source archive: {err}"))?;
@@ -584,6 +584,13 @@ impl RuntimeWorkerFactory for ProfileRuntimeWorkerFactory {
)?
}
};
if let Some(prompt_catalog) = request
.config_bundle
.as_ref()
.and_then(|bundle| bundle.prompt_catalog.clone())
{
loader = loader.with_effective_catalog(prompt_catalog);
}
let flow_transition_enabled = manifest.feature.flow.enabled;
let worker_aggregate_dir = self.worker_aggregate_dir(&request.worker_ref)?;
@@ -719,7 +726,14 @@ impl RuntimeWorkerFactory for ProfileRuntimeWorkerFactory {
self.worker_mutation_identity.as_ref(),
self.embedded_worker_mutation_dispatcher.as_ref(),
);
let (manifest, loader) = Self::restore_fallback_manifest(&worker_name)?;
let (manifest, mut loader) = Self::restore_fallback_manifest(&worker_name)?;
if let Some(prompt_catalog) = request
.config_bundle
.as_ref()
.and_then(|bundle| bundle.prompt_catalog.clone())
{
loader = loader.with_effective_catalog(prompt_catalog);
}
let worker_aggregate_dir = self.worker_aggregate_dir(&request.worker_ref)?;
let session_dir = worker_aggregate_dir.join("session");
@@ -2090,6 +2104,7 @@ mod tests {
label: Some("adapter-test".to_string()),
}],
declarations: Vec::new(),
prompt_catalog: None,
profile_source_archive: Some(sample_profile_archive()),
profile_source_archive_handle: None,
}