# Cron Pre-Summary Workflow Class-level recipe for running the WeChat article pre-summary pipeline on a schedule (e.g. every 30 minutes). This is the cron-side counterpart to the manual `/api/articles/summarize` bulk flow. ## What it does 1. `POST /api/articles/extract` — extract new articles from WeChat DB into `articles` + `article_shares`. 2. `GET /api/articles/unsummarized?limit=20` — fetch articles that have no cached summary. 3. Submit at most **3** summaries to `POST /api/articles/summarize` (the API has a global semaphore of 3 Hermes jobs). 4. Write a timestamp file to record last run. 5. Report counts. ## Why at most 3 summaries per run? `wechat-viewer/app.py` spawns each `/api/articles/summarize` as a Hermes CLI subprocess guarded by a global semaphore of 3. Submitting more than 3 at once causes the extra jobs to fail with `CONCURRENCY_LIMIT`. The remaining unsummarized articles are picked up in the next cron run (30 minutes later). ## LLM-driven cron prompt ```text TGO群文章预摘要: 1. POST /api/articles/extract 2. GET /api/articles/unsummarized?limit=20 3. For each item: POST /api/articles/summarize {"id": item.id, "url": item.url} - The summarize endpoint is SINGLE-ARTICLE ONLY. It does NOT accept batch_size, limit, all, or ids. 4. Write the timestamp file to /data/data/com.termux/files/usr/tmp/scheduler_tgo_summary_last (or $HOME/tmp/scheduler_tgo_summary_last on non-Android). On Termux, /tmp itself is not writable. 5. Report: extracted N, submitted M, timestamp written Use terminal curl or the tgo_summary_pipeline.py script. Do NOT query WeChat DB directly. ``` ## Script-driven cron (recommended) Use the class-level pipeline script that handles `extract → unsummarized → summarize all` and updates the timestamp file: ```bash python3 ~/pixelphone/digest/wechat-group-digest/scripts/tgo_summary_pipeline.py ``` By default it writes the timestamp to the Termux tmp directory on Android, or `$HOME/tmp/scheduler_tgo_summary_last` elsewhere. Override with env vars: ```bash WECHAT_VIEWER_URL=http://127.0.0.1:5001 \ SCHEDULER_TGO_SUMMARY_LAST=/data/data/com.termux/files/usr/tmp/scheduler_tgo_summary_last \ python3 ~/pixelphone/digest/wechat-group-digest/scripts/tgo_summary_pipeline.py ``` The script submits summaries **sequentially** with a 0.5s delay to avoid the global 3-job Hermes concurrency limit. It also reports counts so cron logs are self-describing. ## Android / Termux gotcha: /tmp is not writable The Termux app user cannot write to `/tmp`. If you try `date +%s > /tmp/scheduler_tgo_summary_last`, you get `Permission denied`. Reliable fixes: - Change the path to the Termux tmp directory: `/data/data/com.termux/files/usr/tmp/scheduler_tgo_summary_last` - Or use `$HOME/tmp/scheduler_tgo_summary_last` - Or use `tgo_summary_pipeline.py`, which picks the correct default automatically. ## Verification After a run, check: - `/api/articles/unsummarized` count decreases over time (as Hermes jobs complete). - `/tmp/scheduler_tgo_summary_last` (or your chosen path) contains the latest epoch timestamp. - `hermes cron status` shows the job running on schedule. ## Session-specific detail This reference was produced during 2026-07-25 and 2026-07-26 TGO runs: - **2026-07-25 cron run**: `extract` returned `{new_articles: 0, new_shares: 0, total: 985}`, 20 articles were unsummarized, only the first 3 were submitted (task IDs `a81dff9662ee`, `8720c26f7b46`, `e3736a26b7f6`). Direct write to `/tmp/scheduler_tgo_summary_last` failed with `Permission denied`; `su -c` succeeded, writing `1784979182`. - **2026-07-26 manual pipeline run**: A full `extract → unsummarized → summarize all` cycle was executed via `terminal()` + a standalone Python script. `extract` returned `{new_articles: 0, new_shares: 0, total: 988}`. 20 articles were unsummarized. All 20 were submitted sequentially to `POST /api/articles/summarize` with `{"id": id, "url": url}`; responses were either `started` (new tasks) or `cached` (already cached). The endpoint rejected every batch-style payload (`batch_size`, `limit`, `all`, `ids`) with `{"ok": false, "error": "需要 url"}`. The timestamp file was updated to `/data/data/com.termux/files/usr/tmp/scheduler_tgo_summary_last` with value `1785002684` (2026-07-26 02:04:44).