@@ -417,7 +417,9 @@ for (const native of [false, true]) {
417417 const commit = prepareCoordinationProjectionCommit ( { goal_id : head . goal_id ,
418418 operation_id : "next-mutation" , expected_provider_revision : initial . provider_revision ,
419419 projection : reopened . head , mutations : [ { kind : "todo_upsert" , todo : changed } ] } ) ;
420- assert . deepEqual ( commit . next_projection . todo_read_model , coordinationTodoReadModel ( [ changed ] , schema ) ) ;
420+ assert . deepEqual ( commit . next_projection . todo_read_model , {
421+ ...head . todo_read_model , records_sha256 : canonicalAuthoritySha256 ( [ changed ] ) ,
422+ } , "an ordinary edit must keep the exact persisted field declaration" ) ;
421423 assert . equal ( ( await store . commitAuthority ( commit ) ) . status , "applied" ) ;
422424 const updated = await listLocalCoordinationTodos ( request , { createStore} ) ;
423425 assert . equal ( updated . status , "loaded" ) ;
@@ -489,6 +491,10 @@ for (const native of [false, true]) {
489491// fixture and its registered additions, independently of today's field list.
490492const preReceiptFields = [ ...previousReleaseFields ] ;
491493preReceiptFields . splice ( preReceiptFields . indexOf ( "completion_turn_key" ) + 1 , 0 , "completion_result" ) ;
494+ const releasedBeforeScopedMonitors = [ ...preReceiptFields ] ;
495+ releasedBeforeScopedMonitors . splice (
496+ releasedBeforeScopedMonitors . indexOf ( "completion_recovery" ) + 1 , 0 , "completion_receipt_id" ,
497+ ) ;
492498for ( const native of [ false , true ] ) {
493499 test ( `pre-receipt ${ native ? "domain" : "canonical" } head remains readable and upgrades on commit` , ( ) => {
494500 const fields = preReceiptFields . filter ( field =>
@@ -516,6 +522,53 @@ for (const native of [false, true]) {
516522 } ) ;
517523}
518524
525+ for ( const native of [ false , true ] ) {
526+ test ( `released ${ native ? "domain" : "canonical" } manifest changes only when the mutation uses a newer field` , ( ) => {
527+ const fields = releasedBeforeScopedMonitors . filter ( field =>
528+ ! native || ! historicalFields . projection_metadata_fields . includes ( field ) ) ;
529+ const schema = native ? TODO_DOMAIN_READ_RECORD_SCHEMA : TODO_CANONICAL_READ_RECORD_SCHEMA ;
530+ const monitor : JsonObject = {
531+ schema_version : native ? TODO_DOMAIN_ITEM_SCHEMA : "todo_item_v0" ,
532+ todo_id : "todo_monitor" , role : "agent" , status : "open" , done : false ,
533+ text : "Observe the assigned run" , archive_state : "active" ,
534+ task_class : "continuous_monitor" ,
535+ ...( native ? { } : { source_section : "Agent Todo" } ) ,
536+ } ;
537+ const head = {
538+ goal_id : "monitor-goal" , todos : [ monitor ] , leases : [ ] ,
539+ todo_read_model : {
540+ schema_version : schema , contract_fields : fields , todo_count : 1 ,
541+ records_sha256 : canonicalAuthoritySha256 ( [ monitor ] ) ,
542+ } ,
543+ } ;
544+ const noteEdit = { ...monitor , note : "Keep the existing watch" } ;
545+ const edited = reduceCoordinationProjection ( head , head . goal_id , [ { kind : "todo_upsert" , todo : noteEdit } ] ) ;
546+ assert . deepEqual ( edited . todo_read_model , {
547+ ...head . todo_read_model , records_sha256 : canonicalAuthoritySha256 ( [ noteEdit ] ) ,
548+ } ) ;
549+
550+ const observation = {
551+ ...noteEdit , material_change_scope : "case-a/run-1" ,
552+ // The Monitor persists a scope digest, generation, and result digest.
553+ material_change_scope_generations : "95866d27011023fae340614c:1:cb27aee87af9e0125c0766d8" ,
554+ } ;
555+ const observed = reduceCoordinationProjection ( edited , head . goal_id , [ { kind : "todo_upsert" , todo : observation } ] ) ;
556+ const model = validateCoordinationTodoReadModel ( observed , head . goal_id ) ;
557+ assert . deepEqual ( observed . todos , [ observation ] ) ;
558+ assert . deepEqual ( model . contract_fields , [
559+ ...fields . slice ( 0 , fields . indexOf ( "material_change_generation" ) + 1 ) ,
560+ "material_change_scope" , "material_change_scope_generations" ,
561+ ...fields . slice ( fields . indexOf ( "material_change_generation" ) + 1 ) ,
562+ ] ) ;
563+ const cleared = reduceCoordinationProjection ( observed , head . goal_id , [ {
564+ kind : "todo_upsert" , todo : noteEdit ,
565+ clear_fields : [ "material_change_scope" , "material_change_scope_generations" ] ,
566+ } ] ) ;
567+ assert . deepEqual ( validateCoordinationTodoReadModel ( cleared , head . goal_id ) . contract_fields , model . contract_fields ,
568+ "once committed, a newer field declaration does not downgrade implicitly" ) ;
569+ } ) ;
570+ }
571+
519572for ( const native of [ false , true ] ) {
520573 test ( `read-model order uses unique Unicode identities without weakening ${ native ? "domain" : "canonical" } content validation` , ( ) => {
521574 // U+E000 precedes U+10000 in persisted Unicode code-point order, but not
0 commit comments