Sdlc/Structural/LifecycleIvarBehindAttrReader: fire only when a collaborator can answer #1369

Open
opened 2026-10-25 21:23:23 +00:00 by jared · 0 comments
Owner

Problem

Sdlc/Structural/LifecycleIvarBehindAttrReader fires when no collaborator owns the value, and its fallback suggestion changes behavior.
Shape: attr_reader/attr_accessor whose ivar is set to a non-nil value in one non-initialize def and to literal nil in another.
The fallback suggestion def <attr>; end always returns nil.

Observed

The repo has 0 hits, but this sample fires and no collaborator owns the user or the position:

class Session
  attr_reader :user

  def log_in(user)
    @user = user
  end

  def log_out
    @user = nil
  end
end

class Cursor
  attr_reader :position

  def advance(rows)
    @position = rows.first
  end

  def rewind
    @position = nil
  end
end

Reproduce

Run the cop on the sample above.

Approach

Required work:

  1. Fire only when the non-nil assignment is a message to a held collaborator ivar (@x = @collab.m), so the delegation def x = @collab.m exists.
  2. Delete the def <attr>; end fallback suggestion (attr_lifecycle_offense.rb:33-37), which returns nil.

Carve-outs go in the cop matcher. Do not add config Exclude lists or test-path exclusions.

Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md)

Origin

  • Trigger: #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: false positive on valid code ← cop matcher tests a proxy shape, not the real condition ← DESIGN (cop source named in Where:)
  • Root candidate: none found; searched the cop name, its mechanism terms, and false positive
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/lifecycle_ivar_behind_attr_reader.rb (lifecycle_defs.rb, attr_lifecycle_offense.rb:17-19)
  • Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl

VERDICT: CREATE

## Problem Sdlc/Structural/LifecycleIvarBehindAttrReader fires when no collaborator owns the value, and its fallback suggestion changes behavior. Shape: attr_reader/attr_accessor whose ivar is set to a non-nil value in one non-initialize def and to literal nil in another. The fallback suggestion `def <attr>; end` always returns nil. ## Observed The repo has 0 hits, but this sample fires and no collaborator owns the user or the position: ```ruby class Session attr_reader :user def log_in(user) @user = user end def log_out @user = nil end end class Cursor attr_reader :position def advance(rows) @position = rows.first end def rewind @position = nil end end ``` ## Reproduce Run the cop on the sample above. ## Approach Required work: 1. Fire only when the non-nil assignment is a message to a held collaborator ivar (`@x = @collab.m`), so the delegation `def x = @collab.m` exists. 2. Delete the `def <attr>; end` fallback suggestion (attr_lifecycle_offense.rb:33-37), which returns nil. Carve-outs go in the cop matcher. Do not add config Exclude lists or test-path exclusions. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md) ## Origin - Trigger: #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: false positive on valid code ← cop matcher tests a proxy shape, not the real condition ← DESIGN (cop source named in Where:) - Root candidate: none found; searched the cop name, its mechanism terms, and false positive - Where: plugins/os-sdlc/lib/os_sdlc/cops/lifecycle_ivar_behind_attr_reader.rb (lifecycle_defs.rb, attr_lifecycle_offense.rb:17-19) - Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl VERDICT: CREATE
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#1369
No description provided.