Summary
ClaimBackgroundJobs currently sets idle_ms on autoclaimed BackgroundJob and PendingBackgroundJob entries to autoclaim_min_idle_ms — a lower bound, not the entry's true PEL idle duration. PR #42 documented this as minimum-threshold semantics, but downstream workers (for example duihua-background-worker) may need the actual idle time for stale-job detection, retry/backoff, and distinguishing freshly claimed work from long-abandoned PEL entries.
Redis XAUTOCLAIM only returns stream entries that exceeded the threshold; it does not include per-entry idle metadata in the reply.
Problem
An entry idle for minutes but reclaimed with autoclaim_min_idle_ms = 50 is exposed as idle_ms = 50. Workers treating idle_ms as exact idle duration will substantially understate abandonment time and may schedule retries as live work instead of interrupted/stale handling.
Related review: Codex on PR #42 — #42 (comment) (approx.)
Proposed direction
Extend the proto/API to expose both values explicitly, for example:
Option A — add idle_ms_actual (preferred)
Keep existing idle_ms as documented minimum threshold (autoclaim_min_idle_ms) for backward compatibility, and add:
message BackgroundJob {
// ...
optional uint64 idle_ms_actual = 6; // true PEL idle when autoclaimed
}
message PendingBackgroundJob {
// ...
optional uint64 idle_ms_actual = 5;
}
Populate idle_ms_actual from Redis XPENDING (or equivalent) for autoclaimed entries in the claim batch.
Option B — repurpose idle_ms
Change idle_ms to mean actual idle time and add idle_ms_min for the reclaim threshold. Clearer semantics but breaking for consumers that already read PR #42's minimum-threshold docs.
Implementation notes
- Fetch per-entry idle in the autoclaim hydration path (
jobs_from_stream_ids / claim_jobs) before or alongside XAUTOCLAIM output mapping.
XPENDING returns last_delivered_ms per stream ID; verify whether post-XAUTOCLAIM idle is still useful or whether pre-claim lookup is required.
- Batch
XPENDING where possible to avoid N+1 round-trips on large autoclaim batches.
- Propagate fields through Rust core/client, server conversion, and Go SDK.
- Update tests in
crates/core/tests/pending_job_metadata.rs to assert idle_ms_actual exceeds the minimum threshold when entries have aged.
Acceptance criteria
Related
Summary
ClaimBackgroundJobscurrently setsidle_mson autoclaimedBackgroundJobandPendingBackgroundJobentries toautoclaim_min_idle_ms— a lower bound, not the entry's true PEL idle duration. PR #42 documented this as minimum-threshold semantics, but downstream workers (for exampleduihua-background-worker) may need the actual idle time for stale-job detection, retry/backoff, and distinguishing freshly claimed work from long-abandoned PEL entries.Redis
XAUTOCLAIMonly returns stream entries that exceeded the threshold; it does not include per-entry idle metadata in the reply.Problem
An entry idle for minutes but reclaimed with
autoclaim_min_idle_ms = 50is exposed asidle_ms = 50. Workers treatingidle_msas exact idle duration will substantially understate abandonment time and may schedule retries as live work instead of interrupted/stale handling.Related review: Codex on PR #42 — #42 (comment) (approx.)
Proposed direction
Extend the proto/API to expose both values explicitly, for example:
Option A — add
idle_ms_actual(preferred)Keep existing
idle_msas documented minimum threshold (autoclaim_min_idle_ms) for backward compatibility, and add:Populate
idle_ms_actualfrom RedisXPENDING(or equivalent) for autoclaimed entries in the claim batch.Option B — repurpose
idle_msChange
idle_msto mean actual idle time and addidle_ms_minfor the reclaim threshold. Clearer semantics but breaking for consumers that already read PR #42's minimum-threshold docs.Implementation notes
jobs_from_stream_ids/claim_jobs) before or alongsideXAUTOCLAIMoutput mapping.XPENDINGreturnslast_delivered_msper stream ID; verify whether post-XAUTOCLAIMidle is still useful or whether pre-claim lookup is required.XPENDINGwhere possible to avoid N+1 round-trips on large autoclaim batches.crates/core/tests/pending_job_metadata.rsto assertidle_ms_actualexceeds the minimum threshold when entries have aged.Acceptance criteria
autoclaim_min_idle_msreportsidle_ms_actualabove the thresholdRelated
PendingBackgroundJobclaim metadata work