# Memory interface

1. **Scheduler** timing, execution, status, results
2. `MemoryRef` read at each run; `memory_update` by the agent
3. **Memory** long-term facts, Git transactions

| Task type | Behaviour |
| --- | --- |
| One-time | Timezone-aware `run_at`, runs once |
| Recurring | Five-field cron, owner signatures, frozen sandbox policies, non-interactive execution |
| Monitoring | Observation prompts on cron; records logs and state, no cross-channel exactly-once notification |

Excluded: the Memory writer inferring tasks, Commitments on Memory pages, the service implicitly changing Memory, cross-store transactions, an external-token permission model, placeholders or forwarding for deleted records, a second executor, project management, dependencies, subtasks.

## Lifecycle of a run

1. Owner Web UI, an Agent tool or an external API creates the task.
2. The runtime signs prompt or command, cwd, permissions, sandbox and MemoryRef.
3. The persistent worker checks once and cron schedules every minute.
4. Each run begins by loading the memory as it stands now, through `workspace_id + memory_id`.
5. Execution stays in the frozen non-interactive boundary and writes Scheduler logs and state.

**Tick exceptions**

- An `Exception` in the `@reboot` tick or an ordinary tick goes to stderr as a warning and full traceback; the daemon continues at the next minute boundary without replay. After an initial failure, later ticks use `reboot=False`.
- Persistent worker: stderr goes to the global worker log. Foreground `scheduler-worker`: the terminal. Neither is a task execution log.
- `run_once`, `KeyboardInterrupt`, `SystemExit` and other `BaseException` stay fail-fast.
- `scheduler-worker` and its alias `cron-worker`, with `--once` and `--list`, bypass the stdio redirection meant for Ink TUI startup.

## MemoryRef

| Field | Rule | Failure |
| --- | --- | --- |
| `workspace_id` | Stable ID of the current Memory workspace | Implicit cross-workspace reads rejected |
| `memory_id` | Resolves to a unique Topic block at create and update; content reread at each execution | On write: missing, duplicate, cross-workspace or malformed rejected. Before execution: the task fails, with no fallback to an old snapshot. If several refs exceed the limit, all IDs and Topic paths stay, only content is cut and marked. |
| Write capability | The ref grants none. Local-owner prompt tasks may use `memory_search`, `memory_get`, `memory_update`, through existing citation checks, format validation, derived views and Git transactions. | A failed Memory transaction leaves Scheduler state alone |

## Agent protocol

| Phase | Agent | Boundary |
| --- | --- | --- |
| Planning | Only for a task worth keeping: `memory_update.create_record`, then attach the returned `memory_id` as `memory_refs` | Sequential, not atomic; either failure is reported. Temporary reminders need no Memory. |
| Execution | Reads the original record, then `update_record` with status, results or what the next run needs | Other tools follow the conversation's permission mode. Only Memory lifecycle tools are refused to a schedule not set up by the owner. |
| Closure | Mark completed or closed, or `delete_record` when nothing is worth keeping. An interactive agent may disable or delete the task. | The old ID returns `NOT_FOUND`; a task still referencing it fails next time, so remove the task first. |

Deleted content stays recoverable from reachable Git history if it was committed, the repository exists and history was not rewritten. `memory_get` queries only HEAD, so an old ID is not queryable through the API.

## Legacy Commitments

| Record | Becomes |
| --- | --- |
| `open`, dated | Enabled one-time task at 09:00 local on that date |
| `open`, undated | Paused one-time draft keeping text and provenance until the owner sets a time |
| Original file | `commitments.jsonl` moves to the Scheduler migration archive; repeated startups create no duplicates |
| Memory writer | No `record_commitments` tool or prompts. The old parser stays only for migration. |

Where the user sees and edits the tasks: [Tasks page](https://fzkuji.github.io/OpenProgram/docs/reference/design/scheduler/tasks-page.html).

**Choices**

| Source | Handling |
| --- | --- |
| Existing cron | Execution safety and cron-compatible entry points stay; named Scheduler, in the persistent worker |
| Commitments, heartbeat | Not a Memory type; migration reads only, no tab, status field or special heartbeat |
| Automatic dual writes | Rejected. Agents compose two existing tools. |

## Acceptance

- The three Memory tools execute from a Scheduler prompt worker, deny and ask rules still win, and a scripted run updates a Topic with a Memory Git commit.
- Regressions cover initial and ordinary ticks, waits, oversleep, logging, CLI entry points and both fail-fast boundaries.

## Implementation status

Implemented: internal-agent lifecycle, tick isolation. Deferred: the external-token permission model.
