The old payment link has expired. You try to create a new one, and the system says there's already a request in progress. How can both be true? In the code we reviewed, expiry and the stored request status had drifted apart.
If you’ve ever had a website insist that something is still active after it stopped working, you know how maddening that feels. The link was done. The database just hadn’t gotten the memo.
We followed this one through Git history with AI helping us compare revisions. It's a business-system example, with identifying details and real order data left out. The history shows how the code changed; it doesn't tell us whether AI helped write the original fix.
The rule made sense—until time got involved
The duplicate check had a sensible job: don't let staff create a second payment request while one is unfinished. When the first link still works, that's exactly the behavior you want.
The catch was time. The duplicate check read the stored status without checking the request's age. Elsewhere, the system treated a link as expired after 48 hours. Opening that expired link could mark its record invalid. Leave it unopened, though, and the record could keep looking unfinished.
So the two parts of the system disagreed. One said, “This link has expired.” The other said, “There’s still a payment request in progress.” The second answer won, and the new link never got created.
What the Git history revealed
The history filled in the sequence. The partial-payment feature came first, then a dedicated permission check a few days later. About a month after the original change, another commit addressed expired records blocking the next request.
The permission review is a separate case from this expiration problem. They concern the same feature, but answer different engineering questions.
We couldn't get that explanation from the messages alone. We had to read the earlier and later code, then follow both the expiry check and the path that creates a request.
One detail was easy to get wrong: a comment mentioned 15 minutes. That check had been commented out; the active rule was 48 hours. It's worth checking the condition itself before copying a number from a comment into your own fix.
The fix cleans up the old request before checking for duplicates
The newer code deals with eligible expired requests for the current order first. If an unfinished request is old enough to expire, it marks it invalid. Then it runs the duplicate check again, so a genuinely active request can still block a second one.
Both steps sit inside the same transaction. So if a later check rejects the request, or creating it fails, the cleanup rolls back too. That detail matters when you're trying to understand what remains in the database after an unsuccessful attempt.
The cleanup happens when someone tries to create a request. There isn't a scheduled sweep here clearing every old payment record.
What still needs testing
Before treating this as a finished fix in your own system, we'd check a few cases:
- An expired unfinished request should stop blocking a new one.
- A recent unfinished request should still prevent a duplicate.
- If another active request exists, the operation should fail and the transaction should restore any status it changed.
- If creating the new request fails, the transaction should roll back the cleanup.
- Simultaneous requests and delayed payment callbacks need a closer look at the surrounding locking and callback logic.
Those are the tests we'd want to run in a safe environment. This review followed the source code; we didn't run the scenarios against production or verify the deployment date.
A useful way to investigate “stuck” records
If you're chasing a similar ‘still in progress’ message, put three things side by side: the status in the database, the expiry condition, and the code that updates the status. Time can run out on a link without anything having written that fact back to its record.
Then follow the sequence from the old link to the new request:
- Find the rule that decides whether the old link is still usable. Read the active condition, not only its comment.
- Find the query that blocks duplicate requests. Check whether it reads status, creation time, or both.
- List every path that changes the stored status. Ask what happens if the expired link is never opened again.
- Inspect the creation transaction. If it marks an old request invalid and a later step fails, determine whether that change rolls back.
- Test an expired request, a recent request, and two competing requests in a safe environment. Record the observed result rather than assuming the code covers every timing case.
AI was useful for finding related commits and following the two paths together. The important part was checking the conditions it found. To find out what users actually experienced after the change, we'd still need deployment records and monitoring.
Check the stored state after a failed attempt
For a synthetic test, give one order an expired unfinished request and another active request. The cleanup may invalidate the expired record temporarily, but the active request should reject creation. Under the transaction described above, that rejection rolls the cleanup back. Inspect the stored state after the transaction finishes; a log line from inside it is not enough.
| Starting point | Expected committed result |
|---|---|
| Expired request only; creation succeeds | Old request invalid; one new request created |
| Expired request plus active request | Creation rejected; cleanup rolled back |
| Expired request; creation fails | No new request; old status restored by rollback |
These are proposed checks, not newly measured production results. Download the expiry test worksheet to record what your implementation actually does. It also leaves concurrency and delayed callbacks as separate investigations.
