Skip to content

docs(conventions): mutable panel op-state fields must be cleared on all non-applicable code paths #98

Description

@jongio

PR #59 surfaced a recurring pattern: mutable "pending" state fields on panel structs (pendingPath, pendingName, etc.) are set on the applicable code path but not explicitly cleared on other branches. This creates stale-state bugs where a value set in one interaction leaks into a later, unrelated interaction.

Example from PR #59 review:

In gitinfo, p.pendingPath was set inside if item.kind == kindWorktree in both handleMouseRightClick and doAction, but no else branch cleared it for non-worktree items. A stale pendingPath from a prior worktree action could survive across modal round-trips and corrupt a subsequent non-worktree action.

Fixes applied in PR #59:

  • handleMouseRightClick: added else { p.pendingPath = "" } for non-worktree items
  • doAction first-use confirm branch: added else { p.pendingPath = "" } for non-worktree items

Convention to codify:

When a panel sets a mutable op-state field on one branch of an if/switch, add an explicit zero-assignment on all other branches — even when the value "shouldn't matter" on those paths. This makes the invariant explicit and prevents future regressions as new code paths are added.

Document this in the conventions guide alongside the existing op-state clearing pattern in handleModalResult.

Activity

  1. added
    automatedFiled by automated analysis
    pr-learnLearning from PR feedback
    swarm:lockedIssue claimed by an active swarm session
    on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedFiled by automated analysispr-learnLearning from PR feedbackswarm:lockedIssue claimed by an active swarm session

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions