Skip to content

feat(optimize-skill) - reduce recurring context cost - #1379

Open
anbv29 wants to merge 4 commits into
apache:mainfrom
anbv29:optimize-optimize-skill
Open

anbv29 wants to merge 4 commits into
apache:mainfrom
anbv29:optimize-optimize-skill

Conversation

@anbv29

@anbv29 anbv29 commented Sep 25, 2026

Copy link
Copy Markdown

Summary

  • Reduce the optimize-skill context cost while preserving its seven optimization passes and safety gates.
  • Reduce the full skill from 3,995 to 3,024 tokens and shorten its always-on metadata.
  • Add behavioral fixtures for the previously uncovered extract-code and rewrite passes.

Type of change

  • Skill change
  • Documentation
  • Behavioral eval coverage

Test plan

  • Verified all 75 skill surface hashes are synchronized
  • Verified generated token measurements are current
  • Loaded and reviewed all seven optimize-skill eval cases
  • Ran formatting, Markdown, typo, placeholder, JSON, and changed-file link checks
  • Full prek run --all-files — local Windows execution was blocked while compiling the lychee Rust dependency; GitHub CI will run the complete Linux suite

RFC-AI-0004 compliance

  • HITL behavior remains unchanged
  • Vendor-neutral placeholders remain intact
  • No new unrestricted access or autonomous mutations
  • Write-access discipline remains unchanged

Linked issues

Closes #1350

Notes for reviewers

The rewrite preserves the existing workflow, approval boundaries, validator gates, and seven-pass diagnosis contract. The main change is reduced recurring context cost plus complete eval coverage.

@potiuk potiuk added the substrate:framework-dev Tool substrate: build / validate / eval the framework itself label Sep 25, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, and for filling the eval gap for extract-code and rewrite. Two rules were lost in the condensing, one new fixture is ambiguous, and the branch needs a rebase before CI can run. Details below and inline.

Rebase needed — conflicts are in generated files only

The branch is 6 commits behind main and conflicts in docs/mode-economics.md and tools/skill-evals/README.md. Both are generated counts that moved on main (#1372, #1373). Please rebase, then regenerate them rather than hand-merging:

uv run --project tools/skill-token-count skill-token-count --write
python3 tools/dev/check-doc-sync.py --fix

CI has not run on this PR yet because of the conflict.

Two rules were lost in the condensing

A wording pass must keep what the skill decides. The umbrella asks for exactly that ("headings, golden-rule headlines, code blocks and the pre-flight block kept byte-identical"), and this skill's own Hard rules say "Structure changes, behaviour does not". Two sentences carried rules and did not survive:

  • Step 4: "the budgets from What counts as small enough must have moved the right way" became "measure both budgets again". Measuring is no longer tied to an outcome, so a pass that grows the skill is no longer caught.
  • Hard rules: "A pass that needs it relaxed is not an optimization" is gone. "Require a green validator" can be satisfied by loosening the validator, which is exactly what the old sentence forbade.

Suggested wording is inline. The rest of the condensing keeps the rules. It mostly drops the why sentences, which is a fair trade for this pass.

Evals: run them, and note what they cannot see

The test plan says the seven cases were loaded and reviewed, not run. #1350 step 4 and AGENTS.md both ask for the suite to run before and after:

tools/skill-evals/magpie-run-evals.sh tools/skill-evals/evals/optimize-skill

Please include the before/after result in the description. Note also that the suite only extracts ## Step 1 — Diagnose, which this PR leaves unchanged. So a green run proves the new fixtures, but says nothing about the rewritten Steps 2–5 and Hard rules. Those rest on review, which is why the two lost rules above matter.

Smaller observations

  • case-7-verbose-prose/report.md: the fixture says the largest section is "substantially longer than the other orchestration sections". Smell 1 in Step 1 triggers split on "one section dominating", so a model can reasonably return ["split", "rewrite"], and the case becomes flaky. Case 2 says "within range, no dominating section". Use the same wording here.
  • Scope: #1350 asks for the utilities family, starting with the three skills over the always-on budget (report-framework-issue, skill-reconciler, list-skills). optimize-skill was already within both budgets. Please change Closes #1350 to Part of #1350 so the issue stays open for the rest.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Magpie handles maintainer review:
CONTRIBUTING.md.


The validator must return the same green it returned at Step 0, and the
budgets from *What counts as small enough* must have moved the right way.
Require the Step 0 validator result and measure both budgets again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This dropped the outcome: on main Step 4 says the budgets "must have moved the right way". As written, a pass that grows the skill still passes Step 4.

Suggested change
Require the Step 0 validator result and measure both budgets again.
Require the Step 0 validator result, and both budgets must have moved the right way.

- Move identical bytes except for a necessary heading-level change, and
update every heading reference.
- Propose before applying; never batch passes.
- Require a green validator and measure both budgets and evals before

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The old rule also said "A pass that needs it relaxed is not an optimization." Without it, "require a green validator" can be met by loosening the validator. Please keep that clause.

Suggested change
- Require a green validator and measure both budgets and evals before
- Require a green validator, never a relaxed one, and measure both budgets and evals before


wc -l SKILL.md: 420
Largest section: "## Step 3 — Apply one pass at a time" (120 lines) —
within the structural limit and still substantially longer than the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Substantially longer than the other orchestration sections" reads as smell 1's "one section dominating", which triggers split, so ["split", "rewrite"] is a defensible answer and the case will be flaky. Case 2 phrases it as "within range, no dominating section"; the same here would leave rewrite as the only answer.

Add diagnosis fixtures for embedded deterministic code and verbose
prose so the evaluation contract covers extract-code and rewrite.

Generated-by: Codex (GPT-5)
Rewrite duplicated guidance without changing pass behavior or safety gates.
Reduce the full skill from 3,995 to 3,050 tokens and its always-on metadata
from 160 to 107 tokens.

Generated-by: Codex (GPT-5)
Keep the structural surface hash stable, shorten the always-on description, and regenerate the token manifest at 3,024 tokens.

Generated-by: Codex (GPT-5)
@anbv29
anbv29 force-pushed the optimize-optimize-skill branch from 8fbbb44 to fbcf31f Compare September 25, 2026 19:21
@anbv29

anbv29 commented Sep 25, 2026

Copy link
Copy Markdown
Author

Hey @potiuk , I made some changes as you said, is the PR now ready to be merged?
Thanks

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @anbv29. The text fixes in SKILL.md (Step 4 budget direction, Hard rules validator clause) and case-7-verbose-prose/report.md address the wording findings.

However, the PR is not ready to merge yet due to the following blocking items:

  1. Git history / rebase (PR diff is bloated to 66 files):

    • The branch has pulled in 6 unrelated commits from main (#1382–#1387) into its own commit history rather than rebasing cleanly. As a result, the PR diff currently touches 66 files across the repo instead of being scoped to optimize-skill.
    • Please rebase cleanly onto latest upstream/main (git rebase upstream/main) so the diff contains only your changes, then regenerate the sync files if needed:
      uv run --project tools/skill-token-count skill-token-count --write
      python3 tools/dev/check-doc-sync.py --fix
  2. PR Description updates:

    • Change Closes #1350 to Part of #1350 in the PR body (#1350 covers the full utilities family: report-framework-issue, skill-reconciler, list-skills).
    • Run the eval suite and paste the before/after results in the Test plan:
      tools/skill-evals/magpie-run-evals.sh tools/skill-evals/evals/optimize-skill

Once the rebase is clean and the description is updated, maintainers can trigger the CI suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

substrate:framework-dev Tool substrate: build / validate / eval the framework itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize the utilities skill family

3 participants