@@ -60,14 +60,13 @@ export async function stageSkillProposalGeneration(params: {
6060 const generationDir = path . join ( generationsDir , generationId ) ;
6161 try {
6262 await stateRoot . mkdir ( stagingDir ) ;
63- await stateRoot . create ( path . join ( stagingDir , PROPOSAL_DRAFT_FILE ) , params . content , {
64- encoding : "utf8" ,
65- } ) ;
63+ await createDurableGenerationFile (
64+ stateRoot ,
65+ path . join ( stagingDir , PROPOSAL_DRAFT_FILE ) ,
66+ params . content ,
67+ ) ;
6668 for ( const file of params . supportFiles ?? [ ] ) {
67- await stateRoot . create ( path . join ( stagingDir , file . path ) , file . content , {
68- encoding : "utf8" ,
69- mkdir : true ,
70- } ) ;
69+ await createDurableGenerationFile ( stateRoot , path . join ( stagingDir , file . path ) , file . content ) ;
7170 }
7271 // The record only names the destination after this same-filesystem move, so
7372 // readers can never observe a partially populated generation.
@@ -80,6 +79,20 @@ export async function stageSkillProposalGeneration(params: {
8079 }
8180}
8281
82+ async function createDurableGenerationFile (
83+ stateRoot : Awaited < ReturnType < typeof root > > ,
84+ relativePath : string ,
85+ content : string ,
86+ ) : Promise < void > {
87+ await stateRoot . create ( relativePath , content , { encoding : "utf8" , mkdir : true } ) ;
88+ const opened = await stateRoot . openWritable ( relativePath , { writeMode : "update" } ) ;
89+ try {
90+ await opened . handle . sync ( ) ;
91+ } finally {
92+ await opened . handle . close ( ) ;
93+ }
94+ }
95+
8396export async function discardSkillProposalGeneration (
8497 record : SkillProposalRecord ,
8598 store ?: SkillWorkshopStoreOptions ,
0 commit comments