Skip to content

Optimize Documentation Maintainer token usage and prompt/cache behavior#3202

Merged
lpcox merged 3 commits into
mainfrom
copilot/optimize-copilot-token-usage
May 15, 2026
Merged

Optimize Documentation Maintainer token usage and prompt/cache behavior#3202
lpcox merged 3 commits into
mainfrom
copilot/optimize-copilot-token-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

✨ Enhancement

The Documentation Maintainer workflow was consuming ~1.17M tokens/run with 28 LLM requests, driven largely by repeated bash round-trips (git show per commit) and unstable prompt caching. This change restructures the workflow to reduce request fan-out, shift work into precomputed step outputs, and run on a smaller model.

  • Model sizing

    • Switched workflow engine config to Copilot + claude-haiku-4-5 for lower-cost doc maintenance tasks.
  • Precomputed change context (fewer tool round-trips)

    • Replaced commit-list-only step with a single-pass diff aggregation step:
      • git-changes now emits RECENT_DIFFS with bounded unified diffs for src/, containers/, scripts/ (+ relevant doc paths).
    • Added affected-docs step to emit prioritized candidate files (AFFECTED_DOCS) from recent source-touching paths.
    • Added has-changes step to emit has_changes/changed_count for explicit no-op handling.
  • Prompt structure + execution guidance (cache/write and scope control)

    • Reordered prompt so stable instructions remain first and dynamic run context is appended at the end.
    • Updated agent instructions to:
      • exit immediately with no-op when has_changes=false
      • use precomputed RECENT_DIFFS as primary input
      • prioritize AFFECTED_DOCS before broad doc review
      • avoid per-commit git show unless strictly necessary
  • Related failure context

    • Recent run failure root cause was in safe-outputs PR creation (CLAUDE.md protected-file modification), independent of this token-optimization flow.
steps:
  - name: Check for relevant changes
    id: has-changes
    run: |
      COUNT=$(git log --since="7 days ago" --oneline -- src/ containers/ scripts/ | wc -l)
      echo "changed_count=$COUNT" >> $GITHUB_OUTPUT
      echo "has_changes=$([ "$COUNT" -gt 0 ] && echo true || echo false)" >> $GITHUB_OUTPUT

  - name: Gather recent git diffs
    id: git-changes
    run: |
      echo "RECENT_DIFFS<<EOF" >> $GITHUB_OUTPUT
      git log --since="7 days ago" --format="%H %s" -- src/ containers/ scripts/ | \
        while read -r sha title; do
          echo "=== Commit $sha: $title ==="
          git show --stat --unified=3 "$sha" -- src/ containers/ scripts/ docs/ '*.md' 2>/dev/null | head -150
        done | head -500
      echo "EOF" >> $GITHUB_OUTPUT

Copilot AI changed the title [WIP] Optimize Copilot token usage based on analysis Optimize Documentation Maintainer token usage and prompt/cache behavior May 15, 2026
Copilot AI requested a review from lpcox May 15, 2026 13:33
Copilot finished work on behalf of lpcox May 15, 2026 13:33
@lpcox lpcox marked this pull request as ready for review May 15, 2026 13:52
@lpcox lpcox requested a review from Mossaka as a code owner May 15, 2026 13:52
Copilot AI review requested due to automatic review settings May 15, 2026 13:52
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
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 updates the Documentation Maintainer agent workflow to reduce token usage by switching to a smaller Copilot model and attempting to precompute change context for the agent prompt.

Changes:

  • Sets the Documentation Maintainer engine to Copilot with claude-haiku-4-5.
  • Adds pre-agent steps for source-change detection, recent diffs, and affected-doc candidates.
  • Reorders prompt context so run-specific data is appended near the end.
Show a summary per file
File Description
.github/workflows/doc-maintainer.md Updates workflow source configuration, precomputed git context steps, and prompt instructions/context.
.github/workflows/doc-maintainer.lock.yml Regenerated compiled workflow reflecting model, prompt substitutions, and new pre-agent steps.

Copilot's findings

Tip

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

Comments suppressed due to low confidence (1)

.github/workflows/doc-maintainer.md:65

  • The AFFECTED_DOCS body is also printed to stdout instead of $GITHUB_OUTPUT, so the output will be empty even when relevant files exist. The multiline output needs to append the command output between the heredoc markers.
      echo "AFFECTED_DOCS<<EOF" >> $GITHUB_OUTPUT
      git log --since="7 days ago" --name-only --format="" -- src/ containers/ scripts/ | \
        grep -v '^$' | sort -u | head -30
  • Files reviewed: 2/2 changed files
  • Comments generated: 7

Comment thread .github/workflows/doc-maintainer.md Outdated
Comment on lines +47 to +51
git log --since="7 days ago" --format="%H %s" -- src/ containers/ scripts/ | \
while read -r sha title; do
echo "=== Commit $sha: $title ==="
git show --stat --unified=3 "$sha" -- src/ containers/ scripts/ docs/ '*.md' 2>/dev/null | head -150
done | head -500
Comment on lines +172 to +175
GH_AW_EXPR_4072EBFD: ${{ steps.has-changes.outputs.has_changes }}
GH_AW_EXPR_8CF6695E: ${{ steps.has-changes.outputs.changed_count }}
GH_AW_EXPR_8F5D95B0: ${{ steps.git-changes.outputs.RECENT_DIFFS }}
GH_AW_EXPR_FAA4E739: ${{ steps.affected-docs.outputs.AFFECTED_DOCS }}
Comment thread .github/workflows/doc-maintainer.md Outdated
- name: Check for relevant changes
id: has-changes
run: |
COUNT=$(git log --since="7 days ago" --oneline -- src/ containers/ scripts/ | wc -l)
Comment thread .github/workflows/doc-maintainer.md Outdated
Comment on lines +64 to +65
git log --since="7 days ago" --name-only --format="" -- src/ containers/ scripts/ | \
grep -v '^$' | sort -u | head -30
Comment thread .github/workflows/doc-maintainer.md Outdated
Comment on lines 46 to 52
echo "RECENT_DIFFS<<EOF" >> $GITHUB_OUTPUT
git log --since="7 days ago" --format="%H %s" -- src/ containers/ scripts/ | \
while read -r sha title; do
echo "=== Commit $sha: $title ==="
git show --stat --unified=3 "$sha" -- src/ containers/ scripts/ docs/ '*.md' 2>/dev/null | head -150
done | head -500
echo "EOF" >> $GITHUB_OUTPUT
Comment thread .github/workflows/doc-maintainer.md Outdated
### 3. Review Current Documentation

Read the documentation files listed above that are likely affected by the recent changes.
Start with the prioritized list from `${{ steps.affected-docs.outputs.AFFECTED_DOCS }}`. Review the broader documentation list only when there is a clear link to the recent source changes.
Comment thread .github/workflows/doc-maintainer.md Outdated
### 1. Analyze Pre-computed Changes

Review the git commit list above. For commits that touch source code (`src/`, `containers/`, `scripts/`), use `git show <sha>` to examine the actual diffs and understand what changed.
If `${{ steps.has-changes.outputs.has_changes }}` is `false`, exit immediately using a no-op result without editing files or creating a PR.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 15, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 15, 2026

@copilot address review feedback

Addressed in 80a8b78. I fixed the workflow review items: robust $GITHUB_OUTPUT writes with safe delimiters, shallow-history handling, affected docs now emit doc paths, moved dynamic context out of activation-time prompt interpolation, and regenerated the lock file accordingly.

Copilot finished work on behalf of lpcox May 15, 2026 14:44
@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

Test Summary: 2/3 PASS (1 FAIL)

Test Result Details
GitHub API ❌ FAIL gh CLI authentication failed (401: Bad credentials)
Playwright ✅ PASS Successfully navigated to github.com, title contains 'GitHub'
File Verify ✅ PASS smoke-test-claude-25923980148.txt exists with expected content

Note: GitHub API test failed due to gh CLI authentication in this environment. Playwright and file verification tests passed successfully.

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity ❌ 401 Bad credentials
GitHub.com HTTP ⚠️ Pre-step data unavailable (template not expanded)
File write/read ⚠️ Pre-step data unavailable (template not expanded)
BYOK inference (api-proxy → api.githubcopilot.com)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

Overall: FAIL — GitHub MCP returned 401 and pre-step outputs were not injected.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity ❌ 401 Bad credentials
GitHub.com HTTP connectivity ⚠️ Template vars unresolved
File write/read ⚠️ Template vars unresolved

Overall: FAIL — GitHub MCP returned 401; workflow template variables (${{ steps.smoke-data.outputs.* }}) were not substituted before agent execution.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test

PRs: Cap /reflect effective-token totals at configured maxEffectiveTokens; refactor: [Export Audit] Remove test-only re-exports from barrel modules
GitHub PR review: ✅
SafeInputs GH / Tavily / Discussion: ❌
Playwright / File / Bash / Build: ✅
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #3202 · ● 5.1M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke test in progress...

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results — FAIL ❌

Check Result
Redis PING ❌ Timeout (no response)
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ No response

host.docker.internal is unreachable from this environment. Service containers do not appear to be running or accessible. Overall: FAIL

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit 39720f5 into main May 15, 2026
61 of 65 checks passed
@lpcox lpcox deleted the copilot/optimize-copilot-token-usage branch May 15, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚡ Copilot Token Optimization2026-05-15 — Documentation Maintainer

3 participants