Skip to content

chore(agents): rule 73 becomes a blocking check, Stop test gate on, Codex hook config validated - #2790

Merged
simple-agent-manager[bot] merged 15 commits into
mainfrom
sam/stream-agent-context-work-707dej
Nov 16, 2026
Merged

simple-agent-manager[bot] merged 15 commits into
mainfrom
sam/stream-agent-context-work-707dej

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stream A of the agent-context work (SAM task 01M7HX013ZBS5KJAXB0H707DEJ; plan, reviews and probe reports on idea 01M7H32EK6S4E31EHWVSJSENR5). Raphaël asked for all three parts on 2026-11-16 (chat 749fad59). Outcome per part:

Part Shipped here Evidence
1. Rule 73 becomes a check Blocking Go check; rule 73 leaves launch context, scoped to Go/TS/TSX/SQL Incident reproduced and caught; 0 other hits in 25 sampled commits; fresh Claude probes C1/C2
2. Codex rule delivery Not shipped. Codex hook-config validation only Real Codex probes: SAM Codex sessions never run repository hooks (project untrusted). Hook kept on sam/codex-rule-delivery-hook
3. Stop gate Rewritten, enabled for Claude Code; feedback/block per class from measurement Fired in a fresh Claude Code session (probe C1). Codex: same trust blocker as part 2

One PR: the parts share check-agent-context-budget.ts, agent-hook-config.ts, the CI step and filter, and one test entry point; none changes deployed code.

1. Rule 73: blocking check, then out of launch context

  • scripts/quality/go-optional-fields/ (Go standard library, go/ast). Options value: a param or receiver whose struct type ends in Opts/Options/Opt/Patch/Override(s), a variadic of one or named opts, opts[i], and locals bound from them (aliases, generics, embedded fields resolved). Reports a non-string scalar field (bool, int, float, time.Duration, named type over one) written onto existing state, directly or via an expression (!o.F, T(o.F)) or a replacing struct literal (*r = R{F: o.F}), when no enclosing if/case/early-return checks it was supplied (field mention or HasF-style presence flag; else/default branches and if o.F != r.F do not count), or when the only check is its own truthiness (if o.F, o.F > 0, also if o.F { r.F = true }). Writes onto locals the function builds are construction, unless the local is loaded, passed to a call, address-taken or written through. //sam:optional-field-ok <reason> opts out (reason required, anchored to the statement).
  • Proof: the verbatim pre-fix workspace_routing.go (a1c1d00^) yields exactly one finding, runtime.Lightweight, and none for its 13 guarded strings. main_test.go pins every shape with // want annotations, including all the variants a Go review of the first version found (it reported 3 HIGH: opts[0].F and load-then-modify missed, any variadic struct treated as options; all fixed). Deleting each of seven guards reddens its fixture.
  • Noise: 0 findings on the tree (323 Go files, 16 functions taking options). 25 commits sampled February-November 2026: the only finding ever is the incident, present at every sampled commit from 2026-03-16 until Stop WebSocket and restore upserts from clearing runtime.Lightweight #2055 fixed it. Hence blocking from the start (policy f9ae7f88: promotion on measured low noise), Code Quality Checks, pnpm quality:go-optional-fields.
  • TypeScript: no lint. Strict null checks reject the direct form; the forms that pass (patch.x ?? false, spreads) are 46 sites today and the ones inspected are creation defaults. SQL override layer (NOT NULL DEFAULT override column): not checkable without a declared registry of which table overrides which; stays judgment text, scoped to **/*.sql.
  • Launch: rule 73 gets paths: **/*.go, **/*.ts, **/*.tsx, **/*.sql (covers apps/api/src/db/migrations and the TS Durable Object migrations) and an "Enforcement" section; removed from launchRules. Claude Code launch context 214.5 KB on main -> 204.8 KB (ceiling 220,000 -> 210,000; the procedure added to the always-loaded routing rule costs 1.7 KB of the 11.4 KB). It now loads on first access to any Go/TS/TSX/SQL file instead.
  • Fresh-session probes: C1 (01M7HYQHAH3787PH8A0TCV6296): absent from the 36-file launch set; loaded with the result of the first Write of a brand-new .ts file (the same tool call, so the first write itself precedes it); --observed "model matches the session". C2 (01M7HYQVK025M14GN4QG9G8WTF): loaded on the Read of 0200_skills_optional_agent_type.sql, before any edit (Claude Code requires a Read before Edit); --observed matches. The mechanical part is caught by the blocking check whichever comes first.
  • Procedure for the next rule: .claude/rules/00-rule-routing.md, "Taking a Rule Out of Launch Context".

2. Codex rule delivery: experiment run, not good, not shipped

  • Built per the Codex docs (SessionStart + PreToolUse on Bash/apply_patch, bounded additionalContext, deny-once before the first write, log, generated lookup with a --check staleness gate, Node built-ins only), tested, then security-reviewed and hardened.
  • Real runtime: probe round 1b (01M7HZ6Q1EVPVPCBN00AM3WN8A, script committed): no SessionStart, no injected context, no refusal, no Stop prompt. CODEX_HOME unset; the vm-agent-written ~/.codex/config.toml has no trust entry for the repository and no hook-trust records, and Codex runs project hooks only for trusted projects and trusted hook definitions. (Round 1, 01M7HXMSG7M18TYKAEKHTBZEF0, was inconclusive: .gitignore had kept .codex/hooks/ out of the commit, which probe C2 caught; fixed, and --check now judges hook scripts and generated files by what git can see.) A nested trusted codex exec (01M7HY7P831WQG19HADM5JS85X) could not complete ("failed to load workspace requirements").
  • So delivery was not observable, and per the brief it is not claimed or shipped. The hook and the Codex Stop entry are preserved on branch sam/codex-rule-delivery-hook (f3b156c). Making them live needs the vm-agent to trust repository hooks: a security-design decision put to Raphaël (idea 01M7J0TXAHGRY8CWA7Y7SJZAK0).
  • Shipped: checkCodexHookConfig validates Codex hook entries against the current schema (events, matcher groups, handler fields, timeouts, skipped prompt/agent handlers, [features] hooks = false); the flat [[hooks.Stop]] entry that held no handler is removed and would now fail --check.

3. Test-quality Stop gate, fixed and switched on (Claude Code)

  • .claude/hooks/verify-test-quality.sh -> .claude/hooks/verify-test-quality.mjs (Node built-ins), enabled in .claude/settings.json.
  • Each defect has a test driving the real script against a fixture git repo, with a control: non-code files ignored; committed (merge base with origin/main, preferred over a stale local main), staged, unstaged and untracked changes seen; packages/project-data/src/do and the worker packages covered; stop_hook_active no longer bypasses findings; no pipes (no exit 141); output only {} or {"decision":"block","reason":...}. After the security review: fails open if its state cannot be saved, reads regular files under 1 MB only, hashes long session ids.
  • Per class, from merged PRs as they landed: untested-boundary-change flagged 2 of 80 (4 of 300); one false positive (pure move refactor(api): split tts, ai-token-budget and agent-loop (L3, pure move) #2733), one plausible (fix: stop stale project sockets from disabling chunk merging #2774) -> feedback (continues the turn once per session and finding set). shallow-test flagged 0 of 300 -> block, at most 3 times.
  • Observed: probe C1 ended a turn with an untested new service file; the gate continued the turn once with the "Test-quality gate" message, then let it end. Codex: not enabled, same trust blocker as part 2.

Validation

  • pnpm quality:agent-tooling:test (110 tests), pnpm quality:go-optional-fields (Go table tests + whole-repo run), pnpm quality:agent-context-budget --check, CI wiring tests (22)
  • pnpm lint (exit 0 earlier on this branch; focused ESLint on every changed TS/MJS file at the head)
  • pnpm typecheck: not run to completion locally (workspace restarts); scripts/quality is outside the turbo typecheck. Focused strict tsc on the changed files: no new errors (one pre-existing --observed argument line, unchanged from main)
  • pnpm test: not run; no package or app code changed. The affected suites are the script tests above, which CI runs in Code Quality Checks
  • Format ratchet passed
  • Mutation runs: checker (7 guards) and Stop gate (12 guards), each reddening its test
  • N/A candidate-selection loops: no sweep/cron change

Staging Verification (REQUIRED for all code changes — merge-blocking)

N/A: no deployed code changes. The diff is agent hook scripts (.claude/hooks/), repository quality tooling (scripts/quality/), the CI workflow, rules and AGENTS.md files. Nothing under apps/*/src, packages/*/src or packages/vm-agent changes, so no Worker, web bundle or VM agent changes on deploy. The hooks were verified in real harness sessions instead (probes above).

  • Infrastructure verification completed — N/A: no infra changes

Staging Verification Evidence

N/A: tooling-only; see the harness probes in Summary.

UI Compliance Checklist (Required for UI changes)

N/A: no UI changes.

UI Screenshot Evidence

N/A: no UI changes.

End-to-End Verification (Required for multi-component changes)

  • Capability test exercises the complete happy path: the Stop gate is driven as the harness runs it (JSON on stdin, real git repos) and observed in a fresh Claude Code session; rule 73 loading observed in fresh sessions and compared with the model.

Data Flow Trace

Stop gate: Claude Code Stop event -> .claude/settings.json handler -> verify-test-quality.mjs:run -> changedFiles (git merge base, diff, ls-files) -> evaluate -> decide (+ .tmp/stop-gate/<session>.json) -> stdout JSON. Rule 73: paths frontmatter -> agent-instructions.ts:InstructionModel.loadsOnAccess -> generated indexes; Claude Code InstructionsLoaded log -> --observed.

Untested Gaps

Codex: no repository hook runs in SAM Codex sessions (see part 2); tracked in idea 01M7J0TXAHGRY8CWA7Y7SJZAK0.

Post-Mortem (Required for bug fix PRs)

N/A: not a bug fix. (The Stop gate never ran because of a malformed entry; history in idea 01M7H8SDG77AE0FH39QXW3NPYX. agent-hook-config.ts now also checks Codex entries and that hook scripts are in the repository.)

Specialist Review Evidence (Required for agent-authored PRs)

  • All local reviewers completed and findings addressed before merge
  • If any reviewer did NOT complete: needs-human-review label added and merge deferred to human
Reviewer Status Outcome
task-completion-validator ADDRESSED No CRITICAL/HIGH. MEDIUMs fixed: checker blind spots (0854ed5), task file status, CI guard for the rule-73 step, Codex wording
go-specialist ADDRESSED 3 HIGH (missed opts[i].F, missed load-then-modify, variadic false positive) and the MEDIUMs fixed in 0854ed5 / 6085038; reviewer fixtures now pinned in testdata/
security-auditor ADDRESSED No CRITICAL/HIGH. Stop gate MEDIUM (unbounded block if state unwritable) and LOW (symlink/large file, session id) fixed in f3b156c; Codex-hook MEDIUMs fixed there too, hook since moved off this PR
test-engineer ADDRESSED HIGH: git env leak into fixtures, unpinned base resolution (fixed, mutations now red); Codex deny-once gap moot (hook moved). Stop-gate MEDIUM/LOW gaps (areas, deletions, reset, mixed classes, temp cleanup) closed in f3b156c / 784add6

CodeRabbit Review Evidence (Required for agent-authored PRs)

  • CodeRabbit requested when the PR was marked ready for review
  • Waited about 15 minutes (or until a skip, rate-limit or quota reply)
  • Either CodeRabbit reviewed and no CodeRabbit feedback is unresolved, or it did not review and the observed outcome is recorded below

CodeRabbit Notes

No review. Requested with the coderabbit-review label when the PR was marked ready (11:12:18Z); the request workflow (run 43855669453) succeeded and CodeRabbit replied at 11:15:39Z "Action not completed: Review rate limited", which ends the wait (policy 73ed7a68). Its earlier 10:36Z comment was the automatic "Review skipped: auto reviews are disabled" when the draft was opened.

Exceptions (If any)

  • Scope: none
  • Rationale:
  • Expiration:

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • external-api-change
  • cross-component-change
  • business-logic-change
  • public-surface-change
  • docs-sync-change
  • security-sensitive-change
  • ui-change
  • infra-change

External References

Official documentation, fetched 2026-11-16: Codex hooks https://developers.openai.com/codex/hooks (event/matcher-group/handler shape, trust model, SessionStart sources, PreToolUse tool coverage, additionalContext spill limit, Stop output contract); Codex config schema https://developers.openai.com/codex/config-schema.json (HooksToml, MatcherGroup, HookHandlerConfig, HookStateToml); Claude Code hooks https://code.claude.com/docs/en/hooks (Stop decision control, handler fields). Context7 not used: the official pages above are the primary sources.

Codebase Impact Analysis

.claude/hooks/verify-test-quality.mjs (new, replaces .sh), .claude/settings.json (Stop entry), .codex/config.toml (broken flat Stop entry removed; no hooks), scripts/quality/agent-hook-config.ts (Codex validation, script existence), check-agent-context-budget.ts (hook findings judged by git-visible files), agent-rule-index.ts (backticked wildcard scopes), agent-context-budget.json (73 out of launchRules, ceiling lowered), go-optional-fields/ (new Go module), tests, .github/workflows/ci.yml (filter + three steps), package.json (two scripts), .claude/rules/00-rule-routing.md, .claude/rules/73-...md, generated AGENTS.md indexes, new apps/installer/AGENTS.md and packages/harness/AGENTS.md. No runtime code in apps/ or packages/ src changes.

Documentation & Specs

scripts/quality/README.md (Stop gate with numbers, Codex hooks status, rule-73 check), .claude/rules/00-rule-routing.md (procedure for taking a rule out of launch context), .claude/rules/73-optional-struct-fields-must-not-overwrite-on-absence.md (Enforcement section, scope).

Constitution & Risk Check

Principle XI: the Stop gate's modes, block limit and file-size cap are named constants documented with their measurements. Principle X (simplicity): no new dependencies; the hook uses Node built-ins, the checker the Go standard library. Risks: the Stop gate could nag on a false positive (bounded: feedback once; block at most 3 times; fails open if it cannot keep state); rule 73 out of launch context (mitigated by the blocking check, the four-language scope and the fresh-session probes). No SAM policy or knowledge value changed; launchRules changed only for rule 73.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codspeed

codspeed Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing sam/stream-agent-context-work-707dej (45a0885) with main (26aaacd)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

…opts[i], receivers, generics, load-then-modify, truthiness forms, switch, anchored opt-out)
…files only, validated rule paths, quoted paths) and close Stop-gate test gaps
…hook moves to sam/codex-rule-delivery-hook (Codex sessions in SAM do not run repository hooks)
@simple-agent-manager simple-agent-manager Bot changed the title chore(agents): rule 73 check, Codex rule hook, Stop test-quality gate chore(agents): rule 73 becomes a blocking check, Stop test gate on, Codex hook config validated Nov 16, 2026
@simple-agent-manager
simple-agent-manager Bot marked this pull request as ready for review November 16, 2026 11:12
@simple-agent-manager simple-agent-manager Bot added the coderabbit-review Trigger CodeRabbit review for opt-in PRs label Nov 16, 2026
@raphaeltm

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager
simple-agent-manager Bot merged commit 4455081 into main Nov 16, 2026
37 checks passed
simple-agent-manager Bot pushed a commit that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simple-agent-manager Bot pushed a commit that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simple-agent-manager Bot pushed a commit that referenced this pull request Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simple-agent-manager Bot pushed a commit that referenced this pull request Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simple-agent-manager Bot pushed a commit that referenced this pull request Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simple-agent-manager Bot added a commit that referenced this pull request Nov 17, 2026
* refactor(api): move cron expression parsing into packages/cron

First slice of the apps/api/src/services split (seam map: SAM idea
01M7HXHPQ46H3YK0GC9Q2QHAFF). services/cron-utils.ts moves unchanged to
packages/cron; its unit test moves with it. The ten worker importers and six
worker tests import @simple-agent-manager/cron instead of the old path.
No re-export is left behind.

Wiring: apps/api dependency, CI path filters, runtime-boundary scope, build
order in CLAUDE.md, rule 08 and the local-development guide, a package
AGENTS.md, regenerated rule indexes.

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

* chore(agents): regenerate cron package rule index after #2790

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

* chore(quality): scan packages/cron in ast-checks; record review evidence

Review follow-ups for the cron package move: the API AST checks scanned
cron-utils.ts before the move, so they now scan packages/cron/src as they do
the other worker packages. AGENTS.md says who consumes the package, and the
task file records the evidence and the rule 51 decision.

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

* task: archive extract-cron-package

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

* chore(sonar): keep the moved cron test out of copy/paste analysis

SonarCloud counts packages/cron/tests/unit/cron-utils.test.ts as new code
after the move, and its repeated test blocks (102 lines, unchanged from the old
path) failed the new-code duplication gate. Tests are excluded from CPD by
policy (sonar-project.properties); automatic analysis needs the exact path.

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

* docs(agents): trim cron additions to stay inside the launch-context budget

Claude Code launch context reached 210,107 bytes against the 210,000 ceiling
after rebasing onto main. Shorten the CLAUDE.md structure line and drop cron
from the rule 08 diagram, where it implied the worker module packages depend
on it; both build-order sentences still list cron. Net launch addition is now
68 bytes.

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

---------

Co-authored-by: Raphaël Titsworth-Morin <raphael@raphaeltm.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review Trigger CodeRabbit review for opt-in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant