Skip to content

t1398.4: Add session count awareness#2883

Merged
alex-solovyev merged 1 commit intomainfrom
feature/session-count-awareness
Mar 5, 2026
Merged

t1398.4: Add session count awareness#2883
alex-solovyev merged 1 commit intomainfrom
feature/session-count-awareness

Conversation

@alex-solovyev
Copy link
Collaborator

Summary

  • Add session-count-helper.sh that detects interactive AI coding sessions (OpenCode, Claude Code, Cursor, Windsurf, Aider) and warns when the count exceeds a configurable threshold (default: 5)
  • Distinguishes interactive TUI sessions from headless workers by examining process command lines (opencode run, claude -p are excluded)
  • Integrates into startup flow (aidevops-update-check.sh) and pre-edit check (pre-edit-check.sh) as non-blocking warnings

Configuration

  • Config key: safety.max_interactive_sessions (default: 5, set to 0 to disable)
  • Env override: AIDEVOPS_MAX_SESSIONS
  • Schema (aidevops-config.schema.json) and defaults (aidevops.defaults.jsonc) updated

Files Changed

File Change
.agents/scripts/session-count-helper.sh New — core detection logic with count, check, list commands
.agents/scripts/aidevops-update-check.sh Calls session check during startup greeting
.agents/scripts/pre-edit-check.sh Non-blocking session warning before edits
.agents/configs/aidevops.defaults.jsonc Added safety.max_interactive_sessions
.agents/configs/aidevops-config.schema.json Added schema for new config key
.agents/scripts/shared-constants.sh Added env var mapping for AIDEVOPS_MAX_SESSIONS

Testing

Verified on Linux with 2 interactive OpenCode sessions + multiple headless workers:

$ session-count-helper.sh list
Interactive AI sessions:
  PID 3325002 | OpenCode | 568 MB | uptime: 1-23:50:50
  PID 3742902 | OpenCode | 1149 MB | uptime: 1-20:46:47
Total: 2 interactive | Threshold: 5

$ AIDEVOPS_MAX_SESSIONS=1 session-count-helper.sh check
SESSION_WARNING: 2 interactive AI sessions detected (threshold: 1).
Consider closing unused sessions to reduce memory pressure (~100-400 MB each).

Headless workers (opencode run ...) are correctly excluded from the count.

Closes #2877

…sions (t1398.4)

Add session-count-helper.sh that detects interactive AI coding sessions
(OpenCode, Claude Code, Cursor, Windsurf, Aider) and warns when the count
exceeds a configurable threshold (default: 5). Distinguishes interactive
TUI sessions from headless workers by examining process command lines.

Integration points:
- Startup flow (aidevops-update-check.sh): warns on session start
- Pre-edit check (pre-edit-check.sh): non-blocking warning before edits

Configuration:
- Config key: safety.max_interactive_sessions (default: 5, 0 = disabled)
- Env override: AIDEVOPS_MAX_SESSIONS
- Schema and defaults updated

Closes #2877
@github-actions github-actions bot added the enhancement Auto-created from TODO.md tag label Mar 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Warning

Rate limit exceeded

@alex-solovyev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 9 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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a8fa036b-08f9-4e66-8396-ac58b432e348

📥 Commits

Reviewing files that changed from the base of the PR and between 088f783 and bd5325f.

📒 Files selected for processing (6)
  • .agents/configs/aidevops-config.schema.json
  • .agents/configs/aidevops.defaults.jsonc
  • .agents/scripts/aidevops-update-check.sh
  • .agents/scripts/pre-edit-check.sh
  • .agents/scripts/session-count-helper.sh
  • .agents/scripts/shared-constants.sh
✨ 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-count-awareness

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.

@gemini-code-assist
Copy link

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 introduces a new system to monitor and manage the number of concurrent interactive AI coding sessions. The primary goal is to help users prevent potential memory pressure and performance degradation by providing timely warnings when too many AI assistants are running simultaneously. This enhancement aims to improve system stability and resource management without interrupting the user's workflow.

Highlights

  • New Session Count Helper: A new script, session-count-helper.sh, was added to detect and count interactive AI coding sessions (e.g., OpenCode, Claude Code, Cursor, Windsurf, Aider). It distinguishes between interactive TUI sessions and headless workers by analyzing process command lines.
  • Integrated Session Warnings: The session count check is now integrated into the startup flow (aidevops-update-check.sh) and as a non-blocking pre-edit check (pre-edit-check.sh), providing warnings when the number of interactive sessions exceeds a configurable threshold.
  • Configurable Threshold: A new configuration key, safety.max_interactive_sessions, was introduced with a default value of 5. This threshold can be overridden via an environment variable (AIDEVOPS_MAX_SESSIONS) or set to 0 to disable the check entirely. The schema and default configuration files were updated accordingly.
Changelog
  • .agents/configs/aidevops-config.schema.json
    • Added schema definition for the new safety.max_interactive_sessions configuration key, specifying it as an integer with a default of 5 and a minimum of 0.
  • .agents/configs/aidevops.defaults.jsonc
    • Included the safety.max_interactive_sessions key with its default value of 5 in the aidevops.defaults.jsonc file, along with descriptive comments.
  • .agents/scripts/aidevops-update-check.sh
    • Incorporated a call to session-count-helper.sh to perform a session check during the initial startup greeting.
    • Ensured any session warnings are captured and included in the cached session greeting output.
  • .agents/scripts/pre-edit-check.sh
    • Added a non-blocking call to session-count-helper.sh to display a warning if the interactive session count exceeds the configured limit before an edit operation.
  • .agents/scripts/session-count-helper.sh
    • Created a new Bash script responsible for detecting, counting, and listing interactive AI coding sessions.
    • Implemented logic to differentiate between interactive TUI sessions and headless worker processes for various AI tools (OpenCode, Claude, Cursor, Windsurf, Aider).
    • Provided commands for count, check (against threshold), and list (with details like PID, memory, uptime).
    • Included functionality to retrieve the maximum session threshold from environment variables or the configuration system.
  • .agents/scripts/shared-constants.sh
    • Added a mapping for max_interactive_sessions to its corresponding environment variable override, AIDEVOPS_MAX_SESSIONS, within the _ft_env_map function.
Activity
  • No human activity has been recorded on this pull request yet.
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

github-actions bot commented Mar 5, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Thu Mar 5 03:08:53 UTC 2026: Code review monitoring started
Thu Mar 5 03:08:54 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 107

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 107
  • VULNERABILITIES: 0

Generated on: Thu Mar 5 03:08:56 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2026

Copy link

@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 helpful feature to monitor and warn about a high number of concurrent interactive AI sessions, which can help manage system resources. The implementation is well-structured, with a dedicated helper script and integration into existing startup and pre-edit checks.

My review focuses on improving the robustness and clarity of the new script. I've suggested removing error suppression (2>/dev/null) in a few places to align with project guidelines and improve debuggability. I also noted an opportunity to make the list command's output more complete and less confusing for the user, aligning with the principle that informational functions should be comprehensive.

The changes to configuration files and environment variable mappings are all correct. Overall, this is a solid addition.

# Check for excessive concurrent interactive sessions (t1398.4)
local session_warning=""
if [[ -x "${script_dir}/session-count-helper.sh" ]]; then
session_warning="$("${script_dir}/session-count-helper.sh" check 2>/dev/null || true)"

Choose a reason for hiding this comment

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

medium

Suppressing stderr with 2>/dev/null can hide important diagnostic messages from the helper script, such as syntax errors or problems with dependencies like pgrep. The project's general rules advise against blanket error suppression to make debugging easier. The || true is sufficient to prevent the script from exiting on a warning (exit code 1).

Suggested change
session_warning="$("${script_dir}/session-count-helper.sh" check 2>/dev/null || true)"
session_warning="$("${script_dir}/session-count-helper.sh" check || true)"
References
  1. Avoid blanket suppression of command errors with '2>/dev/null' in shell scripts to ensure that system issues remain visible for debugging.


# Session count warning (t1398.4) — non-blocking, informational only
if [[ -x "$SCRIPT_DIR/session-count-helper.sh" ]]; then
session_warning=$("$SCRIPT_DIR/session-count-helper.sh" check 2>/dev/null || true)

Choose a reason for hiding this comment

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

medium

As in aidevops-update-check.sh, suppressing stderr with 2>/dev/null here can hide important errors from the helper script. Please remove it to allow diagnostic messages to be visible, in line with the project's general rules for debugging.

Suggested change
session_warning=$("$SCRIPT_DIR/session-count-helper.sh" check 2>/dev/null || true)
session_warning=$("$SCRIPT_DIR/session-count-helper.sh" check || true)
References
  1. Avoid blanket suppression of command errors with '2>/dev/null' in shell scripts to ensure that system issues remain visible for debugging.

# the first argument after the binary name.
# Headless: .opencode run ...
local opencode_pids=""
opencode_pids=$(pgrep -f '\.opencode' 2>/dev/null || true)

Choose a reason for hiding this comment

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

medium

Using 2>/dev/null here suppresses all stderr output from pgrep, which could hide important errors like 'command not found' if pgrep isn't installed, or other system issues. According to the project's general rules, error suppression should be avoided to aid debugging. The || true is sufficient to handle the case where no processes are found. This applies to all pgrep calls in this script (e.g., lines 120, 143, 148, 153, 167, 204).

Suggested change
opencode_pids=$(pgrep -f '\.opencode' 2>/dev/null || true)
opencode_pids=$(pgrep -f '\.opencode' || true)
References
  1. Avoid blanket suppression of command errors with '2>/dev/null' in shell scripts to ensure that system issues remain visible for debugging.


# List detected interactive sessions with details.
# Output format: PID | APP | RSS_MB | UPTIME | DIR
list_sessions() {

Choose a reason for hiding this comment

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

medium

The list_sessions function currently only lists details for 'OpenCode' and 'Claude Code' sessions. However, count_interactive_sessions also counts 'Cursor', 'Windsurf', and 'Aider' sessions. This can lead to confusing output from the list command, where the detailed list is shorter than the reported total. To improve clarity, please extend list_sessions to also find and display details for Cursor, Windsurf, and Aider processes, similar to how it's done for OpenCode and Claude Code.

References
  1. An info/describe function like 'list_sessions' should be comprehensive and include all relevant items, especially if another related function (e.g., 'count_interactive_sessions') counts them, to allow users to inspect their own work and avoid confusing output, aligning with the principle that info/describe functions must include relevant details.

@alex-solovyev alex-solovyev merged commit 15f3f4c into main Mar 5, 2026
27 of 28 checks passed
@alex-solovyev alex-solovyev deleted the feature/session-count-awareness branch March 5, 2026 03:40
marcusquinn added a commit that referenced this pull request Mar 6, 2026
…p -c incompatibility

Address PR #2883 review feedback (Gemini Code Assist):
- Remove 2>/dev/null from session-count-helper.sh calls in pre-edit-check.sh
  and aidevops-update-check.sh to surface diagnostic errors
- Remove 2>/dev/null from pgrep calls in session-count-helper.sh (retain only
  on ps calls where PID race conditions justify suppression)
- Fix pgrep -c flag usage (not available on macOS) — replace with pgrep | wc -l
- Extend list_sessions() to include Cursor, Windsurf, and Aider details,
  matching the apps already counted by count_interactive_sessions()
- Extract _print_session_detail() helper to reduce duplication

Closes #2897
marcusquinn added a commit that referenced this pull request Mar 6, 2026
…ibility (#2945)

* fix: remove blanket 2>/dev/null stderr suppression and fix macOS pgrep -c incompatibility

Address PR #2883 review feedback (Gemini Code Assist):
- Remove 2>/dev/null from session-count-helper.sh calls in pre-edit-check.sh
  and aidevops-update-check.sh to surface diagnostic errors
- Remove 2>/dev/null from pgrep calls in session-count-helper.sh (retain only
  on ps calls where PID race conditions justify suppression)
- Fix pgrep -c flag usage (not available on macOS) — replace with pgrep | wc -l
- Extend list_sessions() to include Cursor, Windsurf, and Aider details,
  matching the apps already counted by count_interactive_sessions()
- Extract _print_session_detail() helper to reduce duplication

Closes #2897

* fix: remove redundant wc whitespace normalization in session-count-helper.sh

Arithmetic expansion already handles leading whitespace from wc -l output,
making the $((var + 0)) normalization steps unnecessary. Addresses Gemini
Code Assist review feedback on PR #2945.
marcusquinn added a commit that referenced this pull request Mar 6, 2026
…ions() coverage

Address PR #2883 review feedback (GH#2898):
- Remove 2>/dev/null from all pgrep calls — || true already handles no-match
  exit codes, and stderr suppression hid real errors (e.g. pgrep -c unsupported
  on macOS)
- Replace Linux-only pgrep -c with pgrep | wc -l for cross-platform compat
- Extend list_sessions() to include Cursor, Windsurf, and Aider processes,
  matching the coverage of count_interactive_sessions()
- Extract _print_session_detail() helper to reduce duplication in list output
- Remove 2>/dev/null from session-count-helper.sh callers in
  aidevops-update-check.sh and pre-edit-check.sh

Closes #2898
marcusquinn added a commit that referenced this pull request Mar 6, 2026
…ions() coverage

Address PR #2883 review feedback (GH#2898):
- Remove 2>/dev/null from all pgrep calls — || true already handles no-match
  exit codes, and stderr suppression hid real errors (e.g. pgrep -c unsupported
  on macOS)
- Replace Linux-only pgrep -c with pgrep | wc -l for cross-platform compat
- Extend list_sessions() to include Cursor, Windsurf, and Aider processes,
  matching the coverage of count_interactive_sessions()
- Extract _print_session_detail() helper to reduce duplication in list output
- Remove 2>/dev/null from session-count-helper.sh callers in
  aidevops-update-check.sh and pre-edit-check.sh

Closes #2898
marcusquinn added a commit that referenced this pull request Mar 6, 2026
…ions() coverage (#2962)

Address PR #2883 review feedback (GH#2898):
- Remove 2>/dev/null from all pgrep calls — || true already handles no-match
  exit codes, and stderr suppression hid real errors (e.g. pgrep -c unsupported
  on macOS)
- Replace Linux-only pgrep -c with pgrep | wc -l for cross-platform compat
- Extend list_sessions() to include Cursor, Windsurf, and Aider processes,
  matching the coverage of count_interactive_sessions()
- Extract _print_session_detail() helper to reduce duplication in list output
- Remove 2>/dev/null from session-count-helper.sh callers in
  aidevops-update-check.sh and pre-edit-check.sh

Closes #2898
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.

t1398.4: Add session count awareness

1 participant