Skip to content

fix(rl.php): return 422 + errors on fully-rejected batches#48

Merged
jjroelofs merged 1 commit into
1.xfrom
fix/rl-php-return-indent
Apr 29, 2026
Merged

fix(rl.php): return 422 + errors on fully-rejected batches#48
jjroelofs merged 1 commit into
1.xfrom
fix/rl-php-return-indent

Conversation

@jjroelofs
Copy link
Copy Markdown
Contributor

Summary

  • When every decide/turn/reward entry in a batch is rejected, rl.php now returns HTTP 422 with the per-item errors array instead of 200.
  • Fixes a PHPCS DrupalPractice violation on the @return docblock (closing brace indentation).

Test plan

  • Send a batch where all entries fail validation; response code is 422 and body contains errors[].
  • Send a mixed batch; response is still 200 with partial errors[].
  • composer lint / CI drupal-lint job passes.

Why: rl.php used to swallow every rejected decide/turn/reward with a
`continue` and reply 200 `{"ok":true,"decisions":{}}`. The Drupal.rl
client then falls back to `armIds[0]` silently, so a site-wide
misconfiguration (e.g. a new entity-hook that never got its
implementations cache rebuilt, leaving experiments unregistered
despite the container being stamped with a valid-looking eid) is
indistinguishable from a healthy no-op request. The operator has
nothing to grep for in devtools or webserver logs; variants just
appear to never rotate.

handle_batch_request now:
- returns a structured array with `decisions`, `errors`, `requested`,
  `succeeded`
- tags each rejected entry with a machine-readable reason
  (unknown_experiment, invalid_id, missing_arms, invalid_arm_id,
  scoring_failed, manager_unavailable, malformed_entry)
- lets the caller pick the status code: 422 when a non-empty batch
  produced zero useful work, 200 for partial or full success

Partial failures stay 200 on purpose. A page rendering three healthy
containers plus one stale one should still get decisions for the
three, not reject the whole batch because one container is wrong
mid-deploy. The `errors` array surfaces the stale one to the client.

rl.js flushes the `errors` array to `console.warn` and forwards to an
optional `Drupal.rl.onErrors` listener so advanced consumers can wire
an alerting path without patching rl/api.
@jjroelofs jjroelofs force-pushed the fix/rl-php-return-indent branch from d021a9f to b5e169e Compare April 22, 2026 05:34
@jjroelofs jjroelofs merged commit da86d3a into 1.x Apr 29, 2026
3 checks passed
@jjroelofs jjroelofs deleted the fix/rl-php-return-indent branch April 29, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant