{"record":{"id":"d1b7a235f9cfc12c","repo":"gastownhall/beads","slug":"building-label-cache-no-cache-for-primary-team-s","errorCode":null,"errorMessage":"building label cache: no cache for primary team %s","messagePattern":"building label cache: no cache for primary team (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/linear/tracker.go","lineNumber":329,"sourceCode":"\tif primaryCache == nil {\n\t\treturn nil, fmt.Errorf(\"building state cache: no cache for primary team %s\", t.teamIDs[0])\n\t}\n\n\tteamLabelCaches := make(map[string]*LabelCache, len(t.teamIDs))\n\tfor _, teamID := range t.teamIDs {\n\t\tteamClient := t.clients[teamID]\n\t\tif teamClient == nil {\n\t\t\tcontinue\n\t\t}\n\t\tlc, err := BuildLabelCache(ctx, teamClient)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"building label cache for team %s: %w\", teamID, err)\n\t\t}\n\t\tteamLabelCaches[teamID] = lc\n\t}\n\tprimaryLabelCache := teamLabelCaches[t.teamIDs[0]]\n\tif primaryLabelCache == nil {\n\t\treturn nil, fmt.Errorf(\"building label cache: no cache for primary team %s\", t.teamIDs[0])\n\t}\n\n\tresult := &tracker.BatchPushResult{}\n\n\tvar toCreate []*types.Issue\n\tvar toUpdate []*types.Issue\n\n\tfor _, issue := range issues {\n\t\textRef := \"\"\n\t\tif issue.ExternalRef != nil {\n\t\t\textRef = *issue.ExternalRef\n\t\t}\n\t\tif extRef == \"\" || !IsLinearExternalRef(extRef) {\n\t\t\ttoCreate = append(toCreate, issue)\n\t\t} else {\n\t\t\ttoUpdate = append(toUpdate, issue)\n\t\t}\n\t}","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/linear/tracker.go#L311-L347","documentation":"Returned by Tracker.BatchPush when the primary team has no label cache after the build loop. Creates target the primary team and need its label cache to attach labels, so a missing cache fails the batch before any issue is pushed.","triggerScenarios":"BatchPush called where t.teamIDs[0]'s entry was skipped because t.clients[teamIDs[0]] is nil, or BuildLabelCache silently never ran for the primary team — leaving teamLabelCaches[teamIDs[0]] unset.","commonSituations":"Mirrors the primary-team state-cache failure: partially initialized tracker, primary team client missing, tests that set teamIDs without registering the primary client, credential scoping that excludes the primary team.","solutions":["Ensure the primary team's client exists before BatchPush (re-run Init/Validate)","Keep teamIDs and t.clients in sync; register a client for the primary team in tests","Verify the API key has label-read access to the primary team","Add a pre-flight check for t.clients[primary] != nil before calling BatchPush"],"exampleFix":"// before\nteamIDs := []string{\"ENG\"}; t.SetTeamIDs(teamIDs) // no client for ENG\n// after\nt.Init(ctx, cfg) // ensures clients (and thus caches) exist for primary team\nresult, err := t.BatchPush(ctx, issues, nil)","handlingStrategy":"validation","validationCode":"primary := tracker.PrimaryTeamID()\nif primary == \"\" || tracker.ClientForTeam(primary) == nil {\n    return errors.New(\"primary Linear team is not initialized; cannot batch push\")\n}","typeGuard":null,"tryCatchPattern":"result, err := tracker.BatchPush(ctx, issues, forceIDs)\nif err != nil && strings.Contains(err.Error(), \"no cache for primary team\") {\n    // re-init to rebuild clients and caches, then retry once\n    _ = tracker.Init(ctx, cfg)\n    result, err = tracker.BatchPush(ctx, issues, forceIDs)\n}","preventionTips":["Initialize the tracker through its Init path so all caches build consistently","Verify primary-team client existence before any push","In tests, wire fake clients for the primary team before SetTeamIDs-dependent flows","Log team/client registration at startup to catch partial initialization early"],"tags":["linear","labels","initialization","batch"],"backgroundTag":"linear-team-client-not-initialized","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}