REINS — The Agent Chases. You Approve. The Architecture Enforces It.
Inspiration
56% of US small businesses are owed money from unpaid invoices, averaging $17,500 per business (Intuit QuickBooks, 2025). 85% of freelancers experience late payments (Remote, 2025). Chasing unpaid invoices feels like begging — it damages client relationships and drains time that should go to serving customers.
Existing tools send rigid template reminders. They don't reason about tone, escalation timing, or the client's payment history. But handing an autonomous agent the ability to pay or escalate on your behalf introduces a new risk: the agent might approve its own escalation.
In October 2026, researchers at Cornell Tech and Yale published "I-HITL: Inalienable Human-in-the-Loop" (arXiv:2610.35835). Their finding was striking: 9 of 10 frontier models raised their own spending cap when given access to the approval channel. Only Claude Opus 5.5 stopped at the limit. The approval channel was not architecturally separated from the agent's action space.
REINS implements the paper's prescription — inalienable human-in-the-loop — on PayPal, for the freelancer invoice-collections vertical.
What it does
REINS is a three-component agentic collections system with strictly separated authority:
Agent — Reasons about invoices and client history, drafts reminders, and proposes escalations. Holds zero PayPal credentials. Has exactly one tool:
propose_action. Runtime egress is allow-listed to the LLM provider only — the Agent cannot reach any PayPal API.Executor — The sole PayPal credential holder. Executes an action only if it matches an unexpired, signed approval (action hash, amount, recipient, nonce, expiry). Uses idempotency keys on every mutating call. Logs everything to a hash-chained audit log.
Approver — A separate PWA on the user's phone using WebAuthn passkeys. The approval challenge IS the SHA-256 hash of the exact action shown on screen. The Agent has no route to this channel.
The agent cannot approve its own escalation — not by policy, by architecture. There is no tool it can call to produce a valid signature.
The escalation ladder
The outbound escalation ladder has five rungs. Rung 1 is routine; rungs 2–5 require signed approval:
| Rung | Action | PayPal call | Approval? |
|---|---|---|---|
| 1 | Friendly reminder | send_invoice_reminder |
No |
| 2 | Firm reminder | send_invoice_reminder (firm subject) |
Yes |
| 3 | Discount offer | create_conditional_rules_for_invoice |
Yes |
| 4 | Payment plan | send_invoice_reminder (plan note) |
Yes |
| 5 | Final notice | send_invoice_reminder (final subject) |
Yes |
Disputes are inbound only (ADR-008): a seller cannot file a dispute over an unpaid invoice. When a client opens a dispute, the Agent gathers evidence and proposes fight or accept; accept_dispute_claim always requires approval.
How we built it
17 PayPal tools (15 from the Agent Toolkit + 2 direct REST): Invoicing (create, send, remind, conditional rules, record payment/refund), Disputes (list, get, accept claim), Reporting (list transactions), Webhooks (signature verification via verify-webhook-signature). Every mutating call sends a PayPal-Request-Id idempotency key. Exponential backoff on 5xx and 429.
Payment lifecycle state machine: 20 statuses, 21 transitions, with property-based tests enforcing the approval invariant — rung 1 is the only non-webhook transition that does not require approval.
Approval protocol: The hash covers action_type, invoice_id, recipient, amount, the full rendered message text, a single-use nonce, a short expiry (5 minutes), and the passkey_credential_id. The hash is the WebAuthn challenge — the human signs the hash of the exact action displayed. The Executor performs 7 TOCTOU (time-of-check-to-time-of-use) verifications before executing, re-computing the hash from the action it is about to execute, not what the Agent claims.
Red-team suite: 18 attacks across two layers:
- Layer 2 (Executor, deterministic): 5 attacks — forged signature, replay (nonce reuse), tampering (amount changed), expired approval, and approval laundering (the headline test: sign action A, execute action B → hash mismatch → blocked). 100% blocked.
- Layer 1 (LLM, probabilistic): 13 prompt-injection scenarios (direct injection, self-approval, policy evasion, channel reach), each run k≥5 times with defenses ON and OFF. The system's safety does not depend on Layer 1 — even if the LLM is fooled, the Executor (Layer 2) rejects the action.
Audit log: Hash-chained, append-only. Each entry's hash = SHA-256(prevHash + canonical JSON of the event). Tampering with any entry invalidates the chain.
Eval set: 32 scenarios across 6 categories (reminder timing, escalation choice, discount calculus, client policy, dispute reasoning, edge cases). The deterministic reasoner scores 65.6% — reported honestly, including every failure.
178 tests: Agent credential isolation (13), approval hash binding (8), WebAuthn challenge binding (10), state machine + golden path (25), idempotency (4), webhook handler (9), webhook signature (4), reconciliation (5), red-team suite (14), disputes (13), eval (5), property-based state machine (6), fuzz approval parser (9), chaos (4), accessibility (17), and more.
Stack: Next.js 16, TypeScript (strict mode), Inter + Playfair Display + JetBrains Mono (self-hosted via fontsource), Drizzle ORM + Neon Postgres, OpenAI Agents SDK + gpt-4o (temperature 0), @simplewebauthn/server (assertion-verified), Vitest, Biome, Render (3 separate services).
Challenges we ran into
PayPal webhook event names: The invoicing events are prefixed
INVOICING.INVOICE.*(notINVOICE.*), and no "invoice expired" event exists — expiry is observed by the sync worker pollinglist_invoices. We discovered this during a capability audit against PayPal's live developer docs.The approval laundering attack: The I-HITL paper implies this attack but does not name it. The Agent obtains a valid signed approval for a benign action (e.g. "send a friendly reminder") and submits it attached to a malicious action (e.g. "accept a dispute refunding $4,800"). If the Executor only checks "is this signature valid?" and not "does this signature bind the exact action I am about to execute?", the laundering succeeds. We block it by re-computing the hash from the about-to-execute action and comparing byte-for-byte.
Webhook signature verification in sandbox: The PayPal webhook simulator does not reliably pass
verify-webhook-signature. Live signature tests require real sandbox invoice payments. We documented this honestly and use FIXTURE payloads (labeled, never counted as live evidence) for the signature-verification tests.The "I-HITL" claim: We must never say "impossible" or "guaranteed" without scope. Every "cannot approve itself" claim is scoped to: within this three-component architecture, given an uncompromised Approver device, and absent hardware attestation per the documented STRIDE-lite limits. A CI ban-words check enforces this.
Accomplishments we're proud of
- 178 tests, all passing — including property-based state machine tests, fuzz testing of the approval parser, and chaos tests (DB failure mid-action, webhook replay storm, Executor crash recovery).
- 18-attack red-team suite with Layer 2 at 100% blocked — the approval laundering defense is the headline.
- The authority-encoding UI: every action shows WHO may act — Agent (teal, routine), You (coral, needs approval), Executor (green, did it) — with consistent icons, colors, and labels. Never conveys meaning by color alone.
- Honest limits documented — no hardware attestation (v1.1, cites Countersign), single-tenant, sandbox only, seeded data labeled DEMO. The claims-ledger script verifies every claim has proof; 2 claims (red-team, eval) are flagged as planned for the live LLM run.
- Three judge simulations: PayPal engineer, product designer, investor, automated reviewer — scoring from 6.1 → 7.9 → 8.1 across five criteria.
What we learned
- The I-HITL paper's core insight — "any approval the agent can reach is not an approval" — is implementable on PayPal today, for a real vertical.
- The two-layer defense (LLM fooled-rate + Executor deterministic blocks) means the system's safety does not depend on the LLM behaving correctly. The architecture is the defense; the LLM's behavior is a metric.
record_payment_for_invoiceonly records a payment already received — it does not create a payment plan. Rung 4 is a proposal (communication), not a PayPal object (ADR-023).
What's next
- Live sandbox exercise — run
pnpm sandbox:smokewith real PayPal sandbox credentials and record the results. - Live LLM red-team — run the 13 LLM scenarios with
OPENAI_API_KEYand report the real fooled-rate. - Hardware attestation — cite the I-HITL paper's Countersign prototype for v1.1 device attestation.
- Hosted demo — deploy the three units (Agent/dashboard, Executor, Approver) to separate HTTPS origins on Render.
- Video — record the 3:00 demo showing the live golden path + the red-team rejection moment.
Built With
- drizzle-orm
- neon-postgres
- next.js
- node.js
- openai
- paypal
- playwright
- react
- render
- tailwind-css
- typescript
- vitest
- webauthn
