fix(workflow-executor): read composite-key records via the agent by-id route [PRD-450]#1629
Open
matthv wants to merge 1 commit into
Open
Conversation
…d route [PRD-450]
getRecord built the agent filter by zipping primaryKeyFields (alphabetical, from
the orchestrator collection-schema) with the recordId (model primary_key order).
For composite PKs whose model order differs from alphabetical this mis-paired the
columns, so the record was never found ("Record not found").
Fetch by id through the agent's by-id route instead (like update/delete): the
recordId is an opaque ordered token and the agent — the only party that knows the
primary key column order — does the matching. The executor no longer needs to
know the key composition. Same reasoning applied to getRelatedData composite
recordIds (use the agent's opaque row id instead of rebuilding from
primaryKeyFields).
- add Collection#getOne(id, options) to @forestadmin/agent-client (by-id route)
- rewrite getRecord to use it; remove buildPkFilter / resolveSchema
For v1 agents the by-id read needs the agent to accept the pipe-joined id form
(forest_liana: PR #774; forest-express: pending). v2 already supports it.
Relates to PRD-450.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On collections with a composite primary key, the workflow executor failed to read records in orchestrator mode with
Record not found.getRecordbuilt the agent filter by zipping two arrays by position:primaryKeyFields— from the orchestrator collection-schema, in alphabetical order (the agent apimap sorts fields alphabetically;is_primary_keyis just a boolean, no ordinal);recordId— in modelprimary_keyorder.For a PK whose model order ≠ alphabetical (e.g.
Shipping=[order_id, customer_id]), the columns got mis-paired → no match → not found. The executor has no way to recover the real PK order from the schema it receives.Fix
Stop re-pairing the id in the executor. Read by id through the agent's by-id route (like
update/deletealready do) and let the agent — the only party that knows the PK column order — do the matching. The recordId is an opaque ordered token; the executor never needs to know the key composition.Collection#getOne(id, options)to@forestadmin/agent-client(handles 404 / empty as "not found");getRecordto use it; removebuildPkFilter/resolveSchema;getRelatedDatacomposite recordIds — use the agent's opaquerow.idinstead of rebuilding fromprimaryKeyFields.Coupling
For v1 agents the by-id read needs the agent to accept the pipe-joined id form — forest_liana: ForestAdmin/forest-rails#774 ; forest-express: pending. v2 already supports it.
Testing
agent-client-agent-port.test.tsupdated (getRecord/getSingleRelatedData now exercisegetOne; composite getRelatedData uses the opaque id). Full suite: 887 passing, lint clean.Shippingworkflow (get-data → condition → update-data) reads + updates the record in orchestrator mode.Relates to PRD-450. The agent-side id-format fix is tracked separately (see PRD-450).
🤖 Generated with Claude Code
Note
Fix composite-key record fetching in workflow executor to use agent by-id route
Collection.getOne(id, options?)in collection.ts that fetches a single record viaGET /forest/<collection>/<id>, returning null on 404 or empty response.AgentClientAgentPort.getRecordwith a direct call togetOne, removing dependency on schema primary key ordering and filter construction.getRelatedData, derives the record id by splitting the agent's packedrow.idon|instead of mapping from schema-declared field order, fixing key order mismatches.buildPkFilter,resolveSchema, and related imports that are no longer needed.🖇️ Linked Issues
Addresses PRD-450.
Macroscope summarized 06eff38.