{"record":{"id":"f08a9fa396cf4e9f","repo":"gastownhall/beads","slug":"worktree-cleanliness-observation-is-absent-or-inva","errorCode":null,"errorMessage":"worktree cleanliness observation is absent or invalid","messagePattern":"worktree cleanliness observation is absent or invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/worktreeremove/policy.go","lineNumber":192,"sourceCode":"\tswitch facts.Target {\n\tcase PrimaryWorktree:\n\t\treturn Plan{}, fmt.Errorf(\"cannot remove the primary worktree\")\n\tcase CurrentWorktree:\n\t\treturn Plan{}, fmt.Errorf(\"cannot remove the worktree containing the running command\")\n\tcase RegisteredTarget:\n\tdefault:\n\t\treturn Plan{}, fmt.Errorf(\"registered worktree target is absent or invalid\")\n\t}\n\tif facts.Registration != Present || facts.RegisteredPath == \"\" ||\n\t\tfacts.TargetDir != Present || facts.GitAdminDir != Present ||\n\t\tfacts.GitMarker != Present || facts.Head != Present {\n\t\treturn Plan{}, fmt.Errorf(\"registered worktree target is absent or invalid\")\n\t}\n\tif facts.CommonDir != Matched {\n\t\treturn Plan{}, fmt.Errorf(\"target common git directory does not match repository\")\n\t}\n\tif facts.Status != Clean && facts.Status != Dirty {\n\t\treturn Plan{}, fmt.Errorf(\"worktree cleanliness observation is absent or invalid\")\n\t}\n\tif facts.ManagedIgnore != IgnoreAbsent && facts.ManagedIgnore != IgnoreManaged {\n\t\treturn Plan{}, fmt.Errorf(\"managed ignore observation is absent or invalid\")\n\t}\n\tif (facts.ManagedIgnore == IgnoreManaged) != (facts.ManagedIgnoreEntry != \"\") {\n\t\treturn Plan{}, fmt.Errorf(\"managed ignore cleanup identity is absent or invalid\")\n\t}\n\tif request.Mode != Force {\n\t\tif facts.Status != Clean {\n\t\t\treturn Plan{}, fmt.Errorf(\"worktree contains modified, untracked, or ignored files\")\n\t\t}\n\t\tif facts.Comparator != ComparatorAvailable && facts.Comparator != ComparatorMissing && facts.Comparator != ComparatorNotRequired {\n\t\t\treturn Plan{}, fmt.Errorf(\"worktree comparison target observation is absent or invalid\")\n\t\t}\n\t\tif facts.Comparator != ComparatorAvailable {\n\t\t\treturn Plan{}, fmt.Errorf(\"cannot verify unpushed commits: no comparison target is available\")\n\t\t}\n\t\tif facts.Containment != Contained && facts.Containment != NotContained && facts.Containment != ContainmentNotRequired {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/worktreeremove/policy.go#L174-L210","documentation":"Prepare rejects the request because facts.Status is neither Clean nor Dirty. The cleanliness observation was never made or holds an invalid enum value, so the library cannot apply the unclean-worktree safety policy and fails closed.","triggerScenarios":"Calling Prepare with a zero-value Status field, or an adapter that leaves Status unset after a failed git status observation.","commonSituations":"Custom adapter code that skips the status check; constructing PrepareFacts in tests without Status; an enum added later and not handled in the adapter.","solutions":["Populate facts.Status with Clean or Dirty from an actual git status observation","Fix the adapter so a failed status observation sets a defined value rather than leaving Status zero","In tests, set Status: worktreeremove.Clean (or Dirty) explicitly"],"exampleFix":"// before\nfacts := worktreeremove.PrepareFacts{...} // Status left zero\n// after\nfacts := worktreeremove.PrepareFacts{...}\nfacts.Status = worktreeremove.Clean // from actual git status observation","handlingStrategy":"validation","validationCode":"if facts.Status != worktreeremove.Clean && facts.Status != worktreeremove.Dirty {\n\treturn fmt.Errorf(\"status not observed for %s\", facts.RegisteredPath)\n}","typeGuard":"func statusObserved(s worktreeremove.Status) bool {\n\treturn s == worktreeremove.Clean || s == worktreeremove.Dirty\n}","tryCatchPattern":"plan, err := worktreeremove.Prepare(req, facts)\nif err != nil && strings.Contains(err.Error(), \"cleanliness observation is absent\") {\n\treturn fmt.Errorf(\"adapter failed to observe git status: %w\", err)\n}","preventionTips":["Have the adapter always assign a defined Status, even on observation failure paths","Check all PrepareFacts enums in a pre-flight validator before Prepare","In tests, never rely on zero values for enum fields"],"tags":["worktree","git","validation"],"backgroundTag":"incomplete-observations","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}