Skip to content

feat(cron): add per-job permission mode override#367

Merged
chenhg5 merged 2 commits intochenhg5:mainfrom
mkloveyy:feat/cron-job-permission-mode
Apr 2, 2026
Merged

feat(cron): add per-job permission mode override#367
chenhg5 merged 2 commits intochenhg5:mainfrom
mkloveyy:feat/cron-job-permission-mode

Conversation

@mkloveyy
Copy link
Copy Markdown
Contributor

Summary

  • Allow individual cron jobs to specify a permission mode (e.g. bypassPermissions) independent of the project default
  • Mode is applied via LiveModeSwitcher.SetLiveMode() before execution and restored via defer after completion
  • Added PATCH support to management API for editing existing cron jobs
  • Web dashboard supports viewing and editing mode per job

Background

Cron jobs run unattended but inherit the project's permission mode. With mode = "default", a cron job that triggers tool calls (Bash, Write, etc.) will block waiting for user approval — defeating the purpose of automation. This feature lets users set mode = "bypassPermissions" on specific cron jobs while keeping the project in default mode for interactive sessions.

Changes

  • core/cron.goMode field on CronJob + validation + updateJobField support
  • core/message.goModeOverride field on Message as runtime carrier
  • core/engine.go — Apply/restore mode in processInteractiveMessageWith
  • core/api.goCronAddRequest.Mode + job construction
  • core/management.goCronAddRequest.Mode + PATCH handler for /cron/{id}
  • web/ — Inline mode selector, create form dropdown, i18n (5 languages)

Test plan

  • go build ./... passes
  • go test ./core/ -run TestCron -v passes
  • Manual test: cron with bypassPermissions auto-approved Write tool, no permission prompt
  • Manual test: subsequent user message on same session correctly prompted for permission (mode restored)

@mkloveyy mkloveyy force-pushed the feat/cron-job-permission-mode branch from 5f655cf to ef81132 Compare March 29, 2026 14:35
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

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

LGTM. Useful feature for cron job automation.

Review notes:

  • ✅ CI passes
  • Adds per-job permission mode override (mode field on CronJob)
  • Proper validation of mode values
  • Mode applied via LiveModeSwitcher.SetLiveMode() and restored via defer
  • Good test coverage

This enables unattended cron jobs to bypass permissions while keeping project in default mode for interactive sessions. Approved for merge.

Allow individual cron jobs to specify a permission mode (e.g.
bypassPermissions) that overrides the project default during execution.
The mode is restored after the job completes to prevent leakage into
subsequent user messages.

Changes:
- CronJob.Mode field with validation against known modes
- Message.ModeOverride as runtime carrier to processInteractiveMessageWith
- LiveModeSwitcher.SetLiveMode applied with defer-based restoration
- CronAddRequest.Mode in both Unix socket and management HTTP APIs
- Management API PATCH support for editing existing cron jobs
- Web dashboard: inline mode selector per job + create form dropdown
- i18n translations for all 5 languages (EN/ZH/ZH-TW/JA/ES)
@mkloveyy mkloveyy force-pushed the feat/cron-job-permission-mode branch from ef81132 to f637895 Compare March 30, 2026 13:21
@mkloveyy
Copy link
Copy Markdown
Contributor Author

@chenhg5 Hi, I've just rebased this branch onto latest main and resolved all the merge conflicts (management.go, CronList.tsx, i18n files, cron.ts). Build and tests pass. Could you take a look and merge when you get a chance? Thanks!

@chenhg5 chenhg5 merged commit c07740b into chenhg5:main Apr 2, 2026
5 checks passed
@mkloveyy mkloveyy deleted the feat/cron-job-permission-mode branch April 2, 2026 02:19
chenhg5 pushed a commit that referenced this pull request Apr 2, 2026
- fix(relay): process current event before timeout check, close session
  on channel drain (#405)
- fix(claudecode): prevent reader goroutine leak in usage probe, add
  terminal memory bounds (#380)
- fix(cron): validate mode/session_mode on UpdateJob, only restore live
  mode when override succeeds (#367)
- fix(core): simplify idle rotation recovery — remove inconsistent
  fallback to old session (#400)
- fix(feishu): use cache-disabled client for tenant token refresh (#401)
- fix(setup): revert --set-allow-from-empty default to false to avoid
  unintended CLI behavior change (#376)
- feat(telegram): gate message reactions behind enable_reactions config
  flag (#398)

Made-with: Cursor
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.

2 participants