@@ -450,6 +450,8 @@ function sendResultBase(
450450 * the RLS POLICY the tenant is being filtered by:
451451 *
452452 * ```
453+ * ⚠️ PAST TENSE — the leak this entry CLOSED, not what this exit answers today.
454+ * For the current body see the corrected shape at the end of this block.
453455 * POST /analytics/query (tenant caller, object with a broken sharing rule)
454456 * → 500 {"success":false,"error":{"message":"[read-scope-sql] unsafe field
455457 * identifier \"secret_policy_field\" — refusing to build read scope
@@ -464,9 +466,28 @@ function sendResultBase(
464466 * boundaries. ⛔ It is NOT "withhold every 5xx" — #5667 kept UNDECLARED 5xx
465467 * legible on purpose, and a bare `Error` still goes through the heuristic alone.
466468 *
467- * The code still travels: `details.code` (#3842, below) carries
468- * `READ_SCOPE_COMPILE_FAILED` to the client untouched, so what a machine reads is
469- * unchanged and only the prose is withheld — into `errorReporter` and the log.
469+ * The code still travels, and `READ_SCOPE_COMPILE_FAILED` reaches the client
470+ * untouched — so what a machine reads is unchanged and only the prose is withheld,
471+ * into `errorReporter` and the log.
472+ *
473+ * ⚠️ It reaches the client at `error.code` — NOT `error.details.code`, which is
474+ * where this note pointed until #6270 corrected it (#6123 corrected the same
475+ * sentence at three sibling sites). The `details` assembly below (#3842) only
476+ * STAGES the code in a local object; `buildApiError` then runs
477+ * `splitSemanticCode` (`./error-envelope.ts`), which PROMOTES it into the declared
478+ * `ApiErrorSchema` field and returns the now-empty `details` as `undefined` — so
479+ * the key is omitted from the body and `error.details.code` is never present to
480+ * read. Do not mistake the local variable name for the wire contract. The measured
481+ * 500 body is exactly:
482+ *
483+ * ```json
484+ * {"success":false,"error":{"code":"READ_SCOPE_COMPILE_FAILED",
485+ * "message":"Internal server error","httpStatus":500}}
486+ * ```
487+ *
488+ * Pinned end-to-end in `analytics-query-read-scope-withhold.test.ts`, which
489+ * asserts the code at `error.code` against a real `AnalyticsService` on a real
490+ * mounted route.
470491 */
471492function errorResponseBase ( err : any , res : any , securityHeaders ?: Record < string , string > ) : void {
472493 const validation = validationFailureDetails ( err ) ;
0 commit comments