Skip to content

Commit 1556411

Browse files
waveywavesclaude
andauthored
fix(crafter): use deterministic filename for AI config collector (#2943)
Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 19d2cf5 commit 1556411

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

pkg/attestation/crafter/collector_aiagentconfig.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)