Skip to content

refactor: make agent mistakes fail CI or the model checker, not code review - #12

Merged
gpu004 merged 2 commits into
mainfrom
enforce-correction-layers
Nov 20, 2026
Merged

gpu004 merged 2 commits into
mainfrom
enforce-correction-layers

Conversation

@gpu004

@gpu004 gpu004 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

When an agent made a mistake here, the only fix was to tell it again, and a correction like that doesn't survive into the next session. This PR puts each rule in the cheapest place that can enforce it, in this order:

  1. Codebase. Bad shapes can't be written. Ids are branded, so a JobId can't be passed as a LeaseToken. Only a leased job can carry a lease. Handlers can only read route params their path pattern has. Env vars are parsed once into a typed Config.
  2. Static analysis. The turbo lint rules allow the clock, JSON.parse, and raw env vars only in the module that owns each one. Fixtures test the rules, and RULE_OWNERS fails the build if .oxlintrc.json turns a rule off for any other file. test/types.test.ts lists mistakes that must not compile, and property tests check each guarantee in the readme.
  3. Verification. invariantViolation runs on every queue loaded from R2 and before every write, so a model bug fails the request instead of saving a corrupt queue. spec/QueueBroker.tla model-checks the R2 compare-and-set protocol with two brokers racing. A second config turns compare-and-set off and must fail (NoLostJob), which shows the spec catches the bug it exists for. CI runs both in a new model-check job.
  4. Prose. AGENTS.md lays out this order and keeps only the three rules code can't enforce yet, each with the reason.
  5. Human review. The PR template asks which layer now prevents a corrected mistake.

Proof: npm run check, npm test (27 passing), and npm run verify:tla pass locally on the rebased commit. I also broke three things on purpose: an unowned lint override and a fixture line the rule doesn't flag both turned lint:rules red, and removing idempotency-key dedupe failed 6 tests through the runtime invariant.

The first CI run failed on a Worker test that expects two concurrent pushes to share one commit. That assertion was already on main and depends on both requests landing inside the 5 ms batch window, which a loaded runner can miss. I reproduced it locally under full CPU load (2 of 25 runs failed) and gave tests a 100 ms window (0 of 30 failed under the same load). Sol review also found that config parsing had drifted from the old parseInt behavior, so it is restored with a test, and the spec now says it doesn't model replies served from the cached snapshot.

Proof for the follow-up commit: the same stress runs, a config test that fails on the old parser, and npm run check, npm test (28 passing), and npm run verify:tla passing locally.

Reviewed with sol-loop: 2 rounds with gpt-6.2-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code.

…LA+ model

When an agent gets something wrong, fix it at the cheapest layer that can
hold the fix: the code's shape, then static checks, then runtime and
formal verification, and prose only for what code cannot express.

- Branded ids, a pending/leased job union, typed routes, and a config
  schema make the common wrong shapes unrepresentable.
- turbo lint rules confine the clock, JSON parsing, and env vars to one
  owning module each. Fixtures test the rules, and RULE_OWNERS fails the
  build if .oxlintrc.json silences a rule anywhere else.
- invariantViolation checks every queue loaded from R2 and every commit
  before it is written.
- spec/QueueBroker.tla model-checks the compare-and-set commit protocol.
  A second config without compare-and-set must fail, so the spec still
  catches the bug it exists for. CI runs both.
- AGENTS.md states the order and keeps only rules code cannot enforce.
  The PR template asks which layer now prevents a corrected mistake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@socket-security

socket-security Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedfast-check@​4.10.210010010087100

View full report

…ope the spec

The Worker test that expects two concurrent pushes to share one commit failed
on the first GitHub Actions run: a loaded runner can miss the 5 ms batch
window. Tests now use a 100 ms window.

Config parsing used z.coerce.number, which read a blank batch window as 0 and
"0x800" as 2048. It now uses Number.parseInt(value, 10) as before the refactor.

The TLA+ spec now says it does not model batches answered from the cached
snapshot without an R2 write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@gpu004
gpu004 merged commit 3dc9a63 into main Nov 20, 2026
7 checks passed
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.

1 participant