Rewards: credit closed days through the outbox relay #4

Merged
alex merged 3 commits from feat/rewards into feat/habits-day-closing 2026-10-30 19:22:59 +01:00
Owner
  • Platform: the outbox relay reads committed events in order, under an advisory lock so only one instance runs it at a time. It passes each event to its own context's projections and, once that context's publisher translates it, to subscribers in other contexts. A failing event holds later ones back and is set aside after 5 attempts, with its error stored. Consumers handle each event only once, using platform.inbox.
  • Habits publishes HabitPeriodClosedV1, StreakReachedV1 and DayClosedV1. Tentative entries are not published.
  • Rewards context:
    • A Ledger per user, credited when a day closes: diminishing returns, daily caps, half rewards in a habit's first 3 days, perfect-day pollen, and each streak milestone item once per user.
    • A Vitality per user: starts at 50, moves 30% of the way towards each day's adherence, never drops below 20, unchanged on vacation days.
    • All values in BalancePolicy.v1. An anti-corruption layer turns Habits events into Rewards commands.
    • A granted-rewards projection, GET /api/rewards/ledger and /vitality, and RewardGrantedV1 / VitalityChangedV1 for the game.

Design decision (in docs/contexts/rewards.md): the server credits only final facts. Pending earnings will be a client prediction, so undo never reaches Rewards.

Checked against the running API: one user with a missed, a missed and a met day got 5 nectar, 15 pollen and vitality 47, as calculated by hand.

🤖 Generated with Claude Code

- **Platform:** the outbox relay reads committed events in order, under an advisory lock so only one instance runs it at a time. It passes each event to its own context's projections and, once that context's publisher translates it, to subscribers in other contexts. A failing event holds later ones back and is set aside after 5 attempts, with its error stored. Consumers handle each event only once, using `platform.inbox`. - **Habits** publishes `HabitPeriodClosedV1`, `StreakReachedV1` and `DayClosedV1`. Tentative entries are not published. - **Rewards context:** - A `Ledger` per user, credited when a day closes: diminishing returns, daily caps, half rewards in a habit's first 3 days, perfect-day pollen, and each streak milestone item once per user. - A `Vitality` per user: starts at 50, moves 30% of the way towards each day's adherence, never drops below 20, unchanged on vacation days. - All values in `BalancePolicy.v1`. An anti-corruption layer turns Habits events into Rewards commands. - A granted-rewards projection, `GET /api/rewards/ledger` and `/vitality`, and `RewardGrantedV1` / `VitalityChangedV1` for the game. Design decision (in `docs/contexts/rewards.md`): the server credits only final facts. Pending earnings will be a client prediction, so undo never reaches Rewards. Checked against the running API: one user with a missed, a missed and a met day got 5 nectar, 15 pollen and vitality 47, as calculated by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The relay drains the outbox in commit order under an advisory lock, hands each
entry to its own context's projections and, when the context's publisher
translates it, to every subscriber as an integration event. A failing entry
holds later ones back and is set aside after five attempts. Consumers
deduplicate through platform.inbox inside their own unit of work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ledger and Vitality aggregates fed by Habits' integration events through an
anti-corruption layer; one versioned balance policy; a projection of granted
rewards; GET /api/rewards/ledger and /api/rewards/vitality.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alex merged commit 7b94e4f5ef into feat/habits-day-closing 2026-10-30 19:22:59 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Habitea/App!4
No description provided.