{"record":{"id":"61c4dde7d8d06808","repo":"vxcontrol/pentagi","slug":"agentlogs-invalidrequest","errorCode":"Agentlogs.InvalidRequest","errorMessage":"group field not found","messagePattern":"group field not found","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"backend/pkg/server/services/agentlogs.go","lineNumber":100,"sourceCode":"\t\t}\n\t} else if slices.Contains(privs, \"agentlogs.view\") {\n\t\tscope = func(db *gorm.DB) *gorm.DB {\n\t\t\treturn db.\n\t\t\t\tJoins(\"INNER JOIN flows f ON f.id = flow_id\").\n\t\t\t\tWhere(\"f.user_id = ?\", uid)\n\t\t}\n\t} else {\n\t\tlogger.FromContext(c).Errorf(\"error filtering user role permissions: permission not found\")\n\t\tresponse.Error(c, response.ErrNotPermitted, nil)\n\t\treturn\n\t}\n\n\tquery.Init(\"agentlogs\", agentlogsSQLMappers)\n\n\tif query.Group != \"\" {\n\t\tif _, ok := agentlogsSQLMappers[query.Group]; !ok {\n\t\t\tlogger.FromContext(c).Errorf(\"error finding agentlogs grouped: group field not found\")\n\t\t\tresponse.Error(c, response.ErrAgentlogsInvalidRequest, errors.New(\"group field not found\"))\n\t\t\treturn\n\t\t}\n\n\t\tvar respGrouped agentlogsGrouped\n\t\tif respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding agentlogs grouped\")\n\t\t\tresponse.Error(c, response.ErrInternal, err)\n\t\t\treturn\n\t\t}\n\n\t\tresponse.Success(c, http.StatusOK, respGrouped)\n\t\treturn\n\t}\n\n\tif resp.Total, err = query.Query(s.db, &resp.AgentLogs, scope); err != nil {\n\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding agentlogs\")\n\t\tresponse.Error(c, response.ErrInternal, err)\n\t\treturn","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/agentlogs.go#L82-L118","documentation":"GetAgentlogs validates the ?group= query parameter against agentlogsSQLMappers before calling QueryGrouped; if the requested field is not a known mapper key it returns an AgentlogsInvalidRequest (400-style) response with this message. This mirrors the rdb layer check but produces a client-facing invalid-request error instead of an internal error.","triggerScenarios":"GET /agentlogs?group=<field> where <field> is not one of the allowed keys: id, initiator, executor, task, result, flow_id, task_id, subtask_id, created_at, data.","commonSituations":"Frontend grouping dropdown sends a stale or renamed field; API user guesses field names from the JSON payload instead of the mapper list; version skew where frontend was updated before backend.","solutions":["Send a supported group value, e.g. ?group=flow_id or ?group=created_at.","Update the frontend to offer only fields present in agentlogsSQLMappers.","If the field should be groupable, add it to agentlogsSQLMappers as a string SQL expression.","Handle the Agentlogs.InvalidRequest response code in the client and show a validation message."],"exampleFix":"// before\nGET /agentlogs?group=log_level   // not a mapper key -> 400 invalid request\n// after\nGET /agentlogs?group=initiator   // valid mapper key","handlingStrategy":"validation","validationCode":"const agentlogGroupFields = [\"id\",\"initiator\",\"executor\",\"task\",\"result\",\"flow_id\",\"task_id\",\"subtask_id\",\"created_at\"];\nif (params.group && !agentlogGroupFields.includes(params.group)) {\n  return res.status(400).json({ code: \"AgentlogsInvalidRequest\" });\n}","typeGuard":"function isAgentlogGroupField(v) { return typeof v === \"string\" && agentlogGroupFields.includes(v); }","tryCatchPattern":"try { const r = await api.get('/agentlogs', { params }); }\ncatch (e) { if (e.response?.data?.code === 'Agentlogs.InvalidRequest') resetGroupFilter(); else throw e; }","preventionTips":["Whitelist group fields client-side before sending.","Keep frontend field lists in sync with agentlogsSQLMappers.","Use snake_case names exactly as defined server-side.","Handle the InvalidRequest error code with a user-facing message."],"tags":["api","grouping","agentlogs","validation"],"backgroundTag":"invalid-group-field","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}