Raven icon indicating copy to clipboard operation
Raven copied to clipboard

fix(rpc): editing a cron job silently replaces its delivery target

Open loading2332 opened this issue 1 month ago • 0 comments

Summary

Editing an existing channel-bound cron job through cron.save silently changes its delivery target to tui/default. A user can change only the schedule or instruction in the web settings and cause a Telegram or Feishu reminder to stop targeting its original conversation.

The job keeps its ID and the edit succeeds, so the returned row gives no indication that its destination changed.

Reproduction

Verified against upstream main d102810be308aaccb5d9b55c2341e4b3bb4238ff on macOS with Python 3.12. This uses the real RPC handler and CronService with a temporary on-disk store. No model, channel credentials, or network delivery is involved.

Run from a source checkout with its development environment:

uv run --no-sync python - <<'PY'
import asyncio
import json
import tempfile
from pathlib import Path
from types import SimpleNamespace

from raven.proactive_engine.schedulers.cron.service import CronService
from raven.proactive_engine.schedulers.cron.types import CronSchedule
from raven.rpc.methods.console import cron_list, cron_save

async def main():
    with tempfile.TemporaryDirectory() as scratch:
        path = Path(scratch) / "jobs.json"
        service = CronService(path, allowed_channels=None)
        loop = SimpleNamespace(cron_service=service)
        job = service.add_job(
            "summary", CronSchedule(kind="every", every_ms=3600000),
            "Summarize the project", channel="telegram", to="sanitized-chat",
        )
        print("before:", job.payload.channel, job.payload.to)
        rows = (await cron_list({}, agent_loop_factory=lambda: loop))["jobs"]
        assert any(row["id"] == job.id for row in rows)
        await cron_save(
            {"id": job.id, "kind": "every", "every_seconds": 7200,
             "name": "summary", "message": "Summarize the project"},
            agent_loop_factory=lambda: loop,
        )
        stored = json.loads(path.read_text())["jobs"][0]
        print("same ID:", stored["id"] == job.id)
        print("after:", stored["payload"]["channel"], stored["payload"]["to"])

asyncio.run(main())
PY

Actual output, excluding service logs:

before: telegram sanitized-chat
same ID: True
after: tui default

Additional checks using the same real handler and store:

Original target Target persisted after editing only the interval
telegram / sanitized-chat tui / default
feishu / sanitized-chat tui / default
tui / default tui / default

Expected behavior

An edit that changes only a job's name, instruction, or schedule preserves the existing channel and recipient. New jobs created from the web page can retain their current local default.

Source path

  • cron_list and _job_info expose all stored jobs to the page, but omit their channel and recipient from the row.
  • jobToSave submits an existing job's ID and editable fields to cron.save.
  • cron_save always passes channel=LOCAL_CHANNEL and to="default", including when editing an existing ID.
  • CronService.add_job persists both values in the in-place edit branch.
  • The cron runner reads the job's stored channel and recipient as its execution origin.

The same RPC edit also clears an existing topic_tag, because it omits that argument while the service edit branch assigns the default None. Preserving non-editable job metadata belongs to the same edit boundary.

Suggested scope

Preserve the existing job's delivery binding and non-editable metadata when updating a named job. Keep local defaults for genuinely new jobs. Add coverage to tests/test_rpc_console.py using a pre-existing external-channel job, and assert the persisted payload after a schedule-only edit, alongside the existing local create/edit cases.

Verification boundary

Confirmed: real handler execution, successful RPC result, listing visibility, stable job ID, and changed persisted delivery fields on the latest upstream source. The source was loaded from a temporary extraction of the stated commit. Browser interaction, real model execution, and real Telegram/Feishu delivery were not exercised.

loading2332 avatar Oct 15 '26 08:10 loading2332