Skip to content

fix(users): preserve on-hold next-plan activation - #948

Merged
T3ST3ST3R0N merged 2 commits into
PasarGuard:devfrom
dr-hoseyn:codex/fix-next-plan-on-hold
Oct 10, 2026
Merged

T3ST3ST3R0N merged 2 commits into
PasarGuard:devfrom
dr-hoseyn:codex/fix-next-plan-on-hold

Conversation

@dr-hoseyn

@dr-hoseyn dr-hoseyn commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Activating a next-plan template configured to start on first connection currently starts its expiration immediately. The template uses UserStatusCreate, but activation compares it by identity with UserStatus; activation also unconditionally overwrites the result with active. A customer who connects a week after a 30-day renewal therefore loses a week of validity.

Compare against the template enum and preserve on_hold through activation. Convert the template's timeout duration into a deadline relative to renewal, clear the previous plan's connection timestamp, and record the renewal time so only subsequent activity can start the plan. Immediate-start plans clear stale hold settings and retain their normal expiration behavior. Both manual activation and automatic expiration/traffic-limit renewal use this shared path.

Validation: 14 temporary SQLite regression cases plus all 14 existing review-user unit tests passed (28 total). Coverage includes manual and automatic renewal, previous-plan activity, first connection, timeout eligibility, no timeout, unlimited duration, ordinary/template active plans, traffic carryover, and reset logging. Notification/node-sync calls and WireGuard allocation helpers were mocked in the temporary cases; database persistence and review queries used the real implementation. Ruff lint/format and git diff --check passed.

Only app/db/crud/user.py is changed; no test, documentation, dependency, or migration files are included.

Summary by CodeRabbit

  • Bug Fixes
    • Resetting a user with an on-hold plan now preserves the on-hold status and applies the plan’s timeout settings.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81d67aba-74c1-4251-bcdc-43b6163f37a0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2e890082-293e-47e4-a2de-3a36dc7451c0


📥 Commits

Reviewing files that changed from the base of the PR and between 26047f6 and d6d1ca4.


📒 Files selected for processing (1)
  • app/db/crud/user.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



Walkthrough

reset_user_by_next now initializes user status fields and uses one timestamp for expiration calculations. When the selected template is on hold, the reset preserves that status and sets the on-hold timeout from the template duration.

Changes

User reset behavior

Layer / File(s) Summary
Reset status and apply plan
app/db/crud/user.py
reset_user_by_next captures one timestamp, sets the user active, clears on-hold fields, and updates edit_at. It uses the captured timestamp for expiration calculations. For an on-hold template, it sets the user on hold, sets expiration duration, calculates the timeout when configured, and clears online_at. The reset no longer overwrites the on-hold status after chart cleanup.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: m03ed

Merge Risk | ⚪ Minimal · up to d6d1c

Merge Risk: ⚪ Minimal · up to d6d1c

Renewed on-hold plans remain held until a connection or configured timeout starts expiration. The inspected lifecycle paths align, and no actionable merge risk remains.

Security Architecture Review

Security architecture risk: 🔵 Low · up to d6d1c

Renewals now preserve plans that should wait for a connection, without evidence of a new access path or broader permissions. Delayed usage reporting could still start a waiting plan earlier than intended; concurrent renewals and production timing have not been verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant exposure is the renewed user's plan state and downstream status processing, rather than a demonstrated expansion of administrative authority or service topology.

Trust Boundaries and Controls

  • observed — The manual operation validates a target user before invoking the reset; the scheduled path selects users by lifecycle status rather than accepting a caller-supplied target.

Resilience and Maintainability Implications

  • inferred — Usage recording supplies a collection-time online timestamp, not proof that the underlying activity occurred after renewal. The reset clears the previous value, but a later write can repopulate it; concurrent renewal behavior remains unverified.

Hardening Proposals

  • proposed — Consider tying connection eligibility to an activity event or renewal epoch, and checking the ordering of usage writes and repeated renewals, if first-post-renewal activity must be guaranteed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving on-hold activation for users assigned a next plan.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the clock at dawn
One timestamp guides the plan along
On-hold stays when templates say
Timeout fields are set that way
Then hops off, content with the change

Comment @coderabbitai help to get the list of available commands.

@dr-hoseyn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@dr-hoseyn
dr-hoseyn force-pushed the codex/fix-next-plan-on-hold branch from d6d1ca4 to ea9a948 Compare October 8, 2026 22:29
An on-hold template next plan keeps the user on hold with the template's timeout as a deadline, and an immediate template plan clears an on-hold user's hold fields. Both fail before this fix. The user template helper gains an optional on_hold_timeout.
@T3ST3ST3R0N
T3ST3ST3R0N merged commit aa59258 into PasarGuard:dev Oct 10, 2026
9 checks passed
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 2, 2026
…ain bba95f274

Checked with git ls-remote on 2026-10-11 02:55 UTC. Panel dev moved from
d94e157 to 83fe90e with 22 commits; main is still v5.4.1.

- PasarGuard#879 (2d0ca81, loopback Xray client inbounds) is ported by design: the
  fork took the open pull request on 2026-09-25 as 2e7fc45 with migration
  bfd88026565b, the same listener rewrite.
- PasarGuard#934 (a5b28f3) moves from the port queue to a dated waiver until
  2026-11-09: the fork refuses to delete a core that nodes still use
  (W3-013, fix/node-health) instead of restarting those nodes.
- PasarGuard#993 (Hysteria2 FinalMask without a udp mask) is queued until 2026-10-18:
  the fork has the same FinalMask | dict field and the same non-null-safe
  udpHop reads, so a udpHop-only host can fail the whole subscription.
- PasarGuard#984, PasarGuard#985, PasarGuard#986, PasarGuard#989, PasarGuard#944, PasarGuard#864, PasarGuard#948, PasarGuard#951, PasarGuard#778, PasarGuard#774, PasarGuard#787, PasarGuard#994,
  PasarGuard#865, PasarGuard#875, PasarGuard#718, PasarGuard#967, PasarGuard#772, PasarGuard#662, PasarGuard#995 and PasarGuard#913 are queued as
  security: no until 2026-10-25, each with its reason; PasarGuard#913's node-removal
  half is already in the fork through sync_remove_users.
- The branch commits that upstream squash-merged (the three dashboard
  branches, telegram/tests, fix/core-editor-api-section-followup,
  fix/hwid-count-test-cleanup, fix/hysteria-finalmask-quic-only) follow
  their squash, by patch-id or by an equal tree.

Scripts main moved to bba95f274 (PasarGuard#35, PasarGuard#36, PasarGuard#37 after PasarGuard#34). The three
squashes are queued security: no until 2026-10-25, and their pre-squash
branch commits are waived as superseded (equal trees).

Against live upstream the panel gate now fails only on the 17 port-queue
commits classified security: yes, and the forks gate only on node
f72ac0ef (security: yes). No upstream commit is undecided.
Free-Guy-IR pushed a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
* fix(users): preserve on-hold next-plan activation

* test(users): cover on-hold next-plan activation

An on-hold template next plan keeps the user on hold with the template's timeout as a deadline, and an immediate template plan clears an on-hold user's hold fields. Both fail before this fix. The user template helper gains an optional on_hold_timeout.

---------

Co-authored-by: T3ST3ST3R0N <[email protected]>

Fork resolution: reset_user_by_next keeps the fork's proxy-secrets
named lock, the FOR UPDATE refresh of the user and of the next plan, and
NextPlanUnavailable, all before any field is written. The fork's
'only force active when not on_hold' tail is dropped in favour of
upstream's reset-to-active at the start, which keeps the fork's
test_reset_by_next_preserves_on_hold_template_status green. Upstream's
test hunks are already in the RED commit before this pick.

(cherry picked from commit aa59258)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants