Skip to content

Git configuration not saved to task JSON, causing GitHub CLI authentication failures #520

@jolestar

Description

@jolestar

Bug Report: Git configuration not saved to task JSON, causing GitHub CLI authentication failures

Problem Description

When creating tasks with GitHub repositories, Git configuration fields (git_url, git_domain, git_repo, etc.) are not being saved to the task JSON data in the database. This causes GitHub CLI commands to fail with authentication errors during task execution.

Root Cause Analysis

1. Missing Git configuration in task JSON creation
In backend/app/services/adapters/task_kinds.py, the _create_task method (lines 205-241) creates the task JSON but does not include Git configuration fields:

task_json = {
    "kind": "Task",
    "spec": {
        "title": title,
        "prompt": obj_in.prompt,
        "teamRef": {"name": team.name, "namespace": team.namespace},
        "workspaceRef": {"name": workspace_name, "namespace": "default"},
        # ❌ MISSING: Git configuration fields
    },
    # ...
}

2. Schema supports Git fields but they're not persisted
The TaskCreate schema in backend/app/schemas/task.py includes Git fields:

  • git_url: Optional[str] = ""
  • git_domain: Optional[str] = ""
  • git_repo: Optional[str] = ""
  • git_repo_id: Optional[int] = 0
  • branch_name: Optional[str] = ""

However, these are not being saved to the task JSON during creation.

Current Behavior

Task Creation (OK):

  • User selects GitHub repository and sets Git configuration in the UI
  • Git fields are passed to the backend API correctly
  • Schema validates Git fields successfully

Task Execution (FAILS):

  • Claude Code Agent tries to execute gh issue view or other GitHub CLI commands
  • Git configuration is missing from task JSON, so git_domain is NULL
  • GitHub CLI authentication fails because no token/domain info is available
  • Error: HTTP 401: Bad credentials (https://api.github.com/graphql)

Database Evidence

Affected Tasks: Tasks 62, 64, and others with GitHub operations

-- Task configuration shows NULL Git fields
SELECT id, JSON_EXTRACT(json, '$.git_url') as git_url, 
       JSON_EXTRACT(json, '$.git_domain') as git_domain
FROM kinds WHERE id IN (62, 64) AND kind = 'Task';

-- Result: All Git fields are NULL

Expected Behavior

Git configuration fields should be saved to the task JSON spec section:

{
  "kind": "Task",
  "spec": {
    "title": "Resolve GitHub issue #505",
    "prompt": "Fix issue https://github.com/nuwa-protocol/nuwa/issues/505",
    "git_url": "https://github.com/nuwa-protocol/nuwa",
    "git_domain": "github.com", 
    "git_repo": "nuwa-protocol/nuwa",
    "git_repo_id": 12345,
    "branch_name": "main",
    "teamRef": {...},
    "workspaceRef": {...}
  }
}

Affected Components

  1. Backend Task Creation (backend/app/services/adapters/task_kinds.py)

    • _create_task method around lines 205-241
    • Missing Git field preservation logic
  2. Task Execution (executor/agents/claude_code/claude_code_agent.py)

    • _set_git_env_variables method expects Git fields in task data
    • Cannot authenticate GitHub CLI without Git domain/token info
  3. Database Schema (kinds table)

    • Git fields should be persisted in the JSON spec section

Impact Assessment

  • Severity: High (blocks GitHub functionality)
  • Frequency: Affects all tasks with GitHub operations
  • User Impact: Complete failure of GitHub-related tasks
  • Data Impact: Existing tasks need data migration

Proposed Solution

1. Fix Task Creation Logic

# In backend/app/services/adapters/task_kinds.py, _create_task method
git_config = {}
if obj_in.git_url:
    git_config["git_url"] = obj_in.git_url
if obj_in.git_domain:
    git_config["git_domain"] = obj_in.git_domain  
if obj_in.git_repo:
    git_config["git_repo"] = obj_in.git_repo
if obj_in.git_repo_id:
    git_config["git_repo_id"] = obj_in.git_repo_id
if obj_in.branch_name:
    git_config["branch_name"] = obj_in.branch_name

task_json = {
    "kind": "Task",
    "spec": {
        "title": title,
        "prompt": obj_in.prompt,
        "teamRef": {"name": team.name, "namespace": team.namespace},
        "workspaceRef": {"name": workspace_name, "namespace": "default"},
        **git_config,  # Add Git configuration
    },
    # ... rest remains unchanged
}

2. Data Migration Script

-- Update existing tasks with Git information from other sources
-- (Implementation needed based on available data sources)

3. Add Validation

  • Ensure Git configuration is properly saved during task creation
  • Add error handling for missing Git fields when GitHub operations are required

Environment

  • Version: v1.0.21
  • Component: Backend Task Service
  • Database: MySQL
  • Affected Tasks: All GitHub-related tasks (Tasks 62, 64, etc.)

Related Issues

Additional Context

This bug was discovered when trying to execute task 64 which involves GitHub issue #505. The task failed with GitHub CLI authentication error because the Git configuration was not available to the Claude Code Agent.

The GitHub CLI authentication improvements in commit 077b40a successfully addressed token decryption, but the root cause—missing Git configuration in task data—remains unresolved.

Steps to Reproduce

  1. Create a new task with GitHub repository information
  2. Include a GitHub issue or PR URL in the task prompt
  3. Submit the task
  4. Check the database: SELECT JSON_EXTRACT(json, '$.git_url') FROM kinds WHERE id = <task_id>
  5. Observe that Git fields are NULL
  6. Claude Code Agent fails to execute gh commands with 401 error

Test Cases for Fix

  1. New Task Creation: Verify Git fields are saved to task JSON
  2. GitHub CLI Operations: Verify gh commands work properly after fix
  3. Existing Task Migration: Verify existing tasks can be updated
  4. Error Handling: Verify proper error messages when Git config is missing

Urgency

High Priority - This blocks core GitHub integration functionality and affects the entire user workflow for code-related tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions