Skip to content

Commit 211281b

Browse files
rjmurillo-botclaude
andcommitted
docs(memory): add session 100 learnings
New memories from autonomous PR workflow session: - skill-triage-001-verify-before-stale-closure: Mandatory git history search before closing issues as stale - skill-triage-002-bot-closure-verification: Verify triage bot PR closures citing "superseded" - skill-git-004-branch-switch-file-verification: Verify file state after branch switches - skill-recovery-001-lost-code-investigation: Complete workflow for investigating "lost" code on unmerged branches - pester-variable-scoping: Use $script: prefix for cross-block variable visibility in Pester tests Updated memory-index with new entries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 207cbe7 commit 211281b

6 files changed

+297
-0
lines changed

.serena/memories/memory-index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| gh extension notify combine metrics milestone webhook grep sub-issue | skills-gh-extensions-index |
1010
| label milestone issue create tag priority | project-labels-milestones |
1111
| powershell ps1 psm1 module pester test discovery isolation | skills-powershell-index, skills-pester-testing-index, pattern-thin-workflows |
12+
| pester variable scope script BeforeAll It block visibility | pester-variable-scoping |
1213
| bash exit code cross-language contract AUTOFIX pre-commit hook | skills-bash-integration-index |
1314
| security vulnerability TOCTOU secret injection | skills-security-index |
1415
| planning task file path scope breakdown | skills-planning-index |
@@ -33,6 +34,9 @@
3334
| analysis gap root-cause trade-off git blame investigation | skills-analysis-index |
3435
| git hook pre-commit autofix cross-language grep TOCTOU | skills-git-hooks-index |
3536
| git branch merge conflict checkout cleanup workflow resolution worktree parallel isolation | skills-git-index |
37+
| git branch switch checkout file state verification lost | skill-git-004-branch-switch-file-verification |
38+
| triage stale closure verify history bot superseded duplicate | skill-triage-001-verify-before-stale-closure, skill-triage-002-bot-closure-verification |
39+
| lost code recovery investigation unmerged branch orphaned | skill-recovery-001-lost-code-investigation |
3640
| protocol blocking gate RFC MUST verification template legacy | skills-protocol-index |
3741
| retrospective learning session failure skill persistence extract | skills-retrospective-index |
3842
| regex pattern match escape lookahead anchor quantifier | utilities-regex |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Pester Variable Scoping: Use $script: for Cross-Block Visibility
2+
3+
## Problem
4+
5+
In Session 100, a Pester test file triggered PSScriptAnalyzer warning:
6+
> "The variable 'scriptPath' is assigned but never used"
7+
8+
The variable was defined in `BeforeAll` but used in `It` blocks.
9+
10+
## Root Cause
11+
12+
Pester runs each `It` block in its own scope. Variables defined in `BeforeAll` without `$script:` prefix are not visible in `It` blocks.
13+
14+
## Correct Pattern
15+
16+
```powershell
17+
# BeforeAll - use $script: prefix
18+
BeforeAll {
19+
$script:scriptPath = Join-Path $PSScriptRoot ".." "path" "to" "script.ps1"
20+
$script:testData = @{ key = "value" }
21+
}
22+
23+
# It blocks - reference with $script: prefix
24+
Describe "MyTests" {
25+
It "Should find file" {
26+
Test-Path $script:scriptPath | Should -Be $true
27+
}
28+
29+
It "Should have test data" {
30+
$script:testData.key | Should -Be "value"
31+
}
32+
}
33+
```
34+
35+
## Anti-Pattern
36+
37+
```powershell
38+
# BAD - variable not visible in It blocks
39+
BeforeAll {
40+
$scriptPath = "..." # No $script: prefix
41+
}
42+
43+
It "Test" {
44+
Test-Path $scriptPath # PSScriptAnalyzer: variable never used
45+
}
46+
```
47+
48+
## Scope Reference
49+
50+
| Block | Scope | Visibility |
51+
|-------|-------|------------|
52+
| `BeforeAll` | Script/Describe | Use `$script:` for cross-block |
53+
| `BeforeEach` | It block | Local to each It |
54+
| `It` | Own scope | Isolated per test |
55+
56+
## Source
57+
58+
- Session 100 (2025-12-29)
59+
- File: tests/Detect-CopilotFollowUpPR.Tests.ps1
60+
- PSScriptAnalyzer rule: PSUseDeclaredVarsMoreThanAssignments
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Skill: Verify File State After Branch Switches
2+
3+
## Problem
4+
5+
In Session 100, when switching from `feat/282-centralize-bot-authors` to `main` and then creating `feat/275-unified-rate-limit`, edits to `GitHubHelpers.psm1` were lost because the file reverted to main's version.
6+
7+
## Root Cause
8+
9+
Branch switches reset working directory to the target branch state. Uncommitted or staged changes on the previous branch are lost if not committed first.
10+
11+
## Verification Pattern
12+
13+
After any `git checkout` or branch switch:
14+
15+
```bash
16+
# 1. Verify current branch
17+
git branch --show-current
18+
19+
# 2. Check if expected file exists and has expected content
20+
git diff HEAD~1 --name-only # See what changed in last commit
21+
22+
# 3. If working on a file that should have edits, verify:
23+
head -20 {file_path} # Quick visual check
24+
```
25+
26+
## Safe Branch Switch Workflow
27+
28+
```bash
29+
# Before switching branches
30+
git status # Check for uncommitted changes
31+
git stash # If needed, stash changes
32+
33+
# Switch branch
34+
git checkout {new-branch}
35+
36+
# After switching
37+
git stash pop # If you stashed
38+
# OR re-apply edits if they belong on the new branch
39+
```
40+
41+
## Anti-Pattern
42+
43+
```text
44+
BAD: git checkout main && git checkout -b new-branch # Assumes file state preserved
45+
GOOD: git status && git checkout main && git checkout -b new-branch && verify file state
46+
```
47+
48+
## Source
49+
50+
- Session 100 (2025-12-29)
51+
- Lost ~50 lines of edits to GitHubHelpers.psm1
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Skill: Lost Code Investigation Workflow
2+
3+
## When to Use
4+
5+
When code is reported missing, a function "doesn't exist", or an issue references code that can't be found on main.
6+
7+
## Investigation Checklist
8+
9+
### Step 1: Search All Git History
10+
11+
```bash
12+
# Search for the term across ALL branches (including unmerged)
13+
git log --all -S "{function_name}" --oneline --source
14+
15+
# If found, shows which branch contains it
16+
# Example output:
17+
# f12f237 refs/remotes/origin/feat/pr-162-phase4 feat: Add detection script
18+
```
19+
20+
### Step 2: Check Related PRs
21+
22+
```bash
23+
# Search closed PRs
24+
gh pr list --state closed --search "{keyword}" --json number,title,state,mergedAt
25+
26+
# Look for mergedAt: null (closed without merge)
27+
```
28+
29+
### Step 3: Check Orphaned Branches
30+
31+
```bash
32+
# List all remote branches
33+
git branch -a | grep -i "{keyword}"
34+
35+
# Check if branch still exists
36+
git ls-tree -r remotes/origin/{branch} --name-only | grep -i "{file}"
37+
```
38+
39+
### Step 4: Extract and Recover
40+
41+
```bash
42+
# View file from unmerged branch
43+
git show remotes/origin/{branch}:{path/to/file}
44+
45+
# Save to current branch
46+
git show remotes/origin/{branch}:{path/to/file} > recovered_file.ps1
47+
```
48+
49+
### Step 5: Investigate Why Not Merged
50+
51+
```bash
52+
# Get PR details
53+
gh pr view {number} --json title,state,closedAt,body,comments
54+
55+
# Check last comments for closure reason
56+
```
57+
58+
## Common Causes of "Lost" Code
59+
60+
| Cause | Detection | Recovery |
61+
|-------|-----------|----------|
62+
| PR closed without merge | `mergedAt: null` | Recover from branch |
63+
| Incorrect triage bot closure | "superseded" in comments | Reopen or new PR |
64+
| Branch deleted after close | No remote branch | Check local or reflog |
65+
| Bad merge conflict resolution | `git log --all -S` finds it | Cherry-pick |
66+
67+
## Key Principle
68+
69+
**Never trust "doesn't exist" without searching git history.** Code can exist on:
70+
- Unmerged branches
71+
- Closed PRs
72+
- Orphaned commits
73+
- Stale remote branches
74+
75+
A quick `git log --all -S` search takes seconds and prevents false stale closures.
76+
77+
## Source
78+
79+
- Session 100 (2025-12-29)
80+
- Issues #238, #293 recovered from unmerged branches
81+
- PRs #202, #203 incorrectly closed by triage bot
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Skill: Verify Git History Before Closing Issues as Stale
2+
3+
## Problem
4+
5+
In Session 100, issues #238 and #293 were incorrectly closed as "stale" because the referenced functions (`Get-CopilotAnnouncement`, `Detect-CopilotFollowUpPR.ps1`) didn't exist on `main`. However, the code existed on unmerged branches (`feat/pr-162-phase4`, `copilot/add-copilot-context-synthesis`) from PRs #202/#203 that were incorrectly closed by triage bot.
6+
7+
## Root Cause
8+
9+
The triage bot closed PRs #202/#203 claiming content was "superseded" because template documentation existed. But the actual **PowerShell implementation** (268 lines) was never merged.
10+
11+
## Mandatory Checklist Before Closing as Stale
12+
13+
```bash
14+
# 1. Search ALL git history (including unmerged branches)
15+
git log --all -S "{function_name}" --oneline
16+
17+
# 2. Check for related PRs (open AND closed)
18+
gh pr list --state all --search "{function_name}"
19+
20+
# 3. Check for orphaned branches
21+
git branch -a | grep -i "{keyword}"
22+
23+
# 4. If found on unmerged branch, investigate WHY it wasn't merged
24+
git show {branch}:{file_path} | head -50
25+
```
26+
27+
## Anti-Pattern
28+
29+
```text
30+
BAD: "Function doesn't exist on main" → Close as stale
31+
GOOD: "Function doesn't exist on main" → Search git history → Found on unmerged branch → Recover
32+
```
33+
34+
## Recovery Command
35+
36+
```bash
37+
# Extract file from unmerged branch
38+
git show remotes/origin/{branch}:{path/to/file} > recovered_file.ps1
39+
```
40+
41+
## Source
42+
43+
- Session 100 (2025-12-29)
44+
- Issues #238, #293 (incorrectly closed, then reopened)
45+
- PRs #202, #203 (incorrectly closed by triage bot)
46+
- Recovery PR #493
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Skill: Verify Triage Bot PR Closures
2+
3+
## Problem
4+
5+
In Session 100, PRs #202 and #203 were closed by the triage bot with rationale:
6+
> "Superseded Content (already on main): Phase 4.5 Copilot Follow-Up Handling already exists in templates/..."
7+
8+
However, only **template documentation** (inline bash examples) existed on main. The actual **PowerShell implementation** (268 lines with structured JSON output, categorization, tests) was never merged.
9+
10+
## Root Cause
11+
12+
Triage bot matched keywords in the template but didn't verify the actual implementation existed.
13+
14+
## Verification Required
15+
16+
When reviewing bot closures that cite "superseded", "already exists", or "duplicate":
17+
18+
```bash
19+
# 1. Check what the PR was adding
20+
gh pr view {number} --json files -q '.files[].path'
21+
22+
# 2. Verify those files exist on main
23+
for file in $(gh pr view {number} --json files -q '.files[].path'); do
24+
if [[ -f "$file" ]]; then
25+
echo "EXISTS: $file"
26+
else
27+
echo "MISSING: $file"
28+
fi
29+
done
30+
31+
# 3. If files don't exist, the bot closure was INCORRECT
32+
```
33+
34+
## Red Flags for Incorrect Bot Closures
35+
36+
| Bot Rationale | Verification |
37+
|---------------|--------------|
38+
| "Superseded" | Check if actual code exists, not just docs |
39+
| "Already exists" | Verify exact file paths, not just concepts |
40+
| "Duplicate" | Compare actual implementations, not titles |
41+
42+
## Recovery
43+
44+
If bot closure was incorrect:
45+
46+
1. Reopen the original PR, OR
47+
2. Cherry-pick/recover from the branch: `git show {branch}:{path}`
48+
3. Create new PR with recovered implementation
49+
50+
## Source
51+
52+
- Session 100 (2025-12-29)
53+
- PRs #202, #203 (incorrectly closed)
54+
- Recovery PR #493
55+
- 268+ lines of implementation recovered

0 commit comments

Comments
 (0)