[codex] add skill context budget guardrails#1264
Open
mzhaom wants to merge 1 commit intogarrytan:mainfrom
Open
[codex] add skill context budget guardrails#1264mzhaom wants to merge 1 commit intogarrytan:mainfrom
mzhaom wants to merge 1 commit intogarrytan:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the first implementation slice from
docs/designs/SKILL_CONTEXT_BUDGET.md:scripts/skill-context-budget.tswith--reportand--checkmodesbun run skill:budgetandbun run skill:budget:checkbun run skill:checktriggers:metadataSKILL.mdfiles from the updated templatesWhy this helps Codex context windows
Codex context is not spent only on the user's prompt and the repo files it reads. A real coding turn also carries system/developer instructions, tool schemas, AGENTS.md guidance, conversation history, and any skill catalog text exposed for routing. That means eager skill discovery text competes directly with source files, diffs, test output, and review context before Codex has started the task.
Before this PR, visible generated skill frontmatter descriptions alone were about 20,919 chars (~5,230 approximate tokens), and the eager catalog estimate was about 22,791 chars (~5,698 approximate tokens). The full visible generated
SKILL.mdbodies are about 570k approximate tokens, so blurring discovery and execution can dominate even large context windows. There is already a concrete Codex symptom intest/skill-e2e-workflow.test.ts: the Codex workflow test slices out only the review-relevant section because reading the fullcodex/SKILL.mdis too large for the turn.This PR separates the cheap routing layer from the expensive execution layer. After the description slimming, visible descriptions are 6,491 chars (~1,623 approximate tokens), and the eager catalog estimate is 8,365 chars (~2,092 approximate tokens). Codex keeps more window available for the actual task while selected skills still load their full workflow text when needed.
Impact
This reduces eager discovery context while preserving skill execution bodies. Current visible metrics from
bun run skill:budget:check:The budget check is intentionally conservative for this PR: hard failures are limited to parser errors, generated skills over the 160 KB ceiling, and changed templates with descriptions over 360 chars. Existing oversized skill bodies remain warnings.
Follow-up Work
references/preamble/*.md; ratchet tier >= 2 preamble warnings toward 22 KB.codexfirst: extract review, challenge, consult, and session-continuity modes intocodex/references/*.md; update the E2E workflow test so it reads the full generatedcodex/SKILL.mdinstead of slicing a section.review,ship, the plan-review family,qa, anddesign-review.Validation
bun installbun run gen:skill-docsbun run skill:budget:checkbun run skill:checkbun test test/skill-context-budget.test.tsbun test test/gen-skill-docs.test.tsbun test test/skill-context-budget.test.ts test/gen-skill-docs.test.ts test/skill-validation.test.ts(693 pass, 0 fail)Need help on this PR? Tag
@codesmithwith what you need.