Skip to content

chore: hoist regexp.MustCompile calls to package-level vars across pkg/cli and pkg/workflow#20073

Merged
pelikhan merged 2 commits intomainfrom
copilot/hoist-regexp-compile-variables
Mar 8, 2026
Merged

chore: hoist regexp.MustCompile calls to package-level vars across pkg/cli and pkg/workflow#20073
pelikhan merged 2 commits intomainfrom
copilot/hoist-regexp-compile-variables

Conversation

Copy link
Contributor

Copilot AI commented Mar 8, 2026

Constant regex patterns compiled inside function bodies incur allocation overhead on every call. The worst offenders (extractToolName: 4 regexes × N log lines; hasAgentLogPatterns: 5 regexes per detection attempt) are hot paths.

Changes

  • pkg/cli/copilot_agent_logs.go — hoisted agentTurnPattern, agentToolCallPattern, and toolNamePatterns (slice of 4) out of ParseCopilotCodingAgentLogMetrics and extractToolName
  • pkg/cli/copilot_agent.go — hoisted agentLogPatterns (slice of 5) out of hasAgentLogPatterns
  • pkg/workflow/concurrency_validation.go — hoisted concurrencyExpressionPattern and concurrencyGroupPattern out of validateExpressionSyntax and extractConcurrencyGroupFromYAML
  • pkg/workflow/lock_schema.go — hoisted lockMetadataPattern and lockHashPattern out of ExtractMetadataFromLockFile
  • pkg/workflow/action_sha_checker.go — hoisted actionUsesPattern out of ExtractActionsFromLockFile
  • pkg/workflow/redact_secrets.go — hoisted secretReferencePattern out of CollectSecretReferences
  • pkg/workflow/secrets_validation.go — hoisted secretNamePattern out of validateSecretReferences

Dynamic patterns in template_injection_validation.go (string interpolation) are intentionally left unchanged.

// Before — compiled on every call
func extractToolName(line string) string {
    patterns := []*regexp.Regexp{
        regexp.MustCompile(`(?i)tool[:\s]+([a-zA-Z0-9_-]+)`),
        // ...
    }
}

// After — compiled once at init
var toolNamePatterns = []*regexp.Regexp{
    regexp.MustCompile(`(?i)tool[:\s]+([a-zA-Z0-9_-]+)`),
    // ...
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE x_amd64/vet git rev-�� --show-toplevel x_amd64/vet /usr/bin/git -json GO111MODULE 64/bin/go git (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw git /usr/bin/git git rev-�� --show-toplevel git /usr/bin/git ithub/workflows git /usr/bin/git git (http block)
  • https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha --show-toplevel _9a60CKVjggF /usr/bin/git e=false GO111MODULE 64/bin/go git rev-�� --show-toplevel resolved$ /usr/bin/git -json GO111MODULE 64/bin/go git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha --show-toplevel git /usr/bin/git pace:]]*:[[:spacgit /opt/hostedtoolcrev-parse /home/REDACTED/wor--show-toplevel git rev-�� --show-toplevel node /usr/bin/git 2524233410/.githgit --package-lock-orev-parse /usr/bin/git git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v3
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha ithub-script/git/ref/tags/v8 GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE 9624630/b385/importcfg env 9624630/b385/embedcfg GO111MODULE ache/node/24.14.0/x64/bin/node GOINSECURE GOMOD GOMODCACHE /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha /tmp/file-tracker-test2670016192/test1.md /tmp/file-tracker-test2670016192/test2.lock.yml /usr/bin/git --show-toplevel om/owner/repo.girev-parse lone-3272584664 git conf�� runs/20260308-153301-35837/test-55031174/.github/workflows test@example.com /usr/bin/git l ache/go/1.25.0/xrev-parse /usr/bin/git git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v5
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel -dwarf=false /opt/hostedtoolcache/node/24.14.0/x64/bin/node go1.25.0 -c=4 -nolocalimports node /tmp�� /home/REDACTED/work/gh-aw/gh-aw/.github/workflows/ace-editor.md /tmp/go-build2889624630/b428/_testmain.go /opt/hostedtoolcache/node/24.14.0/x64/bin/node "prettier" --chegit node 64/bin/go /opt/hostedtoolcache/node/24.14.0/x64/bin/node (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE 64/bin/go git rev-�� --show-toplevel go /usr/bin/git 99/001/test-frongit GO111MODULE ache/go/1.25.0/x--show-toplevel git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v6
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha k/gh-aw/gh-aw/pkg/stringutil/ansi.go k/gh-aw/gh-aw/pkg/stringutil/identifiers.go /opt/hostedtoolcache/node/24.14.0/x64/bin/node heck '**/*.cjs' git GO111MODULE 64/bin/go node /tmp�� /tmp/TestHashConsistency_GoAndJavaScript3170144199/001/test-empty-frontmatter.md l ache/node/24.14.0/x64/bin/node -json GO111MODULE 64/bin/go ache/node/24.14.0/x64/bin/node (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --git-dir -tests /usr/local/bin/iptables -json GO111MODULE 64/bin/go iptables -w -t security /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/compile OUTPUT -d 168.63.129.16 /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE 64/bin/go git rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE 64/pkg/tool/linu--show-toplevel git (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v8
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE ortcfg env g/sliceutil/slicGOINSECURE g/sliceutil/slicGOMOD 64/bin/go GOINSECURE GOMOD GOMODCACHE ache/go/1.25.0/xGO111MODULE (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -c=4 -nolocalimports -importcfg /tmp/go-build2889624630/b385/importcfg -embedcfg /tmp/go-build2889624630/b385/embedcfg -pack env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -c=4 -nolocalimports -importcfg /tmp/go-build2889624630/b394/importcfg -pack /home/REDACTED/work/gh-aw/gh-aw/pkg/envutil/envutil.go /home/REDACTED/work/gh-aw/gh-aw/pkg/envutil/envutil_test.go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
  • https://api.github.com/repos/actions/setup-go/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha /tmp/gh-aw-test-runs/20260308-152807-30196/test-2409684731/.github/workflows config 9624630/b427/vet.cfg remote.origin.urgit GO111MODULE 64/bin/go iptables -w -t security /usr/bin/gh OUTPUT -d 168.63.129.16 gh (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha REDACTED git /usr/bin/git (http block)
  • https://api.github.com/repos/actions/setup-node/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha sistency_KeyOrdering1826389142/001/test1.md go /usr/local/sbin/iptables heck '**/*.cjs' git GO111MODULE 64/bin/go iptables -w -t security /tmp/go-build2889624630/b424/testutil.test OUTPUT -d 168.63.129.16 /tmp/go-build2889624630/b424/testutil.test (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha 70 --log-level /usr/bin/git --log-target journal-or-kmsg /usr/bin/git git rev-�� --show-toplevel git e/git ster.patch 64/pkg/tool/linurev-parse /usr/bin/git e/git (http block)
  • https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha auto-triage-issues.md GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env 2807-30196/test-1414816036 GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha --show-toplevel (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/1/artifacts
    • Triggering command: /usr/bin/gh gh run download 1 --dir test-logs/run-1 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 1 --dir test-logs/run-1 o "��� Warning: .github/aw/actions-lock.json does not exist yet"; \ fi e/git -json GO111MODULE /opt/hostedtoolc--show-toplevel e/git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet /usr/bin/git -bool -buildtags /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run download 1 --dir test-logs/run-1 git ndor/bin/bash --show-toplevel go /usr/bin/git git rev-�� --show-toplevel git /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet --show-toplevel go /usr/bin/git /opt/hostedtoolcache/go/1.25.0/xInitial commit (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12345/artifacts
    • Triggering command: /usr/bin/gh gh run download 12345 --dir test-logs/run-12345 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE dx8vjli/h6bNdPCflz1EHL_uQAkD estl�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 12345 --dir test-logs/run-12345 9624630/b372/importcfg /usr/bin/git sistency_GoAndJagit GO111MODULE /opt/hostedtoolc/tmp/gh-aw-test-runs/20260308-152955-34719/test-1693974802 git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet /usr/bin/git -bool -buildtags /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run download 12345 --dir test-logs/run-12345 git /usr/bin/git --show-toplevel lYcIpM0DEuKD /usr/bin/git git rev-�� --show-toplevel t /usr/bin/git --show-toplevel go /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12346/artifacts
    • Triggering command: /usr/bin/gh gh run download 12346 --dir test-logs/run-12346 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go estl�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 12346 --dir test-logs/run-12346 ache/go/1.25.0/x64/pkg/tool/linux_amd64/compile /usr/bin/git 9624630/b422/_pkgit GO111MODULE 9624630/b422=> git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh run download 12346 --dir test-logs/run-12346 git ps --show-toplevel x_amd64/link /usr/bin/git ps rev-�� t git (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/2/artifacts
    • Triggering command: /usr/bin/gh gh run download 2 --dir test-logs/run-2 GO111MODULE x_amd64/link GOINSECURE GOMOD GOMODCACHE x_amd64/link env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE gQ/wQtfmYPJyckR0gnX0JTX/_8DtxLzCsecurity (http block)
    • Triggering command: /usr/bin/gh gh run download 2 --dir test-logs/run-2 9624630/b391/importcfg e/git k/gh-aw/gh-aw/pkgit k/gh-aw/gh-aw/pkcheckout /opt/hostedtoolc.github/workflows/test.md e/git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet /usr/bin/git -bool -buildtags /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run download 2 --dir test-logs/run-2 git /usr/bin/git --show-toplevel go /usr/bin/git git rev-�� --show-toplevel git 31916/b435/vet.cfg --show-toplevel go layTitle /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linuremote.origin.url (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/3/artifacts
    • Triggering command: /usr/bin/gh gh run download 3 --dir test-logs/run-3 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 3 --dir test-logs/run-3 go /usr/bin/git sistency_GoAndJagit GO111MODULE ache/go/1.25.0/x/tmp/gh-aw-test-runs/20260308-152955-34719/test-1693974802 git rev-�� --show-toplevel ache/go/1.25.0/x64/pkg/tool/linu./... /usr/bin/git se 9624630/b108/vetrev-parse /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run download 3 --dir test-logs/run-3 git 31916/b439/vet.cfg --show-toplevel go /usr/bin/git git rev-�� --show-toplevel git /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet --show-toplevel go /usr/bin/git /opt/hostedtoolcache/go/1.25.0/x--auto (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/4/artifacts
    • Triggering command: /usr/bin/gh gh run download 4 --dir test-logs/run-4 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 4 --dir test-logs/run-4 go /usr/bin/git ithub/workflows/git GO111MODULE /opt/hostedtoolc/tmp/gh-aw-test-runs/20260308-152955-34719/test-1693974802 git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet /usr/bin/git -bool -buildtags /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run download 4 --dir test-logs/run-4 git r,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,disp--show-toplevel --show-toplevel flow-12345 /usr/bin/git git rev-�� --show-toplevel (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/5/artifacts
    • Triggering command: /usr/bin/gh gh run download 5 --dir test-logs/run-5 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run download 5 --dir test-logs/run-5 go /usr/bin/git -json GO111MODULE /opt/hostedtoolcHEAD git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/compile x_amd64/vet /tmp/go-build288git -trimpath /usr/bin/git x_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh run download 5 --dir test-logs/run-5 git 31916/b432/vet.cfg --show-toplevel go /usr/bin/git git rev-�� --show-toplevel git /usr/bin/infocmp --show-toplevel go /usr/bin/git infocmp (http block)
  • https://api.github.com/repos/github/gh-aw/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 100 GOMOD erignore go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 6 GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env 2831220410/.github/workflows GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha --show-toplevel 0/x64/bin/node x_amd64/vet /tmp/go-build288git l /usr/bin/git x_amd64/vet rev-�� --show-toplevel git /usr/bin/git --show-toplevel -extld=gcc /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq .object.sha ck 'scripts/**/*GOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE sh (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE ache/go/1.25.0/x--show-toplevel git rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE Name,createdAt,s/tmp/gh-aw-test-runs/20260308-152955-34719/test-2931953492/.github/workflows git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq .object.sha --show-toplevel git /usr/bin/git GOMODCACHE ache/go/1.25.0/xrev-parse /usr/lib/git-cor--show-toplevel git rev-�� HEAD /usr/lib/git-core/git /usr/bin/git run --auto /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v2.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha ck 'scripts/**/*GOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE sh (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha ck 'scripts/**/*GOINSECURE GO111MODULE 9ec382778d959a84-d GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE sh (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE les.test git rev-�� --show-toplevel les.test /usr/bin/git lidations passedgit GO111MODULE /opt/hostedtoolc/tmp/gh-aw-test-runs/20260308-152955-34719/test-2931953492/.github/workflows git (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v3.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq .object.sha ck 'scripts/**/*GOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE sh (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq .object.sha --show-toplevel go /usr/bin/git -json GO111MODULE /opt/hostedtoolc--show-toplevel git rev-�� --show-toplevel go /usr/bin/git aw/actions-lock.git GO111MODULE /opt/hostedtoolc--show-toplevel git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq .object.sha --show-toplevel git /usr/bin/sed user.name Test User /usr/bin/git sed s|[/�� 64/bin/go git /usr/bin/git GOMODCACHE go /usr/bin/git git (http block)
  • https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env 1358215325/.github/workflows GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha --show-toplevel /tmp/go-build2889624630/b395/env-ifaceassert /usr/bin/git -test.paniconexigit (http block)
  • https://api.github.com/repos/nonexistent/repo/actions/runs/12345
    • Triggering command: /usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion -json GO111MODULE /usr/bin/git git rev-�� ster.patch git /usr/bin/git assword=$GITHUB_git assword=$GITHUB_rev-parse /usr/bin/git git (http block)
    • Triggering command: /usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion --show-toplevel go /usr/bin/git bash --no�� --noprofile git /usr/bin/git --show-toplevel 64/pkg/tool/linu-1 /usr/bin/git git (http block)
  • https://api.github.com/repos/owner/repo/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/bin/go GOINSECURE GOMOD GOMODCACHE go ache�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo /usr/bin/git 1414816036 GO111MODULE ache/go/1.25.0/x--show-toplevel git rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE .cfg git (http block)
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/bin/node g_.a GO111MODULE ache/go/1.25.0/x--show-toplevel git 0/x6�� --show-toplevel go /usr/bin/git rEXa8Ewqh GO111MODULE ache/go/1.25.0/x--show-toplevel git (http block)
  • https://api.github.com/repos/owner/repo/contents/file.md
    • Triggering command: /tmp/go-build2889624630/b383/cli.test /tmp/go-build2889624630/b383/cli.test -test.testlogfile=/tmp/go-build2889624630/b383/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true GOINSECURE GOMOD GOMODCACHE ortcfg env ternal/tools/actGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE ache/go/1.25.0/xGO111MODULE (http block)
    • Triggering command: /tmp/go-build29531916/b383/cli.test /tmp/go-build29531916/b383/cli.test -test.testlogfile=/tmp/go-build29531916/b383/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true g_.a GO111MODULE ache/go/1.25.0/x--show-toplevel git rev-�� --show-toplevel go /usr/bin/git sn0JBHv-D GO111MODULE ache/go/1.25.0/x--show-toplevel git (http block)
    • Triggering command: /tmp/go-build1796110291/b001/cli.test /tmp/go-build1796110291/b001/cli.test -test.testlogfile=/tmp/go-build1796110291/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE clusion,workflow--show-toplevel git rev-�� --show-toplevel git /usr/bin/git s/test.md GOPROXY /usr/bin/git git (http block)
  • https://api.github.com/repos/test-owner/test-repo/actions/secrets
    • Triggering command: /usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name --show-toplevel 64/pkg/tool/linux_amd64/vet 0/x64/bin/npm -json GO111MODULE ache/go/1.25.0/x--show-toplevel 0/x64/bin/npm rev-�� --show-toplevel go /usr/bin/git 2807-30196/test-git GO111MODULE .cfg git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name --show-toplevel ache/go/1.25.0/x64/pkg/tool/linux_amd64/link x_amd64/vet 9624630/b428/timgit log 9624630/b428/imp--show-toplevel x_amd64/vet rev-�� --show-toplevel iiEtxJ64HjgrP/g5FpiJ9ENbZatjTay5oJ/BhqTCoRMGewfss9ZXZGY/X4XoDkfiiEtxJ64HjgrP /usr/bin/git ry=1 config 9624630/b428/_pk--show-toplevel git (http block)

If you need me to access, download, or install something from one of these locations, you can either:


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…vars

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor regex compilation to package-level variables chore: hoist regexp.MustCompile calls to package-level vars across pkg/cli and pkg/workflow Mar 8, 2026
@pelikhan pelikhan marked this pull request as ready for review March 8, 2026 15:38
Copilot AI review requested due to automatic review settings March 8, 2026 15:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces per-call allocations in several hot paths by hoisting regexp.MustCompile(...) invocations from function bodies to package-level variables in pkg/cli and pkg/workflow.

Changes:

  • Hoists frequently-used CLI log parsing regexes to package scope to avoid recompilation on each parsed line.
  • Hoists workflow validation/parsing regexes (concurrency, lock metadata/hash, actions usage, secret refs/names) to package scope.
  • Keeps dynamic/interpolated regex compilation unchanged where patterns aren’t constant.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/cli/copilot_agent_logs.go Hoists turn/tool-call/tool-name regexes used while parsing Copilot coding agent logs.
pkg/cli/copilot_agent.go Hoists agent detection regex slice used when scanning run logs for agent indicators.
pkg/workflow/concurrency_validation.go Hoists expression and group: extraction regexes used during concurrency validation.
pkg/workflow/lock_schema.go Hoists lock metadata/hash extraction regexes used in lock schema parsing.
pkg/workflow/action_sha_checker.go Hoists action uses extraction regex used when scanning lock files.
pkg/workflow/redact_secrets.go Hoists secret reference extraction regex used while scanning generated workflow YAML.
pkg/workflow/secrets_validation.go Hoists secret-name validation regex used during secret reference validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.


// Extract tool calls from agent logs
if matches := toolCallPattern.FindStringSubmatch(line); len(matches) > 1 {
if matches := agentToolCallPattern.FindStringSubmatch(line); len(matches) > 1 {
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

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

Tool-call detection is gated on FindStringSubmatch returning a capture group (len(matches) > 1), but agentToolCallPattern has alternations that don’t define any capturing group (e.g., tool.*call, executing.*tool). Lines matching those branches will never enter this block, so tool calls will be missed. Use agentToolCallPattern.MatchString(line) (or update the regex to always capture) since the tool name is extracted separately by extractToolName.

Suggested change
if matches := agentToolCallPattern.FindStringSubmatch(line); len(matches) > 1 {
if agentToolCallPattern.MatchString(line) {

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit c90d204 into main Mar 8, 2026
113 checks passed
@pelikhan pelikhan deleted the copilot/hoist-regexp-compile-variables branch March 8, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Hoist function-body regexp.MustCompile calls to package-level vars across pkg/cli and pkg/workflow

3 participants