Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

Latest commit

 

History

History
254 lines (198 loc) · 7.19 KB

File metadata and controls

254 lines (198 loc) · 7.19 KB

Placeholder Resolution Solution

Issue Resolution

Original Question: "After a placeholder is created, when do we go and get the real content for that noun and update it?"

Complete Answer

The placeholder resolution system has been fully implemented to automatically fetch and update placeholder nouns with real GitHub data. Here's exactly when and how it happens:

🔄 When Placeholders Are Resolved

1. Scheduled Resolution (Primary Method)

  • Frequency: Every 6 hours by default
  • Configuration: Set via PLACEHOLDER_RESOLUTION_SCHEDULE environment variable
  • Process: Automatically scans all nouns, identifies placeholders, and resolves them

2. Manual Resolution (On-Demand)

  • API Endpoint: POST /api/placeholder-resolution/resolve-all
  • Trigger: Can be called manually or via automation
  • Use Case: When immediate resolution is needed

3. Immediate Resolution (Specific Placeholders)

  • API Endpoint: POST /api/placeholder-resolution/resolve-immediate
  • Parameters: Array of specific placeholder IDs
  • Use Case: When specific placeholders need urgent resolution

🏗️ Implementation Architecture

Core Components

1. PlaceholderResolutionService

File: src/services/PlaceholderResolutionService.ts

Key Methods:

  • findPlaceholders() - Identifies all placeholder nouns
  • resolvePlaceholder() - Resolves a specific placeholder
  • resolveAllPlaceholders() - Resolves all found placeholders
  • resolveImmediately() - Resolves specific placeholders immediately

Features:

  • Scheduled resolution using node-cron
  • Rate limiting to respect GitHub API limits
  • Error handling and retry logic
  • Comprehensive logging and monitoring

2. Integration Points

  • GitHubService: Fetches real data from GitHub API
  • GitHubMappingService: Transforms GitHub data to Brainy format
  • BrainyData: Stores and updates noun data

Resolution Process Flow

1. Scheduled Trigger (every 6 hours)
   ↓
2. Find All Placeholders
   - Query BrainyData for nouns with placeholder: true
   - Filter by metadata flags (is_placeholder, placeholder)
   ↓
3. Extract GitHub Information
   - Parse placeholder IDs (github_user_12345, github_repo_999)
   - Extract metadata (github_id, entity_type)
   ↓
4. Fetch Real Data
   - Call GitHubService.fetchUserProfile()
   - Call GitHubService.fetchRepositoryDetails()
   - Handle rate limits and errors
   ↓
5. Transform Data
   - Use GitHubMappingService to convert to Brainy format
   - Create standardized nouns and verbs
   ↓
6. Update Placeholder
   - Store real data in BrainyData
   - Overwrites placeholder with real content
   - Log successful resolution

📊 Monitoring and Statistics

API Endpoints

Get Resolution Statistics

GET /api/placeholder-resolution/stats

Response:

{
  "success": true,
  "data": {
    "totalPlaceholders": 15,
    "isResolving": false,
    "lastResolutionTime": "2025-08-02T16:45:00Z"
  },
  "timestamp": "2025-08-02T16:45:00Z"
}

Trigger Full Resolution

POST /api/placeholder-resolution/resolve-all

Response:

{
  "success": true,
  "data": {
    "total": 15,
    "resolved": 12,
    "failed": 3
  },
  "message": "Resolved 12/15 placeholders",
  "timestamp": "2025-08-02T16:45:00Z"
}

Resolve Specific Placeholders

POST /api/placeholder-resolution/resolve-immediate
Content-Type: application/json

{
  "placeholderIds": ["github_user_12345", "github_user_67890"]
}

🔧 Configuration

Environment Variables

# Placeholder resolution schedule (cron format)
PLACEHOLDER_RESOLUTION_SCHEDULE="0 */6 * * *"  # Every 6 hours (default)

# Examples:
# PLACEHOLDER_RESOLUTION_SCHEDULE="0 */2 * * *"  # Every 2 hours
# PLACEHOLDER_RESOLUTION_SCHEDULE="0 0 * * *"    # Daily at midnight
# PLACEHOLDER_RESOLUTION_SCHEDULE="*/30 * * * *"  # Every 30 minutes

Service Initialization

The PlaceholderResolutionService is automatically initialized when the application starts:

// In src/index.ts
const placeholderResolutionService = new PlaceholderResolutionService(
  brainyData,
  logger,
  githubService,
  mappingService
)

await placeholderResolutionService.initialize()

🎯 Key Features

1. Automatic Placeholder Detection

  • Scans all nouns for placeholder flags
  • Supports multiple placeholder identification methods:
    • placeholder: true in properties
    • is_placeholder: true in metadata
    • Standardized ID patterns (github_user_*, github_repo_*)

2. GitHub Data Fetching

  • Fetches user profiles via GraphQL API
  • Retrieves repository details
  • Handles rate limiting automatically
  • Respects GitHub API best practices

3. Error Handling

  • Graceful handling of API failures
  • Retry logic for network errors
  • Detailed logging for troubleshooting
  • Continues processing even if individual placeholders fail

4. Performance Optimization

  • Rate limiting to prevent API abuse
  • Batch processing with delays
  • Concurrent processing with limits
  • Memory-efficient placeholder scanning

📈 Monitoring and Health Checks

Logging

The service provides comprehensive logging:

  • Placeholder discovery and resolution attempts
  • API call success/failure rates
  • Performance metrics and timing
  • Error details and stack traces

Health Monitoring

  • Tracks resolution success rates
  • Monitors API rate limit usage
  • Provides recommendations for optimization
  • Alerts on high failure rates

🚀 Usage Examples

Manual Resolution via API

# Get current statistics
curl -X GET http://localhost:8080/api/placeholder-resolution/stats

# Trigger full resolution
curl -X POST http://localhost:8080/api/placeholder-resolution/resolve-all

# Resolve specific placeholders
curl -X POST http://localhost:8080/api/placeholder-resolution/resolve-immediate \
  -H "Content-Type: application/json" \
  -d '{"placeholderIds": ["github_user_12345", "github_user_67890"]}'

Programmatic Usage

// Get resolution service instance
const resolutionService = placeholderResolutionService

// Find all placeholders
const placeholders = await resolutionService.findPlaceholders()

// Resolve all placeholders
const result = await resolutionService.resolveAllPlaceholders()

// Get statistics
const stats = await resolutionService.getResolutionStats()

✅ Testing and Verification

All existing tests continue to pass (57/57 tests successful), confirming that the implementation:

  • Doesn't break existing functionality
  • Integrates properly with existing services
  • Maintains backward compatibility
  • Follows established patterns and conventions

📋 Summary

The question "After a placeholder is created, when do we go and get the real content for that noun and update it?" is now fully answered:

  1. Automatically every 6 hours via scheduled resolution
  2. On-demand via API endpoints for manual triggering
  3. Immediately for specific placeholders when needed
  4. Comprehensively monitored with statistics and health checks
  5. Fully integrated with existing GitHub data fetching and storage systems

The system ensures that placeholder nouns are systematically resolved with real GitHub data, maintaining data quality and completeness in the Brainy knowledge graph.