Skip to content

feat: split session time into human hours vs machine hours#3921

Merged
marcusquinn merged 3 commits intomainfrom
feature/session-time-v2
Mar 8, 2026
Merged

feat: split session time into human hours vs machine hours#3921
marcusquinn merged 3 commits intomainfrom
feature/session-time-v2

Conversation

@marcusquinn
Copy link
Copy Markdown
Owner

@marcusquinn marcusquinn commented Mar 8, 2026

Summary

  • Replaces opaque session duration with precise human vs machine time split using SQLite LAG() window functions on message timestamps
  • Human time = gap between assistant completing and next user message (reading + thinking + typing)
  • Machine time = assistant response generation time
  • Adds quarter period support alongside day/week/month/year

Why

The previous session time metric (total duration) was misleading — it mixed human effort with machine generation time and idle gaps. For transparency of effort, you need to know: "how many hours did the human actually spend reading and directing?"

Results (aidevops repo)

Period Interactive Sessions Human Hours Machine Hours
Day 154 5.1h 27.0h
Week 323 19.9h 51.7h
Month 1,465 141.9h 341.9h
Quarter 1,883 292.6h 471.4h
Year 1,955 314.2h 484.1h

Interactive sessions are ~70-85% human time. Worker sessions are ~0% human time (confirmed: 2.3h human vs 100.1h machine for workers last month).

Changes

contributor-activity-helper.sh

  • Rewrote session_time() SQL to use LAG() window function computing human_ms and machine_ms per session
  • Updated Python aggregation to output human hours + machine hours columns
  • Updated cross_repo_session_time() to aggregate new fields
  • Updated JSON schema: interactive_human_hours, interactive_machine_hours, worker_machine_hours
  • Added quarter (90 days) to period options
  • Added PR #N to worker session title patterns
  • Updated help text

No changes to pulse-wrapper.sh

The body assembly embeds markdown from the helper — the new table format flows through automatically.

Summary by CodeRabbit

  • New Features

    • Session time analytics now distinguish between human and machine hours instead of total duration.
    • Added quarter period option for time range analysis.
    • Reports now display human hours and machine hours separately for interactive and worker sessions.
  • Improvements

    • Enhanced JSON and markdown output with expanded metrics including total session counts and per-category hour breakdowns.
    • Improved worker pattern classification with extended support.
    • Updated documentation for new period options and analytics capabilities.

Replace opaque session duration with precise human/machine time split
using SQLite LAG() window functions on message timestamps:
- human_time = gap between assistant completing and next user message
  (reading + thinking + typing)
- machine_time = assistant.completed - assistant.created (AI generating)

Interactive sessions are ~70-85% human time; workers are ~0%.
This surfaces the actual human effort for transparency.

Add quarter period support (day/week/month/quarter/year).
Add PR #N pattern to worker session classification.
@github-actions github-actions bot added the enhancement Auto-created from TODO.md tag label Mar 8, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the session time reporting by introducing a detailed breakdown of human versus machine interaction time. This change provides a clearer understanding of how time is spent in interactive and worker sessions, moving beyond a single, aggregated duration metric. Additionally, it extends the reporting capabilities by adding support for quarterly periods, offering more flexibility in analyzing activity trends.

Highlights

  • Granular Session Time Metrics: The session time calculation has been refactored to distinguish between 'human hours' (time spent by the user reading, thinking, and typing) and 'machine hours' (time spent by the AI generating responses). This provides a more transparent view of effort.
  • Advanced SQL for Time Calculation: Implemented SQLite LAG() window functions to precisely calculate human and machine time based on message timestamps within a session, replacing the previous simple duration calculation.
  • New 'Quarter' Period Support: Added 'quarter' (90 days) as a supported period option for activity reporting, alongside existing day, week, month, and year periods.
  • Expanded Worker Session Classification: The classification for worker sessions now includes 'PR #N' patterns, ensuring pull request-related automated sessions are correctly categorized.
  • Updated JSON Schema and Output: The JSON output and internal aggregation logic have been updated to reflect the new interactive_human_hours, interactive_machine_hours, and worker_machine_hours fields.
Changelog
  • .agents/scripts/contributor-activity-helper.sh
    • Updated comments to reflect the new human vs machine time calculation and expanded worker session patterns.
    • Modified default JSON output for session_time() to include new human and machine hour fields.
    • Added 'quarter' period (7776000 seconds) to the period options.
    • Rewrote the SQLite query to use LAG() window functions for precise human_ms and machine_ms calculation per session.
    • Included PR #N patterns in the Python script's worker session classification.
    • Refactored Python aggregation logic to process and output human and machine time metrics.
    • Adjusted cross_repo_session_time() aggregation to handle the new time metrics.
    • Updated help text for session-time and cross-repo-session-time commands, including the new 'quarter' period and detailed session time explanations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 367 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 8 20:44:34 UTC 2026: Code review monitoring started
Sun Mar 8 20:44:34 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 367

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 367
  • VULNERABILITIES: 0

Generated on: Sun Mar 8 20:44:37 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 54e456e4-bd69-4eac-82ec-6fd9a3a68c0a

📥 Commits

Reviewing files that changed from the base of the PR and between 94a7aff and a4b2118.

📒 Files selected for processing (1)
  • .agents/scripts/contributor-activity-helper.sh

Walkthrough

The contributor activity helper script now computes per-session human vs machine interaction time using message-level timestamps and SQL windowed functions. Period support extends to quarters, and JSON/markdown outputs expand to include separate human and machine hour metrics for interactive and worker session categories, with cross-repo aggregations using set unions and per-type accumulation.

Changes

Cohort / File(s) Summary
Session Time Analytics
.agents/scripts/contributor-activity-helper.sh
Introduces SQL LAG() windowed functions to compute human_ms and machine_ms per session from message timestamps, caps human gaps to 1 hour, and filters non-idle sessions. Replaces previous duration-based aggregation with per-message role-based sums.
Period Support & Classification
.agents/scripts/contributor-activity-helper.sh
Adds quarter interval to period options (day, week, month, quarter, year). Expands worker pattern detection with PR (#) support for session classification and updates threshold mappings accordingly.
Output Aggregations
.agents/scripts/contributor-activity-helper.sh
Extends JSON schema with interactive_human_hours, interactive_machine_hours, total_human_hours, total_machine_hours, and total_sessions. Refactors per-repo and cross-repo aggregations to accumulate human/machine times separately and use set unions for active days.
Console Formatting & Documentation
.agents/scripts/contributor-activity-helper.sh
Updates markdown table columns to display Type, Sessions, Human Hours, Machine Hours for both interactive and worker categories with totals. Enhances help text to document human vs machine time semantics, expanded period/format options, and worker pattern support.

Sequence Diagram

sequenceDiagram
    participant Input as Message Feed<br/>(Timestamps + Roles)
    participant SQL as SQL Engine<br/>(LAG Window)
    participant Python as Session<br/>Classifier
    participant Output as Output<br/>Formatter

    Input->>SQL: Raw messages with timestamps
    SQL->>SQL: Compute LAG() for gaps
    SQL->>SQL: Calculate human_ms, machine_ms<br/>per session
    SQL->>SQL: Cap human gaps to 1hr,<br/>filter idle
    SQL->>Python: Aggregated session metrics<br/>(human/machine hours)
    Python->>Python: Classify by worker patterns<br/>(with PR detection)
    Python->>Python: Accumulate per-type<br/>human/machine times
    Python->>Output: Classified sessions<br/>with time metrics
    Output->>Output: Generate markdown table<br/>(Type, Hours, Sessions)
    Output->>Output: Generate JSON<br/>(nested aggregations)
    Output-->>Input: Console & JSON output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🤖⏳ Session hours now split with grace,
Human and machine time find their place,
Windowed functions reveal the flow,
Quarters counted, analytics glow! 📊✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: splitting session time into human hours vs machine hours, which is the core enhancement throughout the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/session-time-v2

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

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a more granular session time tracking by splitting it into 'human hours' and 'machine hours', providing a clearer picture of user engagement versus automated processing. It also adds support for a 'quarter' time period and expands the classification for worker sessions. A critical security concern is the potential for SQL injection due to direct variable interpolation in SQLite queries; a more robust parameterized approach is recommended. Additionally, minor code style improvements are suggested for better readability in the embedded Python scripts.

Comment on lines 540 to 579
query_result=$(sqlite3 -json "$db_path" "
WITH msg_data AS (
SELECT
s.id AS session_id,
s.title,
json_extract(m.data, '\$.role') AS role,
m.time_created AS created,
json_extract(m.data, '\$.time.completed') AS completed,
LAG(json_extract(m.data, '\$.role'))
OVER (PARTITION BY s.id ORDER BY m.time_created) AS prev_role,
LAG(json_extract(m.data, '\$.time.completed'))
OVER (PARTITION BY s.id ORDER BY m.time_created) AS prev_completed
FROM session s
JOIN message m ON m.session_id = s.id
WHERE s.parent_id IS NULL
AND m.time_created > ${since_ms}
AND (s.directory = '${safe_path}'
OR s.directory LIKE '${like_path}.%' ESCAPE '\\'
OR s.directory LIKE '${like_path}-%' ESCAPE '\\')
)
SELECT
s.title,
(max(m.time_created) - min(m.time_created)) as duration_ms
FROM session s
JOIN message m ON m.session_id = s.id
WHERE s.parent_id IS NULL
AND m.time_created > ${since_ms}
AND (s.directory = '${safe_path}'
OR s.directory LIKE '${like_path}.%' ESCAPE '\\'
OR s.directory LIKE '${like_path}-%' ESCAPE '\\')
GROUP BY s.id
HAVING count(m.id) >= 2
AND duration_ms > 5000
session_id,
title,
SUM(CASE
WHEN role = 'user' AND prev_role = 'assistant'
AND prev_completed IS NOT NULL
AND (created - prev_completed) BETWEEN 1 AND 3600000
THEN created - prev_completed
ELSE 0
END) AS human_ms,
SUM(CASE
WHEN role = 'assistant' AND completed IS NOT NULL
AND (completed - created) > 0
THEN completed - created
ELSE 0
END) AS machine_ms
FROM msg_data
GROUP BY session_id
HAVING human_ms + machine_ms > 5000
") || query_result="[]"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The SQL query on line 540 (in the session_time function) is constructed by interpolating shell variables ${since_ms}, ${safe_path}, and ${like_path} directly into the query string. This direct interpolation is vulnerable to SQL injection if an attacker can control the input (e.g., the repo path argument), potentially allowing arbitrary SQL commands against the Claude.db database. To prevent SQL injection in shell scripts using sqlite3, it is recommended to create a helper function that uses .param set for safe parameterized bindings instead of direct string interpolation. This approach is more robust than manual escaping.

References
  1. To prevent SQL injection in shell scripts using sqlite3, create a helper function that uses .param set for safe parameterized bindings instead of direct string interpolation.

Comment on lines +653 to +654
print(f'| Interactive | {i[\"count\"]} | {i_human_h}h | {i_machine_h}h |')
print(f'| Workers/Runners | {w[\"count\"]} | — | {w_machine_h}h |')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The backslashes (\) used to escape the double quotes within these f-strings are unnecessary. Since the f-strings are delimited by single quotes ('...'), the inner double quotes for dictionary key access (["count"]) are treated as literal characters by Python. The shell also passes them through correctly because the entire Python script is wrapped in double quotes. Removing these redundant escapes improves code readability.

Suggested change
print(f'| Interactive | {i[\"count\"]} | {i_human_h}h | {i_machine_h}h |')
print(f'| Workers/Runners | {w[\"count\"]} | — | {w_machine_h}h |')
print(f'| Interactive | {i["count"]} | {i_human_h}h | {i_machine_h}h |')
print(f'| Workers/Runners | {w["count"]} | — | {w_machine_h}h |')

Comment on lines +766 to +767
print(f'| Interactive | {i[\"interactive_sessions\"]} | {i[\"interactive_human_hours\"]}h | {i[\"interactive_machine_hours\"]}h |')
print(f'| Workers/Runners | {i[\"worker_sessions\"]} | — | {i[\"worker_machine_hours\"]}h |')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the other comment, the backslashes (\) for escaping double quotes here are redundant. The f-strings use single quotes, so the inner double quotes for dictionary keys don't need to be escaped for either the shell or Python. Removing them will make the code cleaner and easier to maintain.

Suggested change
print(f'| Interactive | {i[\"interactive_sessions\"]} | {i[\"interactive_human_hours\"]}h | {i[\"interactive_machine_hours\"]}h |')
print(f'| Workers/Runners | {i[\"worker_sessions\"]} | — | {i[\"worker_machine_hours\"]}h |')
print(f'| Interactive | {i["interactive_sessions"]} | {i["interactive_human_hours"]}h | {i["interactive_machine_hours"]}h |')
print(f'| Workers/Runners | {i["worker_sessions"]} | — | {i["worker_machine_hours"]}h |')

coderabbitai[bot]
coderabbitai bot previously requested changes Mar 8, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.agents/scripts/contributor-activity-helper.sh (2)

668-668: Minor doc nit: missing quarter in period list.

The comment says --period day|week|month|year but quarter is now supported (it passes through to session_time which handles it). Consider updating for consistency.

-#   --period day|week|month|year (optional, default: month)
+#   --period day|week|month|quarter|year (optional, default: month)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/contributor-activity-helper.sh at line 668, Update the
inline comment that lists supported --period values to include "quarter" so it
reflects current behavior; specifically change the comment string "#   --period
day|week|month|year (optional, default: month)" to include quarter (e.g. "#  
--period day|week|month|quarter|year (optional, default: month)") so it matches
how the flag is passed through to session_time and supported by the script.

625-643: Note: worker_human_hours is computed but not exposed in JSON.

The code correctly accumulates w['human_ms'] (line 630) into total_human_h, but doesn't expose worker_human_hours as a separate JSON field. This is fine for single-repo output (workers have ~0% human time anyway), but creates an aggregation gap in cross_repo_session_time — see the related comment there.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/contributor-activity-helper.sh around lines 625 - 643, The
result JSON is missing worker_human_hours: compute worker_human_h =
ms_to_h(w['human_ms']) (using the existing ms_to_h) and add a
'worker_human_hours': worker_human_h entry to the result dict so worker human
time is exposed (refer to variables i, w, ms_to_h and the result dictionary).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/scripts/contributor-activity-helper.sh:
- Around line 747-748: The cross-repo total_human_h is missing worker human
hours; in cross_repo_session_time() update the aggregation to include worker
human time as session_time() does (i.e., sum interactive human hours and worker
human hours from the per-repo totals) — use the per-repo totals keys (e.g.,
totals['interactive_human_hours'] plus totals['worker_human_hours'] or
totals['total_human_hours'] if present) when computing total_human_h so the
cross-repo report matches session_time()’s definition.

---

Nitpick comments:
In @.agents/scripts/contributor-activity-helper.sh:
- Line 668: Update the inline comment that lists supported --period values to
include "quarter" so it reflects current behavior; specifically change the
comment string "#   --period day|week|month|year (optional, default: month)" to
include quarter (e.g. "#   --period day|week|month|quarter|year (optional,
default: month)") so it matches how the flag is passed through to session_time
and supported by the script.
- Around line 625-643: The result JSON is missing worker_human_hours: compute
worker_human_h = ms_to_h(w['human_ms']) (using the existing ms_to_h) and add a
'worker_human_hours': worker_human_h entry to the result dict so worker human
time is exposed (refer to variables i, w, ms_to_h and the result dictionary).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c3fdbac-63ac-4c24-acf1-ff8a45add38d

📥 Commits

Reviewing files that changed from the base of the PR and between f41b0ba and 94a7aff.

📒 Files selected for processing (1)
  • .agents/scripts/contributor-activity-helper.sh

Ensures cross-repo total includes worker human hours (negligible but
consistent with per-repo session_time() which sums both).
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 367 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 8 20:53:01 UTC 2026: Code review monitoring started
Sun Mar 8 20:53:02 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 367

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 367
  • VULNERABILITIES: 0

Generated on: Sun Mar 8 20:53:04 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

…comment

Address CodeRabbit nitpicks:
- Expose worker_human_hours in session_time() JSON result for schema completeness
- Add worker_human_hours aggregation in cross_repo_session_time()
- Update cross_repo_session_time comment to include quarter in period list
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 367 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 8 20:58:40 UTC 2026: Code review monitoring started
Sun Mar 8 20:58:41 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 367

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 367
  • VULNERABILITIES: 0

Generated on: Sun Mar 8 20:58:43 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 8, 2026

@marcusquinn marcusquinn merged commit e2083bc into main Mar 8, 2026
12 checks passed
@marcusquinn marcusquinn deleted the feature/session-time-v2 branch March 8, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant