{
  "schemaVersion": "1",
  "revision": "22ce5d34dbcb5a78",
  "id": "foundations-overnight-cron-playbook",
  "slug": "overnight-cron-playbook",
  "title": "Overnight emulated-cron loop playbook",
  "summary": "Web developers often need long-running investigation without a real scheduler: flaky auth, broken localhost flows, intermittent console errors, or UI drift that only appears after repeated checks. This pattern gives an agent a bounded timestamp loop, runtime evidence, and a hard stop so overnight work produces receipts instead of vague claims.",
  "category": "Execution",
  "tags": [
    "context triad",
    "overnight",
    "goals",
    "playbook",
    "prompts"
  ],
  "sources": [
    {
      "label": "Agent foundations: Combine intent, implementation, and output for autonomous work (authorized access required)",
      "url": "https://codex-workshop-followup.pages.dev/lesson-10.html"
    }
  ],
  "sourceUnits": [
    "scenarios/topics.mjs#overnight-cron",
    "scenarios/overnight-cron.json#audienceFit",
    "toolkit/prompts/10-overnight-codex-cron-loop.md",
    "scenarios/overnight-cron.json#scenarios/0",
    "scenarios/overnight-cron.json#scenarios/1",
    "scenarios/overnight-cron.json#scenarios/2",
    "scenarios/overnight-cron.json#implementationNotes",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/0",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/2",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/3",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/4",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/5",
    "scenarios/overnight-cron.json#notTaughtOrAvoid/6",
    "scenarios/overnight-cron.json#agentReferences"
  ],
  "collection": "foundations",
  "categoryId": "execution",
  "wordCount": 2430,
  "url": "/topics/foundations-overnight-cron-playbook/",
  "markdownUrl": "/markdown/foundations-overnight-cron-playbook.md?raw=1&v=22ce5d34dbcb5a78",
  "jsonUrl": "/api/v1/documents/foundations-overnight-cron-playbook.json",
  "headings": [
    {
      "id": "copy-paste-workflow",
      "text": "Copy-paste workflow",
      "level": 2
    },
    {
      "id": "copy-paste-prompt",
      "text": "Copy-paste prompt",
      "level": 3
    },
    {
      "id": "how-it-works",
      "text": "How it works",
      "level": 3
    },
    {
      "id": "scenarios",
      "text": "Scenarios",
      "level": 2
    },
    {
      "id": "overnight-flaky-auth-flow-watchdog",
      "text": "Overnight flaky auth-flow watchdog",
      "level": 3
    },
    {
      "id": "agent-brief",
      "text": "Agent brief",
      "level": 4
    },
    {
      "id": "implementation-references",
      "text": "Implementation references",
      "level": 4
    },
    {
      "id": "browser-verification",
      "text": "Browser verification",
      "level": 4
    },
    {
      "id": "definition-of-done",
      "text": "Definition of done",
      "level": 4
    },
    {
      "id": "failure-modes-and-mitigations",
      "text": "Failure modes and mitigations",
      "level": 4
    },
    {
      "id": "repeated-visual-regression-and-console-smoke-loop",
      "text": "Repeated visual-regression and console-smoke loop",
      "level": 3
    },
    {
      "id": "agent-brief-2",
      "text": "Agent brief",
      "level": 4
    },
    {
      "id": "implementation-references-2",
      "text": "Implementation references",
      "level": 4
    },
    {
      "id": "browser-verification-2",
      "text": "Browser verification",
      "level": 4
    },
    {
      "id": "definition-of-done-2",
      "text": "Definition of done",
      "level": 4
    },
    {
      "id": "failure-modes-and-mitigations-2",
      "text": "Failure modes and mitigations",
      "level": 4
    },
    {
      "id": "overnight-dependency-upgrade-investigation-brief",
      "text": "Overnight dependency-upgrade investigation brief",
      "level": 3
    },
    {
      "id": "agent-brief-3",
      "text": "Agent brief",
      "level": 4
    },
    {
      "id": "implementation-references-3",
      "text": "Implementation references",
      "level": 4
    },
    {
      "id": "browser-verification-3",
      "text": "Browser verification",
      "level": 4
    },
    {
      "id": "definition-of-done-3",
      "text": "Definition of done",
      "level": 4
    },
    {
      "id": "failure-modes-and-mitigations-3",
      "text": "Failure modes and mitigations",
      "level": 4
    },
    {
      "id": "implementation-notes",
      "text": "Implementation notes",
      "level": 2
    },
    {
      "id": "boundaries-and-caveats",
      "text": "Boundaries and caveats",
      "level": 2
    },
    {
      "id": "agent-reference-map",
      "text": "Agent reference map",
      "level": 2
    },
    {
      "id": "existing-overnight-cron-prompt",
      "text": "Existing overnight cron prompt",
      "level": 3
    },
    {
      "id": "lesson-10-validated-references",
      "text": "Lesson 10 validated references",
      "level": 3
    },
    {
      "id": "lesson-10-validation-guardrails",
      "text": "Lesson 10 validation guardrails",
      "level": 3
    },
    {
      "id": "lesson-10-interactive-checklist",
      "text": "Lesson 10 interactive checklist",
      "level": 3
    },
    {
      "id": "packx-focused-bundle-flow",
      "text": "PackX focused bundle flow",
      "level": 3
    },
    {
      "id": "agent-browser-evidence-pattern",
      "text": "Agent Browser evidence pattern",
      "level": 3
    },
    {
      "id": "uploaded-scenario-bundle",
      "text": "Uploaded scenario bundle",
      "level": 3
    }
  ],
  "markdown": "# Overnight emulated-cron loop playbook\n\n> Original source pages and recordings require authorized access. The full article text here is public.\n\nWeb developers often need long-running investigation without a real scheduler: flaky auth, broken localhost flows, intermittent console errors, or UI drift that only appears after repeated checks. This pattern gives an agent a bounded timestamp loop, runtime evidence, and a hard stop so overnight work produces receipts instead of vague claims.\n\n[Core principles](/topics/foundations-context-triad-and-overnight-work/)\n\n## Copy-paste workflow\n\n**When to use:** When Codex has no real scheduler but you want bounded overnight work (research/verification) while you sleep. This uses a natural-language time loop with a hard stop condition so credits and your repo stay safe.\n\n### Copy-paste prompt\n\n```text\nThis is a /goal-style overnight task. Codex has no real cron, so you will emulate one in natural language with a HARD stop condition baked into this goal. Stay read-only unless I explicitly ask for a mutation.\n\nGOAL: <RESEARCH/VERIFICATION OBJECTIVE>\n\nLOOP:\n1. Record a starting timestamp now.\n2. Every <N> minutes, run this routine: <THE RESEARCH/VERIFICATION ROUTINE>.\n3. STOP when the FIRST of these is hit (this bound is part of the goal, not optional):\n     - <DURATION, e.g. 6 hours> has elapsed since the starting timestamp, OR\n     - the clock reaches <TARGET TIME>, OR\n     - <ITERATION LIMIT> iterations completed, OR\n     - <BUDGET CAP> is reached.\n\nFor any debugging the loop does, bundle the context triad so you find the REAL mismatch:\n  - intent (this goal text)\n  - implementation (the source)\n  - output (logs / screenshots / traces)\nWhen those three disagree, that disagreement points at the actual bug.\n\nGuardrails: prefer read-only discovery before any mutation; keep the durable contract in this natural-language goal.\n```\n\n### How it works\n- The loop is an emulated cron written in natural language: record a starting timestamp, repeat a routine every N minutes, and stop at a fixed duration / target clock time / iteration limit / budget cap.\n- The stop condition is written INTO the goal — it's mandatory, not a suggestion — so overnight runs stay bounded and credits/repo stay safe.\n- For debugging, bundle the context triad — intent (goal text) + implementation (source) + output (logs/screenshots/traces); when those three disagree the model finds the real mismatch.\n- Prefer read-only discovery before any mutation; keep the durable contract in natural-language goals.\n- Reference: [PackX](https://www.npmjs.com/package/packx), [codex-daemons](https://github.com/johnlindquist/codex-daemons), [Agent Browser](https://www.npmjs.com/package/agent-browser).\n\n## Scenarios\n\n### Overnight flaky auth-flow watchdog\n\n**Role:** As a product web developer maintaining a Next.js app with login-gated dashboards\n\nA local Next.js dashboard sometimes loses authenticated state after refresh, route changes, or idle time. The team has a dev server, a test account, and a browser-capable agent, but no built-in Codex scheduler.\n\n> As a product web developer, I want an agent to re-check the login and dashboard flow every 10 minutes overnight, so that I wake up to concrete logs, screenshots, and a narrowed failure theory instead of a one-off reproduction attempt.\n\n#### Agent brief\n\n```text\nCreate `.goals/overnight-auth-watch.md` and run it as a bounded /goal-style task. Goal: record a starting timestamp, then every 10 minutes until 7:00 AM local time or 24 iterations, whichever comes first, verify the local auth flow against the running app. Stay read-only unless I explicitly approve a mutation. First inspect the project scripts and start or reuse the dev server. For each iteration, capture the context triad: intent from this goal file, implementation from the smallest relevant auth/session/routes files, and output from browser console logs, network or terminal errors, screenshots, and a short iteration summary. Write artifacts under `.notes/overnight-auth-watch/` using timestamped filenames such as `iteration-003.json`, `iteration-003-console.log`, and `iteration-003-screenshot.png`. At the end, write `.notes/overnight-auth-watch/final-report.md` with pass/fail counts, first failing iteration, suspected mismatch between intent/implementation/output, and the exact evidence files to inspect. Do not declare success without inspecting the written artifacts.\n```\n\n#### Implementation references\n\n[Open reference](/topics/foundations-overnight-cron-playbook/)\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n```text\n.goals/overnight-auth-watch.md\n```\n\n```text\n.notes/overnight-auth-watch/\n```\n\n```text\npackx --preview -s \"auth session dashboard runtime artifacts\"\n```\n\n```text\npackx -s \"auth session dashboard runtime artifacts\" -f markdown --no-interactive -o .notes/overnight-auth-watch/debug-bundle.md\n```\n\n#### Browser verification\n\nUse an agent-browser-style flow against localhost: take an accessibility snapshot of the login page, fill the test credentials, click submit, wait for the dashboard route, evaluate `document.title`, visible route markers, and any session/banner text, then refresh and navigate away/back. Capture console output and a screenshot per iteration. If using a CMUX browser pane, keep the browser pane visible while the terminal pane writes artifacts.\n\n#### Definition of done\n\n- A bounded goal file exists with starting timestamp, 10-minute interval, and hard stop at 7:00 AM or 24 iterations.\n- Each iteration writes a JSON/log/screenshot receipt under `.notes/overnight-auth-watch/`.\n- `final-report.md` compares expected auth behavior, relevant implementation files, and actual runtime output, with links or paths to the strongest evidence.\n- No source files are modified unless a separate human-approved implementation step is started.\n\n#### Failure modes and mitigations\n\n- The agent only reports that the flow worked without saving browser evidence; mitigate by requiring timestamped console logs, screenshots, and iteration JSON before any final answer.\n- The loop keeps running because the stop condition is written vaguely; mitigate by including both a target clock time and an iteration cap in the goal text.\n- The browser agent assumes existing cookies are available; mitigate by scripting the login path explicitly with a test account and treating cookies as non-portable.\n- The agent bundles the whole repo instead of the relevant auth implementation plus output artifacts; mitigate by running `packx --preview` first and keeping the bundle focused.\n\n### Repeated visual-regression and console-smoke loop\n\n**Role:** As a frontend engineer responsible for a marketing site or app shell\n\nA responsive landing page looks fine on the first pass, but layout drift, hydration warnings, or console errors appear after rebuilds, route changes, or viewport changes. The developer wants an overnight evidence loop, not a permanent test-suite expansion.\n\n> As a frontend engineer, I want an agent to periodically open the app in the browser, inspect key routes and viewports, and save proof artifacts, so that visual or console regressions are grounded in screenshots and logs.\n\n#### Agent brief\n\n```text\nCreate `.goals/overnight-ui-smoke.md`. Record the starting timestamp. Every 15 minutes, until 6 hours have elapsed or 20 iterations are complete, run a read-only UI smoke routine against the local web app. Inspect `package.json` for the dev and build commands. Start or reuse the dev server. Visit the agreed routes: `/`, `/pricing`, and `/dashboard` if present; if a route does not exist, record that instead of inventing one. For each route, capture console errors/warnings, one screenshot at desktop width, one screenshot at mobile width if the browser tool supports viewport changes, and a short artifact summary. Write files under `.notes/overnight-ui-smoke/`. If an error appears, bundle intent, implementation, and output with PackX: goal file, smallest route/component files, console logs, screenshots, and terminal output. End with `.notes/overnight-ui-smoke/final-report.md` listing stable routes, failing routes, first failure time, and the likely mismatch.\n```\n\n#### Implementation references\n\n[Open reference](/topics/foundations-overnight-cron-playbook/)\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n[Open reference](/topics/foundations-overnight-cron-playbook/)\n\n```text\n.goals/overnight-ui-smoke.md\n```\n\n```text\n.notes/overnight-ui-smoke/\n```\n\n```text\npackage.json\n```\n\n```text\npackx --preview -s \"ui smoke screenshots console logs routes components\"\n```\n\n```text\npackx -s \"ui smoke screenshots console logs routes components\" -f markdown --no-interactive -o .notes/overnight-ui-smoke/debug-bundle.md\n```\n\n#### Browser verification\n\nUse browser verification as the proof, not source inspection alone: open each localhost route, take an accessibility snapshot to confirm the main landmark/header/CTA exists, evaluate `window.location.pathname` and visible route text, collect console errors, and save screenshots. In CMUX, keep a browser pane beside the agent terminal or open a live Markdown tracker with the latest iteration summary.\n\n#### Definition of done\n\n- The loop is bounded by a 15-minute interval, 6-hour duration, and 20-iteration cap.\n- Every checked route has saved browser evidence, not just a textual claim.\n- Any failure has a focused context triad bundle: goal text, relevant route/component implementation, and runtime output.\n- The final report separates actual browser failures from missing routes or unsupported viewport operations.\n\n#### Failure modes and mitigations\n\n- The agent treats screenshots as optional and only reads source; mitigate by requiring browser artifacts as the primary receipt for this scenario.\n- The agent turns the smoke loop into broad redesign work; mitigate by stating read-only investigation only and deferring mutations to a separate Builder goal.\n- The agent over-tests unstable UI experiments as if they are permanent contracts; mitigate by framing this as disposable overnight evidence, not a maintained regression suite.\n- The bundle is too large to inspect usefully; mitigate by previewing PackX and including only goal, changed or relevant source, logs, screenshots, and traces.\n\n### Overnight dependency-upgrade investigation brief\n\n**Role:** As a tech lead preparing a risky dependency or framework upgrade\n\nA repo has a pending upgrade, failing tests, or intermittent build warnings. The lead wants a Researcher/Validator-style overnight investigation that collects evidence and proposes next steps, but does not mutate the repo while unattended.\n\n> As a tech lead, I want an agent to periodically run read-only checks and package the strongest evidence, so that the next morning I can decide whether to hand a focused implementation goal to a Builder agent.\n\n#### Agent brief\n\n```text\nCreate `.goals/overnight-upgrade-investigation.md`. This is a read-only overnight research and verification loop. Record the starting timestamp. Every 20 minutes until 4 hours have elapsed or 12 iterations are complete, inspect the current dependency-upgrade state. Run only read-only or normal verification commands discovered from the repo, such as package-manager install status checks, typecheck, lint, test, or build commands already present in scripts. Do not edit package files or source files. Save terminal output to `.notes/overnight-upgrade-investigation/iteration-###.log` and a structured summary to `iteration-###.json`. When failures appear, capture the context triad: the goal text, relevant package/config/source files, and actual command output. Use PackX only after previewing the candidate files. Finish with `final-report.md` containing a ranked list of blockers, commands run, evidence paths, and a recommended next goal file for implementation.\n```\n\n#### Implementation references\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n[Open reference](/topics/foundations-overnight-cron-playbook/)\n\n```text\n.goals/overnight-upgrade-investigation.md\n```\n\n```text\n.notes/overnight-upgrade-investigation/\n```\n\n```text\npackage.json\n```\n\n```text\npnpm-lock.yaml, package-lock.json, yarn.lock, or bun.lockb if present\n```\n\n```text\npackx --preview -s \"dependency upgrade failing build test lint output\"\n```\n\n```text\npackx -s \"dependency upgrade failing build test lint output\" -f markdown --no-interactive -o .notes/overnight-upgrade-investigation/debug-bundle.md\n```\n\n#### Browser verification\n\nBrowser proof is only useful if the upgrade affects a running web surface. If the app starts successfully, open the local app once per iteration, capture console errors and a homepage screenshot, and save them beside the command logs. If the failure is purely install/typecheck/build-level, browser proof is not the right proof; use terminal logs and PackX bundles instead.\n\n#### Definition of done\n\n- The investigation uses a timestamped loop with a 20-minute interval, 4-hour duration, and 12-iteration cap.\n- All verification commands and outputs are saved under `.notes/overnight-upgrade-investigation/`.\n- The final report ranks blockers by evidence strength and points to exact log or bundle files.\n- The repo remains unmodified except for local `.notes/` and `.goals/` artifacts.\n\n#### Failure modes and mitigations\n\n- The agent starts fixing files during an unattended investigation; mitigate by repeating read-only discovery before mutation in the goal and requiring a separate implementation goal later.\n- The agent dumps full command help or the entire repo into context; mitigate by inspecting project scripts first and using PackX preview with a focused topic.\n- The agent reports a generic dependency recommendation without command evidence; mitigate by requiring saved logs and expected-versus-actual comparison.\n- The loop wastes credits rerunning the same failing command with no new information; mitigate by writing a per-iteration summary and stopping early if three consecutive iterations produce identical failure output.\n\n## Implementation notes\n\n- Keep the loop as a natural-language goal file, not a production scheduler. The point is bounded overnight agent work, not pretending Codex has cron.\n- Every scenario must include a hard stop: target clock time, elapsed duration, iteration cap, or budget cap. Use at least two bounds for unattended work.\n- For web app scenarios, runtime output means browser evidence: console logs, screenshots, route state, traces, or visible UI checks. Source code alone is not enough.\n- Prefer read-only discovery overnight. Save implementation for a separate morning Builder goal after a human reviews the evidence.\n- Write artifacts to local `.notes/` and goal files to `.goals/`; keep them out of committed source unless the repo intentionally tracks them.\n- Use specialized responsibilities without turning them into ceremony: Researcher/Validator overnight, Builder later if the evidence supports a change.\n- Stop early when repeated iterations produce identical evidence and no new signal; record that early stop in the final report.\n- Redact secrets from logs, screenshots, and browser captures before bundling or sharing.\n\n## Boundaries and caveats\n\n- Do not present the overnight loop as a real cron scheduler or production automation system.\n- Do not make warm daemon internals, CODEX_HOME isolation, app-server reuse, or low-level Codex SDK profile mechanics part of this playbook.\n- Do not require CMUX as a standalone taught workflow for this workflow; use browser panes or CMUX only where they help produce web-dev proof.\n- Do not introduce unrelated tools that were only mentioned, such as ScreenPipe-based workflow mining, NotebookLM, n8n, ADB, or Codex Mobile, as required implementation steps.\n- Do not tell the agent to keep improving indefinitely, rewrite the project overnight, deploy changes, or mutate destructive systems while unattended.\n- Do not trust the agent's self-reported success without written logs, screenshots, traces, command output, or bundled artifacts.\n\n## Agent reference map\n\n### Existing overnight cron prompt\n\nUse as the exact taught prompt shape: starting timestamp, repeated interval, hard stop, context triad, and read-only guardrail.\n\n[Open reference](/topics/foundations-overnight-cron-playbook/)\n\n### Lesson 10 validated references\n\nTreat as ground truth for what was actually taught: context triad, QA artifacts, short goal files, Oracle-generated goal files, specialized agents, overnight timestamp loops, and loose coupling.\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n### Lesson 10 validation guardrails\n\nUse to avoid reintroducing removed or over-specific claims such as warm daemon internals, profile isolation, or unrelated course redesign.\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n### Lesson 10 interactive checklist\n\nUse for implementation-ready receipts: intent.md, execution logs, screenshots, traces, PackX bundle, and fixed stop condition.\n\n[Open reference](/topics/foundations-context-triad-and-overnight-work/)\n\n### PackX focused bundle flow\n\nUse when a failure needs a model-readable bundle of intent, implementation, and runtime output; always preview before writing the bundle.\n\n```text\npackx --preview -s \"<topic>\" && packx -s \"<topic>\" -f markdown --no-interactive -o .notes/<scenario>/debug-bundle.md\n```\n\n### Agent Browser evidence pattern\n\nUse for web-app runtime proof: console logs, screenshots, and live browser state rather than source-only guessing.\n\n[Open reference](https://www.npmjs.com/package/agent-browser)\n\n### Uploaded scenario bundle\n\nUse as the local source snapshot for the scenario pipeline and lesson/toolkit context.\n\n```text\n/mnt/data/scenario-overnight-cron.txt\n```"
}
