One Brain, Two Front-Ends: Refunded Twice on Sale Day

Yaqin Hei ·

One Brain, Two Front-Ends: Refunded Twice on Sale Day

Day one of the big sale, a complaint popped up in the support console: a user filed one refund and received two payouts. Finance caught it first, during reconciliation. The same refund order number had two payout records under it, identical amounts, less than a second apart. Support pulled the conversation. The user had filed once, and had clicked "confirm refund" exactly once on screen. The user clicked once. Why did the money go out twice?

It was not a display bug. Real money left the building twice. Everyone's first instinct was that the user had double-clicked, but the front-end log shows that click was clean: exactly one. The second time was fired by a machine. The refund logic was not wrong either. One request maps to one refund, and it is tested. Trace up the chain and the problem is inside no single agent. It sits on the unwatched seam between two entry points.

This system is one brain, two front-ends. The public-channel front-end is the marketplace's built-in support entry. The private-channel front-end is the brand's own mini-program or community entry. The two front-ends are independent, but they share one agent brain behind them, and a write operation like a refund goes through the same adapter layer down to the refund service. The one that broke that day was the private-channel front-end. It called the adapter to issue a refund, a network hiccup timed the response out, and by default the front-end retried once. The first request had already reached the refund service and already executed. The two requests were 800 milliseconds apart, with different request IDs. The refund service saw two requests that looked different, and honored both. Two refunds.

In one line: one brain wired to two front-ends, and the moment the shared write layer has no idempotency key, one timeout retry is one duplicate refund. The real bottleneck of multi-agent delivery is organizational integration, not model quality. Below, that seam is broken into four pitfalls that actually happened, each of them between two agents, not inside any one of them.

The layer two front-ends share is the seam that leaks money.

The double refund is not a model error. The seam is missing an idempotency key.

The double refund has nothing to do with the model, and nothing to do with the refund logic. The fault is that the adapter where the two front-ends converge has no idempotency key. It treated a retry of the same refund as two different refunds.

Lay the two raw requests side by side at the review and it is clear. Semantically they are the same refund: the same user, the same order, the same amount. Technically, the two timestamps are 800 milliseconds apart, and the request ID is freshly generated by the front-end on each call. The refund service only knows request IDs. Two different IDs means two refunds, so it pays twice.

The root is not that the refund service is too obedient. It is that no layer owns the question "is this the same piece of business." The front-end only cares whether it sent the request and whether it timed out, and on timeout it retries. That is the front-end's job. The refund service only cares that one request in means one refund out. That is its job. The adapter in the middle, which should be the one place that knows public and private both funnel here in the end, only passed things through. It did no deduplication. It was the only one with standing to block the duplicate, and it did not.

The fix is not to touch the refund logic. It is to add an idempotency gate at the adapter: use a member plus a business request identifier as the idempotency key, and within a time window, five minutes here, let the same combination execute only once. A retry that comes in gets the first result back, and triggers no refund. Do not use (request_id, member_id) to block retries. The request ID changes on every retry, so it cannot stop a retry. What you actually need to deduplicate is the same person and the same piece of business.

Having the key is not the same as making retries safe. The gate recognizes the same key and the same business request. If error recovery mints a new key, or the retry changes the identity of the business request, the gate will not hold. A common practice in public discussion is to write the intent row for that refund first, then call the payment provider; if you have to recover after a timeout, you reuse the key you already stored, and you resend the same business request, rather than minting a new key or changing the identity of the request. Adam Jaber (@adam_jaber, 2026-10-26 13:20, Asia/Shanghai) put the same point sharply: "Your AI agent's refund tool has an idempotency key. It can still refund twice. Not because the key failed. Because the agent never sent the same request twice." He was not writing about this sale-day case, but the sentence lands in the same place. What I would lock down is this: the key is a member plus a business request identifier, and a retry must resend that same business request.

Five minutes is not an arbitrary number either. Too short, and a slightly slow retry lands outside the window and slips through. Too long, and a user's genuine second refund that day, having bought and returned another order, gets blocked by mistake. Five minutes is the balance of covering the vast majority of retry intervals without falsely hitting a real second action. Tune the number to your own retry policy and business rhythm, but someone must own it rather than leave it blank.

And this pitfall is almost impossible to catch in tests, because it only happens at the moment of a timeout. The normal path succeeds once and never retries. Only production sale-day traffic pushes the timeout probability up, retries fire densely, and double refunds surface at scale. That is the nature of seam bugs: they fall outside any unit test's coverage, because what they need is a timing mismatch between two components, and unit tests test one component. A green suite does not stop them.

Double-refund timeline: timeout → retry → executed twice, the idempotency key is the only gate

refundType is defined in reverse across the two systems. One mistranslation is one wrong refund.

A second class of leak on the seam is subtler than the double refund. Two systems define the same enum in reverse. When the adapter mistranslates once, the refund type is wrong once, and that is a direct loss.

The refund service has its own refundType enum, and the order system has one too. The two should map one to one, but look closely and their value orders are reversed. What 1 means in the refund service maps to a different value in the order system. When the adapter translates between them by mapping number to number, it turns "refund only" into "return and refund," and type A into type B. What does a wrong refund type mean? It means a case that should refund 30 yuan refunds the full amount under another type, or a case that should go through the return flow becomes a refund without a return. Every mistranslation is money computed wrong.

Concretely: a user files "refund only," no return, money back only, and on the refund service side refundType should be some value. The adapter, mapping by the order system's order, translates it to "return and refund." The system then waits for the user to ship the goods back before releasing the money. The user clearly chose not to return, the refund sits stuck, the user thinks it was never processed, and another round of complaints begins. The reverse mistake costs more. What should be "return and refund" gets translated to "refund only," the goods never come back, the money goes out first: a clean loss of one item.

The nastiest part is that it does not error. The translation succeeds, the numbers are all in range. The refund succeeds, the refund service honors it. Only reconciliation, or the user's complaint, reveals the wrong type. It hides between two enums maintained by two teams. Each looks fine on its own, and only crossing the seam to compare them reveals the mismatch.

Why are the two enums reversed? Because they were defined by two teams, at two points in time, independently. The refund service ordered by its own business logic, the order system by another historical order, and neither is wrong on its own. The fault is that no one owns the requirement that these two must be aligned. Most seam pitfalls are this shape: not that someone wrote it wrong, but that no one owns the contract between the two. Which is also why this kind of cross-team enum mismatch is the hardest tier on the whole project's blocker list. Fixing it is not editing a line of code. It is two teams sitting down to agree whose definition governs.

The two systems define the same enum in reverse, and a number-to-number mapping flips it.

The router's enum is a security boundary. Internal intents should not be reachable from the customer side.

A third seam problem: an intent used inside one agent leaks into an action another front-end can trigger. The router's enum is not just a classification table. It is a security boundary.

This system's router has an action-intent enum, ActionIntent, with 15 values to start. Look closely and several of them are internal, or desk-only, intents: operations meant for the support console, for human agents, certain back-office state transitions, certain actions only a desk agent should initiate. They sit in the same enum as the user-facing intents.

The problem is that customer input also goes through this router. When one enum holds both what users can trigger and what only desk agents can trigger, the model, classifying by semantic similarity, can route a user's line to an internal intent only a desk agent should touch. A user-facing entry accidentally gains the ability to trigger an internal operation. This is not a feature bug. It is a leak of the permission boundary. Two classes of operation that should be isolated, crammed into one enum, lose their isolation.

Concretely: the support console has a back-office state-transition action, normally only a human agent clicks it on the console. But it shares the same ActionIntent with customer-facing intents, and when a user types something semantically adjacent, the router may well route it to that desk action. An ordinary user accidentally triggers a state change only a desk agent should touch. The user needs no malice. They just said something, and the boundary collapsed on its own.

The fix is to narrow the enum: cut ActionIntent from 15 down to 10, and move the internal and desk-only intents out of the customer-facing router's enum entirely, so that router only recognizes actions the customer side should have. The principle is that a router's enum defines the boundary of what this entry is allowed to do, and whatever this entry should not do should not appear in its enum. One enum serving two subjects, users and desk agents, welds two permission classes together.

For the architecture owner, the detection signal is one line: go count the customer-facing router, and check whether its intent enum has internal or desk-only values mixed in. If it does, that is a boundary standing open. You do not have to wait for it to be exploited. The mixing itself is the risk.

Who can create a ticket is an architecture decision, not an interface tweaked later.

The last seam problem is on the data side. Several agents share one source-of-truth system, and who can write to it, and how the writes relate, must be pinned down as an architecture decision from the start, not adjusted later as an interface detail.

In this system, the ticketing system is the cross-agent source of truth. Whichever front-end or agent handled a conversation, whatever needs a human handoff, an archive, or an audit trail, lands in the ticketing system. It is the one place where every agent's actions ultimately converge.

Precisely because it is the source of truth, two decisions cannot be vague. First, who can create a ticket. If every agent and front-end can write to the ticketing system at will, the source of truth is quickly polluted. The same user issue gets a ticket from the public agent, one from the private agent, and one from the human handoff: three tickets describing one thing, and the desk agent has no idea which to read. Second, how the multiple tickets from one conversation relate. One user session may trigger several actions and generate several tickets, and without a shared key stringing them together, you cannot reconstruct what actually happened in this one conversation. The key used here is session_id: every ticket spawned from the same conversation carries the same session_id, and you join back a full conversation by it.

The mess I have actually seen is the former. In one user session, the public agent decides on a handoff and creates a ticket; midway the user switches to the private channel and keeps asking, and the private agent creates another; when a human steps in, there are two tickets describing one thing on the desk. The agent that was supposed to save labor instead handed the desk a judgment call. Joined by session_id, what the desk sees is one conversation, one user, a chain of actions, rather than a pile of disconnected tickets.

The verdict is blunt. A source-of-truth system's write permissions and join key are architecture decisions. The moment several agents start writing their own way, unrelated, the source of truth degrades into shards that do not line up. This is not some agent's implementation detail. It is the foundation of the whole multi-agent system. A bad foundation, and however right each agent is on top, together they are a muddled account.

What leaks on the seam is fixed by two teams aligning a contract, not by editing a line of code.

At the next architecture review, start by asking whether the seam can leak money.

Flip the four pitfalls over and you get a seam checklist. Its core admission is this: where a multi-agent system leaks money, permission, and truth is almost never inside a single agent, but on the unwatched seam between two of them.

When you review a multi-agent architecture, first confirm whether each of these seams has an owner. The write layer two front-ends share leaks money: is there an idempotency key, and is it a member plus a business request identifier, not the request ID that changes on every retry, and does a retry resend the same business request? Cross-system enum mapping also leaks money: is there a value-by-value table, and have both teams signed off, or does the mapping still trust number to number? The customer-facing router enum leaks permission: are desk-only or internal intents mixed into it? The shared source-of-truth system leaks truth: who can write, and what key joins the multiple tickets? Each capability's degrade path leaks fallback: when the seam breaks, can it hand off to a human cleanly?

Then five questions to press, on the spot, in the review.

Does the write layer the two front-ends share have an idempotency key? Is it a member plus a business request identifier? Do not use the request ID that changes on every retry; that will not block a retry. When a key is already there, does the retry send the same business request? A new key, or a changed request identity, defeats the gate the same way. Without a stable key, or if the retry is no longer the same business request, one timeout retry is one duplicate charge or refund.

Does every cross-system enum mapping have a value-by-value table? For an enum like refundType that two systems each define, do not trust number-to-number mapping. Get both teams to align it in writing and sign off.

Does the customer-facing router have internal or desk-only intents in its enum? One enum serving both users and desk agents welds two permission classes together. Go count, and whatever is mixed in is an open boundary.

Who can write to the source-of-truth system, and what key joins the multiple records? If every agent writes its own way, unrelated, the source of truth degrades into shards that do not line up.

What is the degrade when a seam breaks? If idempotency blocked the retry, if the translation failed, if the downstream timed out, every seam needs a clean exit, a handoff to a human or a refusal to execute, not a silent retry or a silent pass.

What these five share is one shift of view. Do not just review whether each agent does its own job right. Review whether money, permission, and truth leak on the seam between two agents. And fixing these seam problems is almost never editing code. It is getting two teams to sit down and align a contract. That is why the real bottleneck of multi-agent delivery is which team nods, not model quality.

If you want to put this seam review straight to work on the next architecture review, without rereading this essay each time, reply with the keyword SEAM-KIT and I will send the Multi-Agent Seam Checklist and these five questions: a one-page checklist covering idempotency, enum mapping, the router boundary, the source of truth, and degrade paths; a card version of the five questions; and a short note on the four symptoms of a problem that sits on the seam, not inside a single agent. These are judgment tools worn in over a year of multi-agent delivery work. The reply channels are in the footer, on WeChat or X. If neither is convenient, leave an email in the comments.

What you bought as a knowledge center and received as a search box is in Your Knowledge Center Is a Search Box. Which machine the "fix" actually landed on is in Your Code Is Fixed. Production Isn't.. The gates before launch are in Self-Serve Rate ≠ Correct Rate — The Gates a Customer-Service Agent Must Clear Before Launch. When a project stalls, the cause is often not the model, which is the argument in The Org Chart Is the Real Architecture Diagram — 90% of Stalled Agent Projects Aren't a Tech Problem.

Building an agent right now?

Send me your worst conversation. Free failure teardown.

Get a teardown →

Comments