-
-
Spoilclock: a rejected load sold before it spoils. AI agents negotiate, and PayPal holds the money until the dock accepts.
-
The farm's trucks for the day on a Bryntum schedule. Truck 14's strawberries were just turned away.
-
The grower's agent negotiates with three buyer agents. Code holds her floor; the price ladder shows every round.
-
The grower approves the deal. PayPal authorizes the payment on the buyer's saved card: held, not taken.
-
At the new dock, the receiver checks the load on a phone: accept, mark pallets short, or reject.
-
One pallet short: PayPal takes payment for 15 and releases the rest. Each step is confirmed by PayPal's signed webhook.
-
Report any rejection: the AI reads the inspection PDF or photo and fills in the grade, softness and temperature.
-
How it's built: what the AI can't do. Floor and buyer limits in code, a person approves, PayPal holds the money.
Inspiration
In 2024, 29% of the US food supply went unsold or uneaten, worth $381 billion (ReFED). ReFED also finds that strict cosmetic standards leave imperfect-looking produce without buyers.
When a truck of strawberries is turned away at a distribution center, the clock is the enemy. A broker phones buyers one by one while the fruit warms up, and whoever answers first sets the price. Buyers increasingly have software agents of their own. We wondered what it would look like if the grower had one too, and both agents could settle the deal through PayPal on the spot.
Who it's for, and who would pay. Growers and the shippers or brokers who sell for them. Spoilclock would charge a small fee per rescued load, only when a sale settles through PayPal, so it costs nothing when nothing is rejected.
What's simulated. The farm and its buyers are fictional, and the buyer agents' price limits are illustrative, not market data: real prices for rejected produce vary widely. Everything PayPal does is a real sandbox API call.
What it does
- Report a rejection. The grower clicks the turned-away delivery on the Today board and attaches the inspection report or a photo. The AI reads it (reason, grade, % soft, pulp temperature) for the grower to check. A rescue clock starts from the crop's shelf life.
- The agents negotiate. The grower's agent trades offers with three buyer agents at once. Each buyer agent has private limits the grower's agent can't see. Code enforces the floor, the whole load and the clock.
- Talk to your agent. In the load's chat, "Don't sell to Bargain Fresh" or "Raise my floor to $160" changes the rule, and the agent negotiates by it.
- The grower approves. PayPal authorizes the price on the buyer agent's card saved in PayPal's Vault. Nothing is charged yet, and the truck's new delivery appears on the schedule.
- The new dock decides, on a phone. On every option, the screen first shows what PayPal will do with the money:
- Accept: PayPal captures the payment.
- Some pallets short: PayPal captures part and releases the rest.
- Reject: PayPal voids the authorization, and the agent goes back to the other buyers.
Each visitor gets a private copy of the farm's day, so every judge runs a full rescue of their own.
How we built it
- PayPal (sandbox):
- Orders v2 with
intent: AUTHORIZEon a Vaultvault_id. - Payments v2: authorization capture, full and partial with
final_capture, and void. - Vault v3 payment tokens for the buyer agents' test cards. Spoilclock stores only the token and the last four digits.
- Webhooks verified against PayPal's signature on the raw bytes.
- Orders v2 with
- AI: OpenAI
gpt-5.4-mini. The grower's agent has a forced plan, read-only tools and one structured move per round. Each of the three buyer agents is a separate call with its own private brief. There's also the load chat, and a paperwork reader for PDFs and photos. - Rules in code (
src/lib/rules.ts, unit-tested):- asks never go below the floor, and bids never above a buyer's own limit;
- one buyer for the whole load, unloaded before the fruit spoils, at an open dock;
- on the last round, code takes the best allowed bid if the model doesn't.
- Bryntum Scheduler for the Today board. The agent drives the schedule itself: the rescued load's new delivery lands on the board.
- App: Next.js 16 on Vercel, Neon Postgres, a private run per visitor.
Challenges we ran into
- An agent that was too eager. The first grower's agent sold at exactly the floor. It now sees each buyer's bid trail and haggles.
- Bundling Bryntum took the build past 6 GB of memory. It's now served as a prebuilt file.
- Live updates canceled each other on a slow connection. Each refresh now waits for the last.
- The unhappy path. A dock rejection followed by a second sale deleted the record of the void, and buyers who'd lost to the failed deal were left out of the retry. Both fixed, and tested on the live site.
Accomplishments that we're proud of
- The negotiation's eval suite: 6 scenarios, each run 3 times with the real agents: a standard load, a ruled-out buyer, fruit too soft for one buyer, a floor only one buyer can reach, a floor no buyer can reach, and peaches. 18/18 runs passed (198/198 checks): every deal closed above the floor (15/15), there was no deal every time none was possible, and the floor was never revealed to a buyer. About 17 model calls and 2 cents per negotiation.
- A full rescue, end to end, on the live site with real PayPal sandbox calls: authorize on a Vault card, then full capture, partial capture or void from the dock, each confirmed by PayPal's signed webhook.
- The unhappy path works too: the dock says no, PayPal releases the hold, and the agent sells to the next buyer.
- A click-through test passed 13 of 13 checks on the live site, all 15 live PayPal webhooks were verified, and a negotiation takes 16–20 model calls and 17–26 seconds.
What we learned
Agents trading with agents is the easy part to demo and the hard part to trust. What makes it safe is that code, not the model, decides what stands:
- the floor, the buyer limits and the clock are enforced in code;
- a person approves every deal;
- PayPal holds the money until someone at the dock looks at the fruit.
What's next for Spoilclock
- Real buyers' agents over an agent-to-agent protocol, in place of our simulated ones.
- PayPal Payouts for the carrier's redelivery fee.
- Reading USDA inspection certificates directly.
Built With
- bryntum
- drizzle
- neon
- nextjs
- openai
- paypal
- paypal-orders
- paypal-vault
- postgresql
- react
- tailwindcss
- typescript
- vercel