[PR #269·274·283·285·288] Right Even When It Arrives Twice or at Once: Comparing Repeated Request Numbers and Locking Task Actions
These five PRs built the server requests for Detail 4 (quests, routines, head office review). They were merged one after another in a single day, and all of them held on to one question: if the same request arrives twice, or two people change the same thing at once, is the result still right?
- PR 269: rejecting different content under the same request number
- PR 274: the customer app’s list of device input and refill records
- PR 283: the customer app’s today’s tasks, task actions, and undo
- PR 285: admin web review of problem reports, routines, quest list versions, and an order column for the action history
- PR 288: moving a cycle to a new quest list version, and sending and canceling head office quests
The models were as follows. Everything ran on my Windows computer.
- PR 269: the lead session (the Claude session that hands work out to other sessions, Claude Opus 5.5) did the work instructions, implementation, verification, docs and PR, and Codex (
gpt-6.1-terra) wrote the tests. - PR 274: the lead session (Claude Opus 5.5) did the tests, work instructions, verification, docs and PR, and Codex (
gpt-6.1-terra) did the implementation. - PR 283·285·288: the server track session (the Claude session in charge of server work, Claude Opus 5.5) did the work instructions, implementation, verification, docs and PR, and Codex (
gpt-6.1-terra) wrote the tests. - For all five PRs, the final review was
codex exec review(Codex reading the changed code to find things to fix).
| PR | What was done | Who wrote it | Result |
|---|---|---|---|
| 269 | Reject different content under the same request number | Claude (implementation), Codex (tests) | 5 unit tests and 18 flow tests; review found nothing to fix |
| 274 | A list of device input and refill records | Claude (tests), Codex (implementation) | 6 tests failed first, then passed; review found nothing to fix |
| 283 | Today’s tasks, task actions, and undo | Claude (implementation), Codex (tests) | 11 tests passed; 2 review findings applied |
| 285 | Admin review, routines, versions, and a history order column | Claude (implementation), Codex (tests) | 17 new tests passed; 1 review finding applied |
| 288 | Moving cycles and head office quests | Claude (implementation), Codex (tests) | 9 tests passed; 3 review findings applied |
PR 269: Reject different content under the same request number
What was done and why
The customer app attaches a request number to every save request, and if it gets no response, it resends with the same number. Until now, when the same number arrived, the server returned the first result without looking at the content. So if a bug in the app sent different content under the same number, the customer was told “saved” while only the first content actually remained. That is silent data loss (data disappearing without the user knowing). I decided to put this into Detail 4.
The six save points from Detail 3 (input records, post-input checks, material preparation, count changes, device input, refills) now also store a hash of the request body (SHA-256, a short fingerprint of the content). When the same person resends with the same number, the hashes are compared: if they match, the first result comes back; if not, a 409 (conflict) error. Two copies arriving at the same moment go through the same comparison.
What was chosen, and what was dropped
| Chosen | Dropped alternative | Why it was dropped |
|---|---|---|
| Store only a hash of the request body and compare it | Store the whole request body and compare it | The table grows, and personal notes would be stored twice |
- Hash JSON with keys sorted by name: if the app sends the fields in a different order, it still counts as the same request. Array order has meaning, so it is kept.
- One place for the comparison: one comparison function is called from all six places, and the later task actions (PR 283) use the same function.
- A hash column that may be empty: rows saved before the column existed have no hash, so they are not compared and the first result is returned. Old rows don’t need filling in, and it is easy to roll back.
- Dropped alternative — storing the whole request body to compare: the table grows, and personal notes would be stored twice.
How it was checked
- Codex wrote 5 unit tests and 18 flow tests (six places × same body / different body / old row with an empty hash).
- While reviewing the tests, Claude found that for two append-only tables (tables where the database blocks edits and deletes), the test setup that “empties the hash” would fail for the wrong reason. Codex changed the setup to switch off that guard briefly for those two tables only.
- An existing test rolled back an earlier migration (a file that changes the database structure) and re-applied it. Because the new column attaches to a table that migration creates, the tests passed when run alone and failed when run together. Claude changed the test to roll back and re-apply the new migration as well.
- The full
npm run verifypassed, andcodex exec reviewfound nothing to fix. - The comparison for two copies arriving at the same moment was checked only by reading the code (no separate test).
PR 274: A list of device input and refill records
What was done and why
In Detail 3, the customer app could save device inputs and refills, but there was no list to look back over past records. This was another item I decided to move into Detail 4. Picking a module shows the input and refill records of the site that module belongs to, for the last 30 days by Korean date including today, newest first.
- Devices belong to a site, so records left by other people from other modules on the same site are shown, and records from other sites are not.
- Edited records show their current values, and removed records are shown with a “removed” mark.
- The list can be filtered to one device, and the amount on a refill row is the final amount after the refill.
What was chosen, and what was dropped
| Chosen | Dropped alternative | Why it was dropped |
|---|---|---|
| The server joins both tables in one query and returns the list | The customer app builds the list from several Detail 3 requests | More requests, and each app could cut the 30 days differently |
- Claude wrote 6 tests first (all confirmed failing with “no such route”), and Codex implemented the request.
- The input and refill tables are combined in a single query, with device and author names attached at once. Nothing is fetched row by row.
- The 30 days are cut at Korean midnight. A test confirmed that a record at 23:59 on November 17 Korean time is left out and one at 0:00 on November 18 stays in.
- Dropped alternative — having the customer app build the list from several Detail 3 requests: more requests, and each app could cut the 30 days differently.
How it was checked
- 6 tests: row shape and order, the 30-day boundary, filtering by device, removed and edited records, same site versus other site, and rejecting people who are not assigned.
- Claude fixed its own test once. Moving the clock forward more than a month made the login token expire and return 401 (login required). The test now gets a new token after moving the clock; the implementation was not changed.
- The full
npm run verifypassed, andcodex exec reviewfound nothing to fix.
PR 283: Today’s tasks, task actions, and undo
What was done and why
Three server requests were built so that the customer app can see “today’s tasks,” act on a task (done, normal, problem, skip), and undo. Customer responses do not include head office notes or admin names.
What was chosen, and what was dropped
| Chosen | Dropped alternative | Why it was dropped |
|---|---|---|
| On a repeat request, return the task’s current state | Store the first response and return it again | Returning the current state means no response needs to be stored |
- Check the request number before the revision number: each task has a revision number that goes up by one with every change, and if the app’s revision number is stale, the request is rejected as a conflict. But when an app that missed the response resends the same request, its own action has already raised the revision number. So the order was flipped: the request number is checked first, and if the content matches, the task’s current state is returned. Different content, or a number belonging to a different task, is rejected.
- Compare the revision number after locking the row: the task row is held with
FOR UPDATE(a database lock that keeps others from changing this row), and only then is the revision number compared. If two people mark a task done with the same revision number at once, only one is saved, and the other gets a conflict error along with the current task. - A task that has ever had a problem report cannot be undone.
- Dropped alternative — storing the first response for a request and returning it again: returning “the task’s current state” means no response needs to be stored.
- Two things found in the first
codex exec reviewwere fixed.- A module without a cycle can still have tasks to show because of other modules on the same site, but sending a “blocked” flag along with them made the app show its notice first and hide the list. Blocked is now sent only when there are no tasks to show.
- Skipping a head office quest still accepted and stored an amount used. A skip has no amount used, so it is now rejected.
- The second review found one more: if two history rows for the same task are saved in the same millisecond, their order can flip. Fixing it meant adding a new order column to the database (a structural change that is hard to roll back), so it was not fixed in this PR and I was asked instead.
How it was checked
- Codex wrote 11 tests. Before implementation all failed (no such route); after implementation all passed without changing the tests. They cover two people finishing at once, resending the same request after the revision number went up, hiding head office notes, and permissions, among others.
- The full
npm run verifypassed both after implementation and after the review fixes. - The run that gave Codex its instructions ended with exit code 3 after the test files were written. The Git config file shared across the repository had changed during the run (traces of another session creating a branch). Claude stopped without taking the tests and asked, and I accepted them, so they were brought in.
PR 285: Admin review, routines, versions, and an order column for history
What was done and why
Server requests were built for head office to review problem reports in the admin web (confirm, or ask for a re-check) and to manage routines and quest list versions. And for the history-order question raised in PR 283, I answered “go with the recommendation,” so an order column was added to the action history. History is now always listed by this column.
What was chosen, and what was dropped
| Chosen | Dropped alternative | Why it was dropped |
|---|---|---|
| Check quest items at save time | A structural change that loosens the database constraints so checks happen only at approval | Hard to roll back, and checking at save time gives the same screen flow |
- Review also compares the revision number after locking the row: if two admins confirm the same problem report at once, only one is saved and the other gets a conflict error.
- Admin responses built on customer responses: the functions that build customer responses are reused, and admin responses only add head office notes and the admin’s name.
- Quest items are checked when saving: the plan said empty titles, duplicate codes, and date gaps would be checked “at approval.” But an earlier task had already added database constraints that keep such items from being saved at all. So the same checks run at save time and return a list of what is wrong. At approval, the check is whether there are no items at all.
- Dropped alternative — a structural change that loosens the database constraints so checks happen only at approval: hard to roll back, and checking at save time gives the same screen flow.
- Approvals run one at a time: approval runs under a transaction lock (a named lock that lets only one in at a time), so even if two drafts are approved at once, only one approved version remains.
- Existing rows got numbers in no particular order when the new order column was added, but there is no production data yet, so this was left as is.
codex exec reviewfound that the review list’s page size differed from the admin web (50 rows on the server, 20 on screen), and it was set to 20 like the other admin lists.
How it was checked
- Codex wrote four test sets (review, routines, quest versions, history order). A full verify before implementation confirmed that only the new tests failed.
- Three test defects were not fixed by Claude directly but by giving Codex short instructions: a “reject approval after saving bad items” test that didn’t fit the database constraints, a test that compared a date column to a string the wrong way, and a test whose token expired after moving the clock.
- After implementation, the 17 new tests passed. According to the PR description, the full
npm run verifypassed as well. - One Codex run that Claude had stopped left behind a loop still waiting for the lock, which then took the lock and ran. The lock held, but the lesson was that stopping does not reach processes outside the shell loop.
PR 288: Moving cycles and head office quests
What was done and why
Server requests were built for head office to move a running cycle to a new quest list version in the admin web, and to send head office quests to a specific module and cancel them. Before moving, it shows how many quests were already created, how many will change text or date, how many will be new, and how many will disappear. Moving leaves already-created tasks and the original pinning date as they are. A head office quest sent for today creates its task in the same transaction, so the customer sees it on refresh.
What was chosen, and what was dropped
| Chosen | Dropped alternative | Why it was dropped |
|---|---|---|
| Change only the cycle’s pinned version | Delete or re-create not-yet-created tasks when moving | Tasks are created on their day, so the next creation already uses the new text |
- There is only one destination: “the current approved version.” If there is no approved version, the cycle isn’t pinned yet, or it is already on that version, the move is rejected.
- Moving takes the same lock as approval. If another version is approved during a move, the move should see the version after that approval finishes.
- Dropped alternative — deleting or re-creating not-yet-created tasks when moving: tasks are created on their day, so changing only the pinned version means the next creation uses the new text.
- All three things found by
codex exec reviewwere fixed. The first two are the concurrency gaps the review found in this batch.- Task creation could read the cycle before a move and then insert old-version quests after it. Task creation now reads the cycle row with
FOR SHARE(a shared lock: many can read together, but anyone changing the row must wait). Moving usesFOR UPDATE, so the two take turns. - Task creation could read a head office quest before it was canceled and insert the task after (so the customer would see a canceled quest). The head office quest row is now also read with a shared lock and its canceled state is checked.
- A very large page number caused a server error (500). It now uses the page-number check function like the other admin lists.
- Task creation could read the cycle before a move and then insert old-version quests after it. Task creation now reads the cycle row with
How it was checked
- Codex wrote 9 tests (3 for moving, 6 for head office quests), and all were confirmed failing before implementation. They check that after a move, already-created tasks stay the same and the next day brings the new version’s text, and that a canceled quest disappears from the customer list but stays in the detail history.
- After implementation, 2 failed because site names collided in the test setup, and Codex fixed them from short instructions (Claude did not fix the tests). After that all 9 passed, and after the review fixes, 90 related tests passed.
- According to the PR description, the full
npm run verifypassed before merging main in; after merging, the conflicts were resolved and the type check passed. - After the author of a test commit taken from Codex’s working clone was rewritten to this repository’s name (an amend, which rewrites a commit), the next Codex run failed to notice the clone had moved forward and stopped after 2 seconds. The clone was aligned to the branch tip and the run was repeated.
Lessons
- A repeated request number is only safe once “same content” is checked too. Looking at the number alone lets different content from a bug disappear quietly as “saved.”
- The order of checks changes the result. The resend check has to come before the revision check so that an app that missed a response doesn’t get a false conflict. The revision comparison has to come after locking the row so that only one of two people is saved.
- There is a gap between reading and writing, too. Places like task creation that read a value and write later should read with a shared lock so nothing changes in between. The review found two of these gaps.
- If timestamps can tie, keep an order column. Two rows saved in the same millisecond can’t be ordered by time alone.
- Cut date ranges at Korean midnight, and test both sides of the boundary. When a test moves the clock a long way, think about when the login token expires as well.
- When three sessions share one Git repository, the watcher raises false alarms. Merely creating a branch in another session stopped the Codex run watcher. Also, a loop waiting for a lock can outlive a stopped run, and rewriting a clone’s commit leaves the next run lost. In the clone, commit as this repository’s author from the start.