Skip to content

fix(context): the audit's control and fit, and rung 1's price - #185

Merged
chuycepeda merged 2 commits into
The-AIOS:mainfrom
matiasmacera:fix/context-audit-and-rungs
Sep 25, 2026
Merged

chuycepeda merged 2 commits into
The-AIOS:mainfrom
matiasmacera:fix/context-audit-and-rungs

Conversation

@matiasmacera

Copy link
Copy Markdown
Contributor

What

Three defects in the two tools that measure context loading. /aios:housekeeping runs both.

# Where What happened
1 hooks/context-load-audit.py Primary sessions are the audit's control. They were recognised by a regex of session names from a single operator. On any other vault those names match nothing, so the real primary is counted as a worker and can be listed as a suspect.
2 hooks/context-load-audit.py The fit check flags a worker that acted outward without reading a declared/ file. It only scanned the first --cap (120) calls, so a later export was never seen. It also ignored order: a worker that exported first and read the voice file afterwards counted as having read it.
3 hooks/context-rungs.py Rung 1 is defined as what context-floor.py emits. The floor emits a rule library's index and the newest entries of each observed file by date. Rungs priced the last five entries of every file, rule library included. It defined a rule-library regex it never used.

Fix

  1. Primaries come from the first table under ## Identity in USER.md, the table that already decides how a session is greeted, plus --primary NAME. The parser follows GFM (a header row, then a delimiter row). It skips the template's italic example rows and ignores fenced code, and the table ends at the first line that is not a row. With no primary declared, the audit aborts and says how to declare one.
  2. Fit reads the whole transcript. It flags a worker whose first outward action comes before any declared/ read. When one call does both, the positions of the matches that produced the hit decide. --cap and --min-tools still apply to the loading window; the JSON gains tools_total and declared_before_outward.
  3. The floor's per-file selection moved into one function, recent_slice(). context-rungs.py imports it, and its recency constant, from the floor, so price and emission cannot drift. The floor's output is byte-identical before and after, in text and --json, with default, zero and widened --recent.

Proof

  • tests/context-rungs.test.sh builds a vault with a rule library and a chronology whose tail is its oldest part. It asserts rung 1's per-file price equals the words the floor emits for each file. Against the pre-change hook, pinned by sha, the prices differ by two orders of magnitude.
  • tests/context-load-audit.test.sh covers declared primaries, the no-USER.md abort, --primary, and 20 parser cases. It also covers fit past the cap, a read after the ship, a ship then read inside one call, and a look-alike filename earlier in the same call. --min-tools still filters on the loading window. The pre-change hook, pinned by sha, first has to produce a valid report, and then it flags none of the fit cases.
  • Every check has a mutation control: reverting it fails exactly its case.
  • tests/spawned-worker-context-parity.test.sh compared two numeric recency constants. It now also accepts rungs reading the floor's constant, which is the stronger form.
  • The full tests/ run passes. The three suites also pass under bash 3.2.

Scope

hooks/context-load-audit.py, hooks/context-rungs.py, hooks/context-floor.py (refactor only), the three tests, hooks/_index.md, the Bucket 30 text in housekeeping.md, and the CHANGELOG entry. It continues the hooks series announced in #158.

🤖 Generated with Claude Code

matiasmacera and others added 2 commits September 25, 2026 16:40
- context-load-audit.py recognised primary sessions by a regex of one
  operator's session names. Primaries now come from USER.md's
  `## Identity` table (its first GFM table; italic example rows skipped)
  plus --primary. With none declared it aborts and says how to declare one.
- Its fit check (outward action without a declared/ read) only looked at
  the first --cap calls and ignored order. It now reads the whole
  transcript and asks whether a declared/ read came before the first
  outward action, within a single call too. --cap and --min-tools still
  measure the loading window.
- context-rungs.py priced rung 1 as the last five entries of every
  observed file, while the floor emits a rule library's index and the
  newest entries by date. The floor's per-file selection is now one
  function, recent_slice(), and rungs imports it. Floor output is
  byte-identical.

Tests: rung 1 equals the floor's emitted words per file; primaries,
parser counterexamples and fit ordering cases; old-hook reproductions
pinned to the pre-change sha. The parity test accepts the shared
recency constant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

AIOS-Session: 4ce35e79-7182-45d3-a479-d25e0004fda0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chuycepeda added a commit that referenced this pull request Sep 25, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LCjeYxWVWosFKnRiCf8Ae7
@chuycepeda
chuycepeda merged commit d14b1d3 into The-AIOS:main Sep 25, 2026
16 checks passed
@chuycepeda

Copy link
Copy Markdown
Member

Shipped in v0.8.5 with your commits and authorship intact. Thank you. It went in as you wrote it. The floor refactor was checked against a live vault: context-floor.py output was byte-identical before and after, across six argument sets (107–297 KB). On that vault the audit now finds exactly one primary, where the old pattern also counted four workers as primaries.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants