@happyvertical/smrt-jobs 0.40.70 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -135,6 +135,36 @@ change what the agents runtime will dispatch.
135
135
  every sibling method. Adding the decorator to one method of an existing class
136
136
  is therefore a behaviour change for the rest of it.
137
137
 
138
+ ## Retention (#2375)
139
+
140
+ `_smrt_jobs` and `_smrt_job_events` are append-only in practice — `cleanup()`
141
+ existed but nothing ever called it, and job events (one row per log line and
142
+ progress tick) had no prune path at all. `src/retention.ts` contributes both to
143
+ the framework retention sweep in `@happyvertical/smrt-core`.
144
+
145
+ - `TaskRunner` starts a sweeper by default. `retention: false` opts out;
146
+ `retention: { intervalMs, policy, jobs }` tunes it. The **first sweep is one
147
+ interval after `start()`, never at start** — a crash-looping worker must not
148
+ become a delete loop, and a short-lived runner must exit having deleted
149
+ nothing. `stop()` only clears the timer — it does **not** unregister the job
150
+ tasks. The package entry point (`index.ts`) registers them unconditionally
151
+ on import, so "this process loaded `@happyvertical/smrt-jobs`" is the
152
+ contract that contributes them, not "a sweeper happens to be running";
153
+ `unregisterJobRetentionTasks()` is the explicit opt-out for callers that
154
+ want a clean registry (tests, teardown).
155
+ - Windows (`DEFAULT_JOB_RETENTION`): completed/cancelled 7 days, failed 30
156
+ days, events 30 days, 10 000 job rows per sweep. Events deliberately outlive
157
+ the jobs they describe, so a job row removed at 7 days still has a readable
158
+ log for another three weeks.
159
+ - `cleanup()` counts before deleting (`rowCount` is unreliable across engines)
160
+ and honours `dryRun`, which is what makes `smrt db:prune --dry-run` an exact
161
+ preview. Its `(status, completed_at)` predicate is indexed by
162
+ `ensureJobsSystemTableCompatibility()`, which this collection runs on every
163
+ `initialize()` — bootstrap cannot do it, because `_smrt_jobs` does not exist
164
+ yet when bootstrap runs.
165
+ - `cleanup({})` with no cutoff returns 0. It must never be read as "delete
166
+ everything".
167
+
138
168
  ## Gotchas
139
169
 
140
170
  - **Cron not timezone-aware**: cron fields match the server's **local** time, not UTC (set `TZ` for UTC); no missed-run catch-up (fire-once-forward)