FiCl Dev Blog한국어

[PR #267·270·272·277·278] Making Each Day's Tasks Only Once: Shared Contracts, Rule Functions, Database Indexes, a Draft Seed

Work completed 2026-11-25 05:30 KST · Published 2026-12-03 23:20 KST · AI model used for the work Claude Opus 5.5

[PR #267·270·272·277·278] Making Each Day's Tasks Only Once: Shared Contracts, Rule Functions, Database Indexes, a Draft SeedSummary figure. Agreeing first on the contract the three areas share, rule functions that calculate without the database, partial unique indexes that stop duplicates and a concurrent-approval gap, task generation that makes only the day's share with three review fixes, and a seed that goes in only as a draft with a lock for concurrent seedingPR #267·270·272·278·277Making each day'stasks only onceContract → rules → indexes → day's share → seedRun on mycomputerClaude led,built, verifiedCodex tested,built, reviewedTypesRulesIndexTodaySeedⅠContractPR 2671The contract firstTypes, error codes,policy valuesScreens start onmock responses2Two error fieldsThe current task on conflictRows a version check failedⅡRulesPR 2703Dates as textCompare YYYY-MM-DD as textUTC midnight only to add days4Close when a cycle endsA gap Codex asked aboutLeftovers become 'cycle ended'ⅢIndexesPR 2725Four partial unique indexesThe same task can't go in twiceThe database guards it6Concurrent-approval gapFound in reviewFOR SHARE makesapproval waitⅣTodayPR 278: theday's share7Leave it if it existsON CONFLICT DO NOTHINGOne task even if runs overlap8Three review fixesNarrower closing, same lockRetry on the next tickⅤSeedPR 2779Only as a draftUsed once head office approvesUnconfirmed numbers removed10The clock in testsMove the clock a day andthe admin login expiresKey: leave 'never create twice' to thedatabase; the code only makes the day's share.FiCl Dev Blog · Post summary figure
[PR #267·270·272·277·278] Making Each Day's Tasks Only Once: Shared Contracts, Rule Functions, Database Indexes, a Draft SeedSummary figure. Agreeing first on the contract the three areas share, rule functions that calculate without the database, partial unique indexes that stop duplicates and a concurrent-approval gap, task generation that makes only the day's share with three review fixes, and a seed that goes in only as a draft with a lock for concurrent seedingPR #267·270·272·278·277Making each day'stasks only onceContract → rules → indexes → day's share → seedRun on mycomputerClaude led,built, verifiedCodex tested,built, reviewedTypesRulesIndexTodaySeedⅠContractPR 2671The contract firstTypes, error codes,policy valuesScreens start onmock responses2Two error fieldsThe current task on conflictRows a version check failedⅡRulesPR 2703Dates as textCompare YYYY-MM-DD as textUTC midnight only to add days4Close when a cycle endsA gap Codex asked aboutLeftovers become 'cycle ended'ⅢIndexesPR 2725Four partial unique indexesThe same task can't go in twiceThe database guards it6Concurrent-approval gapFound in reviewFOR SHARE makesapproval waitⅣTodayPR 278: theday's share7Leave it if it existsON CONFLICT DO NOTHINGOne task even if runs overlap8Three review fixesNarrower closing, same lockRetry on the next tickⅤSeedPR 2779Only as a draftUsed once head office approvesUnconfirmed numbers removed10The clock in testsMove the clock a day andthe admin login expiresKey: leave 'never create twice' to thedatabase; the code only makes the day's share.FiCl Dev Blog · Post summary figure

Five PRs built the server foundation for Detail 4 (quests, routines, head office review). In one line, it is “make each day’s tasks only once.” A task is one line of what a site has to do that day. Even if the scheduled run and the customer app’s first view arrive at the same moment, or the app goes unopened for days, a task must not go missing or be created twice.

The order was this: first agree on the contract the three areas (server, admin web, customer app) will use (PR 267), build rule functions that calculate without the database (PR 270), make the database tables guard “never create twice” (PR 272), then add task generation that makes only the day’s share (PR 278). Alongside, a seed (a command that fills in initial data) puts the quest candidate sheet in as a draft version (PR 277).

The models involved are below. In every PR, the lead session on my Windows computer (a Claude Code session that hands out work to other sessions, Claude Opus 5.5) directed the work, and Codex (gpt-6.1-terra) wrote either the tests or the implementation. The final review (codex exec review) was done by Codex in all five PRs.

PR What was done Who wrote it Result
267 The shared contract for three areas (types, error codes, policy values) Codex (code) The lead session matched it line by line against the plan; review found nothing to fix
270 Rule functions that calculate without the database Claude (implementation), Codex (tests) 32 tests failed first, then passed
272 Database tables that guard “never create twice” Claude (implementation), Codex (tests) 11 tests passed; 2 review findings applied
278 Task creation that makes only the day’s share Claude (implementation), Codex (tests) 16 tests passed; 3 review findings applied
277 A seed that loads the quest candidate sheet as a draft version Claude (tests), Codex (implementation) 10 tests passed; 1 review finding applied

PR 267: The shared contract first

What was done and why

This was the first task of Detail 4. It set the “contract” the three areas share. Once merged, the admin web and customer app sides can build their screens first with mock responses (server answers fixed in advance) instead of waiting for the real server.

The database structure, server behavior, and screens did not change. The head office memo field went only into the admin types, not the customer types.

What was chosen, and what was dropped

Chosen Dropped alternative Why it was dropped
Hand the code to Codex The lead session writes it directly Faster, but it keeps the split where “the lead session reviews”

How it was checked

PR 270: Rule functions that calculate without the database

What was done and why

“When to create which task, and how its state changes when pressed” was gathered into one file of pure functions (functions that always give the same answer for the same input and never call the database or server). Task generation and customer actions later use these functions.

What was chosen, and what was dropped

Chosen Dropped alternative Why it was dropped
A switch statement that spells out each case Keep the state table as data and look it up The conditions are mixed, so the switch was easier to read

How it was checked

PR 272: The database tables guard “never create twice”

What was done and why

This created the tables Detail 4 stores into: quest list versions and their items, the version pinned to a cycle, routines, head office quests, the day’s tasks, and action history.

What was chosen, and what was dropped

How it was checked

PR 278: Making only the day’s share

What was done and why

This is the heart of Detail 4: “make each day’s tasks only once.” Inside one transaction (a bundle of work that either all succeeds or is all cancelled), it creates the tasks for a module’s planned and running cycles up to today’s share.

What was chosen, and what was dropped

Chosen Dropped alternative Why it was dropped
Make only the day’s share Create all of a cycle’s tasks in advance If the start date or planned end date changes, tasks not yet created have to follow the new date

Three points raised by Codex’s review were applied.

  1. The closing range was too wide. At first, every past to-do routine in the module was closed as “no record.” That would also close tasks on days the schedule doesn’t match (weekday or every-two-weeks routines) and tasks from the previous cycle. Following the plan’s rule, it was narrowed to “the same routine and the same target that got a task today.”
  2. Pinning could be missed when cycle creation and version approval came at the same time, because each can’t see the other’s uncommitted rows. Both now take the same transaction lock (pg_advisory_xact_lock, a named lock that releases on its own when the transaction ends) so they run one after the other.
  3. In the scheduled run, the day counted as done even if a module failed. Now, if anything failed, it runs again on the next 5-minute tick. Tasks already created aren’t created again.

How it was checked

PR 277: The seed goes in only as a draft

What was done and why

So that head office doesn’t have to enter the quest list from scratch, a command was built that puts the quest candidate sheet in as a draft version. It adds one draft version with 22 items and, if there are no routines at all, 4 routines (equipment check, cleaning, stock check, device inspection). If they already exist, it does nothing.

What was chosen, and what was dropped

Chosen Dropped alternative Why it was dropped
A transaction lock so concurrent seeds run in turn A unique constraint on the version name It changes the database structure, which was outside this scope

How it was checked

Lessons