Skip to content

t1006: Fix cron PATH and GH_TOKEN detection#1291

Merged
alex-solovyev merged 1 commit intomainfrom
feature/t1006
Feb 12, 2026
Merged

t1006: Fix cron PATH and GH_TOKEN detection#1291
alex-solovyev merged 1 commit intomainfrom
feature/t1006

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Feb 12, 2026

WIP - incremental commits

Ref #1289

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of cron-triggered automated pulses by ensuring proper environment variables (PATH and GitHub authentication) are available during execution, reducing failures in scheduled automation tasks.

- Detect current $PATH and add to crontab env
- Auto-detect GH_TOKEN from 'gh auth token' if available
- Fixes 'opencode CLI not found' errors in cron execution
- Ref GH#1289
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

Walkthrough

The pull request enhances the supervisor-helper.sh script to detect and propagate the user's PATH and GitHub token environment variables to cron-initiated pulses, ensuring automated tasks execute with the same tooling and authentication context as interactive sessions.

Changes

Cohort / File(s) Summary
Cron Environment Inference
.agents/scripts/supervisor-helper.sh
Detects availability of PATH and GH_TOKEN environment variables, constructs an env_vars string, and injects it into the cron command payload to ensure cron-triggered pulses execute with proper tool access and GitHub authentication context.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🕐 When cron pulses lack their PATH and key,
They stumble blind through automation's sea—
But now with token passed and tooling blessed,
The scheduled tasks run strong and fully dressed! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Failed to fetch base branch: From https://github.com/marcusquinn/aidevops
! [rejected] main -> main (non-fast-forward)
+ a731926...3a20847 main -> origin/main (forced update)
✅ 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 'Fix cron PATH and GH_TOKEN detection' directly and specifically describes the main changes in the pull request, which address environment variable propagation for cron-initiated pulses.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t1006
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch feature/t1006
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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.

@github-actions
Copy link

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Thu Feb 12 20:20:01 UTC 2026: Code review monitoring started
Thu Feb 12 20:20:01 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 0

📈 Current Quality Metrics

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

Generated on: Thu Feb 12 20:20:04 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@alex-solovyev alex-solovyev marked this pull request as ready for review February 12, 2026 20:20
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sonarqubecloud
Copy link

@alex-solovyev alex-solovyev merged commit 035f8a8 into main Feb 12, 2026
10 of 11 checks passed
Copy link
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: 2

🤖 Fix all issues with AI agents
In @.agents/scripts/supervisor-helper.sh:
- Around line 13194-13210: The cron entry construction currently injects
GH_TOKEN into env_vars (variables gh_token and env_vars) which writes the secret
into the crontab; remove any logic that appends GH_TOKEN into env_vars so
GH_TOKEN is never placed into the generated cron line. Keep detection of gh CLI
and the gh_token retrieval (the command -v gh / gh auth token block) if you want
to cache or use it at runtime, but stop adding "${gh_token}" to env_vars (the
branch that sets env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}");
instead rely on runtime resolution of credentials and only export non-secret
envs like PATH (user_path) into the cron entry.
- Around line 13194-13212: The PATH value stored in user_path can contain
newlines or '%' characters that break cron entries; after assigning user_path,
sanitize it by stripping newlines/carriage-returns and escaping '%' (e.g.,
replace $'\n' and $'\r' with nothing and replace '%' with '\%'), then use that
sanitized variable (e.g., sanitized_path) when building env_vars and cron_cmd
instead of the raw user_path; ensure env_vars uses sanitized_path so cron
receives a single-line, percent-escaped PATH.

Comment on lines +13194 to +13210
# Detect current PATH for cron environment (t1006)
local user_path="${PATH}"

# Detect GH_TOKEN from gh CLI if available (t1006)
local gh_token=""
if command -v gh &>/dev/null; then
gh_token=$(gh auth token 2>/dev/null || true)
fi

# Build cron command with environment variables
local env_vars=""
if [[ -n "$user_path" ]]; then
env_vars="PATH=${user_path}"
fi
if [[ -n "$gh_token" ]]; then
env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid writing GH_TOKEN into crontab (secret exposure risk).

Embedding GH_TOKEN in the cron entry stores it in plaintext and makes it visible via crontab -l, which is a hard security no-go. The script already resolves GH_TOKEN at runtime (cache + gh/gopass/credentials), so the cron entry doesn’t need the token.

✅ Safer approach (remove GH_TOKEN from cron line)
-	# Detect GH_TOKEN from gh CLI if available (t1006)
-	local gh_token=""
-	if command -v gh &>/dev/null; then
-		gh_token=$(gh auth token 2>/dev/null || true)
-	fi
-
-	# Build cron command with environment variables
+	# Build cron command with environment variables
 	local env_vars=""
 	if [[ -n "$user_path" ]]; then
 		env_vars="PATH=${user_path}"
 	fi
-	if [[ -n "$gh_token" ]]; then
-		env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}"
-	fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Detect current PATH for cron environment (t1006)
local user_path="${PATH}"
# Detect GH_TOKEN from gh CLI if available (t1006)
local gh_token=""
if command -v gh &>/dev/null; then
gh_token=$(gh auth token 2>/dev/null || true)
fi
# Build cron command with environment variables
local env_vars=""
if [[ -n "$user_path" ]]; then
env_vars="PATH=${user_path}"
fi
if [[ -n "$gh_token" ]]; then
env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}"
fi
# Detect current PATH for cron environment (t1006)
local user_path="${PATH}"
# Build cron command with environment variables
local env_vars=""
if [[ -n "$user_path" ]]; then
env_vars="PATH=${user_path}"
fi
🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 13194 - 13210, The cron
entry construction currently injects GH_TOKEN into env_vars (variables gh_token
and env_vars) which writes the secret into the crontab; remove any logic that
appends GH_TOKEN into env_vars so GH_TOKEN is never placed into the generated
cron line. Keep detection of gh CLI and the gh_token retrieval (the command -v
gh / gh auth token block) if you want to cache or use it at runtime, but stop
adding "${gh_token}" to env_vars (the branch that sets
env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}"); instead rely on
runtime resolution of credentials and only export non-secret envs like PATH
(user_path) into the cron entry.

Comment on lines +13194 to +13212
# Detect current PATH for cron environment (t1006)
local user_path="${PATH}"

# Detect GH_TOKEN from gh CLI if available (t1006)
local gh_token=""
if command -v gh &>/dev/null; then
gh_token=$(gh auth token 2>/dev/null || true)
fi

# Build cron command with environment variables
local env_vars=""
if [[ -n "$user_path" ]]; then
env_vars="PATH=${user_path}"
fi
if [[ -n "$gh_token" ]]; then
env_vars="${env_vars:+${env_vars} }GH_TOKEN=${gh_token}"
fi

local cron_cmd="*/${interval} * * * * ${env_vars:+${env_vars} }${script_path} pulse ${batch_arg} >> ${SUPERVISOR_DIR}/cron.log 2>&1 ${cron_marker}"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Sanitize PATH before injecting into cron (cron treats %/newlines specially).

Cron treats % as a newline and rejects embedded newlines, so an unsanitized PATH can silently break the crontab line. Strip newlines and escape % before composing the entry.

🧹 Harden PATH for cron
 	# Detect current PATH for cron environment (t1006)
-	local user_path="${PATH}"
+	local user_path="${PATH}"
+	# Cron treats % as newline; strip newlines and escape %
+	user_path=${user_path//$'\n'/}
+	user_path=${user_path//$'\r'/}
+	user_path=${user_path//%/\\%}
🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 13194 - 13212, The PATH
value stored in user_path can contain newlines or '%' characters that break cron
entries; after assigning user_path, sanitize it by stripping
newlines/carriage-returns and escaping '%' (e.g., replace $'\n' and $'\r' with
nothing and replace '%' with '\%'), then use that sanitized variable (e.g.,
sanitized_path) when building env_vars and cron_cmd instead of the raw
user_path; ensure env_vars uses sanitized_path so cron receives a single-line,
percent-escaped PATH.

marcusquinn pushed a commit that referenced this pull request Feb 12, 2026
…6) (#1291)

- Detect current $PATH and add to crontab env
- Auto-detect GH_TOKEN from 'gh auth token' if available
- Fixes 'opencode CLI not found' errors in cron execution
- Ref GH#1289
marcusquinn pushed a commit that referenced this pull request Feb 12, 2026
…6) (#1291)

- Detect current $PATH and add to crontab env
- Auto-detect GH_TOKEN from 'gh auth token' if available
- Fixes 'opencode CLI not found' errors in cron execution
- Ref GH#1289
@marcusquinn marcusquinn deleted the feature/t1006 branch February 21, 2026 01:59
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.

1 participant