Skip to content

Commit

Permalink
Hotfix: requested group ids arrays must be of same length (#9038)
Browse files Browse the repository at this point in the history
Description
---
Fixes issue from [this kind of
monitor](https://dust4ai.slack.com/archives/C05F84CFP0E/p1732945133294399)

The longer term fix would be to store requested ids differently:
- either as string[] with comma-separated values;
- or as a JSONB object

Risks
---
na

Deploy
---
front
  • Loading branch information
philipperolet authored Nov 30, 2024
1 parent 4e3b933 commit 8c9a9b2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2152,9 +2152,26 @@ export async function updateConversationRequestedGroupIds(
...requirementsToAdd.map((req) => sortBy(req.map(getModelId))),
];

// Hotfix: Postgres requires all subarrays to be of the same length
//
// since a requirement (subarray) is a set of groups that are linked with OR
// logic we can just repeat the last element of each requirement until all
// requirements have the maximal length.
const longestRequirement = allRequirements.reduce(
(max, req) => Math.max(max, req.length),
0
);
// for each requirement, repeatedly add the last id until array is of longest requirement length
const updatedRequirements = allRequirements.map((req) => {
while (req.length < longestRequirement) {
req.push(req[req.length - 1]);
}
return req;
});

await Conversation.update(
{
requestedGroupIds: allRequirements,
requestedGroupIds: updatedRequirements,
},
{
where: {
Expand Down

0 comments on commit 8c9a9b2

Please sign in to comment.