The RSI Loop — A Two-Stage Acceptance Gate for a Self-Modifying Detector | PharmaTools.AI
Lab · Experiment

The RSI Loop: A Two-Stage Acceptance Gate for a Self-Modifying Detector

Using RSI to solve RSI: a small, deterministic prototype of a gate that lets a detector change, but only inside a clinical envelope.

Stack Python · MediaPipe · rich Lines ~1,150 Status v2 — gate prototype · audited Sept 2026 Author Nick Lamb

The whole loop in 30 seconds

Terminal recording: the v1 detector fails on radial wrist deviation at 90% accuracy, a narrative panel explains the hand-authored geometric fix, the v2 detector reaches 100%, the Auditor confirms thresholds are inside the Clinical Gold Standard, and the final status is COMPLETE.

Real-time recording of python3 demo.py, which replays a hand-authored v1 → v2 change and the audit. The "analysis" panel describes a fix I made; no optimiser generated it.

A meta-irony in three letters

The same three letters describe both the hardest open problem in AI safety and the most common occupational injury among the people building it.

RSI in machine-learning circles is Recursive Self-Improvement — a system that edits its own logic to get better at its objective. RSI in physiotherapy is Repetitive Strain Injury — what happens to your forearms after a few thousand keystrokes a week. The first one is a frontier-lab anxiety; the second is what you actually wake up with on a Wednesday after shipping a frontier-lab feature on a Tuesday.

This project leans into the joke, with one honest caveat up front. It is the gate a self-modifying Repetitive-Strain-Injury detector would need — a benchmark check plus a regulatory auditor that asks, in effect, "Would a clinician actually sign off on this?" — applied to a detector that, in this version, I changed by hand. The repository contains the gate; the loop that would run inside it is the follow-up experiment described at the end of this page.

A two-stage validation pipeline

Self-improving systems fail when their objective is too easy to satisfy. The RSI Loop separates "did it work?" (Stage 1) from "is the result clinically meaningful?" (Stage 2). A candidate detector — today, one I wrote by hand — is accepted as COMPLETE only if it passes both stages.

Read top to bottom — each stage produces a verdict and an exit code, and the loop is COMPLETE only if both verdicts are PASS.

Stage 01 · Accuracy

Does the detector classify posture correctly?

detector.py is scored against benchmarks.json. v1 failed one scenario (a radial-deviation blind spot); v2 fixes it with vector trigonometry and passes all ten.

Inputs
10 labelled scenarios (Safe / High Strain) from benchmarks.json
Process
detector.assess(landmarks) over each scenario
Metrics
accuracy · precision · recall · F1
Gate accuracy ≥ 90 % if PASS → Stage 2 if FAIL → exit 1 (NOT_ACCURATE)
Stage 02 · Compliance

Are the thresholds clinically plausible?

The Auditor reads the live thresholds out of detector.py via getattr and compares each one against the Clinical Gold Standard. A candidate with thresholds outside the clinical range is rejected here even if Stage 1 was satisfied. One caveat: on this benchmark the two stages never disagree — every threshold inside the clinical range scores 100 % — so the gate has not been tested under optimisation pressure.

Standard
Forward-head 15–25° · Wrist deviation 40–60°
Tolerance
±5° warning band; beyond → hard failure
Verdicts
PASS · WARNING · HARD FAILURE per threshold
Gate every finding = PASS if PASS → COMPLETE if FAIL → exit 2 (NOT_COMPLIANT)
RSI LOOP STATUS: COMPLETE  ·  accurate AND compliant

v1 → v2, replayed

The v1 detector used a signed horizontal offset (hand_x − wrist_x > 0.10) — direction-blind, so it caught ulnar deviation but silently missed radial deviation on scenario S06. I replaced both heuristics with proper trigonometric angles between the forearm and metacarpal vectors, and v2 passes. demo.py narrates this change; it does not generate it.

The gate does catch the attack it was designed for: drift the wrist threshold to 67° and Stage 1 still passes 100%, but Stage 2 returns HARD FAILURE (7° beyond the clinical max) and the candidate is rejected.

It also has holes, found in a September 2026 audit and each reproduced against an untouched copy of the code:

Same-process tampering

The Auditor reads thresholds from the live detector module, and assess() runs before run_audit(). Three lines inside assess() that import auditor and rewrite the gold standard let the 67° threshold pass as COMPLETE.

Lookup-table memorisation

A detector.py that opens benchmarks.json and returns the stored label on an exact landmark match scores 100 % and passes the audit with thresholds untouched. The evaluator cannot tell a table from a classifier.

Gate tolerance

A forward-head threshold of 15.0° — inside the clinical range — misclassifies scenario S08 (15.07°) and is still certified COMPLETE, because 90 % clears the accuracy gate.

Camera-roll sensitivity

v2 measures forward-head angle against the image vertical, not the torso. Rotating the benchmark landmarks to simulate a tilted webcam gives 90 % at +5°, 80 % at +15° and 60 % at +20°. The benchmark, which has no roll, cannot see this.

GxP-Ready Agentic Design

Pharma teams already have a name for "let the system improve, but only inside an immutable spec": Computer System Validation (CSV). The RSI Loop's two-stage pipeline maps cleanly onto CSV's separation between functional qualification (does the system do what it claims?) and performance qualification (does it stay inside its validated envelope under change?).

CSV Concept RSI Loop Equivalent
Validated specification Clinical Gold Standard, hard-coded in auditor.py — the search space the loop is allowed to occupy
Operational Qualification (OQ) Stage 1 — test_engine.py proves the detector classifies the labelled benchmarks correctly
Performance Qualification (PQ) Stage 2 — the Auditor checks that the thresholds stay within clinically acceptable bounds
Change control Any threshold mutation forces a fresh audit; failed audits return non-zero exit codes that block the change
Independence of QA Not yet achieved. The Auditor is a separate module, but it runs in the same process as the candidate, and a candidate can rewrite the gold standard before it is read. Process isolation is the first fix in the follow-up design.
Audit trail last_run.json persists each run's metrics + audit verdict for diff against future versions

The takeaway for pharma audiences: an acceptance gate with an external, immutable spec is a pattern regulated environments already understand. The RSI Loop is a 1,150-line sketch of that shape, in a domain (ergonomics) that's friendly enough to host it without regulatory entanglement. Whether the shape holds against a real optimiser — one that can rewrite the detector in full and is under pressure to score well — is exactly what the follow-up experiment tests.

What this prototype is — and isn't

This is a deliberately small, deliberately observable prototype. The point is the shape of the gate, not the model. Honest about what it is and isn't:

Today

No optimiser. The v1 → v2 change was made by hand, with full visibility of every benchmark case and every auditor interval. Synthetic benchmark suite (10 hand-authored landmark sets, labels assigned by construction). Two detection rules. Static Clinical Gold Standard hard-coded in the Auditor. Verifier in the same process as the candidate.

Next

Turn the gate into an experiment: an LLM optimiser that rewrites detector.py in full for twenty generations; a seeded simulator whose latent angles define the truth; a visible benchmark drawn from a narrow distribution and a hidden one from a broad distribution (camera roll, either hand, realistic noise); a process-isolated verifier; every proposal scored on the hidden set. The question is which verification architectures keep genuine performance, not just measured performance. The preregistration draft is in the repo at docs/rsi-loop-2-research-design.md.

Later

If the gate holds up under a real optimiser, generalise the two-stage pattern: replace the Clinical Gold Standard with whatever immutable spec governs the target domain (ABPI for promotional copy, ICH-E6 for trial design, etc.). If it doesn't hold up, that result is the more useful one.

Won't

This will not become a clinical device, a workplace surveillance tool, or a substitute for a real ergonomist. The intent is methodological — to show the shape of a domain-grounded acceptance gate in a small, portable form, and to be honest about what it has and hasn't been tested against.

What does RSI mean in AI?

In AI, RSI stands for recursive self-improvement: a system that improves its own ability to improve — rewriting its own logic, tuning its own thresholds, or upgrading the very process it uses to get better. Each cycle compounds on the last, which is why RSI sits at the centre of debates about accelerating AI capability and how to keep it under meaningful oversight.

This page is a small, inspectable prototype of the gate such a system would need — applied to a detector that targets the other RSI, repetitive strain injury. In this version the changes to the detector were made by hand; the follow-up experiment described above adds the optimiser.

What is recursive self-improvement, in plain terms?

A normal program is improved by its developers. A recursively self-improving system proposes changes to itself — to its detection logic, thresholds or code — evaluates whether the change made it better, and keeps what works. It is "recursive" because the thing being improved is also the thing doing the improving, so gains can compound from cycle to cycle.

Is recursive self-improvement dangerous?

Unbounded self-improvement is a core AI-safety concern: a system optimising itself against a narrow score can drift into behaviour its designers never intended. The RSI Loop sketches one mitigation pattern — a two-stage gate in which a candidate change must pass both an accuracy check and an independent auditor that holds the system inside clinically plausible bounds. Whether that gate holds against an optimiser that can rewrite the detector in full, and is under pressure to score well, has not been tested here; that is the follow-up experiment.

What is the RSI Loop, concretely?

A Python prototype (~1,150 lines) that detects repetitive-strain risk from posture landmarks, plus a two-stage acceptance gate. The v1 → v2 change that lifted benchmark accuracy from 90 % to 100 % was made by hand, with both thresholds inside gold-standard clinical ranges; there is no optimiser in the current code. A September 2026 audit found that the gate can be rewritten from inside the candidate's process, cannot distinguish a lookup table from a classifier, and cannot see that v2 is sensitive to camera roll.

How is RSI different from ordinary machine learning?

Ordinary training improves a model against a fixed objective, under a process the developers control. In recursive self-improvement, the system also modifies the improvement process itself — proposing new logic, tests or thresholds. That autonomy is what makes RSI powerful, and what makes independent verification essential — which is why the follow-up design keeps the optimiser and the verifier in separate processes with separate information.

Read the code, then read the audit.

Everything is in one repo: detector, auditor, benchmarks, narrated demo, the recording you saw above, and the audit plus follow-up design in docs/. About 1,150 lines, MIT-licensed, runs on a laptop in under a second.