Skip to content

Report actual per-entry idle time for autoclaimed background jobs #45

Description

@beranekio

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

  • Proto exposes actual autoclaim idle separately from the reclaim threshold (or documents and implements a single field with guaranteed accurate semantics)
  • Rust and Go SDKs regenerated and committed
  • Integration test proves an entry idle longer than autoclaim_min_idle_ms reports idle_ms_actual above the threshold
  • README documents both fields and intended worker usage
  • Downstream worker can use actual idle for stale/autoclaim retry policy without underestimating abandonment

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions