OpenNHP/opennhp · error
failed to get agent unique id
Error message
failed to get agent unique id: %v
What it means
Raised by GetEvidenceWithAgentUuid when the helper CalculateAgentUniqueId returns an error. The fallback evidence path builds a synthetic test-purpose evidence object keyed on the agent's unique id; without that id the evidence cannot be constructed, so the failure of the underlying id calculation is wrapped and propagated to the WASM guest.
Solutions
- Inspect the wrapped inner error to see which identity source failed
- Ensure the container/host exposes /etc/machine-id (or systemd-machine-id-setup) and a resolvable hostname
- Fix file permissions on the identity files or configure an explicit agent id in the agent config
Example fix
// before
agentUniqueId, err := CalculateAgentUniqueId()
if err != nil {
return nil, fmt.Errorf("failed to get agent unique id: %v", err)
}
// after
agentUniqueId, err := CalculateAgentUniqueId()
if err != nil {
return nil, fmt.Errorf("failed to get agent unique id: %v (check /etc/machine-id and hostname)", err)
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat("/etc/machine-id"); err != nil {
return errors.New("host identity unavailable: /etc/machine-id missing")
} Try / catch
ev, err := engine.GetEvidence()
if err != nil {
if strings.Contains(err.Error(), "failed to get agent unique id") {
return fmt.Errorf("cannot build fallback evidence: %w", err)
}
} Prevention
- Ensure /etc/machine-id exists in container images
- Set a hostname at container start
- Pre-seed an explicit agent id in config for minimal environments
When it happens
Trigger: Calling GetEvidence (test/fallback path) when CalculateAgentUniqueId fails — typically because required machine/host identity sources (hostname, machine-id file, MAC address, or crypto/rand) are unavailable.
Common situations: Running the agent in a minimal container without /etc/machine-id or hostname configured; restricted filesystem permissions; crypto entropy source unavailable at boot.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- failed to generate UUID:
- cluster : missing publicKeyBase64
- cluster ( ): no instances configured
- cluster ( )
- no private key configured; check etc/config.toml
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/07cebfdb63542ad4.
Report an issue: GitHub.
Appendix: source
Thrown at nhp/core/wasm/engine/host.go:72
}
var buf bytes.Buffer
w := zlib.NewWriter(&buf)
_, err = w.Write(body)
w.Close()
if err != nil {
return nil, fmt.Errorf("failed to compress response body: %w", err)
}
compressedBody := buf.Bytes()
return compressedBody, nil
}
func GetEvidenceWithAgentUuid() ([]byte, error) {
agentUniqueId, err := CalculateAgentUniqueId()
if err != nil {
return nil, fmt.Errorf("failed to get agent unique id: %v", err)
}
evidence := map[string]any{
"test_purpose": "this evidence is for testing purposes only",
"measure": agentUniqueId,
"serial_number": agentUniqueId,
}
evidenceBytes, err := json.Marshal(evidence)
if err != nil {
return nil, fmt.Errorf("failed to marshal evidence: %v", err)
}
var buf bytes.Buffer
w := zlib.NewWriter(&buf)
_, err = w.Write(evidenceBytes)
w.Close()
if err != nil {View on GitHub (pinned to 6e04ca5ff0)