Skip to content

Praxis Today: time budgets and atomic PostgreSQL planning

How Praxis Today handles a 24-hour budget, task limits, atomic moves, concurrency and PostgreSQL capacity checks.

By 5 min read
  • postgresql
  • supabase
  • software architecture
  • transactions
  • typescript
Praxis Today illustration of 24 hours divided into sleep, routine, tasks and free time, with SQL planning and verification.

A different question from the goal graph

My earlier Praxis article described one goal tree powering a 2D map, list and 3D constellation. The new Today feature poses a different challenge: a goal tree can contain hundreds of tasks, but each day has only 24 hours. Dragging cards into a calendar does not solve capacity, competing edits or the need to preserve a plan when a change fails.

Passage link

The implementation is documented in praxis-app, particularly src/lib/day.ts and migration 027_daily_blocks.sql. This is a code-based engineering analysis, not a claim about adoption or measured production performance.

Passage link

Two budgets inside one day

The default preferences reserve eight hours for sleep, three for routine and up to six for tasks. These are configurable product defaults, not a prescription. Seven hours remain unallocated in that initial example.

Passage link
text
24h = 8h sleep + 3h routine + 6h tasks + 7h unallocated
Passage link

A completed task still occupies time; a released task does not. Completion changes progress, not the length of the day. That distinction is easy to miss when a user interface presents everything as a checklist.

Passage link

A pure function for capacity

dailyCapacity calculates vital minutes, task minutes, the effective limit and percentage without depending on React. The essential rule is:

Passage link
ts
const taskLimit = Math.max(0, Math.min(limit, 1440 - vitalMinutes))
const percent = taskLimit > 0 ? taskMinutes / taskLimit * 100 : 100
Passage link

The UI labels up to 80% sustainable, above 80% attention and 100% full. assessAddition prompts pruning when the limit is reached; the database check rejects totals above the limit. A UX warning and a persistence invariant are different policies, and both deserve tests.

Passage link

Drag-and-drop is a proposal

The task drawer prioritizes items due today, weekly commitments and if-then plans. Difficulty suggests durations of 30, 60 or 120 minutes. Before saving, assessAddition considers an existing edit and the planned blocks that could be moved out.

Passage link

Sleep, routine and completed blocks are not candidates for pruning. The custom drag type application/x-praxis-day checks the shape of dropped data. It is a useful interface boundary, while the final decision about a schedule remains with the domain operation.

Passage link

One budget across all maps

The migration separates daily_preferences, daily_days and daily_blocks. Preferences define the vital base; days contain limits and closure state; blocks contain durations, statuses, order and optional links to the goal tree. The day is keyed by user and local date. Opening another map cannot create another six-hour allowance.

Passage link

A partial unique index prevents the same active goal-tree node from being allocated twice on the same day. The restored_from_id field connects a recovered block to its source. These database properties matter when two screens save near the same moment.

Passage link

Why one database operation matters

A single 45-minute block may fit, while two simultaneous 45-minute additions do not fit the same remaining hour. Validating each row is insufficient; the sum must be checked after changes.

Passage link

The database migration keeps reads scoped to the user and routes modifications through public.daily_plan, which also checks the caller's map-edit permission. The function groups related changes so that the budget is assessed as a whole. Its privileged execution context warrants dedicated review and access tests; see the Supabase documentation for the interaction between row policies and database privileges.

Passage link

Two tabs, one remaining hour

The operation uses a transaction-scoped advisory lock keyed to the user. This lets one edit finish before the next recalculates the remaining capacity. The same approach covers moves between today and tomorrow, including tasks from different maps, without serializing unrelated users.

Passage link

The PostgreSQL documentation distinguishes session-scoped from transaction-scoped locks. A lock is part of a consistent writing protocol, not a replacement for constraints or final capacity checks.

Passage link

Pruning must be atomic

The critical workflow begins when today is full. The user selects planned blocks to move. The operation validates them, prepares tomorrow, checks tomorrow's capacity, releases the selected blocks from today, inserts the new task and verifies today's final capacity.

Passage link
text
Validate -> Prepare tomorrow -> Check capacity
         -> Release today -> Add task -> Commit
Passage link

If tomorrow is full, the migration signals DAILY_TOMORROW_CAPACITY and the transaction aborts. Today's previous plan remains intact. Splitting the move into two unrelated requests would allow a failure between them to leave a partial schedule. The same principle applies to inventory transfers and financial allocations.

Passage link

Completion, shutdown and reopening

daily_plan handles save, complete, release, shutdown, settings and reopen. Completing a block linked to a goal-tree node updates the node. Shutdown records closed_at and resolves pending work, either returning it to the tree or moving it to tomorrow. Reopening makes adjustments possible again.

Passage link

The operation receives an explicit local date. The server's midnight is not necessarily the user's midnight. Closure is therefore a recorded decision, not a side effect of the clock.

Passage link

Testing without overstating evidence

The repository documents Vitest and PGlite for calculations and daily database flows. PGlite runs PostgreSQL in WebAssembly and is suitable for local testing. Still, pure functions, database operations and integration with multiple signed-in sessions are distinct test layers.

Passage link

I inspected the implementation and documented commands; I did not run the suite or benchmark production. Important cases include two tabs competing for the last slot, a closed tomorrow, changes to vital preferences, completed blocks and repeated restoration.

Passage link

Alternatives and the lesson

A single JSON document per day could simplify reads but complicate uniqueness and queries. Several independent client writes could reduce database code but increase partial-state risk. A dedicated backend transaction would also work; the chosen RPC keeps the aggregate rule near its data.

Passage link

The trade-off is more PL/pgSQL and some waiting between edits from the same user. The benefit is that an unsuccessful replan does not erase the existing schedule. My checklist is to separate physical and plannable capacity, count completed time, enforce uniqueness, validate totals transactionally, test simultaneous edits and use explicit local dates.

Passage link

Today looks like a calendar, but its core is resource allocation: the UI proposes, a pure function explains, and PostgreSQL decides whether the whole change can be committed. See the Praxis case study.

Passage link

Reference with source and version

Download BibTeX

Suggest a correction

https://lagrotti.dev/blog/praxis-today-time-budget-postgresql-transactions · EN

Your text stays in this form until you prepare and open the draft. You review and publish the issue on GitHub.

Which topic should go deeper?

Results are unavailable right now

Share this article

LinkedInWhatsAppXEmail

Need someone for a challenge like this one?

I work end to end: architecture, development and running in production. I'm open to remote roles and custom projects.