@@ -20,6 +20,7 @@ import (
2020 "encoding/json"
2121 "fmt"
2222 "os"
23+ "path/filepath"
2324 "sort"
2425
2526 schemaapi "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
@@ -99,20 +100,16 @@ func (c *AIAgentConfigCollector) uploadAgentConfig(
99100 return fmt .Errorf ("marshaling AI agent config for %s: %w" , agentName , err )
100101 }
101102
102- tmpFile , err := os .CreateTemp ("" , fmt .Sprintf ("ai-agent-config-%s-*.json" , agentName ))
103- if err != nil {
104- return fmt .Errorf ("creating temp file: %w" , err )
105- }
106- defer os .Remove (tmpFile .Name ())
107-
108- if _ , err := tmpFile .Write (jsonData ); err != nil {
109- tmpFile .Close ()
103+ // Use a constant filename per agent so retries produce the same
104+ // Artifact.Name (via fileStats -> os.Stat().Name()).
105+ materialName := fmt .Sprintf ("ai-agent-config-%s" , agentName )
106+ tmpPath := filepath .Join (os .TempDir (), fmt .Sprintf ("%s.json" , materialName ))
107+ if err := os .WriteFile (tmpPath , jsonData , 0o600 ); err != nil {
110108 return fmt .Errorf ("writing temp file: %w" , err )
111109 }
112- tmpFile . Close ( )
110+ defer os . Remove ( tmpPath )
113111
114- materialName := fmt .Sprintf ("ai-agent-config-%s" , agentName )
115- if _ , err := cr .AddMaterialContractFree (ctx , attestationID , schemaapi .CraftingSchema_Material_CHAINLOOP_AI_AGENT_CONFIG .String (), materialName , tmpFile .Name (), casBackend , nil ); err != nil {
112+ if _ , err := cr .AddMaterialContractFree (ctx , attestationID , schemaapi .CraftingSchema_Material_CHAINLOOP_AI_AGENT_CONFIG .String (), materialName , tmpPath , casBackend , nil ); err != nil {
116113 return fmt .Errorf ("adding AI agent config material for %s: %w" , agentName , err )
117114 }
118115
0 commit comments