Skip to content

Integrate Approved Session Tracking Fixes into 10.0.x#566

Closed
rammakablecode wants to merge 4 commits intodoubtfire-lms:10.0.xfrom
rammakablecode:resolve-merge-tutor-analysis-10x
Closed

Integrate Approved Session Tracking Fixes into 10.0.x#566
rammakablecode wants to merge 4 commits intodoubtfire-lms:10.0.xfrom
rammakablecode:resolve-merge-tutor-analysis-10x

Conversation

@rammakablecode
Copy link

References:

Approved PR: thoth-tech#83
Unmerged PR: thoth-tech#74

Description

This PR merges the changes from the approved PR #83 into the 10.0.x branch. It ensures the session tracking logic integrated includes schema fixes, environment blockers, and backend improvements previously approved in #83.

This PR directly references the approved work from #83 and makes it available in the target branch for further development and frontend integration.

Fixes identified issues that blocked development and limited the usefulness of the existing schema:

  • MySQL tablespace errors (errno: 194) that prevented successful migrations in Windows-hosted Docker environments.
  • CRLF line endings in shell scripts causing Dev Container startup failures.
  • Inefficient frontend computation of session_activity gaps.

Frontend impact
Persisting duration_minutes enables direct aggregation via the API and removes the need for complex time-delta calculations in the Angular frontend. This change is intended to support(thoth-tech/doubtfire-web#402). By providing this data via the API, we avoid complex time-delta calculations in the Angular frontend, allowing 402 to be refactored to connect directly to this backend logic since the frontend contributions are yet to connect to exisitng backend.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Test A: Migration Sequence
    Executed bundle exec rails db:migrate:redo VERSION=20250922103033.

    Verified:
    marking_sessions table is created successfully
    duration_minutes column exists
    No MySQL tablespace errors occur

  • Test B: Session Tracking Logic
    Ran bundle exec ruby -I test test/services/session_tracker_test.rb.
    Result: 2 runs, 13 assertions, 0 failures, 0 errors.
    Ran bundle exec rails test test/api/marking_sessions_api_test.rb
    6 runs, 67 assertions, 0 failures, 0 errors, 0 skips

image
Screenshot 2026-01-29 162100

Confirmed:
15-minute "sticky" session window works
duration_minutes is correctly updated upon activity.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

martindolores and others added 4 commits January 26, 2026 19:14
@rammakablecode rammakablecode changed the base branch from development to 10.0.x February 1, 2026 05:36
Copy link
Member

@b0ink b0ink left a comment

Choose a reason for hiding this comment

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

Thanks for your contributions, but I don't think we require any of these changes and I have added comments explaining why

If you were looking to optimise how we handle the session duration, it would probably be even better not to expose the duration_minutes from the backend at all, reducing the size of the data sent from the server, and to do the calculation client-side the performance cost is negligible

t.string :ip_address
t.datetime :start_time
t.datetime :end_time
t.integer :duration_minutes, default: 0
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to start a new migration if you want to make changes to the schema, as this is already shipped in production

)

session.update_session_details
session.update_session_details if action == 'assessing'
Copy link
Member

Choose a reason for hiding this comment

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

We want various actions to let the backend know the tutor is still active - this includes adding comments, opening different submissions, etc.

We can't limit this to just the assessing action, because a tutor could - for example - spend 2 hours opening and reviewing submissions, leaving comments, and not change the status of any tasks (triggering the assessing action) - this would result in multiple sessions being created back-to-back once the previous session is older than 15 minutes.

Comment on lines +18 to +26
if start_time.present?
duration = ((now.to_f - start_time.to_f) / 60).to_i
update(
end_time: now,
duration_minutes: duration
)
else
update(end_time: now, duration_minutes: 0)
end
Copy link
Member

Choose a reason for hiding this comment

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

duration_minutes is redundant and should not be part of the schema.
The cost of calculating duration from start_time and end_time is negligible, and storing it would duplicate derived data.

Persisting duration_minutes introduces a risk of data inconsistency - for example, if one value is updated without the other - leading to conflicting sources of truth

We dynamically calculate duration_minutes when we expose the MarkingSession entity

task_id: task&.id,
task_definition_id: task&.task_definition_id,
created_at: Time.zone.now
created_at: DateTime.now
Copy link
Member

Choose a reason for hiding this comment

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

Time.zone.now should be used

@b0ink b0ink closed this Feb 4, 2026
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.

3 participants