regression: timed status sometimes never reverts after expiring#41047
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughTwo small fixes to the status expiration pipeline: the MongoDB query in ChangesStatus Expiration Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ee/packages/presence/src/Presence.ts`:
- Around line 134-138: The setupNextExpiration() method has a race condition
where an older call can resolve after a newer call, clearing the newer timeout
and leaving an expiration unscheduled. Fix this by implementing a monotonic
request token mechanism: create a counter that increments each time
setupNextExpiration() is invoked, store the current token value for each
request, and only proceed with the clearTimeout and timeout assignment if the
stored token still matches the current counter value, ensuring stale requests
cannot overwrite newer timeouts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c03e4276-9546-47bd-af02-0fd7a2e93d48
📒 Files selected for processing (2)
ee/packages/presence/src/Presence.tspackages/models/src/models/Users.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
- GitHub Check: 📦 Build Packages
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/models/src/models/Users.tsee/packages/presence/src/Presence.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
packages/models/src/models/Users.tsee/packages/presence/src/Presence.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
packages/models/src/models/Users.tsee/packages/presence/src/Presence.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
packages/models/src/models/Users.tsee/packages/presence/src/Presence.ts
🔇 Additional comments (1)
packages/models/src/models/Users.ts (1)
1136-1136: LGTM!
There was a problem hiding this comment.
1 issue found across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release-8.6.0 #41047 +/- ##
===============================================
Coverage 70.12% 70.12%
===============================================
Files 3357 3360 +3
Lines 129552 129674 +122
Branches 22407 22500 +93
===============================================
+ Hits 90843 90930 +87
- Misses 35416 35436 +20
- Partials 3293 3308 +15
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ee/packages/presence/src/Presence.ts`:
- Around line 136-148: The stopped() method clears expirationTimeout but fails
to invalidate expirationScheduleToken. This allows in-flight
setupNextExpiration() calls that are awaiting Users.findNextStatusExpiration()
to pass the token check at line 141 after the await completes, re-arming the
timer even after shutdown. In the stopped() method, invalidate
expirationScheduleToken (by assigning it a new unique value like Symbol() or a
sentinel value) in addition to clearing expirationTimeout so that any pending
setupNextExpiration invocations will fail their token equality check and exit
early without re-arming the timer.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 484309b7-43c7-4d8b-874b-474d949badb3
📒 Files selected for processing (1)
ee/packages/presence/src/Presence.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
ee/packages/presence/src/Presence.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
ee/packages/presence/src/Presence.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
ee/packages/presence/src/Presence.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
ee/packages/presence/src/Presence.ts
🔇 Additional comments (1)
ee/packages/presence/src/Presence.ts (1)
51-51: LGTM!
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="ee/packages/presence/src/Presence.ts">
<violation number="1" location="ee/packages/presence/src/Presence.ts:142">
P2: The token guard prevents reschedule races but doesn't account for the shutdown path. `stopped()` clears `expirationTimeout` but never invalidates `expirationScheduleToken`. If `setupNextExpiration` is awaiting `findNextStatusExpiration()` when `stopped()` is called, the token check will still pass after the await resolves, re-arming the timer on a stopped service. Add `this.expirationScheduleToken = undefined;` (or assign a new Symbol) in `stopped()` so in-flight calls bail out.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Proposed changes (including videos or screenshots)
A temporary status with an expiration (e.g. Busy "until 14:32") could intermittently never revert — it stayed stuck until the user changed status again or the server restarted.
Status expiry runs off a single in-memory timer rescheduled on every status change. Concurrent reschedules raced over that timer: a slow, stale lookup could resolve last and wipe out a newer call's timer, leaving the expiration unscheduled. A status that then went overdue with no timer was invisible to the scheduler.
Fix (keeps the precise on-time timer):
Presence.ts— guard the reschedule with a per-call token: each call stamps a uniqueSymbolbefore its lookup and bails if a newer call replaced it, so a stale lookup can't clear the newer timer. Calls stay independent (no serialization). Shutdown invalidates the token so an in-flight reschedule can't re-arm the timer after the service stops.Users.ts—findNextStatusExpirationnow returns the soonest expiry including overdue ones ({$exists: true}), so a missed expiry self-heals on the next scheduling pass.The revert logic (
endActive) was already correct — only the scheduling was broken.Issue(s)
Steps to test or reproduce
Further comments
Summary by CodeRabbit
Summary