JuliusBrussee/caveman · error
key_id is required
Error message
${label} key_id is required What it means
Thrown by decodeReceiptKey while validating a receipt public key entry under a label such as 'public_key' or 'public_keys[0]'. The key_id field is either missing, not a string, or an empty/whitespace-only string. key_id identifies which key in the keyring signed a receipt, so a bundle without it cannot be verified.
Solutions
- Add a non-empty string key_id to the public key entry in the bundle.
- Regenerate the bundle with the official export command so all key metadata is included.
- If the bundle is from another tool, check its schema/version and upgrade the exporter.
Example fix
// before
{"public_key": {"alg": "Ed25519", "key": "..."}}
// after
{"public_key": {"key_id": "2026-q3", "alg": "Ed25519", "key": "..."}} Defensive patterns
Strategy: validation
Validate before calling
function validateKeyInfo(info: any) {
if (!info || typeof info.key_id !== 'string' || !info.key_id.trim()) throw new Error('key_id required');
} Type guard
function hasKeyId(info: unknown): info is { key_id: string } {
return typeof info === 'object' && info !== null && typeof (info as any).key_id === 'string' && (info as any).key_id.trim() !== '';
} Try / catch
try {
verifyBundle(bundle);
} catch (e) {
if ((e as Error).message.includes('key_id is required')) console.error('bundle key entry missing key_id');
throw e;
} Prevention
- Validate bundle JSON against the receipt schema before verification.
- Never hand-strip fields when redacting bundles; use the official redaction tool.
- Always generate bundles via the official export command.
When it happens
Trigger: Verifying a receipt bundle whose ReceiptPublicKey object lacks key_id, contains key_id: "" or " ", or where key_id is a non-string (number/null) — typically from hand-constructed JSON or a bundle produced by an incompatible exporter.
Common situations: Hand-writing bundle JSON for testing and omitting key_id; a schema change in the producing tool dropped the field; copy/paste losing the key_id line; deserializing an older bundle format.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- key is required
- bundle completeness cannot be attested by unsigned export…
- canonical span
- cave_agent_definition_invalid
- cave_context_ir_invalid
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/679d6c85ae14d141.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:17848
const sorted = [...receipts].sort((a, b) => a.seq - b.seq);
let prev: Receipt | undefined;
for (const r of sorted) {
const decoded = keys.get(r.signature?.key_id);
if (!decoded) return `seq ${r.seq}: no trusted public key for key_id ${String(r.signature?.key_id)}`;
const err = verifyReceipt(r, decoded.key, decoded.info.key_id);
if (err) return err;
if (prev) {
if (r.seq !== prev.seq + 1) return `seq ${r.seq}: not strictly after ${prev.seq}`;
if (r.prev_receipt_hash !== prev.receipt_hash) return `seq ${r.seq}: prev_receipt_hash does not link to seq ${prev.seq}`;
if (r.day <= prev.day) return `seq ${r.seq}: day ${r.day} does not follow ${prev.day}`;
}
prev = r;
}
return null;
}
function decodeReceiptKey(info: ReceiptPublicKey, label: string): DecodedReceiptKey {
if (!info || typeof info.key_id !== "string" || !info.key_id.trim()) throw new Error(`${label} key_id is required`);
if (info.alg !== "Ed25519") throw new Error(`${label} has unsupported algorithm ${String(info.alg)}`);
if (typeof info.key !== "string" || !info.key.trim()) throw new Error(`${label} key is required`);
const raw = Buffer.from(info.key, "base64");
if (raw.length !== 32 || raw.toString("base64") !== info.key) throw new Error(`${label} must be a canonical base64 Ed25519 public key`);
return { info, raw, key: ed25519PublicKey(raw) };
}
function decodeUniqueKeyring(infos: ReceiptPublicKey[], label: string): Map<string, DecodedReceiptKey> {
const keys = new Map<string, DecodedReceiptKey>();
for (const [index, info] of infos.entries()) {
const decoded = decodeReceiptKey(info, `${label}[${index}]`);
if (keys.has(decoded.info.key_id)) throw new Error(`${label} contains duplicate key_id ${decoded.info.key_id}`);
keys.set(decoded.info.key_id, decoded);
}
return keys;
}
function embeddedReceiptKeys(bundle: ReceiptBundle): { current: DecodedReceiptKey; keys: Map<string, DecodedReceiptKey> } {View on GitHub (pinned to 3ee70a1026)