Skip to content

[Feature:Forum] Unique anonymous names#12459

Draft
GarvitKhandelwal31 wants to merge 36 commits into
Submitty:mainfrom
GarvitKhandelwal31:improve-chat-anon-names
Draft

[Feature:Forum] Unique anonymous names#12459
GarvitKhandelwal31 wants to merge 36 commits into
Submitty:mainfrom
GarvitKhandelwal31:improve-chat-anon-names

Conversation

@GarvitKhandelwal31

@GarvitKhandelwal31 GarvitKhandelwal31 commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Why is this Change Important & Necessary?

Fixes #11999

Live Chat anonymous names were previously deterministic but generated using a simple and easily reverse-engineered formula. Also the names were not persistent.

This PR completely overhauls the anonymous naming system to be secure, fast, and completely stateless.

What is the New Behavior?

  • Cryptographic Naming: Anonymous names are generated using the crc32() hash function, combined with the chatroom ID, session start time, and a newly implemented system-wide server_secret.
  • Expanded Vocabulary: Adjective and noun arrays have been expanded to exactly 64 words each.
  • Stateless Persistence: Because the algorithm is purely mathematical and deterministic per chatroom session, users naturally retain the exact same anonymous name across page refreshes and rejoins without needing a database lookup.
  • The catch We no longer guarantee 100% collision-free names for massive courses. There would most likely be students with same anonymous name for larger course sizes, but the number of such pair whose names are same will still be quite less. But the current algo is incredibly fast, secure and absolutely persistent.

What steps should a reviewer take to reproduce or test the bug or new feature?

Ensure live chat is enabled in course settings.

  1. Create or open a chatroom with "Allow Anonymous Users" enabled.
  2. Join as an anonymous user and record your displayed anonymous name (e.g., Anonymous Quick Duck).
  3. Leave and rejoin the room, and confirm your name persists exactly as before.

Automated Testing & Documentation

  • Added PHPUnit tests to verify ConfigurationController integration with the new server_secret.

Other Information

Please run migrations before reviewing

…uffix

- Add chatroom_anonymous_names table for persistent anonymous IDs
- Generate truly random names instead of hashing
- Format: Anonymous [Adjective] [Noun] #XXXX
- Persist across leave/rejoin, logout, cookie clear
- Add Shuffle Names button for instructors
@github-project-automation github-project-automation Bot moved this to Seeking Reviewer in Submitty Development Feb 22, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title Fixes #11999 - Improve Live Chat anonymous naming [Feature:Forum] Improve Live Chat anonymous naming Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Feature:Forum] Improve Live Chat anonymous naming [Feature] Improve chat anon naming Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Feature] Improve chat anon naming [Feature:Forum] Unique anonymous names Feb 23, 2026
@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

Hi @williamschen23, could you please approve the workflows for this PR when you have a moment so the CI checks can initiate? Thank you!

@codecov

codecov Bot commented Feb 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.12766% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.33%. Comparing base (01f8919) to head (d5419f9).
⚠️ Report is 48 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12459      +/-   ##
============================================
- Coverage     21.35%   21.33%   -0.02%     
- Complexity     9990     9992       +2     
============================================
  Files           275      275              
  Lines         37317    37346      +29     
  Branches        505      505              
============================================
  Hits           7969     7969              
- Misses        28847    28876      +29     
  Partials        501      501              
Flag Coverage Δ
autograder 21.16% <ø> (ø)
js 1.98% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.39% <2.12%> (-0.02%) ⬇️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Eli-J-Schwartz

Copy link
Copy Markdown
Contributor

Hi @GarvitKhandelwal31, it looks like you're missing a closing curly-bracket on line 200 of chatroom.js, which is causing most of the CI tests to fail. If you fix this I will re-approve the CI workflows to run.

@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

@Eli-J-Schwartz I have added the bracket in the latest commit. Can you please re-run workflows now?
Thanks

…ith persistent storage

- Merge changes from upstream/main for read-only chat feature (PR Submitty#12428)
- Resolve Chatroom.php conflict: combine anonymous name functions with read-only methods
- Fix JavaScript lint errors: remove line continuation after else clause, add parentheses to arrow function
- Fix migration idempotency: check for table/column existence before creating
- All migrations complete successfully
- Ready for PR review
@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

@Eli-J-Schwartz Can you please re-run workflows. It should pass now.

Copilot AI review requested due to automatic review settings February 26, 2026 19:50
@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Feb 26, 2026
@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

I've fixed all the failing workflows:

Database Migrations:

  • Fixed 1st migration (20250222150000): Added check before CREATE TABLE to prevent "DuplicateTable" errors on re-runs
  • Fixed 2nd migration (20250222150100): Replaced buggy ResultProxy checks with proper database.table_has_column() to prevent "DuplicateColumn" errors

Schema Dump Mismatch:

  • Updated course_tables.sql with chatroom_anonymous_names table definition so DB check passes

PHP (PHPCS):

  • Fixed 8 violations: header spacing, trailing whitespace, Stroustrup catch formatting

JavaScript Linting:

  • Fixed 2 violations: separated else statement and added parentheses to arrow function parameter

Cypress Test Failure:

  • Fixed getHostId() return type from int to string (was causing type mismatch in anonymous chat)
  • Corrected typo: "Hack" → "Hawk"

Can you please re-run?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements improved anonymous naming for Live Chat by switching from deterministic/predictable name generation to persistent, randomly generated anonymous display names stored in the course database, plus an instructor action to reshuffle names.

Changes:

  • Adds a chatroom_anonymous_names table (and Doctrine entity) to persist per-(chatroom,user) anonymous display names.
  • Updates chatroom anonymous name generation to read/write the persisted name and include a #XXXX suffix.
  • Adds an instructor-only “Shuffle Names” UI action and socket event handling to regenerate names for a chatroom.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
site/public/templates/chat/ChatroomRow.twig Adds “Shuffle Names” button for active anonymous-enabled chatrooms.
site/app/templates/chat/ChatroomRow.twig Same “Shuffle Names” button addition for server-side twig template.
site/public/js/chatroom.js Adds AJAX call for reshuffling and client handling of the anon_names_regenerated socket event.
site/app/views/ChatroomView.php Uses the new calcAnonName(..., EntityManager) signature so names can persist via DB.
site/app/entities/chat/ChatroomAnonymousName.php New Doctrine entity for persisted anonymous display names.
site/app/entities/chat/Chatroom.php Reworks anonymous name generation to persist and adds bulk regeneration helper.
site/app/controllers/ChatroomController.php Adds instructor-only endpoint to regenerate names and broadcasts socket message.
migration/migrator/migrations/course/20250222150000_chatroom_anonymous_names.py Creates chatroom_anonymous_names table and supporting index.
migration/migrator/migrations/course/20250222150100_chatroom_anonymous_names_display_name.py Migration path for legacy schema to new display_name column.
migration/migrator/data/course_tables.sql Adds chatroom_anonymous_names table + PK + index to baseline schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread site/app/controllers/ChatroomController.php Outdated
Comment thread site/public/js/chatroom.js Outdated
Comment thread site/app/entities/chat/Chatroom.php Outdated
Comment thread migration/migrator/migrations/course/20250222150000_chatroom_anonymous_names.py Outdated

@JManion32 JManion32 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must've been a lot of work, great job! Please include screenshots of user interface changes, specifically the dashboard where the Shuffle Names button is now located:
Image

A few things regarding the functionality here:

  1. If the chat allows users to join anonymously, the Shuffle Names button should be visible, rather than only being visible when the session has started.
  2. The dashboard for chatrooms is starting to become cluttered. How can we improve the user interface without obscuring features? A solid solution to this should probably be a separate PR, but for now, I think we should start by keeping the Shuffle Names button on the same row as the rest of the buttons on the table
  3. The Shuffle Names button should be white and blue, like all other utility buttons on Submitty.
  4. When a session has started and I click the Shuffle Names button, the functionality works as intended. Any subsequent attempts to click the button does not shuffle the names.

Some other thoughts:

  1. Please add documentation to your description for the different "join messages" that can occur for the user when the instructor clicks Shuffle Names. I noticed it in the code, but if I hadn't, it would've gone untested.
  2. Can we add a basic Cypress test to support this change? I can't imagine it would be too much work especially since live_chat.spec.js is already pretty thorough.
  3. There should be a follow-up to this that allows instructors to more easily view the real names of anonymous chatters.

Overall, great work here! I will likely conduct a more thorough review later, but I think this is a good starting point. Feel free to ping me here if you have any questions.

Comment thread vagrant Outdated
@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Feb 26, 2026
@GarvitKhandelwal31

GarvitKhandelwal31 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

@JManion32 Addressed requested changes and updated this PR for re-review.

Shuffle Names is now visible whenever anonymous mode is enabled.
Button remains on the same dashboard row and uses standard white/blue utility styling.
Fixed repeated shuffle behavior (multiple clicks now continue to reshuffle names).
Added Cypress coverage in live_chat.spec.js for multiple shuffles.
Updated PR documentation with the join/shuffle message cases and added screenshots.
Removed vagrant from the current PR diff (the earlier file comment was on a previous commit snapshot).
And also when anonymous names is not enabled the shuffle option is not visible.
Please take another look when you have time—thank you!

@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Mar 1, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Jun 10, 2026

@dagemcn dagemcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Functionality remains the same after removing the shuffle button, tested light and dark mode along with joining multiple chats, clearing cookies and refreshing the page.

@github-actions github-actions Bot removed the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Jun 11, 2026
Comment thread site/app/controllers/ChatroomController.php Outdated
Comment thread site/app/entities/chat/Chatroom.php Outdated
Comment thread site/app/entities/chat/Chatroom.php Outdated
Comment thread site/public/js/chatroom.js Outdated
@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Jun 19, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Jun 25, 2026

@dagemcn dagemcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality remains the same after the changes. Name still persists through clearing cookies, joining other chats, logging into other accounts and through browsers. I can't speak much to the code, I'm not familiar with many of the functions used here but from what I know the code looks good.

@bmcutler
bmcutler requested a review from cjreed121 June 29, 2026 17:04
@GarvitKhandelwal31 GarvitKhandelwal31 moved this from In Review to Awaiting Maintainer Review in Submitty Development Jun 30, 2026

@cjreed121 cjreed121 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm to determine randomized names seems quite solid here and would be extraordinarily difficult to reverse. Few more comments and this should be good after that.

Comment thread site/app/entities/chat/Chatroom.php Outdated
Comment thread migration/migrator/migrations/system/20260629170327_seed_key.py
Comment thread migration/migrator/migrations/system/20260629170327_seed_key.py
Comment thread site/app/models/Config.php Outdated
@github-project-automation github-project-automation Bot moved this from Awaiting Maintainer Review to Work in Progress in Submitty Development Jul 1, 2026
@GarvitKhandelwal31
GarvitKhandelwal31 marked this pull request as draft July 2, 2026 18:01
@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

Sorry, we should probably wait to get this merged. I just encountered some error on running submitty_install, will fix that soon.

@github-actions github-actions Bot added the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete

Projects

Status: Work in Progress

Development

Successfully merging this pull request may close these issues.

Improve Live Chat Anonymous Naming

6 participants