os: memoize base_branch so finish runs git symbolic-ref once #719

Closed
opened 2026-09-25 15:04:24 +00:00 by jared · 1 comment
Owner

Blocked-by: #717

Problem

FinishCommand#base_branch (plugins/os/lib/worktree/finish_command.rb:59-61) runs git symbolic-ref --short HEAD on every call, and run (line 21-33) calls it up to 3 times in one finish: once via base_moved? (line 63-64), once via base_moved_notice (line 70) when the base has moved, and once via verify_ancestry!/the final puts (line 31, 88). It is not memoized.

Approach

Required work:

  1. Memoize base_branch in FinishCommand with @base_branch ||= @git.read('symbolic-ref', '--short', 'HEAD').strip (the @git collaborator from #717).

Acceptance criteria

  1. Given a finish that completes successfully, when it runs against a FakeGit double, then symbolic-ref --short HEAD was recorded exactly once in the double's call log.

Owner sketch

# plugins/os/lib/worktree/finish_command.rb
def base_branch
  @base_branch ||= @git.read('symbolic-ref', '--short', 'HEAD').strip
end

Retired tests

none

Non-goals

Any change to what base_branch resolves to, or to the finish flow's control order.

Origin

Session: 89876543-c418-46b0-b994-dd6dc6887802
Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/89876543-c418-46b0-b994-dd6dc6887802.jsonl
Trigger: review of #634/#707/#708 (commits 8ef12ae8, e2817ffe, ADR-0218)
Improvised this session: none
Chain: env:/thread-local in lib ← ADR-0218 item 1 chose spawn-env-hash + Thread.current ← DESIGN (docs/adr/ADR-0218…, contradicts ADR-0213 and ADR-0207)
Root candidate: #716 (the superseding ADR)

Blocked-by: #717 ## Problem `FinishCommand#base_branch` (`plugins/os/lib/worktree/finish_command.rb:59-61`) runs `git symbolic-ref --short HEAD` on every call, and `run` (line 21-33) calls it up to 3 times in one finish: once via `base_moved?` (line 63-64), once via `base_moved_notice` (line 70) when the base has moved, and once via `verify_ancestry!`/the final `puts` (line 31, 88). It is not memoized. ## Approach Required work: 1. Memoize `base_branch` in `FinishCommand` with `@base_branch ||= @git.read('symbolic-ref', '--short', 'HEAD').strip` (the `@git` collaborator from #717). ## Acceptance criteria 1. Given a finish that completes successfully, when it runs against a `FakeGit` double, then `symbolic-ref --short HEAD` was recorded exactly once in the double's call log. ## Owner sketch # plugins/os/lib/worktree/finish_command.rb def base_branch @base_branch ||= @git.read('symbolic-ref', '--short', 'HEAD').strip end ## Retired tests none ## Non-goals Any change to what `base_branch` resolves to, or to the finish flow's control order. ## Origin Session: 89876543-c418-46b0-b994-dd6dc6887802 Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/89876543-c418-46b0-b994-dd6dc6887802.jsonl Trigger: review of #634/#707/#708 (commits 8ef12ae8, e2817ffe, ADR-0218) Improvised this session: none Chain: env:/thread-local in lib ← ADR-0218 item 1 chose spawn-env-hash + Thread.current ← DESIGN (docs/adr/ADR-0218…, contradicts ADR-0213 and ADR-0207) Root candidate: #716 (the superseding ADR)
Author
Owner

Resolution

Done: base_branch memoized with @base_branch ||= in FinishCommand (shipped inside #717 aa3475d2); acceptance test added asserting symbolic-ref --short HEAD recorded once through FakeGit

Evidence: main 8156d792; test proven red (Expected 1, Actual 3) with memoization removed, then green; os suite 27 runs 0 failures. Not run through the pipeline: the production change already existed after #717, which is the #724 shape

Follow-ups: none

## Resolution **Done:** base_branch memoized with @base_branch ||= in FinishCommand (shipped inside #717 aa3475d2); acceptance test added asserting symbolic-ref --short HEAD recorded once through FakeGit **Evidence:** main 8156d792; test proven red (Expected 1, Actual 3) with memoization removed, then green; os suite 27 runs 0 failures. Not run through the pipeline: the production change already existed after #717, which is the #724 shape **Follow-ups:** none
jared closed this issue 2026-09-25 16:25:10 +00:00
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#719
No description provided.