The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
ci: auto-fix contract (prepare / agent / publish) + docs (#356)
FrameAutomata943dc6736083
diff --git a/.github/actions/autofix-prepare/action.yml b/.github/actions/autofix-prepare/action.ymlnew file mode 100644index 00000000..b6627aa3--- /dev/null+++ b/.github/actions/autofix-prepare/action.yml@@ -0,0 +1,168 @@+name: Traceway auto-fix prepare+description: >-+ Gates a Traceway-created issue and builds the agent's prompt from its+ validated fields only. Installs the traceway CLI and logs it in with a+ read-only token. Part of the auto-fix contract documented in+ docs/pages/learn/auto-fix.mdx.+inputs:+ issue_number:+ description: Number of the issue the Traceway GitHub channel opened+ required: true+ allowed_authors:+ description: Comma-separated GitHub logins allowed to trigger a run, normally the owner of the channel's token. An empty list refuses every issue+ required: true+ github_token:+ description: Token used to read the issue+ default: ${{ github.token }}+ traceway_url:+ description: Traceway instance the agent queries+ default: https://cloud.tracewayapp.com+ traceway_token:+ description: Read-only Traceway personal access token (a bot user with org role readonly)+ required: true+ project_id:+ description: Traceway project id the exception belongs to+ required: true+outputs:+ proceed:+ description: '"true" when the issue passed every gate; skip the agent and publish steps otherwise'+ value: ${{ steps.gate.outputs.proceed }}+ hash:+ description: The 16-hex exception hash from the issue body; pass it to autofix-publish+ value: ${{ steps.gate.outputs.hash }}+ prompt:+ description: The generated prompt, for agents that take it as a string+ value: ${{ steps.prompt.outputs.prompt }}+ prompt_file:+ description: Path of the generated prompt+ value: ${{ steps.prompt.outputs.prompt_file }}+ skills_dir:+ description: Directory holding traceway/SKILL.md, outside the working tree+ value: ${{ steps.prompt.outputs.skills_dir }}+ report_file:+ description: File the agent must write its report to; pass it to autofix-publish+ value: ${{ steps.prompt.outputs.report_file }}+runs:+ using: composite+ steps:+ - name: Gate the issue+ id: gate+ shell: bash+ env:+ GH_TOKEN: ${{ inputs.github_token }}+ ISSUE: ${{ inputs.issue_number }}+ ALLOWED_AUTHORS: ${{ inputs.allowed_authors }}+ run: |+ set -euo pipefail+ refuse() {+ echo "proceed=false" >> "$GITHUB_OUTPUT"+ echo "::warning::auto-fix skipped: $1"+ exit 0+ }+ authors=",${ALLOWED_AUTHORS// /},"+ if [ "$authors" = ",," ]; then+ refuse "allowed_authors is empty; name the GitHub login that owns the Traceway channel's token"+ fi+ issue=$(gh issue view "$ISSUE" --repo "$GITHUB_REPOSITORY" --json author,body)+ author=$(jq -r .author.login <<< "$issue")+ case "$authors" in+ *,"$author",*) ;;+ *) refuse "issue author '$author' is not in allowed_authors" ;;+ esac+ # Only regex-validated fields leave this step: the issue body quotes+ # the exception message, so it is attacker-influenced and is never+ # interpolated into the prompt. The line formats are the ones+ # buildExceptionBody writes (backend/app/notifications/messages.go).+ body=$(jq -r .body <<< "$issue" | tr -d '\r')+ hash=$(printf '%s\n' "$body" | grep -oE '^Hash: [0-9a-f]{16}$' | head -n1 | cut -d' ' -f2 || true)+ if [ -z "$hash" ]; then+ refuse "the issue body carries no Traceway exception hash (a channel test notification, or not a Traceway issue)"+ fi+ exception_id=$(printf '%s\n' "$body" | grep -oE '^Exception ID: [0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$' | head -n1 | cut -d' ' -f3 || true)+ occurred_at=$(printf '%s\n' "$body" | grep -oE '^Occurred at: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} UTC$' | head -n1 | cut -d' ' -f3- || true)+ {+ echo "proceed=true"+ echo "hash=$hash"+ echo "exception_id=$exception_id"+ echo "occurred_at=$occurred_at"+ } >> "$GITHUB_OUTPUT"+ echo "Issue #$ISSUE by $author: hash=$hash exception_id=${exception_id:-none} occurred_at=${occurred_at:-none}"++ - name: Install the traceway CLI+ if: steps.gate.outputs.proceed == 'true'+ shell: bash+ run: curl -fsSL https://cli.tracewayapp.com/install.sh | sh++ - name: Log in to Traceway with the read-only token+ if: steps.gate.outputs.proceed == 'true'+ shell: bash+ env:+ URL: ${{ inputs.traceway_url }}+ TOKEN: ${{ inputs.traceway_token }}+ PROJECT_ID: ${{ inputs.project_id }}+ run: |+ set -euo pipefail+ printf '%s' "$TOKEN" | traceway login --url "$URL" --token-stdin+ traceway projects use "$PROJECT_ID"++ - name: Deliver the skill and write the prompt+ if: steps.gate.outputs.proceed == 'true'+ id: prompt+ shell: bash+ env:+ ISSUE: ${{ inputs.issue_number }}+ HASH: ${{ steps.gate.outputs.hash }}+ EXCEPTION_ID: ${{ steps.gate.outputs.exception_id }}+ OCCURRED_AT: ${{ steps.gate.outputs.occurred_at }}+ URL: ${{ inputs.traceway_url }}+ run: |+ set -euo pipefail+ SKILLS_DIR="$RUNNER_TEMP/skills"+ REPORT_FILE="$RUNNER_TEMP/fix-report.md"+ PROMPT_FILE="$RUNNER_TEMP/autofix-prompt.md"++ # The skill ships in tracewayapp/traceway two directories above this+ # action; the reusable workflow's sparse checkout lists both paths so+ # the layout holds there as well.+ mkdir -p "$SKILLS_DIR"+ rm -rf "$SKILLS_DIR/traceway"+ cp -R "$GITHUB_ACTION_PATH/../../../skills/traceway" "$SKILLS_DIR/traceway"++ view_url="${URL%/}/issues/$HASH"+ {+ echo "Traceway detected a production error and opened issue #$ISSUE in this repository. The exception, as the notification reported it:"+ echo+ echo "Hash: $HASH"+ if [ -n "$EXCEPTION_ID" ]; then echo "Exception ID: $EXCEPTION_ID"; fi+ if [ -n "$OCCURRED_AT" ]; then echo "Occurred at: $OCCURRED_AT"; fi+ echo "View details: $view_url"+ echo+ cat <<PROMPT+ Before anything else, read $SKILLS_DIR/traceway/SKILL.md and follow its Debug flow, treating the fields above as the issue reference; if the traceway skill from the tw plugin is available to you, invoking it is the same thing. The skill explains how to get from the Hash, Exception ID and Occurred-at timestamp to the occurrence, and from there into traces, sessions and logs. The traceway CLI is installed and already authenticated against the right project with a read-only token: never run \`traceway login\`, and never archive or otherwise change anything in Traceway.++ You have NO access to git or gh, and you must not commit, push, or call any network tool. A later workflow step handles all of that. Your job is only to investigate, edit files in the working tree if a fix is warranted, and write a report.++ If the investigation ties the root cause to code in this repository, fix the cause, not the symptom. Keep the diff minimal. Run the relevant tests for the packages you touch. If you cannot tie the root cause to code with confidence, do NOT guess a fix; leave the working tree untouched.++ Do not add code comments explaining your change, why it is correct, or what the error was. The diff must read like the surrounding code and follow the repository's contribution rules (CLAUDE.md or its equivalent). ALL explanation belongs in the report file, none of it in the code.++ When you are done, write your report to the file $REPORT_FILE in exactly this format:++ Line 1: "STATUS: fixed" if you applied a fix, or "STATUS: analysis" if you investigated but did not change code.+ Line 2: "HASH: $HASH".+ Line 3 onward: your root cause analysis in markdown. If STATUS is fixed, explain the root cause, the fix, and how you verified it, and include the View details link from above. This text becomes the pull request description or the issue comment, so write it for a human reviewer.++ The report file is mandatory. Write it even when you change nothing.++ Never create helper scripts, notes, or any other scratch files inside the repository working tree: everything in the working tree becomes part of the pull request, and the publish step refuses a run that leaves scratch files behind. Use $RUNNER_TEMP for anything temporary.+ PROMPT+ } > "$PROMPT_FILE"++ {+ echo "prompt_file=$PROMPT_FILE"+ echo "skills_dir=$SKILLS_DIR"+ echo "report_file=$REPORT_FILE"+ echo "prompt<<TRACEWAY_PROMPT_$GITHUB_RUN_ID"+ cat "$PROMPT_FILE"+ echo "TRACEWAY_PROMPT_$GITHUB_RUN_ID"+ } >> "$GITHUB_OUTPUT"diff --git a/.github/actions/autofix-publish/action.yml b/.github/actions/autofix-publish/action.ymlnew file mode 100644index 00000000..c22de00f--- /dev/null+++ b/.github/actions/autofix-publish/action.yml@@ -0,0 +1,138 @@+name: Traceway auto-fix publish+description: >-+ Turns the agent's report and working-tree edits into a pull request or an+ issue comment. The only step of the auto-fix loop that holds write+ credentials; it publishes nothing the report and the tree do not agree on.+ Expects the traceway CLI installed by the prepare action in the same job.+inputs:+ issue_number:+ description: Number of the issue the run is for+ required: true+ hash:+ description: The exception hash the prepare action validated. A report naming a different hash is refused+ required: true+ github_token:+ description: GitHub token that pushes the fix branch, opens the pull request and comments on the issue+ required: true+ report_file:+ description: The report the agent wrote (the prepare action's report_file output)+ required: true+ traceway_url:+ description: Traceway instance to archive the exception on+ default: https://cloud.tracewayapp.com+ traceway_token:+ description: Traceway token with write access to the project, used only to archive the exception once the pull request is open. Empty never archives+ default: ""+ project_id:+ description: Traceway project id, needed to archive+ default: ""+ archive_on_open:+ description: Archive the exception when the pull request opens+ default: "true"+ scratch_patterns:+ description: Space-separated basename globs. A new file matching one refuses the run instead of shipping it in the pull request+ default: ".tw_* *.sh *.patch *.log *.tmp fix-report*"+outputs:+ result:+ description: '"pr" when a pull request was opened, "comment" when the analysis was posted on the issue'+ value: ${{ steps.publish.outputs.result }}+ pr_url:+ description: URL of the pull request, when one was opened+ value: ${{ steps.publish.outputs.pr_url }}+runs:+ using: composite+ steps:+ - name: Publish the result+ id: publish+ shell: bash+ env:+ GH_TOKEN: ${{ inputs.github_token }}+ ISSUE: ${{ inputs.issue_number }}+ HASH: ${{ inputs.hash }}+ REPORT_FILE: ${{ inputs.report_file }}+ TRACEWAY_URL: ${{ inputs.traceway_url }}+ TRACEWAY_TOKEN: ${{ inputs.traceway_token }}+ PROJECT_ID: ${{ inputs.project_id }}+ ARCHIVE_ON_OPEN: ${{ inputs.archive_on_open }}+ SCRATCH_PATTERNS: ${{ inputs.scratch_patterns }}+ run: |+ set -euo pipefail+ comment() { gh issue comment "$ISSUE" --repo "$GITHUB_REPOSITORY" --body-file -; }+ refuse() {+ printf '%s\n' "$1" | comment+ echo "::error::$1"+ exit 1+ }++ if [ ! -f "$REPORT_FILE" ]; then+ refuse "The auto-fix agent finished without producing a report. Check the workflow run log."+ fi+ STATUS=$(sed -n '1s/^STATUS: *//p' "$REPORT_FILE")+ REPORT_HASH=$(sed -n '2s/^HASH: *//p' "$REPORT_FILE")+ BODY=$(tail -n +3 "$REPORT_FILE")+ case "$STATUS" in+ fixed|analysis) ;;+ *) refuse "The agent's report has an unknown STATUS ('$STATUS'); nothing was published. Check the run log." ;;+ esac+ # Line 2 is dictated by the prompt, and `tail -n +3` drops it either+ # way: accepting anything else would silently cut the analysis short.+ if [ "$REPORT_HASH" != "$HASH" ]; then+ refuse "The agent's report must carry \"HASH: $HASH\" on line 2 (found '$REPORT_HASH'); nothing was published."+ fi++ # -uall lists a new directory's files instead of collapsing it to+ # "notes/", which would hide every scratch file inside it.+ CHANGES=$(git status --porcelain -uall)+ # noglob keeps the unquoted $SCRATCH_PATTERNS split into words without+ # each word then expanding against the repository's own files.+ set -f+ while IFS= read -r path; do+ [ -n "$path" ] || continue+ for pattern in $SCRATCH_PATTERNS; do+ # shellcheck disable=SC2254 # the pattern is meant to glob+ case "$(basename "$path")" in+ $pattern) refuse "The agent left a scratch file in the working tree ($path); nothing was published." ;;+ esac+ done+ done <<< "$(sed -n 's/^\(??\|A[ M]\) //p' <<< "$CHANGES")"+ set +f+ if [ "$STATUS" = fixed ] && [ -z "$CHANGES" ]; then+ refuse "The agent reported a fix but left the working tree unchanged; nothing was published."+ fi+ if [ "$STATUS" != fixed ] && [ -n "$CHANGES" ]; then+ refuse "The agent changed the working tree without reporting a fix (STATUS: $STATUS); nothing was published. The diff is in the run's artifact."+ fi++ if [ "$STATUS" != fixed ]; then+ { echo "Auto-fix agent report (no PR opened):"; echo; echo "$BODY"; } | comment+ echo "result=comment" >> "$GITHUB_OUTPUT"+ exit 0+ fi++ git config user.name "github-actions[bot]"+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"+ gh auth setup-git+ # The run id and attempt keep the branch unique: the same hash comes+ # back whenever a resolved error regresses, and a re-run repeats the+ # whole job, both of which would otherwise be a rejected push.+ BRANCH="traceway/fix-$HASH-$GITHUB_RUN_ID.$GITHUB_RUN_ATTEMPT"+ git checkout -q -b "$BRANCH"+ git add -A+ git commit -q -m "Fix production error $HASH"+ if ! git push -q -u origin "$BRANCH"; then+ refuse "Could not push $BRANCH; nothing was published. The fix is in the run's artifact."+ fi+ PR_URL=$({ echo "Fixes #$ISSUE"; echo; echo "$BODY"; } | \+ gh pr create --title "Auto-fix: traceway $HASH (issue #$ISSUE)" --head "$BRANCH" --body-file -)+ echo "result=pr" >> "$GITHUB_OUTPUT"+ echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"+ echo "Opened $PR_URL"++ if [ "$ARCHIVE_ON_OPEN" = true ] && [ -n "$TRACEWAY_TOKEN" ] && [ -n "$PROJECT_ID" ]; then+ # A separate CLI profile keeps the write token apart from the+ # read-only session the agent step used.+ printf '%s' "$TRACEWAY_TOKEN" | traceway --profile publish login --url "$TRACEWAY_URL" --token-stdin+ traceway --profile publish --project "$PROJECT_ID" exceptions archive "$HASH" --yes+ elif [ "$ARCHIVE_ON_OPEN" = true ] && [ -n "$TRACEWAY_TOKEN" ]; then+ echo "::warning::project_id is empty; the exception was not archived"+ fidiff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.ymlnew file mode 100644index 00000000..63e68856--- /dev/null+++ b/.github/workflows/autofix.yml@@ -0,0 +1,195 @@+# Reusable Traceway auto-fix loop with Claude Code as the agent: a Traceway+# GitHub channel opens an issue, the agent investigates it with the traceway+# CLI, and a deterministic publish step opens a pull request or comments the+# analysis. See docs/pages/learn/auto-fix.mdx for the contract; other agents+# fit between the same two actions (autofix-prepare / autofix-publish) in a+# caller of their own.+#+# The agent step never holds a GitHub credential and only a read-only Traceway+# token; every write (push, PR, comment, archive) happens in the publish step+# from validated inputs. That split is the security model, not the agent's+# tool allowlist.+name: Traceway auto-fix++on:+ workflow_call:+ inputs:+ issue_number:+ description: Number of the issue the Traceway GitHub channel opened+ type: number+ required: true+ allowed_authors:+ description: Comma-separated GitHub logins allowed to trigger a run (the owner of the channel's token); every other issue author is refused+ type: string+ required: true+ project_id:+ description: Traceway project id the exception belongs to+ type: string+ required: true+ traceway_url:+ description: Traceway instance to query+ type: string+ default: https://cloud.tracewayapp.com+ traceway_ref:+ description: Ref of tracewayapp/traceway to take the prepare/publish actions and the traceway skill from+ type: string+ default: main+ model:+ description: Model passed to Claude Code+ type: string+ default: claude-opus-4-8+ effort:+ description: Effort level passed to Claude Code+ type: string+ default: xhigh+ max_turns:+ description: Turn budget for Claude Code+ type: number+ default: 60+ allowed_tools:+ description: Tool allowlist for Claude Code. The default permits traceway read subcommands, jq and the file tools, nothing that writes anywhere+ type: string+ default: "Bash(traceway exceptions list:*),Bash(traceway exceptions show:*),Bash(traceway exceptions occurrence:*),Bash(traceway logs query:*),Bash(traceway endpoints list:*),Bash(traceway endpoints show:*),Bash(traceway endpoints chart:*),Bash(traceway endpoints slow:*),Bash(traceway traces show:*),Bash(traceway sessions show:*),Bash(traceway tasks show:*),Bash(traceway ai-traces show:*),Bash(traceway metrics query:*),Bash(traceway projects list:*),Bash(jq:*),Read,Edit,Write,Glob,Grep,Skill"+ extra_allowed_tools:+ description: "Appended to allowed_tools, typically the test runner: Bash(go:*), Bash(npm test:*), ..."+ type: string+ default: ""+ go_version_file:+ description: Path of a go.mod; when set, a cached Go toolchain is installed before the agent runs+ type: string+ default: ""+ setup_command:+ description: Shell run before the agent for any other toolchain the tests need+ type: string+ default: ""+ archive_on_open:+ description: Archive the exception in Traceway when the pull request opens (needs TRACEWAY_PUBLISH_TOKEN)+ type: boolean+ default: true+ timeout_minutes:+ description: Job timeout+ type: number+ default: 30+ secrets:+ TRACEWAY_TOKEN:+ description: Read-only Traceway personal access token for the agent step (a bot user with org role readonly)+ required: true+ TRACEWAY_PUBLISH_TOKEN:+ description: Traceway personal access token with write access to the project, used only by the publish step to archive the exception. Leave unset to never archive+ required: false+ GH_PUSH_TOKEN:+ description: GitHub token that pushes the fix branch, opens the pull request and comments on the issue+ required: true+ ANTHROPIC_API_KEY:+ required: true++jobs:+ fix:+ runs-on: ubuntu-latest+ timeout-minutes: ${{ inputs.timeout_minutes }}+ concurrency:+ group: traceway-fix-${{ inputs.issue_number }}+ permissions:+ contents: write+ pull-requests: write+ issues: write+ id-token: write+ steps:+ - uses: actions/checkout@v7+ with:+ persist-credentials: false++ # A local `uses: ./...` resolves against the caller's checkout, so the+ # actions and the skill are fetched into a git-excluded subdirectory+ # for callers outside this repository.+ - name: Fetch the Traceway auto-fix actions+ uses: actions/checkout@v7+ with:+ repository: tracewayapp/traceway+ ref: ${{ inputs.traceway_ref }}+ path: .traceway+ sparse-checkout: |+ .github/actions+ skills/traceway+ persist-credentials: false+ - run: echo '/.traceway/' >> .git/info/exclude++ - name: Validate credentials+ env:+ GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}+ run: |+ echo "GH_PUSH_TOKEN authenticates as: $(gh api user --jq .login)"+ gh auth setup-git+ git push --dry-run origin "HEAD:refs/heads/tw-preflight-$GITHUB_RUN_ID"+ curl -sf https://api.anthropic.com/v1/models \+ -H "x-api-key: $ANTHROPIC_API_KEY" \+ -H "anthropic-version: 2023-06-01" -o /dev/null \+ || { echo "ANTHROPIC_API_KEY was rejected"; exit 1; }++ - name: Prepare+ id: prepare+ uses: ./.traceway/.github/actions/autofix-prepare+ with:+ issue_number: ${{ inputs.issue_number }}+ allowed_authors: ${{ inputs.allowed_authors }}+ traceway_url: ${{ inputs.traceway_url }}+ traceway_token: ${{ secrets.TRACEWAY_TOKEN }}+ project_id: ${{ inputs.project_id }}++ - name: Set up Go+ if: steps.prepare.outputs.proceed == 'true' && inputs.go_version_file != ''+ uses: actions/setup-go@v7+ with:+ go-version-file: ${{ inputs.go_version_file }}+ cache-dependency-path: "**/go.sum"++ - name: Set up the toolchain+ if: steps.prepare.outputs.proceed == 'true' && inputs.setup_command != ''+ run: ${{ inputs.setup_command }}++ - name: Investigate and fix+ if: steps.prepare.outputs.proceed == 'true'+ uses: anthropics/claude-code-action@v1+ with:+ anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}+ plugin_marketplaces: |+ https://github.com/tracewayapp/traceway.git+ plugins: |+ tw@traceway+ claude_args: |+ --model ${{ inputs.model }}+ --effort ${{ inputs.effort }}+ --allowedTools "${{ inputs.allowed_tools }}${{ inputs.extra_allowed_tools && format(',{0}', inputs.extra_allowed_tools) || '' }}"+ --max-turns ${{ inputs.max_turns }}+ prompt: ${{ steps.prepare.outputs.prompt }}++ - name: Save diff and report as artifact+ if: always() && steps.prepare.outputs.proceed == 'true'+ run: |+ mkdir -p "$RUNNER_TEMP/artifact"+ cp "${{ steps.prepare.outputs.report_file }}" "$RUNNER_TEMP/artifact/" 2>/dev/null || true+ git add --intent-to-add --all+ git diff > "$RUNNER_TEMP/artifact/fix.patch" || true+ git reset -q+ git status --porcelain > "$RUNNER_TEMP/artifact/changed-files.txt" || true++ - uses: actions/upload-artifact@v7+ if: always() && steps.prepare.outputs.proceed == 'true'+ with:+ name: traceway-fix-issue-${{ inputs.issue_number }}+ path: ${{ runner.temp }}/artifact+ if-no-files-found: ignore++ - name: Publish+ if: steps.prepare.outputs.proceed == 'true'+ uses: ./.traceway/.github/actions/autofix-publish+ with:+ issue_number: ${{ inputs.issue_number }}+ hash: ${{ steps.prepare.outputs.hash }}+ github_token: ${{ secrets.GH_PUSH_TOKEN }}+ report_file: ${{ steps.prepare.outputs.report_file }}+ traceway_url: ${{ inputs.traceway_url }}+ traceway_token: ${{ secrets.TRACEWAY_PUBLISH_TOKEN }}+ project_id: ${{ inputs.project_id }}+ archive_on_open: ${{ inputs.archive_on_open }}diff --git a/.github/workflows/traceway-autofix.yml b/.github/workflows/traceway-autofix.ymlindex e33cc05d..775d439a 100644--- a/.github/workflows/traceway-autofix.yml+++ b/.github/workflows/traceway-autofix.yml@@ -1,174 +1,35 @@+# In-repo caller of the reusable auto-fix loop (.github/workflows/autofix.yml).+# The label gate lives here; the author gate is enforced inside the loop by+# allowed_authors. workflow_dispatch runs the loop against an existing issue+# from any branch, which is the only pre-merge validation path for the+# claude-code-action pin; it runs the agent for real, so point it at a scratch+# issue.name: Traceway auto-fixon:issues:types: [labeled]+ workflow_dispatch:+ inputs:+ issue_number:+ description: Issue opened by the Traceway GitHub channel+ type: number+ required: truejobs:fix:- if: github.event.label.name == 'traceway' && github.event.issue.user.login == 'dusanstanojeviccs'- runs-on: ubuntu-latest- timeout-minutes: 30- concurrency:- group: traceway-fix-${{ github.event.issue.number }}+ if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'traceway'+ uses: ./.github/workflows/autofix.ymlpermissions:contents: writepull-requests: writeissues: writeid-token: write- steps:- - uses: actions/checkout@v7- with:- fetch-depth: 0- persist-credentials: false-- - name: Validate credentials- env:- GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}- run: |- echo "GH_PUSH_TOKEN authenticates as: $(gh api user --jq .login)"- gh auth setup-git- git push --dry-run origin "HEAD:refs/heads/tw-preflight-$GITHUB_RUN_ID"- curl -sf https://api.anthropic.com/v1/models \- -H "x-api-key: ${{ secrets.ANTHROPIC_API_KEY }}" \- -H "anthropic-version: 2023-06-01" -o /dev/null \- || { echo "ANTHROPIC_API_KEY was rejected"; exit 1; }-- - uses: actions/setup-go@v7- with:- go-version-file: backend/go.mod- cache-dependency-path: backend/go.sum-- - name: Install the Traceway CLI- run: curl -fsSL https://cli.tracewayapp.com/install.sh | sh-- - name: Log in to Traceway- run: |- printf '%s' "${{ secrets.TRACEWAY_TOKEN }}" | \- traceway login --url "https://cloud.tracewayapp.com" --token-stdin- traceway projects use "${{ vars.TRACEWAY_PROJECT_ID }}"-- - name: Investigate and fix- uses: anthropics/claude-code-action@v1- with:- anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}- plugin_marketplaces: |- https://github.com/tracewayapp/traceway.git- plugins: |- tw@traceway- claude_args: |- --model claude-opus-4-8- --effort xhigh- --allowedTools "Bash(traceway:*),Bash(jq:*),Bash(go:*),Read,Edit,Write,Glob,Grep"- --max-turns 60- prompt: |- Traceway detected a production error and opened issue- #${{ github.event.issue.number }} in this repository. The full- notification is between the markers below.-- --- TRACEWAY NOTIFICATION ---- ${{ github.event.issue.title }}-- ${{ github.event.issue.body }}- --- END NOTIFICATION ----- Investigate this with the traceway skill from the tw plugin:- invoke the skill and follow its Debug flow, treating the- notification above as the issue reference. The skill knows how to- extract the Hash, Exception ID, and Occurred-at timestamp from a- Traceway notification, resolve the "View details" URL, and drill- from the occurrence into traces, sessions, and logs. The traceway- CLI is already installed and authenticated against the correct- project; never run `traceway login`.-- You have NO access to git or gh, and you must not attempt to- commit, push, or call any network tool. A later workflow step- handles all of that. Your job is only to investigate, edit files- in the working tree if a fix is warranted, and write a report.-- If the investigation ties the root cause to code in this- repository, fix the cause, not the symptom. Keep the diff- minimal. Run the relevant Go tests for the packages you touch.- If you cannot tie the root cause to code with confidence, do NOT- guess a fix; leave the working tree untouched.-- Do not add code comments explaining your change, why it is- correct, or what the error was. The diff must read like the- surrounding code, following the repository's CLAUDE.md style- rules. ALL explanation belongs in the report file, none of it in- the code.-- When you are done, write your report to the file- "$RUNNER_TEMP/fix-report.md" in exactly this format:-- Line 1: "STATUS: fixed" if you applied a fix, "STATUS: analysis"- if you investigated but did not change code, or "STATUS: no-hash"- if the notification contained no Hash (for example a channel test- notification).- Line 2: "HASH: <the exception hash>" or "HASH: none".- Line 3 onward: your root cause analysis in markdown. If STATUS is- fixed, explain the root cause, the fix, and how you verified it,- and include the "View details" link from the notification. This- text becomes the pull request description or the issue comment,- so write it for a human reviewer.-- The report file is mandatory. Write it even when you change- nothing.-- Never create helper scripts, notes, or any other scratch files- inside the repository working tree; everything that ships in the- working tree becomes part of the pull request. Use $RUNNER_TEMP- for anything temporary.-- - name: Save diff and report as artifact- if: always()- run: |- mkdir -p "$RUNNER_TEMP/artifact"- cp "$RUNNER_TEMP/fix-report.md" "$RUNNER_TEMP/artifact/" 2>/dev/null || true- git add -A- git diff HEAD > "$RUNNER_TEMP/artifact/fix.patch" || true- git status --porcelain > "$RUNNER_TEMP/artifact/changed-files.txt" || true-- - uses: actions/upload-artifact@v7- if: always()- with:- name: traceway-fix-issue-${{ github.event.issue.number }}- path: ${{ runner.temp }}/artifact- if-no-files-found: ignore-- - name: Publish result- env:- GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}- ISSUE: ${{ github.event.issue.number }}- run: |- REPORT="$RUNNER_TEMP/fix-report.md"- if [ ! -f "$REPORT" ]; then- gh issue comment "$ISSUE" --body "The auto-fix agent finished without producing a report. Check the workflow run log."- exit 1- fi-- STATUS=$(sed -n '1s/^STATUS: *//p' "$REPORT")- HASH=$(sed -n '2s/^HASH: *//p' "$REPORT")- BODY=$(tail -n +3 "$REPORT")-- if [ "$STATUS" = "fixed" ] && ! echo "$HASH" | grep -Eq '^[0-9a-f]{16}$'; then- gh issue comment "$ISSUE" --body "The agent reported a fix but an invalid hash ('$HASH'); not opening a PR. Check the run log."- exit 1- fi-- if [ "$STATUS" = "fixed" ] && [ -n "$(git status --porcelain)" ]; then- git config user.name "github-actions[bot]"- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"- gh auth setup-git- BRANCH="traceway/fix-$HASH"- git checkout -b "$BRANCH"- git add -A- git commit -m "Fix production error $HASH"- git push -u origin "$BRANCH"- { echo "Fixes #$ISSUE"; echo; echo "$BODY"; } | \- gh pr create --title "Auto-fix: traceway $HASH (issue #$ISSUE)" --head "$BRANCH" --body-file -- traceway exceptions archive "$HASH" --yes- else- { echo "Auto-fix agent report (no PR opened):"; echo; echo "$BODY"; } | \- gh issue comment "$ISSUE" --body-file -- fi+ with:+ issue_number: ${{ github.event.issue.number || inputs.issue_number }}+ allowed_authors: dusanstanojeviccs+ project_id: ${{ vars.TRACEWAY_PROJECT_ID }}+ traceway_ref: ${{ github.ref_name }}+ go_version_file: backend/go.mod+ extra_allowed_tools: "Bash(go:*)"+ secrets: inheritdiff --git a/CLAUDE.md b/CLAUDE.mdindex 180b37c4..7d2ae351 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -43,7 +43,7 @@ Set `JWT_SECRET` (min 32 characters) before running the backend — it is the onCI on pull requests is opt-in. `backend.yml`, `backend-vulncheck.yml`, `cli.yml`, `cli-lint.yml`, `cli-contract.yml` and `frontend.yml` listen for `pull_request: types: [labeled]` and every job is gated on `github.event.label.name == 'ci'`, so a PR runs nothing until a maintainer applies the `ci` label (only collaborators can), and applying any other label runs nothing either. Each application validates the PR as it is at that moment: to validate later pushes, remove and re-add the label. The same workflows still run on pushes to `main` that touch their paths (`backend/**`, `cli/**`, `frontend/**`, `skills/traceway/**` for `cli.yml`, `.nvmrc` for `frontend.yml`, their own workflow file), on their daily schedules (the two vulnchecks), and from the Actions tab via `workflow_dispatch`.-Action versions are watched by `.github/dependabot.yml` (the `github-actions` ecosystem only; npm and Go modules are deliberately not watched there). It opens a weekly PR per group — `actions/*` in one, every third-party action in the other — and deliberately does **not** auto-apply `ci`, so a bot PR passes the same collaborator gate as any other. Label the first-party group to validate it; `golangci/golangci-lint-action` is reachable the same way via `cli-lint.yml`. The rest of the third-party group lands on `release-*.yml`, `benchmark-*.yml` and `traceway-autofix.yml`, which no label reaches — and `workflow_dispatch` is **not** a dry run on the release path: dispatching `release-docs.yml` or `release-website.yml` deploys to Cloudflare for real, and the other `release-*.yml` workflows publish real assets, so dispatching one from an unreviewed bot branch ships it. Validate those by reading the action's release notes instead, and dispatch only where the target is disposable. `traceway-autofix.yml` has no dispatch at all, so its `claude-code-action` pin — the most privileged action here — has no pre-merge validation path. Note too that labelling a PR which touches no gated workflow yields zero checks, which reads like a pass but is silence. Every updatable pin is a bare major tag, so Dependabot only ever proposes major bumps here.+Action versions are watched by `.github/dependabot.yml` (the `github-actions` ecosystem only; npm and Go modules are deliberately not watched there). It opens a weekly PR per group — `actions/*` in one, every third-party action in the other — and deliberately does **not** auto-apply `ci`, so a bot PR passes the same collaborator gate as any other. Label the first-party group to validate it; `golangci/golangci-lint-action` is reachable the same way via `cli-lint.yml`. The rest of the third-party group lands on `release-*.yml`, `benchmark-*.yml` and `traceway-autofix.yml`, which no label reaches — and `workflow_dispatch` is **not** a dry run on the release path: dispatching `release-docs.yml` or `release-website.yml` deploys to Cloudflare for real, and the other `release-*.yml` workflows publish real assets, so dispatching one from an unreviewed bot branch ships it. Validate those by reading the action's release notes instead, and dispatch only where the target is disposable. `traceway-autofix.yml` is the in-repo caller of the reusable `autofix.yml` (composite actions `.github/actions/autofix-prepare` and `autofix-publish` around the agent step; `docs/pages/learn/auto-fix.mdx` documents the contract); its `workflow_dispatch` takes an `issue_number` and runs the whole loop from the dispatched branch, which is the one pre-merge validation path for the `claude-code-action` pin — the most privileged action here — but it runs the agent for real, so dispatch it only at a scratch issue. Note too that labelling a PR which touches no gated workflow yields zero checks, which reads like a pass but is silence. Every updatable pin is a bare major tag, so Dependabot only ever proposes major bumps here.### Tech Stack- **Frontend**: SvelteKit 2.49, Svelte 5.45, Tailwind CSS v4, shadcn-svelte, Vite 7diff --git a/docs/pages/learn/_meta.json b/docs/pages/learn/_meta.jsonindex 0ca55353..6dbd5966 100644--- a/docs/pages/learn/_meta.json+++ b/docs/pages/learn/_meta.json@@ -17,6 +17,7 @@"dashboards": "Dashboards","logs": "Logs","alerts": "Alerts",+ "auto-fix": "Auto-Fix","on-call": "On-Call","monitors": "Monitors","incidents": "Incidents & Post-Mortems",diff --git a/docs/pages/learn/alerts.mdx b/docs/pages/learn/alerts.mdxindex c37ae5c5..7ecb4345 100644--- a/docs/pages/learn/alerts.mdx+++ b/docs/pages/learn/alerts.mdx@@ -76,6 +76,8 @@ Then configure the GitHub channel in Traceway:<img src="/channel-github.png" alt="GitHub channel configuration dialog" style={{ maxWidth: '100%', height: 'auto', marginTop: '16px', borderRadius: '8px', border: '1px solid #e5e7eb' }} />+Issues opened by this channel can start an AI coding agent in the repository's own GitHub Actions, which investigates the exception with the traceway CLI and opens a pull request or comments its analysis. See [Auto-Fix](/learn/auto-fix).+### Setting Up TelegramTo send alerts to Telegram, you need a **Bot Token** and a **Chat ID**:diff --git a/docs/pages/learn/auto-fix.mdx b/docs/pages/learn/auto-fix.mdxnew file mode 100644index 00000000..4a04a099--- /dev/null+++ b/docs/pages/learn/auto-fix.mdx@@ -0,0 +1,144 @@+# Auto-Fix++import { Callout } from "nextra/components";++Auto-fix closes the loop between an alert and a pull request. A [GitHub channel](/learn/alerts#setting-up-github) opens an issue for a new error, a coding agent running in the repository's own GitHub Actions investigates it with the [traceway CLI](/learn/cli), and a deterministic publish step turns the result into a pull request or an analysis comment. Traceway never runs a model itself: the agent, its vendor and its key live in your CI, and every self-hosted instance works without any LLM configuration.++This page is the productized form of the loop described in [the auto-fix blog post](https://tracewayapp.com/blog/auto-fix-loop).++## The contract++The loop is three steps, and only the middle one is agent-specific:++| Step | Runs as | What it does | Credentials |+|------|---------|--------------|-------------|+| **Prepare** | `tracewayapp/traceway/.github/actions/autofix-prepare` | Refuses issues from anyone but the channel's token owner, extracts the `Hash`, `Exception ID` and `Occurred at` fields from the issue body with strict regexes, copies the [traceway skill](https://github.com/tracewayapp/traceway/tree/main/skills/traceway) outside the working tree, installs and logs in the CLI, and writes the prompt from the validated fields only. Outputs `proceed`, `hash`, `prompt`, `prompt_file`, `skills_dir`, `report_file` | Read-only Traceway token |+| **Agent** | Your choice | Reads the prompt (and `SKILL.md`), investigates with `traceway` read commands, edits the working tree if a fix is warranted, and writes the report file | The same read-only token, no GitHub credential |+| **Publish** | `tracewayapp/traceway/.github/actions/autofix-publish` | Validates the report against the tree (see [What the publish step refuses](#what-the-publish-step-refuses)), then opens the PR (`traceway/fix-<hash>-<run>`, body `Fixes #N` + the report) or comments the analysis, and archives the exception | GitHub write token, Traceway write token |++The report file is the whole interface between the agent and the publish step:++```+STATUS: fixed # or: analysis+HASH: <16 hex characters>+<markdown: root cause, the fix, how it was verified, the View details link>+```++The security model is the split, not the agent's tool allowlist: the agent step holds no GitHub credential and only a read-only Traceway token, every write happens in the publish step, and the prompt is assembled from regex-validated fields, never from the issue body (which quotes the exception message and is therefore attacker-influenced). That holds for any agent you wire in, including ones whose sandboxing Traceway cannot configure.++## Quick start with the reusable workflow++The reusable workflow composes the three steps, with Claude Code as the tested agent.++1. **Create two Traceway bot users** (or one; see [Credentials](#credentials)) and mint a [personal access token](/learn/cli-auth#personal-access-tokens) for each.+2. **Add repository secrets**: `TRACEWAY_TOKEN` (read-only), `TRACEWAY_PUBLISH_TOKEN` (write, optional: without it the exception is never archived), `GH_PUSH_TOKEN` (a GitHub token that can push branches, open pull requests and comment; the built-in `github.token` cannot open a pull request that triggers other workflows), and `ANTHROPIC_API_KEY`.+3. **Add a repository variable** `TRACEWAY_PROJECT_ID` with the project's id (`traceway projects list`).+4. **Point the GitHub channel at the repository** with a label such as `traceway`, and create the caller workflow:++```yaml+# .github/workflows/traceway-autofix.yml+name: Traceway auto-fix+on:+ issues:+ types: [labeled]+ workflow_dispatch:+ inputs:+ issue_number: { type: number, required: true }+jobs:+ fix:+ if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'traceway'+ uses: tracewayapp/traceway/.github/workflows/autofix.yml@main+ permissions:+ contents: write+ pull-requests: write+ issues: write+ id-token: write+ with:+ issue_number: ${{ github.event.issue.number || inputs.issue_number }}+ allowed_authors: the-github-login-that-owns-the-channel-token+ project_id: ${{ vars.TRACEWAY_PROJECT_ID }}+ # traceway_url: https://traceway.example.com # self-hosted+ secrets: inherit+```++`issues: [labeled]` fires for labels applied at creation, so an issue the channel opens with the label starts the run immediately. Only collaborators can apply labels, and the prepare step additionally refuses any issue whose author is not in `allowed_authors`, so a stranger cannot start a run by filing an issue.++Inputs worth knowing: `model`, `effort`, `max_turns` and `allowed_tools` are passed to Claude Code (the default allowlist permits only `traceway` read subcommands, `jq` and the file tools); `extra_allowed_tools` appends your test runner, `Bash(go:*)` for a Go repository; `go_version_file` installs a cached Go toolchain before the agent runs, and `setup_command` covers any other toolchain; `archive_on_open: false` keeps the exception open until you resolve it yourself; `traceway_ref` selects which branch of `tracewayapp/traceway` supplies the actions and the skill.++### Validate a change before it lands++`workflow_dispatch` runs the loop against an existing issue from whichever branch you dispatch. It runs the agent for real and publishes for real. To check the wiring first, send a test notification from the channel dialog and dispatch against the issue it opens: the notification carries no hash, so the prepare step refuses it with a warning after the credential preflight has validated `GH_PUSH_TOKEN` and `ANTHROPIC_API_KEY`, and no model call is spent. The Traceway tokens are only exercised by a run that gets past the gate, so point it at a real issue for that.++## Bring your own agent++Any agent that can read a file, run `traceway`, edit files and write a file fits between the two actions. A caller using them directly:++```yaml+jobs:+ fix:+ runs-on: ubuntu-latest+ permissions:+ contents: write+ pull-requests: write+ issues: write+ steps:+ - uses: actions/checkout@v7+ with:+ persist-credentials: false+ - id: prepare+ uses: tracewayapp/traceway/.github/actions/autofix-prepare@main+ with:+ issue_number: ${{ github.event.issue.number }}+ allowed_authors: the-github-login-that-owns-the-channel-token+ traceway_token: ${{ secrets.TRACEWAY_TOKEN }}+ project_id: ${{ vars.TRACEWAY_PROJECT_ID }}+ - if: steps.prepare.outputs.proceed == 'true'+ # Your agent step. Give it steps.prepare.outputs.prompt (or+ # prompt_file), the working tree and the traceway CLI. Do not give it a+ # GitHub token or any Traceway token but the read-only one it already+ # has through the CLI session.+ run: your-agent --prompt-file "${{ steps.prepare.outputs.prompt_file }}"+ - if: steps.prepare.outputs.proceed == 'true'+ uses: tracewayapp/traceway/.github/actions/autofix-publish@main+ with:+ issue_number: ${{ github.event.issue.number }}+ hash: ${{ steps.prepare.outputs.hash }}+ github_token: ${{ secrets.GH_PUSH_TOKEN }}+ report_file: ${{ steps.prepare.outputs.report_file }}+ traceway_token: ${{ secrets.TRACEWAY_PUBLISH_TOKEN }}+ project_id: ${{ vars.TRACEWAY_PROJECT_ID }}+```++The prompt's first instruction is to read `<skills_dir>/traceway/SKILL.md`, so agents without a skills mechanism still get the debug flow. Agents that prefer MCP can run `traceway mcp` headlessly with `TRACEWAY_URL`, `TRACEWAY_TOKEN` and `TRACEWAY_PROJECT` (see [MCP Server](/learn/mcp)); the same knowledge is exposed as resources there. Whatever the agent's own sandbox offers, keep the split described under [The contract](#the-contract). The publish step judges the run by `git status`, so anything else you check out into the working tree (a tools repository, a cache) has to go into `.git/info/exclude` first, as the reusable workflow does for its own copy of the actions.++<Callout type="info">+ Claude Code is the agent the reusable workflow has been run with. Other agents fit the contract but have not been exercised end to end yet; run one on a fork before relying on it.+</Callout>++## Credentials++The agent step should not be able to change anything in Traceway, and the publish step needs to archive one exception. The least-privilege recipe is two bot users in the organization:++| Secret | User | Role | Used by |+|--------|------|------|---------|+| `TRACEWAY_TOKEN` | `autofix-reader` | Organization role `readonly` | Prepare (login) and the agent step |+| `TRACEWAY_PUBLISH_TOKEN` | `autofix-publisher` | Organization role `readonly` with a per-project override to `user` on the target project ([Settings → Team Members](/learn/projects)) | Publish, to archive the exception |++One token for both works and is documented as weaker: the agent step could then archive exceptions, whatever its tool allowlist says. Neither token needs to be an admin, and neither user needs a password login.++`GH_PUSH_TOKEN` is a fine-grained GitHub token for the repository with **Contents**, **Pull requests** and **Issues** set to read and write. The prepare step reads the issue with the workflow's own `github.token`.++## What the publish step refuses++Each refusal comments the reason on the issue and fails the run, and the run's artifact keeps the diff and the report:++- No report file, or a `STATUS` other than `fixed` / `analysis`.+- A `HASH` line that differs from the hash the prepare step validated.+- `STATUS: fixed` with an unchanged working tree, or any other status with a changed one.+- A new file whose name matches `scratch_patterns` (`.tw_*`, `*.sh`, `*.patch`, `*.log`, `*.tmp`, `fix-report*` by default), including files inside a newly added directory.++## Caveats++- The exception is archived when the pull request **opens**, not when it merges. Set `archive_on_open: false` if a closed-unmerged PR would otherwise hide a live error; archiving on merge is planned.+- Two runs on the same input can differ. The workflow serializes runs per issue (`concurrency`), but does not yet dedup across issues for the same hash.+- The agent is told to follow the repository's contribution rules, but that is a prompt-level instruction; review the diff as you would any contributor's.