-
Notifications
You must be signed in to change notification settings - Fork 66
Description
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] = 0branch_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 viewor other GitHub CLI commands - Git configuration is missing from task JSON, so
git_domainis 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 NULLExpected 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
-
Backend Task Creation (
backend/app/services/adapters/task_kinds.py)_create_taskmethod around lines 205-241- Missing Git field preservation logic
-
Task Execution (
executor/agents/claude_code/claude_code_agent.py)_set_git_env_variablesmethod expects Git fields in task data- Cannot authenticate GitHub CLI without Git domain/token info
-
Database Schema (
kindstable)- 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
- GitHub CLI authentication fix (commit 077b40a) addressed token decryption but not Git configuration persistence
- Issue Code tasks incorrectly have 2-hour expiration instead of 24-hours due to missing taskType label #381: Code task expiration problems
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
- Create a new task with GitHub repository information
- Include a GitHub issue or PR URL in the task prompt
- Submit the task
- Check the database:
SELECT JSON_EXTRACT(json, '$.git_url') FROM kinds WHERE id = <task_id> - Observe that Git fields are NULL
- Claude Code Agent fails to execute
ghcommands with 401 error
Test Cases for Fix
- New Task Creation: Verify Git fields are saved to task JSON
- GitHub CLI Operations: Verify
ghcommands work properly after fix - Existing Task Migration: Verify existing tasks can be updated
- 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.