Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.

feat(scripts): add cron-gate.sh — defer cron jobs while owner tasks are queued - #102

Open
jgluck96 wants to merge 2 commits into
mainfrom
feat/cron-gate-script
Open

jgluck96 wants to merge 2 commits into
mainfrom
feat/cron-gate-script

Conversation

@jgluck96

@jgluck96 jgluck96 commented Jun 4, 2026

Copy link
Copy Markdown

Summary

Cron jobs like check-pending-questions.py and sync-memory.sh should not compete with owner-task processing. cron-gate.sh acts as a gate: if the task queue is non-empty, it defers the wrapped command and exits 0 (so the scheduler sees success and the next scheduled fire retries automatically).

Usage (from crons.json prompt strings):

bash scripts/cron-gate.sh pending-questions python3 src/check-pending-questions.py
bash scripts/cron-gate.sh sync-memory bash scripts/sync-memory.sh

Behavior:

  • Task queue empty → exec the wrapped command (transparent pass-through)
  • Tasks queued → log "N owner task(s) queued — deferring", exit 0
  • No command given → exit 1 with error

Workspace resolution mirrors workspace_default.py: reads $SUTANDO_WORKSPACE, falls back to ~/.sutando/workspace.

Test plan

  • Empty queue: passes through and runs command
  • Tasks queued: defers without running command
  • No command: exits 1 with error message
  • 240/240 TS tests pass (no TS changes)
  • 27/27 Python tests pass (no Python changes)

🤖 Generated with Claude Code

jgluck96 and others added 2 commits June 4, 2026 16:35
…are queued

Cron jobs like `check-pending-questions.py` and `sync-memory.sh` should
not interrupt owner-task processing. `cron-gate.sh` defers the wrapped
command when `$SUTANDO_WORKSPACE/tasks/*.txt` exists, then exits 0 so
the scheduler sees success and the next scheduled fire retries.

Usage (from crons.json prompts):
  bash scripts/cron-gate.sh <name> <command> [args...]

- Empty task queue  → exec the command
- Tasks queued      → log a defer message, exit 0 (retry next fire)
- No command given  → exit 1 with error

Resolves SUTANDO_WORKSPACE the same way workspace_default.py does
(env var → ~/.sutando/workspace default).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…gate in example

Now that scripts/cron-gate.sh ships with the repo, the canonical crons.example.json
should demonstrate its use for the two crons that compete with owner-task processing.
Users who copy this example get deferred execution out of the box.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@bassilkhilo-ag2 bassilkhilo-ag2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good script. Logic is correct: resolve workspace from SUTANDO_WORKSPACE (with home fallback), count .txt files at depth-1 in tasks/, exec the command if queue is empty or defer with exit 0. The crons.example.json updates demonstrate the usage pattern cleanly. Per CLAUDE.md: this gate correctly targets sub-daily crons only (pending-questions */30, sync-memory */30, cross-node-sync) — daily crons like morning-briefing aren't gated since a skipped daily is unrecoverable until the next day. Approved.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants