Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/train-drain3-weights.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Train Log Pattern Weights

on:
schedule:
- cron: "0 4 * * *" # Daily at 04:00 UTC
workflow_dispatch:

permissions: {}

jobs:
train:
name: Download logs and train drain3 weights
runs-on: ubuntu-latest
timeout-minutes: 30
Comment on lines +1 to +14
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a concurrency group for this scheduled workflow to prevent overlapping runs (e.g., if a run is slow or a manual dispatch happens near the cron time). Overlaps can lead to duplicate branches/PRs and wasted runner time.

This repo commonly uses concurrency: { group: "gh-aw-${{ github.workflow }}" } for scheduled workflows (e.g., .github/workflows/daily-integrity-analysis.lock.yml:48-50).

This issue also appears on line 70 of the same file.

Copilot uses AI. Check for mistakes.
permissions:
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job token permissions are missing actions: read, which ./gh-aw logs --train needs to list/download workflow run data. With permissions: {} at the workflow level, unspecified scopes default to none, so the logs step is likely to fail with 403.

Add actions: read to jobs.train.permissions (keep contents: write / pull-requests: write as-is). See .github/aw/debug-agentic-workflow.md:68-71 for the documented requirement.

Suggested change
permissions:
permissions:
actions: read

Copilot uses AI. Check for mistakes.
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
with:
go-version-file: go.mod
cache: true

- name: Build gh-aw
run: make build

Comment on lines +28 to +30
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make build runs sync-action-pins/sync-action-scripts as prerequisites (Makefile:22,669-685), which can modify tracked files unrelated to Drain3 weights during this automation run. To avoid incidental working-tree changes and keep the workflow focused, consider building only the CLI binary via go build ... ./cmd/gh-aw (or a dedicated make build-cli target without sync steps).

Copilot uses AI. Check for mistakes.
- name: Download run logs and train weights
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p /tmp/drain3-logs
./gh-aw logs --train --output /tmp/drain3-logs --count 50

- name: Copy trained weights to source tree
run: |
if [ -f /tmp/drain3-logs/drain3_weights.json ]; then
cp /tmp/drain3-logs/drain3_weights.json pkg/agentdrain/data/default_weights.json
echo "✅ Weights file updated successfully"
else
echo "⚠️ No drain3_weights.json produced – skipping PR creation"
exit 0
fi

- name: Check for changes
id: check-changes
run: |
if git diff --quiet pkg/agentdrain/data/default_weights.json; then
echo "changes=false" >> "$GITHUB_OUTPUT"
echo "No changes to default_weights.json – weights are already up to date"
else
echo "changes=true" >> "$GITHUB_OUTPUT"
echo "Changes detected in default_weights.json"
fi

- name: Configure Git
if: steps.check-changes.outputs.changes == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Create pull request with updated weights
if: steps.check-changes.outputs.changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="ci/train-drain3-weights-$(date +%Y%m%d)"

git checkout -b "$BRANCH_NAME"
git add pkg/agentdrain/data/default_weights.json
git commit -m "chore: update drain3 default weights from daily training run"

git push origin "$BRANCH_NAME"

gh pr create \
--title "chore: update drain3 default log pattern weights" \
--body "This pull request updates the default Drain3 log pattern weights (\`pkg/agentdrain/data/default_weights.json\`) by training on the most recent workflow run logs.

## What changed
- Re-trained log template clusters from the latest run logs using \`gh aw logs --train\`
- Copied resulting \`drain3_weights.json\` to the embedded defaults path

## How to verify
1. Build the binary with \`make build\`
2. Run \`gh aw audit\` or \`gh aw logs --train\` and confirm the anomaly analysis reflects the updated patterns

This PR was created automatically by the [train-drain3-weights](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow." \
--head "$BRANCH_NAME" \
--base main
208 changes: 0 additions & 208 deletions cmd/agentdrain-demo/main.go

This file was deleted.

Loading