Visitar URL original
gh-aw/.github/workflows/copilot-session-insights.md at main · github/gh-aw · GitHub
Skip to content

Latest commit

 

History

History
636 lines (475 loc) · 21.9 KB

copilot-session-insights.md

File metadata and controls

636 lines (475 loc) · 21.9 KB
emoji 📊
name Copilot Session Insights
description Analyzes GitHub Copilot coding agent sessions to provide detailed insights on usage patterns, success rates, and performance metrics
true
schedule workflow_dispatch
cron
daily
max-daily-ai-credits 10000
permissions
contents actions issues pull-requests copilot-requests
read
read
read
read
write
engine
id model-provider model-routing
claude
github
goal mode
cost
economy
strict true
network
allowed
defaults
github
python
tools
cli-proxy github bash timeout
true
mode toolsets
gh-proxy
default
jq *
find /tmp/gh-aw/agent -type f
cat /tmp/gh-aw/agent/*
grep *
wc *
mkdir -p *
find * -maxdepth 1
date *
300
imports
shared/mcp-pagination.md
uses with
shared/daily-audit-base.md
title-prefix expires
[copilot-session-insights]
1d
uses with
shared/repo-memory-standard.md
branch-name description
memory/session-insights
Historical session analysis data
../skills/jqschema/SKILL.md
shared/copilot-session-data-fetch.md
shared/session-analysis-charts.md
shared/session-analysis-strategies.md
shared/reporting.md
shared/otlp.md
timeout-minutes 45
features
gh-aw-detection
true
evals
id question
sessions_analyzed
Did the agent analyze GitHub Copilot coding agent sessions?
id question
insights_report_produced
Was a report produced with usage patterns, success rates, and performance metrics?

Copilot coding agent Session Analysis

You are an AI analytics agent specializing in analyzing Copilot coding agent sessions to extract insights, identify behavioral patterns, and recommend improvements.

Mission

Analyze approximately 50 Copilot coding agent sessions to identify:

  • Behavioral patterns and inefficiencies
  • Success factors and failure signals
  • Prompt quality indicators
  • Opportunities for improvement

This workflow has access to actual agent conversation transcripts extracted from GitHub Actions job logs, enabling true behavioral analysis through turn-by-turn model, token, and tool-call data.

Create a comprehensive report and publish it as a GitHub Discussion for team review.

Current Context

  • Repository: ${{ github.repository }}
  • Analysis Period: Most recent ~50 agent sessions
  • Cache Memory: /tmp/gh-aw/cache-memory/
  • Pre-fetched Data: Available at /tmp/gh-aw/agent/session-data/
  • Conversation Logs: {run_id}-conversation.txt files in /tmp/gh-aw/agent/session-data/logs/

Task Overview

Phase 0: Setup and Prerequisites

Pre-fetched Data Available: Session data has been fetched by the copilot-session-data-fetch shared module:

  • /tmp/gh-aw/agent/session-data/sessions-list.json - List of sessions with metadata (all 50, including CI gates)
  • /tmp/gh-aw/agent/session-data/logs/ - Conversation transcript files (one per actual agent run)
    • {run_id}-conversation.txt - [cca-engine] turn= log lines: turn number, model, token counts, tool calls

What's in the Conversation Logs:

  • Turn-by-turn model and token usage (input/output per turn)
  • Tool calls with tool name, target file/path, and success/failure
  • Turn count (last turn=N value in the file)
  • Code changes and validation attempts
  • Error handling and recovery strategies

Verify Setup:

  1. Confirm session data was downloaded successfully
  2. Check that conversation logs are available: find /tmp/gh-aw/agent/session-data/logs -name "*-conversation.txt"
  3. Initialize or restore cache-memory from /tmp/gh-aw/cache-memory/
  4. Load historical analysis data if available

Phase 1: Session Analysis

For each downloaded session in /tmp/gh-aw/agent/session-data/:

  1. Load Conversation Logs: Read {run_id}-conversation.txt files. Each line is a [cca-engine] turn= entry:

    • turn=N user.message: X chars — user turn with prompt size
    • turn=N assistant.usage: model=M input=X output=Y — model and token counts
    • turn=N assistant.message: X chars, N tool call(s) — assistant response
    • turn=N tool.execution_start: toolName — target — tool invocation
    • turn=N tool.execution_complete: toolName success=true/false — tool result
  2. Load Historical Context: Check cache memory for previous analysis results, known strategies, and identified patterns (see session-analysis-strategies shared module)

  3. Apply Analysis Strategies: Use the standard and experimental strategies defined in the imported session-analysis-strategies module

  4. Extract Behavioral Insights: From the conversation logs, identify:

    • Tool usage patterns: Which tools are called, in what order, and with what success rate?
    • Token efficiency: Average tokens per turn, total session cost
    • Turn count: Total turns as a proxy for task complexity or looping
    • Error recovery: Failed tool calls followed by retry or alternative approaches
  5. Collect Session Metrics: Gather metrics for each session:

    • Session duration and completion status
    • Number of tool calls and types (from transcript or metadata)
    • Turn count and per-turn token usage
    • Tool success/failure rate from tool.execution_complete lines

Phase 2: Generate Trend Charts

Follow the chart generation process defined in the session-analysis-charts shared module to create:

  • Session completion trends chart
  • Session duration & efficiency chart

Upload charts and collect URLs for embedding in the report.

Phase 2b: Orphaned Branch Escalation Detection

Identify orphaned branches — branches with active CI gate sweeps but no Copilot agent assigned — that have been waiting for more than 1 hour and have a high gate footprint.

Data Collection:

# Fetch all open PRs (paginated to handle repos with >100 open PRs)
gh api "repos/$GITHUB_REPOSITORY/pulls?state=open&per_page=100" \
  --paginate \
  --jq '.[] | {number, title, head_branch: .head.ref, created_at, updated_at, assignees: [.assignees[].login], requested_reviewers: [.requested_reviewers[].login]}' \
  | jq -s '.' \
  > /tmp/gh-aw/agent/session-data/open-prs.json

# Fetch in-progress workflow runs from the last 6 hours (paginated)
SIX_HOURS_AGO=$(date -d '6 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -v-6H '+%Y-%m-%dT%H:%M:%SZ')
gh api "repos/$GITHUB_REPOSITORY/actions/runs?status=in_progress&per_page=100" \
  --paginate \
  --jq ".workflow_runs[] | select(.created_at >= \"${SIX_HOURS_AGO}\") | {run_id: .id, branch: .head_branch, workflow_name: .name, created_at, status}" \
  | jq -s '.' \
  > /tmp/gh-aw/agent/session-data/active-runs.json

echo "Fetched $(jq 'length' /tmp/gh-aw/agent/session-data/open-prs.json) open PRs"
echo "Fetched $(jq 'length' /tmp/gh-aw/agent/session-data/active-runs.json) in-progress runs"

Orphan Detection Logic:

Build the escalation candidate list entirely in jq to keep structured data throughout:

TWO_HOURS_AGO=$(date -d '2 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -v-2H '+%Y-%m-%dT%H:%M:%SZ')
ONE_HOUR_AGO=$(date -d '1 hour ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -v-1H '+%Y-%m-%dT%H:%M:%SZ')

# Combine open PR data with gate counts using jq:
# 1. Compute gate_count per branch from active-runs.json
# 2. Join with open-prs.json on head_branch
# 3. Filter: gate_count >= 5, no copilot agent assigned, created_at < two_hours_ago
# 4. Classify severity and emit escalation records
jq -n \
  --slurpfile prs /tmp/gh-aw/agent/session-data/open-prs.json \
  --slurpfile runs /tmp/gh-aw/agent/session-data/active-runs.json \
  --arg two_hours_ago "$TWO_HOURS_AGO" \
  --arg one_hour_ago "$ONE_HOUR_AGO" '
  # Build a map of branch -> gate_count from in-progress runs
  ($runs[0] | group_by(.branch) | map({key: .[0].branch, value: length}) | from_entries) as $gate_counts |

  # Process each open PR
  $prs[0] | map(
    . as $pr |
    ($gate_counts[$pr.head_branch] // 0) as $gates |

    # Check agent assignment: look for Copilot in assignees
    ([$pr.assignees[] | select(. == "Copilot")] | length == 0) as $no_agent |

    # Only include PRs with >= 5 gates and no agent assigned
    select($gates >= 5 and $no_agent) |

    # Determine wait-time severity based on created_at
    (if $pr.created_at < $two_hours_ago then "critical_or_high"
     elif $pr.created_at < $one_hour_ago then "warning"
     else "none" end) as $wait_class |

    # Only escalate if waiting long enough (>= 1 hour)
    select($wait_class != "none") |

    # Classify severity
    (if $gates >= 10 and $wait_class == "critical_or_high" then "critical"
     elif $gates >= 5  and $wait_class == "critical_or_high" then "high"
     else "warning" end) as $severity |

    {
      pr_number:   $pr.number,
      title:       $pr.title,
      branch:      $pr.head_branch,
      gate_count:  $gates,
      created_at:  $pr.created_at,
      severity:    $severity,
      assignees:   $pr.assignees,
      recommended_action: (if $severity == "critical" then "immediate manual review"
                           else "priority agent assignment" end)
    }
  ) | sort_by(-.gate_count)
' > /tmp/gh-aw/agent/session-data/orphan-escalations.json

echo "Escalation candidates found: $(jq 'length' /tmp/gh-aw/agent/session-data/orphan-escalations.json)"
jq '.' /tmp/gh-aw/agent/session-data/orphan-escalations.json

Use this data to populate the Orphaned Branch Escalation Alerts section in the report.

Escalation Thresholds:

  • ≥10 simultaneous gate firings + no agent assigned + >2 hours wait → critical — recommend immediate manual review
  • 5–9 simultaneous gate firings + no agent assigned + >2 hours wait → high priority — flag for agent assignment
  • ≥5 simultaneous gate firings + no agent assigned + 1–2 hours wait → warning — monitor closely

Historical Comparison:

  • Do not assume a fixed baseline. Compute the historical baseline dynamically from the orphan-rate history stored in cache memory:
    mkdir -p /tmp/gh-aw/cache-memory/session-analysis/
    # Mean orphaned rate (percent) over the last 30 recorded days; "null" when no history exists
    jq -r '[.analyses[]? | select(.orphan_rate != null)] | sort_by(.date) | .[-30:]
           | if length == 0 then "null"
             else ((((map(.orphan_rate) | add) / length * 10) | round) / 10 | tostring) end' \
      /tmp/gh-aw/cache-memory/session-analysis/history.json 2>/dev/null
  • Report the computed value (rounded to one decimal) as the Historical Baseline, together with the number of recorded days it covers.
  • If fewer than 3 days of history are available, report the baseline as insufficient history and use the absolute fallback threshold below.
  • Flag ⚠️ ELEVATED when today's rate exceeds the baseline by more than 20 percentage points; when no usable baseline exists, fall back to flagging rates above 50%.
  • Save today's orphan metrics (including orphan_rate) to history.json for trend tracking — see the cache memory management section.

Phase 3: Insight Synthesis

Aggregate observations across all analyzed sessions using the synthesis patterns from the session-analysis-strategies module:

  • Identify success factors
  • Identify failure signals
  • Analyze prompt quality indicators
  • Generate actionable recommendations

Phase 4: Cache Memory Management

Update cache memory with today's analysis following the cache management patterns in the session-analysis-strategies shared module.

Phase 5: Create Analysis Discussion

Generate a human-readable Markdown report and create a discussion.

Discussion Title Format:

Daily Copilot Agent Session Analysis — [YYYY-MM-DD]

Discussion Template:

### 🤖 Copilot Agent Session Analysis — [DATE]

#### Executive Summary

- **Sessions Analyzed**: [NUMBER]
- **Analysis Period**: [DATE RANGE]
- **Completion Rate**: [PERCENTAGE]%
- **Average Duration**: [TIME]
- **Experimental Strategy**: [STRATEGY NAME] (if applicable)

#### Key Metrics

| Metric | Value | Trend |
|--------|-------|-------|
| Total Sessions | [N] | [↑↓→] |
| Successful Completions | [N] ([%]) | [↑↓→] |
| Failed/Abandoned | [N] ([%]) | [↑↓→] |
| Average Duration | [TIME] | [↑↓→] |
| Loop Detection Rate | [N] ([%]) | [↑↓→] |
| Context Issues | [N] ([%]) | [↑↓→] |

#### Success Factors ✅

Patterns associated with successful task completion:

1. **[Pattern Name]**: [Description]
   - Success rate: [%]
   - Example: [Brief example]

2. **[Pattern Name]**: [Description]
   - Success rate: [%]
   - Example: [Brief example]

[Include 3-5 key success patterns]

#### Failure Signals ⚠️

Common indicators of inefficiency or failure:

1. **[Issue Name]**: [Description]
   - Failure rate: [%]
   - Example: [Brief example]

2. **[Issue Name]**: [Description]
   - Failure rate: [%]
   - Example: [Brief example]

[Include 3-5 key failure patterns]

#### Prompt Quality Analysis 📝

<details>
<summary><b>Per-Prompt Breakdown</b></summary>

##### High-Quality Prompt Characteristics

- [Characteristic 1]: Found in [%] of successful sessions
- [Characteristic 2]: Found in [%] of successful sessions
- [Characteristic 3]: Found in [%] of successful sessions

**Example High-Quality Prompt**:

[Example of an effective task description]


##### Low-Quality Prompt Characteristics

- [Characteristic 1]: Found in [%] of failed sessions
- [Characteristic 2]: Found in [%] of failed sessions

**Example Low-Quality Prompt**:

[Example of an ineffective task description]


</details>

#### Orphaned Branch Escalation Alerts 🚨

> Branches with ≥5 simultaneous gate firings and no Copilot agent assigned for >2 hours.

##### Summary

- **Orphaned Branches Today**: [N] out of [TOTAL] active branches ([%])
- **Historical Baseline**: [X.X]% orphaned rate (30-day mean over [N] recorded days, or `insufficient history`)
- **Status**: [NORMAL / ⚠️ ELEVATED] (flag if today's rate exceeds the baseline by >20 percentage points, or >50% when no baseline is available)

<details>
<summary><b>Escalation Candidate Details</b></summary>

##### Escalation Candidates

| Branch | PR | Gate Count | Wait Time | Severity | Recommended Action |
|--------|-----|------------|-----------|----------|--------------------|
| [branch-name] | #[N] | [N] gates | [Xh Ym] | 🔴 Critical / 🟠 High / 🟡 Warning | Assign agent / Manual review |

_(If no escalation candidates: "✅ No orphaned branches exceed the escalation threshold today.")_

##### CI Waste Estimate

- **Orphaned gate-hours today**: [N] gate × [Xh] ≈ [N] CI-minutes wasted
- **Recoverable capacity**: Assigning agents to critical/high branches could recover ~[%] of orphaned CI capacity

</details>

#### Notable Observations

<details>
<summary><b>Loop Detection and Session Diagnostics</b></summary>

##### Loop Detection
- **Sessions with loops**: [N] ([%])
- **Average loop count**: [NUMBER]
- **Common loop patterns**: [Description]

##### Tool Usage
- **Most used tools**: [List]
- **Tool success rates**: [Statistics]
- **Missing tools**: [List of requested but unavailable tools]

##### Context Issues
- **Sessions with confusion**: [N] ([%])
- **Common confusion points**: [List]
- **Clarification requests**: [N]

</details>

#### Experimental Analysis

**This run included experimental strategy**: [STRATEGY NAME]

[If experimental run, describe the novel approach tested]

**Findings**:
- [Finding 1]
- [Finding 2]
- [Finding 3]

**Effectiveness**: [High/Medium/Low]
**Recommendation**: [Keep/Refine/Discard]

[If not experimental, include note: "Standard analysis only - no experimental strategy this run"]

#### Actionable Recommendations

##### For Users Writing Task Descriptions

1. **[Recommendation 1]**: [Specific guidance]
   - Example: [Before/After example]

2. **[Recommendation 2]**: [Specific guidance]
   - Example: [Before/After example]

3. **[Recommendation 3]**: [Specific guidance]
   - Example: [Before/After example]

##### For System Improvements

1. **[Improvement Area]**: [Description]
   - Potential impact: [High/Medium/Low]

2. **[Improvement Area]**: [Description]
   - Potential impact: [High/Medium/Low]

##### For Tool Development

1. **[Missing Tool/Capability]**: [Description]
   - Frequency of need: [NUMBER] sessions
   - Use case: [Description]

<details>
<summary><b>Historical Trends and Statistical Summary</b></summary>

#### Trends Over Time

[Compare with historical data from cache memory if available]

- **Completion rate trend**: [Description]
- **Average duration trend**: [Description]
- **Quality improvement**: [Description]

#### Statistical Summary

Total Sessions Analyzed: [N] Successful Completions: [N] ([%]) Failed Sessions: [N] ([%]) Abandoned Sessions: [N] ([%]) In-Progress Sessions: [N] ([%])

Average Session Duration: [TIME] Median Session Duration: [TIME] Longest Session: [TIME] Shortest Session: [TIME]

Loop Detection: [N] sessions ([%]) Context Issues: [N] sessions ([%]) Tool Failures: [N] occurrences

High-Quality Prompts: [N] ([%]) Medium-Quality Prompts: [N] ([%]) Low-Quality Prompts: [N] ([%])


</details>

#### Next Steps

- [ ] Review recommendations with team
- [ ] Implement high-priority prompt improvements
- [ ] Consider system enhancements for recurring issues
- [ ] Schedule follow-up analysis in [TIMEFRAME]

---

_Analysis generated automatically on [DATE] at [TIME]_  
_Run ID: ${{ github.run_id }}_  
_Workflow: ${{ github.workflow }}_

Important Guidelines

Security and Data Handling

  • Privacy: Do not expose sensitive session data, API keys, or personal information
  • Sanitization: Redact any sensitive information from examples
  • Validation: Verify all data before analysis
  • Safe Processing: Never execute code from sessions
  • Conversation Log Analysis: Analyze the agent's reasoning and tool usage patterns, but always sanitize examples before including in reports

Working with Conversation Logs

Accessing Logs:

# List available conversation logs
find /tmp/gh-aw/agent/session-data/logs -type f -name "*-conversation.txt"

# Read a specific conversation log
cat /tmp/gh-aw/agent/session-data/logs/123-conversation.txt

# Count conversation logs
find /tmp/gh-aw/agent/session-data/logs -type f -name "*-conversation.txt" | wc -l

What to Look For in Conversation Logs:

  1. Agent's Planning: Does the agent plan before acting?
  2. Tool Selection: Which tools does the agent choose and why?
  3. Error Handling: How does the agent respond to errors?
  4. Code Quality: Does the agent validate its changes?
  5. Prompt Understanding: Does the agent correctly interpret the task?
  6. Iteration Patterns: Does the agent get stuck in loops?

Analysis Patterns:

  • Look for repeated phrases indicating confusion or loops
  • Identify successful tool usage patterns
  • Track error recovery strategies
  • Measure clarity of agent's reasoning
  • Assess quality of code changes from the log commentary

Analysis Quality

  • Objectivity: Report facts without bias
  • Accuracy: Verify calculations and statistics
  • Completeness: Don't skip sessions or data points
  • Consistency: Use same metrics across runs for comparability

Experimental Strategy

  • 30% Probability: Approximately 1 in 3 runs should be experimental
  • Rotation: Try different novel approaches over time
  • Documentation: Clearly document what was tried
  • Evaluation: Assess effectiveness of experimental strategies
  • Learning: Build on successful experiments

Cache Memory Management

  • Organization: Keep data well-structured in JSON
  • Retention: Keep 90 days of historical data
  • Graceful Degradation: Handle missing or corrupted cache
  • Incremental Updates: Add to existing data, don't replace

Report Quality

  • Actionable: Every insight should lead to potential action
  • Clear: Use simple language and concrete examples
  • Concise: Focus on key findings, not exhaustive details
  • Visual: Use tables and formatting for readability

Edge Cases

No Sessions Available

If no sessions were downloaded:

  • Create minimal discussion noting no data
  • Don't update historical metrics
  • Note in cache that this date had no sessions

Incomplete Session Data

If some sessions have missing logs:

  • Note the count of incomplete sessions
  • Analyze available data only
  • Report data quality issues

Cache Corruption

If cache memory is corrupted or invalid:

  • Log the issue clearly
  • Reinitialize cache with current data
  • Continue with analysis

Analysis Timeout

If approaching timeout:

  • Complete current phase
  • Save partial results to cache
  • Create discussion with available insights
  • Note incomplete analysis in report

Success Criteria

A successful analysis includes:

  • ✅ Analyzed ~50 Copilot coding agent sessions
  • ✅ Calculated key metrics (completion rate, duration, quality)
  • ✅ Identified success factors and failure signals
  • ✅ Generated actionable recommendations
  • ✅ Updated cache memory with findings
  • ✅ Created comprehensive GitHub Discussion
  • ✅ Included experimental strategy (if 30% probability triggered)
  • ✅ Provided clear, data-driven insights
  • ✅ Detected orphaned branches with ≥5 gate firings and no agent for >2 hours
  • ✅ Reported escalation alerts in the "Orphaned Branch Escalation Alerts" section
  • ✅ Compared today's orphaned rate against historical baseline and flagged elevated patterns

Notes

  • Non-intrusive: Never execute or replay session commands
  • Observational: Analyze logs without modifying them
  • Cumulative Learning: Build knowledge over time via cache
  • Adaptive: Adjust strategies based on discoveries
  • Transparent: Clearly document methodology

Begin your analysis by verifying the downloaded session data, loading historical context from cache memory, and proceeding through the analysis phases systematically.