#104

Engine restores raw payload when usage.consolidate returns null

Opensdivyanshu90opened 24d ago

What is the issue?

The engine restores the raw vendor payload when usage.consolidate explicitly returns output: null.

null is valid JSON and is a valid consolidated output. The contract says only an absent output means that the raw payload should remain unchanged. Treating explicit null as absent can re-expose vendor billing fields that the consolidator intended to remove.

How to reproduce

  1. Define a successful metered endpoint with a usage.consolidate hook that returns:

    { credits: {}, output: null }
  2. Run it against a successful response such as:

    { "results": [{ "id": "a" }], "vendorTotal": 0 }
  3. Inspect the completed run's output.

Observed behavior

The completed run returns the original raw object, including vendorTotal.

Expected behavior

The completed run returns output: null. Only output: undefined or an omitted output property should preserve the raw payload.

Root cause

The settle path uses nullish coalescing when choosing between the consolidated output and the raw response. Nullish coalescing treats both null and undefined as absent, even though the hook contract distinguishes them.

Proposed resolution

Fall back to the raw response only when consolidated.output is undefined, and add a regression test covering an explicit null consolidated payload.

Activity

0

No activity yet.