{"record":{"id":"55f31bfe4e0718d8","repo":"affaan-m/ECC","slug":"capsule-payload-invalid","errorCode":"capsule.payload_invalid","errorMessage":"payloadErrors.join('; ')","messagePattern":"payloadErrors\\.join\\('; '\\)","errorType":"error_code","errorClass":"CapsuleError","httpStatus":null,"severity":"error","filePath":"scripts/lib/eval-harness/capsule.js","lineNumber":188,"sourceCode":"    }\n    return capsule;\n  }\n\n  /**\n   * Serialize cooperating appenders and validate current disk state under lock.\n   * A partial I/O failure is preserved for diagnosis, never silently rolled back.\n   */\n  append(lineage, kind, payload = {}, options = {}) {\n    return withAppendLock(this.dir, () => {\n      const state = readCapsule(this.dir);\n      if (!state.ok) throw new CapsuleError(state.code, state.reason, { failed_at: state.failed_at });\n      if (!envelope.LINEAGES.includes(lineage)) {\n        throw new CapsuleError('capsule.bad_lineage', `unknown lineage ${lineage}`);\n      }\n      const effectClass = options.effect_class || 'SE0';\n      const { payload: clean, dropped, findings, errors: payloadErrors } = envelope.redactPayload(payload, options);\n      if (payloadErrors.length > 0) {\n        throw new CapsuleError('capsule.payload_invalid', payloadErrors.join('; '));\n      }\n      if (findings.length > 0) {\n        throw new CapsuleError('capsule.secret_canary', `payload tripped secret canary ${findings[0].canary} at ${findings[0].path}`, { findings });\n      }\n      if (dropped.length > 0 && options.strict !== false) {\n        throw new CapsuleError('capsule.payload_denied', `payload keys not allowlisted: ${dropped.join(', ')}`, { dropped });\n      }\n      const body = {\n        schema: envelope.SCHEMA_VERSION,\n        run_id: state.meta.run_id,\n        capsule_id: state.meta.capsule_id,\n        seq: state.entries.length,\n        ts: nowIso(this.clock),\n        lineage,\n        kind,\n        effect_class: effectClass,\n        harness_version: state.meta.harness_version,\n        task_family: state.meta.task_family,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/eval-harness/capsule.js#L170-L206","documentation":"append() runs every payload through envelope.redactPayload(), which both validates payload values and scans them for secrets. Validation errors (e.g. non-scalar values, oversized strings, disallowed shapes) are returned in the errors array and thrown joined with ';' under code 'capsule.payload_invalid'. The message lists every failed constraint so the caller can fix all of them in one pass.","triggerScenarios":"Calling append(lineage, kind, payload) with a payload containing values that fail redactPayload validation — e.g. nested objects/functions where scalars are expected, values exceeding size limits, or fields with invalid types.","commonSituations":"Passing a whole error object or class instance as payload; accidentally passing options as the payload (swapped arguments); including large blobs or buffers that exceed payload size limits; passing undefined/null where a scalar is required.","solutions":["Read the joined message — each ';'-separated segment names one failing key and reason; fix them all.","Reduce the payload to small scalar fields (strings/numbers/booleans) relevant to the event.","Confirm the argument order is append(lineage, kind, payload, options) and nothing was swapped.","Pre-validate the payload with the same redactPayload helper (or a local schema check) before calling append()."],"exampleFix":"// before: passing a complex object\nawait capsule.append('fix', 'note', { error: new Error('boom'), stack: err.stack }); // capsule.payload_invalid\n\n// after: flat scalar payload\nawait capsule.append('fix', 'note', { message: 'boom', phase: 'green' });","handlingStrategy":"validation","validationCode":"const clean = envelope.redactPayload(payload, {});\nif (clean.errors.length > 0) throw new Error(`invalid payload: ${clean.errors.join('; ')}`);","typeGuard":"function isScalarPayload(payload) {\n  return payload != null && typeof payload === 'object' &&\n    Object.values(payload).every(v => ['string', 'number', 'boolean'].includes(typeof v));\n}","tryCatchPattern":"try {\n  await capsule.append(lineage, kind, payload);\n} catch (e) {\n  if (e instanceof CapsuleError && e.code === 'capsule.payload_invalid') {\n    console.error('Fix each payload constraint:', e.message.split('; '));\n  }\n  throw e;\n}","preventionTips":["Keep payloads flat and scalar-only (strings/numbers/booleans).","Never pass Error objects, Buffers, or class instances as payloads.","Double-check append(lineage, kind, payload, options) argument order.","Pre-run redactPayload in tests to catch payload schema drift early."],"tags":["payload","validation","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}