Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

agent-context-budget.yml

56 lines2.5 KB

1name: Agent Context Budget
2​
3# Fails when a PR raises a value in agentContextBudget.json above main's. AgentContextBudget.test.ts
4# keeps that file equal to the measured context, so the context cannot grow by editing the file.
5# To accept growth on purpose, a maintainer adds the agent-context-increase label.
6on:
7 pull_request:
8 types: [opened, synchronize, reopened, labeled, unlabeled]
9​
10permissions:
11 contents: read
12​
13# No concurrency group: label events arrive in bursts, and a cancelled run reports as a failed check.
14jobs:
15 budget:
16 name: Agent context budget
17 runs-on: ubuntu-24.04
18 timeout-minutes: 5
19 env:
20 BUDGET: apps/server/src/provider/agentContextBudget.json
21 ALLOW_INCREASE: ${{ contains(github.event.pull_request.labels.*.name, 'agent-context-increase') }}
22 steps:
23 - name: Checkout
24 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
25 with:
26 sparse-checkout: apps/server/src/provider/agentContextBudget.json
27 sparse-checkout-cone-mode: false
28 fetch-depth: 2
29​
30 # The checkout is the PR merged onto main; compare with that merge's main parent. A fresh
31 # fetch of main can be newer and lower, which reports the PR as growing what main just cut.
32 - name: Compare with main
33 # HEAD is the PR merge commit; its first parent is the main it was built on. A freshly
34 # fetched main can hold lower values the PR never saw, which would read as growth.
35 run: |
36 if ! git cat-file -e "HEAD^1:$BUDGET" 2>/dev/null; then
37 echo "main has no agent context budget yet."
38 exit 0
39 fi
40 git show "HEAD^1:$BUDGET" > "$RUNNER_TEMP/main.json"
41 grown=$(jq -r --slurpfile main "$RUNNER_TEMP/main.json" '
42 to_entries[]
43 | select($main[0][.key] != null and .value > $main[0][.key])
44 | "\(.key): \($main[0][.key]) -> \(.value) (+\(.value - $main[0][.key]))"
45 ' "$BUDGET")
46 if [ -z "$grown" ]; then
47 echo "Agent context is not larger than main."
48 exit 0
49 fi
50 printf 'Agent context grew compared to main:\n%s\n' "$grown"
51 if [ "$ALLOW_INCREASE" = "true" ]; then
52 echo "Accepted by the agent-context-increase label."
53 exit 0
54 fi
55 echo "::error file=$BUDGET::Agent context grew compared to main. Cut the added text and rerun the evals that cover it (evals/README.md), or ask a maintainer to add the agent-context-increase label."
56 exit 1