Skip to content

Commit 76e5a9d

Browse files
committed
fix(config): keep failing legacy writes the config silently drops
Serde ignores unknown fields, so a legacy write to a misspelled path, or to a field this host does not know yet, leaves the config unchanged and used to fail on its read-back. Only report a missing leaf as null when the write actually changed the config, which is the case when restoring an omitted default or clearing an optional value.
1 parent cfbea9b commit 76e5a9d

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

‎src/crates/assembly/core/src/agentic/tools/openbitfun_control_config.rs‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,14 @@ pub async fn apply_legacy_config_mutation_with_model_snapshot(
520520
.await
521521
.map_err(|error| error.to_string())?
522522
};
523-
// Fields that keep legacy files unchanged omit their default value when
524-
// serialized, so a successful write of that default leaves no leaf to
525-
// read back. Report it as null, matching an optional read of the path.
523+
// Some fields omit their default (or `None`) when serialized so legacy
524+
// files stay unchanged, so a write that restores it leaves no leaf to read
525+
// back. Report that as null, matching an optional read of the path. Only a
526+
// write that changed the config qualifies: serde drops unknown fields
527+
// without changing anything, and those writes must keep failing loudly.
526528
let effective_value = match config_service.get_config(Some(path)).await {
527529
Ok(value) => value,
528-
Err(crate::util::errors::OpenBitFunError::NotFound(_)) => Value::Null,
530+
Err(crate::util::errors::OpenBitFunError::NotFound(_)) if changed => Value::Null,
529531
Err(error) => return Err(error.to_string()),
530532
};
531533
Ok(AppliedLegacyProductConfig {
@@ -764,6 +766,30 @@ mod tests {
764766
serde_json::to_value(config.app.flow_chat.send_during_turn).unwrap(),
765767
json!("immediate")
766768
);
769+
770+
let cleared_path = "app.flow_chat.last_mode_id";
771+
apply_legacy_config_mutation(&service, cleared_path, json!("Plan"))
772+
.await
773+
.expect("optional write");
774+
let cleared = apply_legacy_config_mutation(&service, cleared_path, Value::Null)
775+
.await
776+
.expect("clearing an optional leaf must not fail its read-back");
777+
assert!(cleared.changed);
778+
assert_eq!(cleared.effective_value, Value::Null);
779+
}
780+
781+
#[tokio::test]
782+
async fn legacy_mutation_still_rejects_paths_the_config_drops() {
783+
let (service, _dir) = test_service("legacy-unknown-path").await;
784+
785+
let error = apply_legacy_config_mutation(
786+
&service,
787+
"app.flow_chat.not_a_known_field",
788+
json!("queue"),
789+
)
790+
.await
791+
.expect_err("a write that serde drops must not report success");
792+
assert!(error.contains("not found"), "{error}");
767793
}
768794

769795
#[tokio::test]

0 commit comments

Comments
 (0)