@@ -520,10 +520,16 @@ pub async fn apply_legacy_config_mutation_with_model_snapshot(
520520 . await
521521 . map_err ( |error| error. to_string ( ) ) ?
522522 } ;
523- let effective_value = config_service
524- . get_config ( Some ( path) )
525- . await
526- . map_err ( |error| error. to_string ( ) ) ?;
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.
528+ let effective_value = match config_service. get_config ( Some ( path) ) . await {
529+ Ok ( value) => value,
530+ Err ( crate :: util:: errors:: OpenBitFunError :: NotFound ( _) ) if changed => Value :: Null ,
531+ Err ( error) => return Err ( error. to_string ( ) ) ,
532+ } ;
527533 Ok ( AppliedLegacyProductConfig {
528534 changed,
529535 changed_path : path. to_string ( ) ,
@@ -739,6 +745,53 @@ mod tests {
739745 ) ;
740746 }
741747
748+ #[ tokio:: test]
749+ async fn legacy_mutation_accepts_writes_of_an_omitted_default ( ) {
750+ let ( service, _dir) = test_service ( "legacy-omitted-default" ) . await ;
751+ let path = "app.flow_chat.send_during_turn" ;
752+
753+ let queued = apply_legacy_config_mutation ( & service, path, json ! ( "queue" ) )
754+ . await
755+ . expect ( "queue write" ) ;
756+ assert ! ( queued. changed) ;
757+ assert_eq ! ( queued. effective_value, json!( "queue" ) ) ;
758+
759+ let immediate = apply_legacy_config_mutation ( & service, path, json ! ( "immediate" ) )
760+ . await
761+ . expect ( "writing the omitted default must not fail its read-back" ) ;
762+ assert ! ( immediate. changed) ;
763+ assert_eq ! ( immediate. effective_value, Value :: Null ) ;
764+ let config: GlobalConfig = service. get_config ( None ) . await . unwrap ( ) ;
765+ assert_eq ! (
766+ serde_json:: to_value( config. app. flow_chat. send_during_turn) . unwrap( ) ,
767+ json!( "immediate" )
768+ ) ;
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}" ) ;
793+ }
794+
742795 #[ tokio:: test]
743796 async fn config_handler_round_trips_through_the_shared_service ( ) {
744797 let ( service, _dir) = test_service ( "product-control-round-trip" ) . await ;
0 commit comments