Skip to content

feat(cron): add per-job profile support#25917

Closed
gianfrancopiana wants to merge 3 commits into
NousResearch:mainfrom
gianfrancopiana:feat/cron-job-profile
Closed

feat(cron): add per-job profile support#25917
gianfrancopiana wants to merge 3 commits into
NousResearch:mainfrom
gianfrancopiana:feat/cron-job-profile

Conversation

@gianfrancopiana

@gianfrancopiana gianfrancopiana commented May 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds per-cron-job Hermes profile pinning so scheduled jobs can run under a specific profile’s config, scripts, and runtime paths without changing behavior for jobs that do not set profile.

This approach keeps the scheduler profile as the storage/scheduling owner, then applies the selected profile only while that job runs via context-local Hermes home scoping, subprocess HERMES_HOME bridging, and profile .env snapshot/restore.

Related Issue

Related: #19958, #14703, #11470, #20622, #25295.
No dedicated issue.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • cron/jobs.py: stores and validates optional profile values on create/update.
  • cron/scheduler.py: runs profile-pinned jobs under context-local profile scope, restores temporary profile .env mutations after each run, and serializes profile/workdir jobs.
  • tools/cronjob_tools.py: exposes profile in the cronjob tool schema and create/update plumbing with an accurate runtime contract.
  • hermes_cli/cron.py and hermes_cli/main.py: add profile support to cron create/edit/list CLI flows.
  • hermes_constants.py and tools/environments/local.py: bridge profile-scoped Hermes home into subprocess environments.
  • tests/cron/test_cron_profile.py and tests/test_subprocess_home_isolation.py: cover validation, runtime scoping, .env restoration, subprocess bridging, and tick serialization.

How to Test

  1. venv/bin/python -m pytest -o 'addopts=' -q tests/cron/test_cron_profile.py
  2. venv/bin/python -m pytest -o 'addopts=' -q tests/cron/test_cron_profile.py tests/cron/test_cron_workdir.py tests/hermes_cli/test_cron.py tests/tools/test_cronjob_tools.py tests/test_subprocess_home_isolation.py tests/tools/test_local_env_blocklist.py tests/tools/test_env_passthrough.py
  3. venv/bin/python -m compileall -q cron/scheduler.py tools/cronjob_tools.py tests/cron/test_cron_profile.py
  4. git diff --check

Focused result: 126 passed.

Full-suite note: a previous full-suite smoke run was attempted, but origin/main already failed on tests/acp/test_approval_isolation.py::TestAcpExecAskGate::test_interactive_env_var_routes_to_callback, so the full-suite failure appears pre-existing.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26.2

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

N/A — this PR does not add a skill.

Screenshots / Logs

126 passed, 8 warnings in 4.47s

Warnings are existing thread-drain warnings from tests/tools/test_local_env_blocklist.py; the focused test set passed.

@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management comp/cli CLI entry point, hermes_cli/, setup wizard labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Overlaps significantly with #19958 (fix(cron): honor per-job profile during scheduler runs) and #14703 (restore cron profile binding). This PR adds CLI/tool plumbing and create/update-time validation on top of the scheduler-only runtime scoping. Related: #11470 (profile job model resolution), #20622 (multi-profile dashboard), #25295 (profile fragmentation).

@slavingia

Copy link
Copy Markdown

Would be awesome!

@gianfrancopiana

Copy link
Copy Markdown
Contributor Author

Overlaps significantly with #19958 (fix(cron): honor per-job profile during scheduler runs) and #14703 (restore cron profile binding). This PR adds CLI/tool plumbing and create/update-time validation on top of the scheduler-only runtime scoping. Related: #11470 (profile job model resolution), #20622 (multi-profile dashboard), #25295 (profile fragmentation).

Agree there’s overlap. This PR covers the E2E flow: checks the profile when jobs are created or edited, supports profiles in the cron CLI/tooling, and keeps existing jobs working the same way.

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

Adds per-cron-job Hermes profile pinning so scheduled jobs can run under a specific profile’s config/scripts/memory paths while preserving legacy behavior when profile is unset.

Changes:

  • Adds an optional profile field to cron job storage + validation, plus CLI/tool plumbing for create/edit/update/list flows.
  • Introduces a context-local HERMES_HOME override (ContextVar-based) and bridges it into subprocess environments.
  • Updates scheduler execution to apply per-job profile context and to serialize profile/workdir jobs; adds targeted regression tests.

Reviewed changes

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

Show a summary per file
File Description
hermes_constants.py Introduces ContextVar-based Hermes home override helpers and makes subprocess HOME resolution honor the override.
cron/jobs.py Adds profile field normalization/validation at create/update time and normalizes the stored record shape.
cron/scheduler.py Adds per-job profile execution context, runs profile/workdir jobs sequentially, and wires profile into script subprocess env.
tools/environments/local.py Bridges context-local Hermes home override into subprocess env for terminal/background tool execution.
tools/cronjob_tools.py Exposes profile on the cronjob tool (formatting, create/update plumbing, schema).
hermes_cli/main.py Adds --profile flags to hermes cron create and hermes cron edit.
hermes_cli/cron.py Plumbs profile through CLI create/edit calls and prints profile on list/create/edit output.
tests/cron/test_cron_profile.py Adds end-to-end tests covering validation/storage, tool wiring, scheduler scoping, and tick serialization.
tests/test_subprocess_home_isolation.py Adds tests for thread-local override semantics and env-bridging into run/background subprocess env.
tests/hermes_cli/test_cron.py Updates CLI tests to cover setting and clearing per-job profile via edit/create.

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

Comment thread cron/scheduler.py
Comment thread tools/cronjob_tools.py Outdated
Comment thread cron/scheduler.py Outdated

@austinpickett austinpickett left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use PULL_REQUEST_TEMPLATE.md, address Copilot comments.

@alt-glitch

Copy link
Copy Markdown
Collaborator

@daimon-nous can you make a proper reproduction environment as well as review?

@daimon-nous daimon-nous Bot 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.

Review: feat(cron): add per-job profile support

Good PR — the ContextVar-based architecture is well-designed. Profile scoping via set_hermes_home_override() + sequential serialization for profile jobs + os.environ snapshot/restore covers the full isolation surface. Tests are comprehensive (406 lines covering validation, runtime scoping, env restoration, subprocess bridging, tick partitioning, and thread isolation). E2E verified: profile override, env restore, subprocess bridging all work against a real isolated HERMES_HOME.

Competing PR #19958 takes a simpler RLock approach but is incomplete — scheduler-only, no CLI --profile, no tool schema update, no subprocess HERMES_HOME bridging. This PR is the right one to land.

See inline comments for specific observations. Nothing blocking — these are follow-up improvements.

Salvage note: AUTHOR_MAP in scripts/release.py is missing an entry for 52470719+gianfrancopiana@users.noreply.github.comgianfrancopiana. CI will block on unmapped emails during release.

Comment thread cron/scheduler.py
Comment thread cron/scheduler.py
Comment thread cron/scheduler.py
Comment thread cron/scheduler.py
Comment thread hermes_constants.py
Comment thread tests/cron/test_cron_profile.py
Comment thread tools/environments/local.py
@daimon-nous

daimon-nous Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #28124 — your 3 commits were cherry-picked onto current main with authorship preserved in git log. Follow-up fixes added on top: AUTHOR_MAP entry, delta-based env restore (idea from #19958), graceful fallback on deleted profiles (idea from #19958), profile+workdir combined test.

#28124

Thank you @gianfrancopiana!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants