Skip to content

fix(agent-bff): read the json array composite id forest_liana serializes - #1968

Merged
Tonours merged 5 commits into
mainfrom
hp/gateway-mcp-bff/t-0027-prd-1472-composite-pk-fix
Oct 6, 2026
Merged

Tonours merged 5 commits into
mainfrom
hp/gateway-mcp-bff/t-0027-prd-1472-composite-pk-fix

Conversation

@Tonours

@Tonours Tonours commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

The BFF now reads the JSON array id forest_liana sends for a real composite key, so listing that collection no longer fails with a 500. fixes PRD-1472

What

  • unpackPrimaryKey reads ["acme",1] as the composite id and returns { seq: 1, tenant_id: "acme" }. Pipe ids (a|b) take the same code path as before.
  • Three OpenAPI descriptions no longer say a composite id is "joined by |". They now say it is packed in the agent's own format.

Why

  • forest_liana serializes a composite id as a JSON array, and split('|') turned every list of such a collection into 500 mapping_error. Measured on the v1-rails bench with composite_primary_keys 14.0.10.
  • The ticket's first symptom ({tenant_id} only) comes from a model that declares self.primary_key = "tenant_id". That is a real Rails ≤ 7.0 workaround, and the BFF already reports the key the agent declares.

How

  • The JSON branch runs only for 2+ keys when the id is bracketed, valid JSON, and its array length matches the key count. Anything else takes the pipe path.
  • Each value is matched to its key through the record's attributes. Values are never paired by position: the array follows the model's column order, while the apimap is alphabetical.
  • Some ids read both ways: valid JSON, and also splitting into as many | segments as there are keys. For those, a reading is used only if the record backs every key, pipe first. Otherwise the result is mapping_error, never a wrong key under 200.
  • Elements must be strings or safe integers. Not narrowed to Ruby lianas: meta.liana never reaches the read-model.

Verification

  • agent-bff suite 2195/2195, plus tsc and eslint clean. New tests cover each stack's id shape, the JSON guards and both collision cases.
  • Trust passes and e2e A/B (CLI BFF, main then ed0d132e0; the served OpenAPI text proves which build is running):
Check Result What was measured
Independent review (same-family) ✅ GO WITH NOTES. All notes fixed in c705b1f90, including the Macroscope collision. ed0d132e0 is a qlty-only refactor with no behavior change
Independent QA pass at ed0d132e0 ✅ PASS. Build proven by recompiling the head and diffing it against the served dist; only EdgeTrueCompositePk takes the JSON branch in a ~500-record scan; conformance vs main differs only on pk-composite
v1-rails composite (EdgeTrueCompositePk) ✅ pk-composite 500 → 200; 6 rows, 6 distinct {seq, tenant_id}; filter, sort, search and projection checks pass
v1-express ✅ conformance and matrix identical across builds
v1-mongoose ✅ identical; no composite fixture exists (_id only)
v2-ruby (OAuth) ✅ identical; API key path not run, the dev project lost its role
v2-node ⛔ not run (reference agent, left untouched)
JSON parentId and guard-boundary ids ⛔ not measurable on the bench: the fixture has no relation, and synthetic ids are covered by unit tests

Limits

  • These remain unsupported on the agent side:
    • a v1 model that declares a non-unique single key;
    • plain Rails ≤ 7.0 with no key. The agent sends no id, so the list returns 500 Agent record is missing its id.
  • On a liana composite key, a float, boolean or date value that the record cannot match returns mapping_error. This is intended.

Definition of Done

General

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • Test manually the implemented changes
  • Validate the code quality (indentation, syntax, style, simplicity, readability)

Security

  • Consider the security impact of the changes made

@linear-code

linear-code Bot commented Oct 5, 2026

Copy link
Copy Markdown

PRD-1472

@qltysh

qltysh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

All good ✅

Comment thread packages/agent-bff/src/data/pack-id.ts Outdated
@qltysh

qltysh Bot commented Oct 5, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/agent-bff/src/openapi/unfolded-paths.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent-bff/src/data/pack-id.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@nbouliol nbouliol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after /validator run 1968-20261006072100-nbouliol: nothing at or above should-fix posted, 1 suppressed.

@Tonours
Tonours merged commit a62e137 into main Oct 6, 2026
37 checks passed
@Tonours
Tonours deleted the hp/gateway-mcp-bff/t-0027-prd-1472-composite-pk-fix branch October 6, 2026 07:46
forest-bot added a commit that referenced this pull request Oct 6, 2026
## @forestadmin/agent-bff [1.38.1](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/agent-bff@1.38.0...@forestadmin/agent-bff@1.38.1) (2026-10-06)

### Bug Fixes

* **agent-bff:** read the json array composite id forest_liana serializes ([#1968](#1968)) ([a62e137](a62e137))
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.

2 participants