feat(start): document onboarding contract + ghost-user monitor (FFM-907)#224
Merged
Conversation
…s (FFM-907) PR #222 plugged the kitchen-branch leak (Sega's case). This audit ensures no future deep_link branch can re-introduce the same drift, and adds a runtime alarm so we don't have to wait for a friend to complain. - Contributor-facing comment in handle_start documenting the rule: every universal onboarding side effect lives ABOVE the deep_link ladder. New side effects must hoist, not bury inside per-branch blocks. - src/flows/monitors/ghost_users.py: Prefect flow runs every minute, counts new users (1-5min ago = WARN, >5min ago = ERROR) with no user_meme_reaction row, posts a single summary to admin chat. Filters out blocked-acquisition deep_links (intentional silent drop). - tests/tgbot/test_start.py: regression coverage for each known deep_link variant (none / kitchen / wrapped / giveaway_77 / s_*_* / blocked-acquisition / existing user). Asserts user_tg + user + user_language + user_deep_link_log rows after every created=True path, plus idempotency of the lazy lang init. Co-Authored-By: Paperclip <noreply@paperclip.ing>
Member
Author
|
STAFF ENGINEER REVIEW: APPROVED — Structural review clean. SQL safety verified: Codex adversarial findings (non-blocking, suggested follow-ups)
None of these are SQL injection, race conditions on writes, or secrets. Auto-merge queued. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pattern-level fix for FFM-907 — Sega's kitchen-branch leak (PR #222) was a symptom; this PR makes the same regression impossible to silently re-introduce and adds an alarm so we never depend on a friend complaining again.
Audit
handle_startdoes seven side effects every new user MUST get. After PR #222 they're all hoisted above the deep_link ladder:user_tgupsertsave_user_data)userupsertdeep_linksaved onuser_tguser_infocache populateduser_deep_link_logrowuser_languagerows seededPer-branch behaviour (
handle_language_settings,handle_invited_user,next_message, etc.) is intentional and stays inside the ladder.What's in this PR
handle_startspelling out the rule: hoist universal side effects above the ladder; never bury them inside per-branch blocks. Cites the FFM-907 incident so future agents/humans understand the why.src/flows/monitors/ghost_users.py— Prefect flow, runs every minute. Counts users created 1–5 min ago without auser_meme_reactionrow (= WARN) and >5 min ago (= ERROR), posts a single summary to the admin chat with sample IDs. Filters out blocked-acquisition deep_links (silent drop is by design — they don't even create auserrow, but the SQL is defensive).tests/tgbot/test_start.py— regression coverage per deep_link variant: bare/start,kitchen,wrapped,giveaway_77,s_*_*share-link,likefollowbotblocked, plus existing-user path and idempotency of the lazy lang init. Each asserts the row-level post-conditions inuser_tg+user+user_language+user_deep_link_log.Why a Prefect flow vs in-process timer
Per-request scheduling would burn an event-loop slot per /start and lose state on bot restart. A 1-min Prefect cron is one query against
user+user_meme_reaction(both already covered by indexes oncreated_at/user_id), reuses the existing failure-alert path, and is easy to pause/inspect.Test plan
tests/tgbot/test_start.pypasses (8 cases)Monitor ghost usersrunning every minuteuserrow with no reactions — confirm WARN appears in admin chat within 60suser.created_atis real wall-clock (notnow()skew across replicas)🤖 Generated with Claude Code