Skip to content

feat(cto): routines can take a check, and wake the CTO only on news - #2496

Open
arul28 wants to merge 3 commits into
mainfrom
worktree-deft-navy-falcon
Open

arul28 wants to merge 3 commits into
mainfrom
worktree-deft-navy-falcon

Conversation

@arul28

@arul28 arul28 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What

A CTO routine (a recurring cron) can now take a check: a shell command ADE runs in the project folder before each fire. The CTO wakes only when there is news.

  • It passes (exit 0) and the sha256 of its stdout differs from the stored hash. Stderr is not hashed.
  • It fails for the first time. Later failures stay quiet until it passes again. The hash from before the failure is kept, so a pass that brings back that same output is not news either.

A quiet run spends the occurrence without a turn and moves the cron on. A wake puts the verdict and the end of the output above the routine's prompt. When the routine is made, the check runs once as the baseline, and that run goes back to the CTO in the tool result.

  • Store: check, checkHash, checkFailing and lastCheckedAt on the scheduled-work row (chatScheduledWorkScheduler.ts). The gate runs in the scheduler's fire path, after the busy-defer and the shared claim. A cancel, pause or replacement that lands while the check runs wins, and the claim is released.
  • Runner: scheduledWorkCheck.ts runs /bin/sh -c on macOS and Linux and cmd.exe /d /s /c on Windows, through runReapedCommand (process-group reaping, 60 s limit, 1 MiB of output), with the login-shell PATH. runReapedCommand gains windowsVerbatimArguments for the cmd line.
  • Tool: scheduleWork takes check (recurring cron only). listScheduledWork shows check and checkFailing.
  • Guidance: one line next to the existing scheduleWork rule in the CTO's guidance: when a routine watches for a change, give it a check, and pick the longest interval that still serves the person. This is deliberately outside IMMUTABLE_CTO_DOCTRINE, so it doesn't collide with feat(cto): reply, react, or stay quiet, and delegate to background helpers #2492.
  • UI parity (redesigned after review: the old rows were tag-heavy):
    • Desktop and web (same renderer, CtoRoutineRows), and iOS (CtoProfileSheet), now share one row:
      • A tinted icon tile carries the state: accent when on, muted when off, red with a dot when the check is failing, and a pulsing dot while it runs.
      • One schedule line. A watch reads "On change · every 30 min"; a paused routine shows no next time.
      • One quiet note, in this order: "Running now", "Check failing · quiet until it passes", the last outcome, or "Quiet since it last woke 3 h ago".
      • In settings a row opens in place to show the prompt, a light "Wakes when this changes" block with the command and its last result, and "Last ran".
      • Fewer controls: the ⋯ menu shows on hover (desktop); a long-press menu on iOS. Motion uses opacity and transform only, and respects reduced motion.
    • iOS has a new -adePreviewScreen cto-settings-routines fixture.
    • Account-copy views (desktop, iOS, GET /cloud/cto) show "on change".
  • Moves: the account copy carries the check, so a moved CTO's routines keep their checks.

Security

A check is a shell command. The public chat.createScheduledWork (IPC, remote devices, ade) takes args only and drops any check. Only the CTO's scheduleWork tool and the routine restore pass one, through an in-process option. A test covers this.

Remote and providers

  • Remote: the check runs in the brain that fires the routine, which is the CTO's home machine. No new pinned call: listing already routes by pin.
  • Providers: the gate is in ADE's own scheduler, so it is the same for every provider the CTO runs on. Claude-native crons are not CTO routines and take no check.

Review fixes

  • An undelivered wake (a retry from fire, or a failed save before delivery) now puts the check state back, so the retry still wakes. Before, the next attempt treated the news as already reported.

  • A brain that follows another brain's claim now adopts its check hash and failure state, so it doesn't report the same news again when it takes over.

  • Two scheduler tests cover these. Each one fails when its fix is removed.

  • Tests: touched files only, 177 pass, plus 45/45 in the scheduler file after the review fixes. New: the check state machine through the real scheduler (quiet / changed / failed / quiet / quiet-on-old-output / changed), cancel during the check, the real runner, and the IPC drop. Both scheduler tests were shown to fail when the rule is broken.

  • Live, real scheduler and real shell checks: the CTO is woken at exactly the expected occurrences, with the expected wake text.

  • Live runner:

    • A missing command fails with exit 127.
    • A hung check is killed at the limit, with no child left behind.
    • stderr noise is ignored.
    • Over-size output fails the check.
    • gh is found through the login PATH.
  • UI: before/after screenshots and two recordings (desktop renderer preview with mock rows; iOS simulator fixture) of toggle, Run now and a failing check passing again are in the task report.

  • Typecheck: clean in desktop source. The only errors are in ade-cli, from missing deps in this worktree. Account-directory is clean apart from an unrelated missing @gravity-ai/api. The iOS build passes.

Not covered

  • A chat moved with a cross-machine handoff loses its check and becomes a plain cron.
  • Not tested live: a real CTO turn on each provider, a home on another machine or ADE Cloud, and the account-copy move.

Also

WorkChatSessionView.swift:1967 broke the iOS build on Xcode 26.5 (a local sponsoredInlineHost shadows the method its closure calls; from #2490). It now calls self.sponsoredInlineHost(for:).

🤖 Generated with Claude Code


Devin Review

ADE   Open in ADE  ·  worktree-deft-navy-falcon branch  ·  PR #2496

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; both previous findings are addressed and no new actionable issues were found.

Summary

Adds shell checks that wake CTO routines only for changed output or a newly failing check. Desktop, web, iOS, and saved account copies show the checks.

  • CTO routines can check for news before waking the chat.
  • Routine rows show check status and open details in place.
  • Account copies carry checks with the CTO's routines.
  • The iOS transcript builder calls its helper explicitly.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Cron becomes due] --> B[Check pause, busy state, and shared claim]
  B --> C[Run shell check]
  C --> D{News?}
  D -- No --> E[Save check result and advance cron]
  D -- Yes --> F[Save firing state and send wake]
  F --> G{Delivery asks to retry?}
  G -- Yes --> H[Restore previous check state and retry later]
  G -- No --> I[Advance cron]
Loading

Reviews (2) · Last reviewed commit: "feat(cto): calmer routine rows on deskto..." · Reviewed by Greptile

A CTO cron can now carry a check: a shell command ADE runs in the project
folder before each fire. The CTO wakes only when the check's stdout hash
differs from the last run's, or the first time it fails; a failing check
stays quiet until it passes again. The hash, failing flag and last check
time live on the scheduled-work row. scheduleWork exposes `check`, the
routine rows on desktop, web and iOS show it, and the CTO's guidance tells
it to prefer a check and the longest interval that serves the person.

Only the CTO tool and the routine restore can set a check; the public
chat.createScheduledWork (IPC, remote, ade) drops it.

Also fixes an iOS build break on Xcode 26.5 in WorkChatSessionView
(a local shadowing the method it calls).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b7ebcac and d5c0f9d.

Files ignored due to path filters: 1

  • docs/features/cto/README.md is excluded by !docs/**
Files selected for processing: 25

  • apps/account-directory/src/cloud/contract.ts
  • apps/account-directory/src/cloud/ctoCopy.ts
  • apps/desktop/src/main/services/ai/tools/ctoOperatorTools.ts
  • apps/desktop/src/main/services/chat/agentChatService.ts
  • apps/desktop/src/main/services/chat/agentChatServiceScheduledWork.test.ts
  • apps/desktop/src/main/services/chat/chatScheduledWorkScheduler.test.ts
  • apps/desktop/src/main/services/chat/chatScheduledWorkScheduler.ts
  • apps/desktop/src/main/services/chat/scheduledWorkCheck.test.ts
  • apps/desktop/src/main/services/chat/scheduledWorkCheck.ts
  • apps/desktop/src/main/services/cto/ctoStateService.ts
  • apps/desktop/src/main/services/shared/runReapedCommand.ts
  • apps/desktop/src/renderer/components/cto/CtoAccountCopyView.tsx
  • apps/desktop/src/renderer/components/cto/CtoRoutineRows.tsx
  • apps/desktop/src/renderer/components/cto/ctoPage.css
  • apps/desktop/src/shared/ctoAccountCopy.ts
  • apps/desktop/src/shared/types/chat.ts
  • apps/ios/ADE/Models/RemoteModels.swift
  • apps/ios/ADE/Services/CloudAtRestReads.swift
  • apps/ios/ADE/Views/Cloud/CloudAtRestPreviews.swift
  • apps/ios/ADE/Views/Cto/CtoAccountCopy.swift
  • apps/ios/ADE/Views/Cto/CtoPreviews.swift
  • apps/ios/ADE/Views/Cto/CtoProfileSheet.swift
  • apps/ios/ADE/Views/Cto/CtoStore.swift
  • apps/ios/ADE/Views/Work/WorkChatSessionView.swift
  • apps/ios/ADE/Views/Work/WorkPreviews.swift
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@devin-ai-integration devin-ai-integration 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.

Devin Review found 5 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +552 to +559
const decision = decideScheduledWorkCheck(schedule, run);
// A check that wakes is stamped with the fire's own time, so a reader can
// tell it from a later quiet one.
schedule.lastCheckedAt = decision.wake ? currentTime : now();
if (decision.checkHash) schedule.checkHash = decision.checkHash;
else delete schedule.checkHash;
if (decision.checkFailing) schedule.checkFailing = true;
else delete schedule.checkFailing;

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.

🔴 Lost news after wake retry

When delivery asks for a retry, processDue has already saved the new check result. The retry restores the fire time, not the old baseline. An unchanged retry result suppresses the wake that was never sent.

Learn more

A check compares its result with the last stored passing hash and failure flag. For a wake-worthy result, the scheduler stores both before asking the chat to deliver the wake. The wake handler returns retry on a retryable refusal. The retry branch releases the claim and rearms the row without restoring the check fields. The next attempt sees the same result as already handled and advances the cron quietly.

Example: A PR check changes from pending to green. The first delivery returns retry, and the next probe is still green. The scheduler makes only one delivery attempt and never sends the green result.

Recommended fix: Keep the prior check state until delivery is accepted, or persist the qualifying result as a pending wake. On a definite pre-delivery refusal, retain the pending wake or restore the prior hash, failure flag, and check timestamp before persisting and rearming.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +26 to +29
function checkEnv(): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = { ...process.env };
setPathEnvValue(env, augmentProcessPathWithShellAndKnownCliDirs({ env, includeInteractiveShell: true, preferShellOrder: true }));
return stripHostRuntimeEnv(env);

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.

🔴 PR watches miss ADE GitHub credentials

With only ADE's GitHub sign-in configured, checkEnv leaves the recommended gh check unauthenticated. Chat launches receive the account's GitHub environment separately. The routine keeps failing instead of watching the PR.

Learn more

Project chats receive GitHub credentials or a credential shim through the project chat environment. The headless runtime wires this to the project GitHub service, which can use an account App connection or a carried GitHub CLI sign-in. Routine checks run as separate children of the brain and do not inherit those session settings. The scheduleWork example therefore depends on a separate local GitHub CLI credential that the rest of the feature does not require.

Example: On a fresh ADE Cloud computer with an ADE GitHub App connection but no local gh login, ask the CTO to watch a private PR. The ordinary chat can read it, but the routine's baseline and every later check fail authentication.

Recommended fix: Route PR watches through an authenticated, project-scoped GitHub read or use the existing scoped GitHub credential mechanism for supported check commands. Do not copy the chat's entire environment or expose raw account credentials to arbitrary check commands.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +539 to +542
if (schedule.kind === "cron" && schedule.check && options.runCheck) {
let run: ChatScheduledWorkCheckRun;
try {
run = await options.runCheck(cloneSchedule(schedule));

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.

🔴 Interrupted check strands its routine

If ADE exits during runCheck, the claim survives without a recorded result. On restart, followClaimOwner keeps waiting for the dead runtime. The routine stops checking until the eight-day claim expires.

Learn more

The scheduler uses a database claim to ensure only one brain handles each occurrence. claimFire records the claim before the check runs, and the occurrence still has its original scheduled time during that wait. If the brain exits before it can save or release the claim, startup reconciliation re-arms the unchanged row. The new brain cannot claim it and finds no result to follow. The new shell wait widens that gap from a scheduler write to as long as the command timeout.

Example: An hourly watch starts a 30-second check and its computer restarts before it finishes. After restart, the watch remains on that same occurrence and misses subsequent hourly checks until the original claim ages out.

Recommended fix: Give the pre-delivery check claim a recoverable lease or a verifiable owner. Keep a distinct durable state for claimed occurrences that have already entered wake delivery, so recovery does not resend a wake that reached the chat.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

...(routine.reason ? { reason: routine.reason } : {}),
...(routine.timeZone ? { timeZone: routine.timeZone } : {}),
});
}, { check: routine.check ?? null });

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.

🟡 Paused checks run during moves

When a CTO moves homes, replaceCtoRoutines executes checks for routines that were off. createScheduledWork runs the baseline before restore reapplies the pause.

Learn more

The saved copy records whether each routine was paused. Restore creates the job before reapplying its pause. For checked jobs, creation runs the shell before inserting the row, so restoring an off routine still executes it. Restore also discards the baseline result it receives, so the run is not reported to the CTO.

Example: Turn off a staging health check, then move the CTO from a laptop to a cloud computer. The destination calls staging during the move even though the routine remains off in settings.

Recommended fix: Hydrate restored routines with their pause state in the initial write and do not run their checks during restore. Carry the previous hash and failure flag where available, so moving homes also preserves the last observed result rather than silently treating changed output as the new baseline.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

...(delaySeconds != null ? { delaySeconds } : {}),
...(recurring != null ? { recurring } : {}),
...(reason?.trim() ? { reason: reason.trim() } : {}),
...(check?.trim() ? { check: check.trim() } : {}),

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.

🟥 Routine checks bypass CTO write restrictions

scheduleWork lets the CTO run unrestricted shell commands in the main checkout without approval. createScheduledWork executes the command immediately, outside the CTO’s repository-write controls.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c2ad4ca. Configure here.

if (decision.checkHash) schedule.checkHash = decision.checkHash;
else delete schedule.checkHash;
if (decision.checkFailing) schedule.checkFailing = true;
else delete schedule.checkFailing;

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.

Check state not rolled back on fire retry

High Severity

processDue mutates schedule.checkHash, schedule.checkFailing, and schedule.lastCheckedAt before persist() and options.fire(), and neither the persist() error handler nor the if (retry) branch restores them. When fire() returns { retry: true } (such as a retryable refusal or cross-machine move lock) or persist() throws, the deferred retry compares against the already-updated check state, treats the occurrence as quiet, advances fireAt, and permanently drops the wake.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ad4ca. Configure here.

let outcomeSummary: string | undefined;
try {
const result = await options.fire(cloneSchedule(schedule), { late });
const result = await options.fire(cloneSchedule(schedule), { late, ...(checkWake ? { check: checkWake } : {}) });

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.

followClaimOwner leaves stale check state in memory

Medium Severity

When another brain claims and runs a checked cron, followClaimOwner copies status, fireAt, lastFiredAt, lateFlag, and terminalAt from the persisted record, but omits checkHash, checkFailing, and lastCheckedAt. This brain retains stale check state in memory, causing list() to report outdated check status and causing decideScheduledWorkCheck to compare against stale state if this brain wins a later claim.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ad4ca. Configure here.

...(routine.reason ? { reason: routine.reason } : {}),
...(routine.timeZone ? { timeZone: routine.timeZone } : {}),
});
}, { check: routine.check ?? null });

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.

Restored routines silence baseline failures and run while paused

Medium Severity

replaceCtoRoutines calls createScheduledWork with routine.check and discards the returned baseline check result. If a restored routine's check fails on the new machine, createScheduledWork sets checkFailing: true assuming the caller saw the failure, so the CTO is never notified and all future failures stay permanently quiet. Additionally, paused routines still execute their shell check command during restore.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ad4ca. Configure here.

: "(Run now: the person started this early. It will not run again.)"}

${schedule.prompt}`
: schedule.prompt,

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.

Tracked CLI wakes omit check verdict and output

Low Severity

createScheduledWork permits a check on any schedulable session, including tracked agent CLIs, and processDue passes context.check to options.fire(). In the tracked-CLI branch, ptyService.sendToSession sends only schedule.prompt, dropping the scheduledWorkCheckWakeText header and check output that chat sessions receive.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ad4ca. Configure here.

arul28 and others added 2 commits November 25, 2026 02:24
… the owner's verdict

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tinted tile carries the state, one schedule line, one quiet note, and
settings rows open in place to show the prompt and the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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