← Back to Pull requests

[AAP-82307] [XLAB] Fix calculation of time taken manually to execute #375

Closed
unknown closed this pull request without merging on Jul 29, 2026 08:05 UTC
View on GitHub
unknown unknown commented on Jul 28, 2026 15:44 UTC
Author

[AAP-82307] Fix calculation of time taken manually to execute

Description


<!-- Mandatory: Provide a clear, concise description of the changes and their purpose -->
  • What is being changed?

  • - Modified _apply_time_estimate_defaults to match the correct calculations described in the ticket - specifically, removed the cap in the estimated calculation
  • Why is this change needed?

  • - The "Time taken to manually execute (min)" should default to 2x the actual running time of the job template, consistent with the standalone Automation Dashboard Utility.
  • How does this change address the issue?

  • - See above

    Type of Change


    <!-- Mandatory: Check one or more boxes that apply -->
  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Documentation update

  • Test update

  • Refactoring (no functional changes)

  • Development environment change

  • Configuration change
  • Self-Review Checklist


    <!-- These items help ensure quality - they complement our automated CI checks -->
  • I have performed a self-review of my code

  • I have added relevant comments to complex code sections

  • I have updated documentation where needed

  • I have considered the security impact of these changes

  • I have considered performance implications

  • I have thought about error handling and edge cases

  • I have tested the changes in my local environment
  • Testing Instructions


    <!-- Optional for test-only changes. Mandatory for all other changes -->
    <!-- Must be detailed enough for reviewers to reproduce -->

    Prerequisites


    Follow README.md to set up local environment. Make sure metrics_service is running.

    1. Run a local instance (or docker compose) for AWX and Metrics Service databases with all recent migrations
    2. Update your environment variables to match your local setup - https://github.com/ansible/metrics-service#quick-start-1

    Steps to Test


    1. Give your local instance some fake data:
    python manage.py shell
    
    # Then copy and paste the below into that running shell
    from apps.dashboard_reports.models import JobData, TemplateMetadata, JobStatusChoices
    import datetime
    
    tmpl = TemplateMetadata.objects.create(
        template_id=99, template_name="Fake Template",
        time_taken_manually_execute_minutes=None,
        time_taken_create_automation_minutes=40,
    )
    now = datetime.datetime.now(datetime.UTC)
    JobData.objects.create(
        job_id=999, template_name=tmpl.template_name, template_id=tmpl.template_id,
        project_id=1, project_name="Fake Project", organization_id=1,
        status=JobStatusChoices.SUCCESSFUL,
        started=now - datetime.timedelta(minutes=10), finished=now,
        elapsed=60, num_hosts=10, launched_by_id=1, launched_by_username="tester",
        template_metadata=tmpl,
    )
    
    # Mimics real AWX-sync ingestion, which is the code path containing the bug
    TemplateMetadata.get_by_awx_id_or_name(name="Fake Template", awx_id=99, elapsed=60)
    
    # Print out the created template PK
    print(tmpl.pk)
    

    2. Check the template metadata via curl:
    curl -u superuser:superpassword http://localhost:8000/api/v1/dashboard_reports/template_metadata/<tmpl.pk>/
    

    Expected Results


    Curl output:
    {"template_id":99,"time_taken_manually_execute_minutes":2,"time_taken_create_automation_minutes":40}
    

    As is seen from this output, time_taken_manually_execute_minutes is 2 (2× the 60-second/1-minute running time), not the old flat 30.

    Diff: 468 lines (+351 / -117) across 5 files Reviewer: kcagran Review duration: 980m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 468 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #375"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18% · Safe to merge
    18%