# Wenbinzhang1990 AI Hotfix Hotfix Perform Bugfix

> Hotfix Perform Bugfix

- Skill: `tomevault-io/wenbinzhang1990-ai-hotfix-hotfix-perform-bugfix` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/wenbinzhang1990-ai-hotfix-hotfix-perform-bugfix`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/wenbinzhang1990-ai-hotfix-hotfix-perform-bugfix/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/wenbinzhang1990-ai-hotfix-hotfix-perform-bugfix

---


# Hotfix Perform Bugfix

Automated workflow for production environment code fixes.

**Core Principles:**
1. **Create fix branch directly from master**, don't use develop branch
2. **Minimal changes**, only modify necessary code, no extra changes
3. **Must create PR**, wait for manual review before merge

## Input Requirements

Before calling this skill, provide:

| Parameter | Description | Source |
|-----------|-------------|--------|
| `repoPath` | Local path of code repository | Path cloned during analysis phase |
| `errorLocation` | Error location | Format: `file_path:line_number` |
| `errorType` | Error type | NullPointerException, business logic error, etc. |
| `fixApproach` | Fix approach | Fix strategy determined during analysis |
| `fixDesc` | Fix description | Specific fix description |
| `traceId` | Trace ID | traceId from error log |
| `errorTime` | Error time | When error occurred |

---

## Workflow

### Step 1: Verify Prerequisites

```bash
cd $repoPath

# Confirm inside git repository
git rev-parse --is-inside-work-tree

# Check for uncommitted changes
git status --porcelain
```

If uncommitted changes exist, prompt user to handle before continuing.

### Step 2: Get Latest master Code

```bash
# Fetch all remote branches
git fetch --all

# Switch to master branch
git checkout master

# Pull latest code
git pull origin master
```

### Step 3: Create Fix Branch (Must Execute)

**Important: Must create independent fix branch from master!**

```bash
# Create fix branch, format: hotfix/bugfix-datetime
bugfix_branch="hotfix/bugfix-$(date +%Y%m%d%H%M%S)"
git checkout -b $bugfix_branch

echo "Created fix branch from master: $bugfix_branch"
```

**Branch naming rules:**
- Format: `hotfix/bugfix-YYYYMMDDHHmmss`
- Example: `hotfix/bugfix-20260316170000`

### Step 4: Execute Code Fix

**⚠️ Minimal Change Principle:**

1. **Only modify code causing the error**, no extra changes
2. **No refactoring** - Even if you see optimizable code, don't change it
3. **No new features** - Only fix current issue
4. **No unrelated changes** - Keep other code unchanged
5. **No formatting changes** - Maintain original code style

---

#### 4.1 NullPointerException Fix

**Typical pattern: Add null check**

```java
// Before fix (line 162)
if(dto.getStatus().equals("16")){

// After fix - minimal change, only this line
if("16".equals(dto.getStatus())){
```

**❌ Wrong Example - Too many changes:**

```java
// Don't do this! Too many lines changed
String status = dto.getStatus();
if("16".equals(status)){
    result = StatusEnum.REFUND.getCode();
}else if("15".equals(status)){
    result = StatusEnum.END.getCode();
}
// Also changed other unrelated code...
```

**✅ Correct Example - Minimal change:**

```java
// Only modify lines that could cause NPE
// Original: if(dto.getStatus().equals("16")){
// Changed to: if("16".equals(dto.getStatus())){

// Original: }else if(dto.getStatus().equals("15")){
// Changed to: }else if("15".equals(dto.getStatus())){
```

---

#### 4.2 Fix Steps

1. **Locate error line** - Precisely find code causing the issue
2. **Analyze root cause** - Determine which variable could be null
3. **Minimal fix** - Only modify necessary code, use simplest solution
4. **No extra changes** - No refactoring, no optimization, no formatting changes

---

### Step 5: Verify Fix

```bash
# Compile check (only check modified module)
mvn compile -q -pl {module_name} 2>&1 | tail -20
```

**Note:** If compilation fails due to other module issues (unrelated to this fix), can skip and continue to commit.

### Step 6: Commit Code

**Commit Message Format:**

```
(hotfix) [auto-fix] Fix {error_type}

Problem:
- Location: {file}:{line}
- Type: {NullPointerException/business logic error/...}
- Trigger: {brief description of trigger condition}

Fix:
- {fix description, explain minimal change content}

Related info:
- traceId: {traceId}
- Time: {error time}

Auto-generated by Claude Code Hotfix Skill
```

**Commit command:**

```bash
git add {modified_file_path}

git commit -m "$(cat <<'EOF'
(hotfix) [auto-fix] Fix NullPointerException

Problem:
- Location: DemoClient.java:162
- Type: NullPointerException
- Trigger: dto.getStatus() returns null when external API returns empty data

Fix:
- Changed dto.getStatus().equals("16") to "16".equals(dto.getStatus())
- Changed dto.getStatus().equals("15") to "15".equals(dto.getStatus())
- Minimal change, only modified 2 lines that could cause NPE

Related info:
- traceId: trace-id-123
- Time: 2026-03-16T13:05:19

Auto-generated by Claude Code Hotfix Skill
EOF
)"
```

### Step 7: Push Fix Branch to Remote

```bash
# Push fix branch to remote
git push -u origin $bugfix_branch

# Check if push succeeded
if [ $? -eq 0 ]; then
  echo "Push succeeded: origin/$bugfix_branch"
else
  echo "Push failed, check network or permissions"
  exit 1
fi
```

### Step 8: Create Pull Request (Must Execute)

**Important: PR target branch is master!**

```bash
# Use gh CLI to create PR
gh pr create \
  --base master \
  --head $bugfix_branch \
  --title "(hotfix) [auto-fix] Fix $errorType" \
  --body "$(cat <<'EOF'
## Problem
- **Location**: {file}:{line}
- **Type**: {errorType}
- **Trigger**: {brief description}

## Fix
- {fix description}

## Change Scope
- Only modified {n} lines, minimal change

## Test Suggestions
- [ ] Verify fix resolves the issue
- [ ] Confirm changes don't affect other functionality

## Related Info
- traceId: {traceId}
- Error time: {error time}

---

⚠️ **This PR is auto-generated by Claude Code Hotfix Skill, please review before merging!**

Auto-generated by Claude Code Hotfix Skill
EOF
)"
```

**If gh CLI not available, output PR creation guide:**

```
========================================
📋 Please manually create Pull Request
========================================

Branch: {bugfix_branch} → master

PR Title: (hotfix) [auto-fix] Fix {errorType}

Please go to code repository web interface to create PR:
{repo_url}/compare/master...{bugfix_branch}

========================================
```

### Step 9: Output Review Notice

**Must output the following review notice:**

```
========================================
📢 Code fix complete, manual review needed
========================================

✅ Fix committed to independent branch
📍 Fix branch: {bugfix_branch}
🔗 Remote: origin/{bugfix_branch}
📝 Commit: {commit_hash}
📋 PR URL: {pr_url}

📏 Change scope: Only {n} lines modified

⚠️ Important reminders:
- Auto-fixed code must be manually reviewed!
- Please verify fix approach is correct
- Confirm change scope is minimal

📋 Review steps:
1. View code changes in PR
2. Confirm change scope is minimal
3. Verify fix approach is reasonable
4. Merge to master after approval

========================================
```

---

## Output Report

After fix completes, output:

```json
{
  "fixStatus": "success",
  "fixBranch": "hotfix/bugfix-20260316170000",
  "baseBranch": "master",
  "commitHash": "abc1234",
  "commitMessage": "(hotfix) [auto-fix] Fix NullPointerException",
  "changedFiles": ["DemoClient.java"],
  "changedLines": 2,
  "fixSummary": "Use constant.equals(variable) pattern to avoid NPE",
  "prUrl": "https://github.com/your-org/your-repo/pull/123",
  "prTitle": "(hotfix) [auto-fix] Fix NullPointerException",
  "needReview": true,
  "nextSteps": [
    "Wait for manual PR review",
    "Merge to master after approval",
    "Deploy to production"
  ]
}
```

---

## Notes

1. **Minimal changes**: Only fix code causing the issue, no extra changes
2. **Security**: Auto-fix only handles simple, clear code issues. Complex issues need manual intervention
3. **Rollback**: Pre-fix code state preserved, can rollback via `git reflog`
4. **Review**: Auto-committed code must undergo manual review

---

## Fix Strategy Reference

### Strategy 1: Constant calls equals (Recommended)

Suitable for NullPointerException type issues, minimal change:

```java
// Before
if(variable.equals("expected")){

// After - only this line changed
if("expected".equals(variable)){
```

### Strategy 2: Add null check

Suitable for scenarios needing special null handling:

```java
// Before
String result = obj.getValue();

// After - add null check
if (obj == null) {
    return null; // or throw business exception
}
String result = obj.getValue();
```

### Strategy 3: Use utility class

Suitable for scenarios needing to compare multiple values:

```java
// Before
if(a.equals(b)){

// After
if(Objects.equals(a, b)){
```

---
> Source: [wenbinzhang1990/ai-hotfix](https://github.com/wenbinzhang1990/ai-hotfix) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

