Skip to content

perf(loop): budgets, STE, and grounding from the body not the thread - #48

Merged
Ardnived merged 2 commits into
mainfrom
claude/perf-token-budgets
Sep 4, 2026
Merged

Ardnived merged 2 commits into
mainfrom
claude/perf-token-budgets

Conversation

@Ardnived

@Ardnived Ardnived commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Measured before designing anything, and the measurement moved the target twice.

Cost Measured
Skills loaded every run — preflight + work-routine + journal + config ~148,600 tok/day
Every bot comment ever written, in total ~152,000 tok
A journal thread 134,000 chars ≈ 33,000 tok
Bot comment, median 3,737 chars — 11.8× the reviewer's 316
Bot ticket body, median 4,854 — shorter than a human's 5,610

The rules cost as much each day as every comment the loop has ever written. The output was never the largest line. And bodies were never the problem — they are already shorter than yours, which is why the grounding fix below depends on them staying rich.

This had already broken production: a run hit Error: result (97,279 characters) exceeds maximum allowed tokens reading a journal's comments.

Four changes

1. Ground from the body, never the thread. triage-issue always said "comments are conversation, the body is state" — nothing enforced it. Now preflight does. Grounding a ticket: ~27,000 chars → ~8,600. Changes nothing already written, which makes it the cheapest saving available. And no run may call get_comments on a journal issue.

2. Budgets, enforced by a script. The old rule — "past roughly fifteen lines outside a <details>" — failed in both directions: 51% of bytes had migrated inside <details> where it did not reach, and the visible half still ran to 3,364 chars. workflow/lib/budget.mjs counts the whole artefact, <details> included, and returns over/under with no clause permitting an explained overage — that clause is what the old rule died of. Bodies stay unbudgeted, deliberately.

3. STE, vendored not installed. The ~8 rules that drive length go into preflight (~600 chars). The upstream skill is 16,260 chars ≈ 4,065 tokens — loading it 11×/day would cost more than the brevity it buys, and it is a single-contributor @main dependency for a plugin with write access to five repos. ste-lint.py is vendored (MIT, attributed) as a local dev check, never a run step.

4. The journal is one document per day. No comments at all — two rewritten surfaces holding the same accumulated content is the duplication this repo exists to avoid. Evidence blocks required for failures and friction, banned for merges and CI status, which GitHub records natively.

Results

Skill Before After Δ Lint (total/hard)
work-routine 23,723 16,601 −30% 49/27 → 14/7
journal 9,489 6,370 −33% 16/11 → 4/2
preflight 14,306 14,021 −2% * 44/23 → 24/12
triage-issue 19,939 18,882 −5% 37/22 → 34/20
finalize-pr 19,699 18,769 −5% 34/23 → 29/19

* preflight absorbed ~1,500 chars of new rules (STE, budgets, grounding) before shrinking.

Per-run load: 47,518 → 36,992 chars. ~29,000 tokens/day saved, on the three skills every run reads.

The rule-delta check earned its place

You chose lint-delta-plus-review as the gate; I ran a rule delta too, as review material. It caught something lint could not: Never read the board back went missing in the journal rewrite — a load-bearing piece of the board-is-a-lens doctrine. Restored.

Directives: 52 → 54. Of the apparent removals, all but one are rewordings (Do not add → Never add, etc.), verified newline-safe with fuzzy matching. One deliberate removal: the journal's ban on the words "rung" and "ladder" — the ⏭️ Ceiling section now names rungs on purpose, and the journal's reader is reflect, not a human reading cold at 6am.

Test results

  • ✓ claude plugin validate ./workflow --strict · ✓ jq -e . loop-config.json · ✓ node --check budget.mjs · ✓ every why.md citation resolves
  • ✓ budget.mjs, 7 cases: at budget, one under, one over, review-reply over, journal under, unknown kind → UNBUDGETED, and bulk hidden inside <details> → OVER (the loophole, closed by construction)
  • ✓ CLI path exits 1 on over-budget

Manual verification

Next scheduled run: the journal is one comment-free document under 2,500 chars, no get_comments on a journal appears in the transcript, and ⚠️ Failed still carries its evidence block.

🤖 Generated with Claude Code

Measured before designing, and the measurement moved the target twice.

  skills loaded every run (preflight + work-routine + journal + config)
    ~148,600 tokens/day
  every bot comment ever written, in total
    ~152,000 tokens

The rules cost as much each day as every comment the loop has ever written.
The output was never the largest line. Two more findings reversed assumptions:
bot ticket bodies are SHORTER than the reviewer's (4,854 vs 5,610), and a
journal thread reached 134,000 characters — one returned 97,279 in a single
response and broke the run that read it.

**Reading.** triage-issue always said "comments are conversation, the body is
state"; nothing enforced it. Now preflight does: ground from the body, read
comments only to find feedback inside the window, and never call get_comments
on a journal issue. Grounding a ticket drops from ~27,000 chars to ~8,600, and
it changes nothing already written.

**Budgets.** The old rule — "past roughly fifteen lines outside a <details>, it
is an essay" — failed in both directions. 51% of bytes had migrated inside
<details> where it did not reach, and the visible half still ran to 3,364 chars.
workflow/lib/budget.mjs counts the whole artefact, <details> included, and
returns over or under with no clause permitting an explained overage. That
clause is what the old rule died of. Bodies stay unbudgeted: they are state,
and the grounding rule depends on them.

**Register.** The ~8 ASD-STE100 rules that drive length are vendored into
preflight, ~600 chars. The upstream skill is 16,260 — loading it eleven times a
day would cost more than the brevity it buys, and it is a single-contributor
@main dependency for a plugin holding write access to five repos. ste-lint.py
is vendored (MIT) as a local dev check, never a run step.

**Journal.** One rewritten document per day, no comments at all. Two rewritten
surfaces holding the same accumulated content would be the duplication this
repo exists to avoid. ~33,000 tokens/day to ~2,500 chars. Evidence blocks are
required for failures and friction and banned for merges and CI status, which
GitHub records natively.

**Skills.** One aggressive pass: STE fixes, deduplication, and stories moved to
why.md behind anchors. The three run-loaded skills drop 10,526 chars per run —
about 29,000 tokens a day.

The rule-delta check earned its place. Lint would have passed silently while
"never read the board back" went missing in the journal rewrite; the delta
caught it and it is restored. Of the other apparent removals, all but one are
rewordings. The one real removal is deliberate: the journal's ban on the words
"rung" and "ladder" is gone, because the Ceiling section now names rungs on
purpose and the journal's reader is reflect, not a human reading cold.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ste-lint.py measures a skill's STYLE. This measures its CONTENT. They are
orthogonal, and only the second answers the question that matters when a skill
is rewritten: is every rule still there?

The case that produced it is in this same PR. The journal rewrite took its
violations from 16 to 4 and cut a third of the bytes, and dropped **Never read
the board back** — half of docs/why.md#the-board-is-a-lens. Lint scored that
rewrite as a clear improvement, because by its measure it was.

That matters more here than it would elsewhere: a skill cannot be validated by
running it. The edit takes effect next session, merging is the deploy, and a
dropped rule surfaces weeks later as a run behaving oddly with nothing to
attribute it to. This is the closest thing to a regression test that prose
admits.

Two implementation details are load-bearing rather than tidy:

  Whitespace collapses before matching. Markdown wraps a directive across
  lines, so a line-oriented match misses it — skipping this reported "Never
  force-push someone else's branch" as deleted when it had never moved.

  Rewordings are filtered. A raw diff of this PR reported 14 disappearances,
  11 of them `Do not X` becoming `Never X`. A reviewer handed 14 items skims,
  and skimming is how the one real removal gets waved through.

Headings count as directives alongside bold. Catching only bold made a
promotion to a heading look like a deletion, which it did for "Never write
state the state machine owns".

It is a tripwire, not a proof, and the docblock says so: it sees bold and
heading imperatives only, so a rule in plain prose is invisible, and `Never X`
weakened to `Avoid X` fuzzy-matches and passes.

Wired into AGENTS.md and reflect/SKILL.md — the two places that edit skills —
as a step whose removals must be accounted for in the PR body. Both it and
ste-lint.py are development tools, never run steps.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Ardnived

Ardnived commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Added: workflow/lib/rule-delta.mjs

The check that caught this PR's own regression is now a tool rather than something I ran by hand and threw away.

node workflow/lib/rule-delta.mjs --base main workflow/skills

ste-lint.py measures style. This measures content. Orthogonal, and only the second answers the question that matters when a skill is rewritten: is every rule still there? The journal rewrite in this PR scored 16 → 4 violations and lost a third of its bytes — and dropped Never read the board back. Lint called it an improvement, because by its measure it was.

Running it against this branch:

directives: 53 → 56
reworded:   11 (filtered — not shown)
ADDED (7) …
REMOVED — adjudicate each (3):
  - Never use the words "rung" or "ladder" outside `⏭️ Ceiling`
  - Do not "fix" it, do not re-post, do not file a ticket about it.
  - Always set Effort. It is never "the reviewer's to set".

Adjudicated, which is what the tool asks of a reviewer:

Flagged Verdict
"rung"/"ladder" ban Deliberately removed. ⏭️ Ceiling now names rungs on purpose, and the journal's reader is reflect, not a human reading cold
Do not "fix" it, re-post, file a ticket Survives, split into two imperatives in journal/SKILL.md:133
Always set Effort. It is never the reviewer's… Survives as **Always set Effort.** plus the ownership table

Three implementation details worth reviewing

  1. Whitespace collapses before matching. Markdown wraps directives across lines. Skipping this reported Never force-push someone else's branch as deleted when it had never moved.
  2. Rewordings are filtered. The raw diff reported 14 disappearances, 11 of them Do not X → Never X. Hand a reviewer 14 items and they skim — which is how the one real removal gets waved through.
  3. Headings count as directives. Catching only bold made a promotion to a heading look like a deletion, which it did for Never write state the state machine owns.

What it does not prove

Stated in the docblock so nobody over-trusts it: it sees bold and heading imperatives only, so a rule written as plain prose is invisible; Never X weakened to Avoid X fuzzy-matches and passes; and it cannot tell you a surviving rule is still correct. A tripwire, not a proof — but one ste-lint structurally cannot be.

Wired into AGENTS.md and reflect/SKILL.md, the two places that edit skills. Both tools are development-time only, never run steps.

Unit-verified: rewording filtered, genuine removal flagged, heading form caught, line-wrapped form caught.

@Ardnived
Ardnived merged commit ef40bbb into main Sep 4, 2026
1 check passed
@Ardnived
Ardnived deleted the claude/perf-token-budgets branch September 4, 2026 19:43
@github-project-automation github-project-automation Bot moved this from In progress to Done in SYDevelopers Technical Roadmap Sep 4, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 4, 2026
`main` gained #48, which rewrote `preflight/SKILL.md` in Simplified Technical
English, and #49, which made `version` a cache key. The one conflict was the
`label:awaiting` paragraph: #48 tightened it, this branch made it plural. Kept
#48's register and carried the plural fact into it in three short sentences.

Folded into the same commit, because two of the three touch the file the merge
had to reconcile:

- Rule 4 said "never let a mention pass silently" while the mention query is
  now issue-scoped. It now says the query is issue-scoped, and that a mention
  on a PR reaches the loop through rung 2 or not at all.
- `docs/why.md` records the two decisions the fix forced. First, the new
  `is:pr label:awaiting` query is what the survey routine's drift sweep reads,
  so half of that sweep's PR row becomes enforceable on the first survey after
  the merge — the sweep doing what its own table specifies, but worth knowing
  without a bisect. Second, `search_issues` with a hand-written `is:pr` stays
  the one tool rather than `search_pull_requests`, deliberately.
- `version` 0.2.0 -> 0.2.1. #49 landed after this branch did, and this branch
  changes two skills, so an unchanged version would leave every installed cache
  serving the old ones.

Gate: `claude plugin validate ./workflow --strict` passed. `rule-delta.mjs
--base origin/main` reports 57 -> 57 directives and no removal.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017bAFozAESzffZgcfH3REWX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant