{"record":{"id":"e3b0315aab89b1d4","repo":"vxcontrol/pentagi","slug":"operation-d-subtask-with-id-d-not-found-for-rem","errorCode":null,"errorMessage":"operation %d: subtask with id %d not found for removal","messagePattern":"operation (.+?): subtask with id (.+?) not found for removal","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/pkg/providers/subtask_patch.go","lineNumber":64,"sourceCode":"\n\t// First pass: process removals and modifications in-place\n\tfor i, op := range patch.Operations {\n\t\topLogger := logger.WithFields(logrus.Fields{\n\t\t\t\"operation_index\": i,\n\t\t\t\"operation\":       op.Op,\n\t\t\t\"id\":              op.ID,\n\t\t\t\"after_id\":        op.AfterID,\n\t\t})\n\n\t\tswitch op.Op {\n\t\tcase tools.SubtaskOpRemove:\n\t\t\tif op.ID == nil {\n\t\t\t\terr := fmt.Errorf(\"operation %d: remove operation missing required id field\", i)\n\t\t\t\topLogger.Error(err.Error())\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif _, ok := idToIdx[*op.ID]; !ok {\n\t\t\t\terr := fmt.Errorf(\"operation %d: subtask with id %d not found for removal\", i, *op.ID)\n\t\t\t\topLogger.Error(err.Error())\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tremoved[*op.ID] = true\n\t\t\topLogger.WithField(\"subtask_id\", *op.ID).Debug(\"marked subtask for removal\")\n\n\t\tcase tools.SubtaskOpModify:\n\t\t\tif op.ID == nil {\n\t\t\t\terr := fmt.Errorf(\"operation %d: modify operation missing required id field\", i)\n\t\t\t\topLogger.Error(err.Error())\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif op.Title == \"\" && op.Description == \"\" {\n\t\t\t\terr := fmt.Errorf(\"operation %d: modify operation missing both title and description fields\", i)\n\t\t\t\topLogger.Error(err.Error())\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tidx, ok := idToIdx[*op.ID]","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/subtask_patch.go#L46-L82","documentation":"applySubtaskOperations checks each remove operation's ID against idToIdx, the index of currently known subtasks. If the referenced subtask ID does not exist in the flow's subtask list, the patch is rejected. This catches stale or hallucinated IDs from the LLM before any mutation happens.","triggerScenarios":"LLM emits {\"op\":\"remove\",\"id\":N} where N is not among the current subtask IDs — fabricated ID, ID from a previous state, or duplicate removal after the list changed mid-patch.","commonSituations":"Model referencing subtask IDs from an outdated snapshot; hallucinated sequential IDs; concurrent modification of the subtask list between generation and application.","solutions":["Retry the refiner call with the current, accurate subtask list in the prompt.","Verify the prompt includes the up-to-date subtask IDs the model may reference.","Tolerate-and-skip unknown removals upstream if partial application is acceptable for your use case.","Use a stronger model that grounds IDs in the provided list."],"exampleFix":"// before\n{\"op\":\"remove\",\"id\":99} // no subtask 99\n// after: pick an existing id from the current list\n{\"op\":\"remove\",\"id\":2}","handlingStrategy":"validation","validationCode":"for i, op := range ops {\n    if op.Op == tools.SubtaskOpRemove {\n        if _, ok := idToIdx[*op.ID]; !ok {\n            return fmt.Errorf(\"op %d: id %d not in current subtasks\", i, *op.ID)\n        }\n    }\n}","typeGuard":"func subtaskExists(id int64, idToIdx map[int64]int) bool {\n    _, ok := idToIdx[id]\n    return ok\n}","tryCatchPattern":"patched, err := applySubtaskOperations(ctx, logger, ops, subtasks)\nif err != nil && strings.Contains(err.Error(), \"not found for removal\") {\n    // regenerate patch with the current subtask list\n    return regeneratePatch(ctx, subtasks)\n}","preventionTips":["Always include the current subtask ID list in the refiner prompt.","Regenerate the patch from fresh state if subtasks changed concurrently.","Optionally skip unknown removals instead of failing the whole patch."],"tags":["validation","llm","subtasks","stale-reference"],"backgroundTag":"referenced-entity-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}