Skip to content

Keep only live taskman work in memory and drop unused startup load - #253

Merged
iamwavecut merged 2 commits into
mainfrom
feat/startup-and-cleanup
Oct 13, 2026
Merged

iamwavecut merged 2 commits into
mainfrom
feat/startup-and-cleanup

Conversation

@iamwavecut

@iamwavecut iamwavecut commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Startup took several minutes because the process restored every taskman job of the last day, including finished dialog jobs that still carried their full agent checkpoint, and then ran heavy analytics and memory scans while it caught up on the update backlog. This change keeps only live work in memory and removes the unused write load.

Task queue: memory holds live work, Postgres holds history

  • Startup loads active jobs plus a short finished tail: jobs that ended in the last hour and the newest 32 finished jobs of each queue (queue-time estimates need them).
  • The periodic cleanup now evicts finished jobs from memory without writing a delete to the journal. Jobs with an undeleted placeholder message stay until the placeholder cleanup runs.
  • The Postgres purge deletes finished rows by finish time. Finished rows stay for twice the completed-job retention, the same window listings and the analytics dashboard had before; soft-deleted rows and history keep the previous retention.
  • taskmanJobs and the admin job list read taskman_jobs for any filter that can include finished jobs (filters, counts, sorting and paging run in SQL; rows come without their event log). Pending/processing-only filters still read memory.
  • Admin "clear jobs" also soft-deletes matching finished rows in Postgres; "restart job" works for a job that already left memory.

Dialog checkpoint is dropped when a job finishes

The agent_checkpoint event exists so a running turn can resume after a crash. Completing, failing or cancelling a job now removes it, so finished rows no longer carry the turn input and agent state.

Remove the chat interest rollup

chat_history/interest rollups were rebuilt from every memory episode on each analytics pass and nothing reads them. The rollup is removed, and migration 201 rebuilds telemetry_rollups without those rows (one-way; the down migration is a no-op).

Less work during startup catch-up

  • The first analytics archive pass waits 30 minutes after start.
  • Memory enqueue at startup scans recent hours only; the daily 03:02 UTC scan still covers the full retention window.

Delivery and deploy

  • Enqueueing a Telegram outbox batch retries up to three times when no Postgres connection is free. A pool timeout fails before any statement runs, so the retry cannot enqueue twice.
  • The deploy script waits up to 10 minutes each for health and readiness.

Compatibility

  • Migration 201 is a one-way data removal of rollup rows that nothing reads.
  • GraphQL schema, admin routes and payloads are unchanged. RuntimeTaskmanInspector::list_jobs is now async.
  • Readiness descriptions of the taskman cleanup, purge and analytics workers changed text.

Deployment risk and verification plan

  • Risk: migration 201 truncates and refills telemetry_rollups inside one transaction at startup; it runs while the previous container is stopped, and only the removed rollup wrote to those rows.
  • Risk: after the first restart, finished jobs older than one hour are no longer in memory; listings and job details read them from Postgres, and the purge window for finished rows is unchanged.
  • The deploy script change only lengthens the health and readiness waits (up to 10 minutes each); it does not change the deploy steps.
  • Plan after deploy: confirm the running image matches the merge commit; measure time from container start to /api/health and /api/ready; check that migration 201 applied and telemetry_rollups holds no chat_history/interest rows; compare process memory with the previous release; open the admin job list with a finished-status filter; watch dialog terminal failures and outbox enqueue warnings for 30 minutes.

Verification

  • cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace.
  • Postgres live tests (pgvector/pg17), serially: cargo test -p openplotva-storage live_ (33 passed), including new tests for startup loading, SQL listing/search/delete, purge by finish time and the outbox pool-timeout retry.
  • New taskman tests: eviction keeps recent, newest-per-queue and placeholder jobs and writes no WAL; terminal transitions drop the checkpoint; restart from a persisted record.
  • Migration 201 SQL checked on sample rows: interest rows removed, other rollups kept.

Startup restored every taskman job of the last day, including finished
dialog jobs that still carried their agent checkpoint, then ran the
interest rollup and a full memory scan while catching up.

- Load active jobs plus a short finished tail at startup; evict finished
  jobs from memory without journal deletes and purge them in Postgres by
  finish time. Finished-job listings read taskman_jobs.
- Drop the agent_checkpoint event when a job finishes.
- Remove the unused chat_history/interest rollup (migration 201).
- Delay the first analytics archive pass; scan recent memory hours at
  startup.
- Retry outbox enqueue on Postgres pool timeouts.
- Wait up to 10 minutes for health and readiness on deploy.
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Warnings
⚠️ Production deploy workflow/assets changed; include an explicit deployment-risk note and verification plan.
⚠️ Large PR (1450 changed lines). Consider splitting unless this is generated/mechanical.
Messages
📖 Danger checked 22 changed file(s).

Generated by 🚫 dangerJS against 05cb980

@iamwavecut

Copy link
Copy Markdown
Owner Author

Danger warnings: the deployment-risk note and post-deploy verification plan are now in the PR description. The size stays in one PR because the startup load, eviction, Postgres listing and purge change the same task-queue contract and must ship together; the remaining parts (interest rollup removal, archive delay, outbox retry, deploy wait) are small and target the same startup slowdown.

@iamwavecut
iamwavecut merged commit 3ba412f into main Oct 13, 2026
12 checks passed
@iamwavecut
iamwavecut deleted the feat/startup-and-cleanup branch October 13, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant