@@ -572,7 +572,10 @@ export class CloudTraceSink extends TraceSink {
572572 private generateIndex ( ) : void {
573573 try {
574574 const { writeTraceIndex } = require ( './indexer' ) ;
575- writeTraceIndex ( this . tempFilePath ) ;
575+ // Use frontend format to ensure 'step' field is present (1-based)
576+ // Frontend derives sequence from step.step - 1, so step must be valid
577+ const indexPath = this . tempFilePath . replace ( '.jsonl' , '.index.json' ) ;
578+ writeTraceIndex ( this . tempFilePath , indexPath , true ) ;
576579 } catch ( error : any ) {
577580 // Non-fatal: log but don't crash
578581 this . logger ?. warn ( `Failed to generate trace index: ${ error . message } ` ) ;
@@ -609,9 +612,30 @@ export class CloudTraceSink extends TraceSink {
609612 return ;
610613 }
611614
612- // Read and compress index file
613- const indexData = await fsPromises . readFile ( indexPath ) ;
614- const compressedIndex = zlib . gzipSync ( indexData ) ;
615+ // Read index file and update trace_file.path to cloud storage path
616+ const indexContent = await fsPromises . readFile ( indexPath , 'utf-8' ) ;
617+ const indexJson = JSON . parse ( indexContent ) ;
618+
619+ // Extract cloud storage path from trace upload URL
620+ // uploadUrl format: https://...digitaloceanspaces.com/traces/{run_id}.jsonl.gz
621+ // Extract path: traces/{run_id}.jsonl.gz
622+ try {
623+ const parsedUrl = new URL ( this . uploadUrl ) ;
624+ // Extract path after domain (e.g., /traces/run-123.jsonl.gz -> traces/run-123.jsonl.gz)
625+ const cloudTracePath = parsedUrl . pathname . startsWith ( '/' )
626+ ? parsedUrl . pathname . substring ( 1 )
627+ : parsedUrl . pathname ;
628+ // Update trace_file.path in index
629+ if ( indexJson . trace_file && typeof indexJson . trace_file === 'object' ) {
630+ indexJson . trace_file . path = cloudTracePath ;
631+ }
632+ } catch ( error : any ) {
633+ this . logger ?. warn ( `Failed to extract cloud path from upload URL: ${ error . message } ` ) ;
634+ }
635+
636+ // Serialize updated index to JSON
637+ const updatedIndexData = Buffer . from ( JSON . stringify ( indexJson , null , 2 ) , 'utf-8' ) ;
638+ const compressedIndex = zlib . gzipSync ( updatedIndexData ) ;
615639 const indexSize = compressedIndex . length ;
616640 this . indexFileSizeBytes = indexSize ; // Track index file size
617641
0 commit comments