Week 5 · Further reading

Always on, in more depth

The slides covered the main ideas. This page has the details and the evidence, with sources, checked on October 23, 2026. Always-on products change weekly (OpenClaw almost daily): when this page and a product's docs disagree, trust the docs.

  1. Always-on agents in 2026
  2. Spacecraft did it first
  3. OpenClaw, in more depth
  4. Waking up: watchers, heartbeats and schedules
  5. Compaction in Claude Code, Codex and the APIs
  6. Context rot: the evidence
  7. Memory files and long-running harnesses
  8. Control while you sleep
  9. Always on, always exposed
  10. Surviving: the log, doing things once, and the service
  11. When nobody was watching

1. Always-on agents in 2026

AgentSinceWhere it runsWhat wakes it
OpenClaw (open source, MIT)Nov 2025one Gateway process on your machine or a serverchat messages (WhatsApp, Telegram, Slack, Discord, Signal, iMessage, …), a heartbeat, scheduled jobs, webhooks
Claude Code /loopMar 2026your open sessiona prompt repeated on an interval (1 minute minimum; a loop expires after seven days)
Claude Code channels (research preview)Mar 2026your open sessionMCP servers that push messages in: Telegram, Discord, iMessage. "Events only arrive while the session is open"
Claude Code scheduled tasks (formerly routines)Apr 2026Anthropic's cloud: "nothing depends on your laptop being open"a schedule (hourly at most), an API call or an event
GitHub Copilot coding agentSep 2025 (GA)GitHub Actionsan issue assigned to it; it opens a draft pull request
Cursor background agents (now "cloud agents")May 2025 (preview)Cursor's clouda task you hand it
OpenAI Agents API (public beta)Sep 2026OpenAI's servers, a managed Codex harnessyour code; OpenAI "handles session orchestration, context compaction, and recovery"

Why now: METR measures the length of task, in human working time, that an agent finishes half the time. Its latest data (Time Horizon 1.1) puts Claude Opus 4.6 at about 12 hours (95% interval 5–61 hours), and since 2023 that length has doubled about every 129 days. METR says measurements above 16 hours are unreliable with its current tasks, and stopped updating the page in September 2026. A twelve-hour task doesn't fit in one sitting; it fits in a night.

OpenClaw docs · Claude Code: scheduled tasks · Claude Code: channels · Introducing routines · GitHub, Sep 25, 2025 · Cursor 0.50 · OpenAI API changelog · METR time horizons (all accessed October 23, 2026)

2. Spacecraft did it first

Deep-space missions have run "always-on agents" for decades, with a delay no chat app has: New Horizons' signal took 4 hours 26 minutes to reach Earth when it woke for Pluto, Voyager 1's takes 22.5 hours. Their operating habits map almost one to one onto this week.

APL, Nov 13, 2014 · APL, Dec 8, 2014 · New Horizons launch press kit (2006) · Fountain et al., The New Horizons Spacecraft (2008) · NASA, Jul 7, 2026 · JPL: DS1 beacon monitor · Basics of Space Flight, ch. 11 · NASA PD-ED-1243, Fault Protection · NASA, Jul 6, 2015 · NASA Voyager blog, Apr 4, 2024 · JPL, Apr 22, 2024 · JPL, Jun 13, 2024

3. OpenClaw, in more depth

OpenClaw is "a self-hosted gateway that connects your favorite chat apps" to AI agents, and the always-on agent most people have heard of: about 393,000 GitHub stars in October 2026, more than React. It began in November 2025 as Clawdbot, was renamed Moltbot on January 27, 2026 after Anthropic asked for a name change, and became OpenClaw on January 30. Its creator, Peter Steinberger, joined OpenAI in February and said the project would move to a foundation. It changes almost daily, so treat what follows as a snapshot.

A real setup: Federico Viticci (MacStories, January 2026) ran it on a Mac mini with Claude Opus 4.5, chatted with it on Telegram, and gave it cron jobs to check an RSS feed every few hours and write a morning report. He wrote: "I've burned through 180 million tokens on the Anthropic API."

architecture · heartbeat, as of Jul 5, 2026 · heartbeat, current · automations · memory · compaction · repository and docs (October 23, 2026) · MacStories

4. Waking up: watchers, heartbeats and schedules

Watch in code

A watcher is a thread or async task that waits on one source and puts events in the queue. It costs no tokens, so it can check often. Two sources are push in disguise: Telegram's getUpdates with a timeout (long polling) holds the request open until a message arrives, and IMAP's IDLE command lets the server tell you about new mail. Plain polling (SEARCH UNSEEN every minute) is simpler and fine for one inbox. Only one program may long-poll a Telegram bot at a time; a second gets 409 Conflict.

def watch_email(events, mcp):
    seen = load_seen()                                    # ids already handled
    while True:
        for msg in mcp.call("email__check_inbox", unread=True, limit=10):
            if msg["id"] not in seen:
                seen.add(msg["id"]); save_seen(seen)
                events.put(Event("email", source=msg["from"], text=msg["subject"], ref=msg["id"]))
        time.sleep(90)

Your harness can call a plugin's tools itself; the model doesn't have to. Give each event a label the model can't confuse with you, and the local time with its zone: [2026-10-29 03:12 PDT · email from x@y] Subject: …. A model knows the time only if you tell it.

Heartbeats

A heartbeat is a timer that asks "anything to do?", for what no event announces: a deadline, a reminder, a check you asked for. Each one is a full model call. With week 2's gpt-6-astra prices and a 20,000-token prompt, an hourly heartbeat costs about $0.20 when the cache is cold (24 a day, about $5) and about $0.02 when warm. Cheaper designs: check a checklist file in code and call the model only when something is due; use a small model for the heartbeat; keep its prompt short; and send nothing when there is nothing to say.

Schedules

Cron lines have five fields: minute (0–59), hour (0–23), day of month, month, day of week (0 or 7 is Sunday). * means any, */15 every 15, 1-5 a range, 1,15 a list. 0 8 * * 1-5 is 08:00 on weekdays; 30 2 1 * * is 02:30 on the first of each month. Keep the schedule in a file the harness reads, record each job's last run so a restart doesn't repeat it, decide what happens to jobs missed while the agent was off (the homework: skip them), and cap how many jobs the model may create and how often they may run.

Telegram Bot API: getUpdates · RFC 2177: IMAP IDLE · crontab(5) · croniter

5. Compaction in Claude Code, Codex and the APIs

Anthropic's definition: "Compaction is the practice of taking a conversation nearing the context window limit, summarizing its contents, and reinitiating a new context window with the summary." The lightest form is clearing old tool results. Everyone now does both.

WhereWhen it compactsNotable
Claude Codeat the 200K boundary for 200K-window models; at about 967K for native 1M-window models; settable from 100K to 1M (/autocompact 500k)clears old tool outputs first, then summarizes; idle compaction summarizes a long conversation about 54 minutes after your last message, just before its one-hour cache expires
Codex CLI90% of the context window (in the source code), or model_auto_compact_token_limitthe prompt can be replaced with compact_prompt; PreCompact and PostCompact hooks
OpenAI Responses APIa compact_threshold you set (server-side, since February 2026), or a call to /responses/compactreturns an encrypted compaction item, "opaque and not intended to be human-interpretable"
Anthropic APIcontext editing clears tool results from 100,000 input tokens by default (keeping the last 3); server-side compaction defaults to 150,000 (at least 50,000)everything before the compaction block is dropped automatically; since September 2026 also on demand

Two compaction prompts, verbatim

Codex:

You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.

Include:
- Current progress and key decisions made
- Important context, constraints, or user preferences
- What remains to be done (clear next steps)
- Any critical data, examples, or references needed to continue

The resuming model then sees the summary after: "Another language model started to solve this problem and produced a summary of its thinking process…"

Anthropic's API, an example default (it "varies by model"):

You have written a partial transcript for the initial task above. Please write a summary of the transcript. The purpose of this summary is to provide continuity so you can continue to make progress towards solving the task in a future context, where the raw history above may not be accessible and will be replaced with this summary. Write down anything that would be helpful, including the state, next steps, learnings etc. You must wrap your summary in a <summary></summary> block.

The one from class adds what research agents lose most often, under headings: Goal, Done, Open, Decisions, Exact (paths, run ids, DOIs, commands, error lines) and People (who wrote, what they want, what you promised).

What survives in Claude Code

Claude Code: context window · model config · idle compaction · memory · hooks · Codex compaction prompt · OpenAI: compaction · Anthropic: context editing · Anthropic: compaction (all accessed October 23, 2026)

6. Context rot: the evidence

A longer context isn't only more expensive. Models get worse at using it long before it is full, which is why compaction helps even when everything still fits.

arXiv 2502.05167 · arXiv 2510.05381 · Chroma: Context Rot · Anthropic: effective context engineering

7. Memory files and long-running harnesses

A memory file has one advantage over a summary: it can be searched, read in part and corrected, by you as well as the agent. Keep it short; whatever is in it is read at every wake-up.

Anthropic, Sep 29, 2025 · Anthropic, Nov 26, 2025 · memory tool · OpenClaw memory, Feb 14, 2026

8. Control while you sleep

RFC 3834: automatic responses to email · RFC 2919: List-Id

9. Always on, always exposed

An always-on agent is a server that reads strangers' messages and holds your keys: week 3's lethal trifecta, around the clock. OpenClaw's first months show each way in.

What to do: keep the harness on localhost; install no plugin you haven't read; update; and remove one leg of the trifecta (private data, untrusted input, a way to send things out). For the homework, the robot rule and the per-sender cap are a start, not a defence.

Censys, Jan 31, 2026 · The Register, Feb 9, 2026 · GHSA-g8p2-7wf7-98mq · The Hacker News, Feb 2, 2026 · Forklog, Jan 27, 2026 · Decrypt, Jun 26, 2026 · Wiz, Feb 2, 2026

10. Surviving: the log, doing things once, and the service

An append-only log

One JSON object per line, appended and flushed as each message happens. A crash can cut off the last line, never the history; on start, skip a line that doesn't parse. Claude Code and Codex keep their sessions the same way, as JSONL files you can resume. Compaction appends a marker line with the summary; on start, rebuild from the last marker.

def load_log(path):
    messages = []
    for line in open(path):
        try: entry = json.loads(line)
        except json.JSONDecodeError: continue            # a line cut off by a crash
        if entry.get("compacted"): messages = [summary_message(entry["summary"])]
        else: messages.append(entry["message"])
    last = messages[-1] if messages else None
    if last and last["role"] == "assistant" and last.get("tool_calls"):
        for call in last["tool_calls"]:                  # died mid-command: say so, don't re-run
            messages.append(tool_result(call["id"], "Interrupted by a restart; not re-run. "
                                        "Check its effects before trying again."))
    return messages

Doing things once

Reading is safe to repeat; sending, deleting and paying are not. Give each action a key (here a hash of recipient, subject and body), write the intent before acting and "done" after, and when a restart finds an intent without "done", check the world before acting again. For email, put the key in the Message-ID and search the Sent folder (SEARCH HEADER Message-ID <key@…>). Payment APIs made the idea familiar as an idempotency key: sending the same key twice creates one charge.

The service files, in full

macOS, ~/Library/LaunchAgents/edu.ucla.myagent.plist; load with launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/edu.ucla.myagent.plist, check with launchctl print gui/$(id -u)/edu.ucla.myagent, stop with launchctl bootout gui/$(id -u)/edu.ucla.myagent:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>             <string>edu.ucla.myagent</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/me/harness/.venv/bin/python</string>
    <string>/Users/me/harness/agent.py</string>
    <string>--always-on</string>
  </array>
  <key>WorkingDirectory</key>  <string>/Users/me/harness</string>
  <key>RunAtLoad</key>         <true/>
  <key>KeepAlive</key>         <true/>
  <key>EnvironmentVariables</key>
  <dict><key>PATH</key><string>/opt/homebrew/bin:/usr/bin:/bin</string></dict>
  <key>StandardOutPath</key>   <string>/Users/me/harness/logs/agent.out</string>
  <key>StandardErrorPath</key> <string>/Users/me/harness/logs/agent.err</string>
</dict>
</plist>

Linux, ~/.config/systemd/user/myagent.service; start with systemctl --user daemon-reload && systemctl --user enable --now myagent, follow with journalctl --user -u myagent -f, and keep it running after logout with loginctl enable-linger $USER:

[Unit]
Description=my research agent
After=network-online.target

[Service]
WorkingDirectory=/home/me/harness
ExecStart=/home/me/harness/.venv/bin/python agent.py --always-on
Restart=on-failure
RestartSec=10

[Install]
WantedBy=default.target

Windows: Task Scheduler, a task triggered "At log on" that runs the venv's python.exe with the script, with "If the task fails, restart every 1 minute" and "Stop the task if it runs longer than" turned off. Export it as XML.

Things that bite: services don't read your shell profile, so load .env in the program and use absolute paths; on macOS a program started by launchd may be refused access to ~/Documents and ~/Desktop, so keep the harness elsewhere; a Mac on battery or with its lid closed sleeps (caffeinate -i keeps it awake while the command runs); and a process can be alive but stuck, so a watchdog should check progress (a status.json rewritten every minute) rather than only the PID.

Apple: creating launchd jobs · systemd.service · ArchWiki: systemd/User · Stripe: idempotent requests

11. When nobody was watching

Four stories that link this week's controls to next week's topic, how AI fails. Each is a failure of control, not of intelligence.

Bring what your agent did overnight to week 6, the failures included.

TechCrunch, Feb 23, 2026 · The Register, Jul 21, 2025 · Fortune, Jul 23, 2025 · The Decoder, Feb 20, 2026 · Anthropic: Project Vend