[Bug]: SessionCommit dependency wait causes unbounded immediate requeue storm
Issue Origin
Observed and reproduced in a real environment.
Bug Description
When several Session Phase 2 commits are queued for the same session, a later commit can be dequeued while its predecessor is still pending. In that case Session.resume_queued_commit() returns False, and SessionCommitProcessor._process() immediately enqueues the same message again.
There is no delay, backoff, deduplication, or retry limit on this dependency-wait path. The consumer can therefore enter a hot dequeue/ack/re-enqueue loop while the predecessor is still running.
Steps to Reproduce
- Create a session and queue one commit whose Phase 2 work takes long enough to remain pending.
- Queue many additional commits for the same session before the first one reaches a terminal state.
- Monitor the
session_commitqueue and itsrequeue_countwhile the first commit is still running. - Observe later commits repeatedly cycling through dequeue and immediate re-enqueue.
Expected Behavior
Commits waiting on an earlier archive should remain deferred without hot-looping. At most one queued entry should exist for each task, and dependency retries should use bounded delay/backoff (or a per-session FIFO scheduler) until the predecessor becomes terminal.
Actual Behavior
The queue rapidly processes and re-enqueues the same waiting messages. In one sanitized observation:
- 33 commits were waiting behind the same session dependency.
- The queue depth stayed around 33-34 rather than draining.
- The requeue counter exceeded 800,000 before manual intervention.
This creates unnecessary queue I/O and CPU work, makes monitoring noisy, and can interfere with normal task processing.
Sanitized Call Path
SessionCommitProcessor._process
-> Session.resume_queued_commit
-> Session._can_run_archive returns false while predecessor is pending
-> QueueManager.enqueue(same SessionCommit message)
-> report_requeue()
Suggested Direction
- Keep one outstanding queue item per
task_id/ archive. - Use delayed retry with bounded exponential backoff and jitter for dependency waits.
- Prefer explicit per-session FIFO scheduling or wake the next archive when its predecessor becomes terminal.
- Report dependency waiting separately from error retries so operators can distinguish healthy serialization from a retry storm.
Environment
- OpenViking: 0.4.16
- Python: 3.12.11
- Operating system: macOS
- Model backend: Other (the problem occurs in queue scheduling before model selection affects the waiting commit)
No session identifiers, message content, local paths, credentials, or user profile data are included in this report.
Confirming this on v0.5.0 (self-hosted, macOS), and adding one additional re-queue path that is not covered by the dependency-wait call chain above — it is a different early return, same hot loop.
1) Our observation matches the dependency-wait loop
Same symptom, no other workload running:
ov observer queue, readings ~20 s apart:
[1] SessionCommit | Pending 185 | In Progress 6 | Processed 984 | Requeued 984 | Errors 0
[2] SessionCommit | Pending 184 | In Progress 7 | Processed 1086 | Requeued 1086 | Errors 0
+102 processed / +102 requeued in 20 s — every delivery is a re-queue, Pending moves by 1. After manually clearing the spinning rows (backup taken, service restarted) the pattern restarts as soon as new duplicate jobs arrive:
[1] Pending 8 | In Progress 4 | Processed 64 | Requeued 64
[2] Pending 8 | In Progress 4 | Processed 256 | Requeued 256
[3] Pending 8 | In Progress 4 | Processed 456 | Requeued 456
2) The trigger we could count exactly: many jobs for one session
Parsing the queue payload (queue_messages.data → {"task_id":…, "session_id":…}):
20261007_173050_293153 18 jobs (pending 17 / processing 1) message_count=34
and across all stuck jobs: of 190 pending/running session_commit tasks, 172 pointed at sessions with message_count == 0, the rest were duplicates of that one session that did have messages. Each loser of the race re-queues — exactly the "no deduplication" part of your report.
3) Additional path: processed == False also re-queues
openviking/storage/queuefs/session_commit_processor.py (v0.5.0, verbatim):
L118: return ProcessResult.success()
L125: return ProcessResult.success() if processed else ProcessResult.requeued()
When the session has nothing left to extract (already archived / messages consumed by a sibling job), processed is False. That is the documented skipped / no_messages outcome — not an error — yet it returns REQUEUED, so the backend re-enqueues immediately and the worker picks it up again. This does not even need a pending predecessor: a stale job for an already-empty session spins on its own. Suggest this branch settle to success() with a skipped/no_messages reason.
4) Why it is hard to see (supporting your "report separately" suggestion)
- Task ledger for those 191 tasks:
execution_events={created: 191, status_changed: 7, started: 0},error: null, status stayspending. - Wait time (now −
created_at): median 881 min (14.7 h), max 1202 min (20 h). queue_messages.timestampfor the same rows reads "within the last minute" on every check, because each re-queue rewrites it — so the queue row itself says the opposite of the truth.- Queue status shows
Errors: 0throughout.
Net effect on this box: server sat at ~13 % CPU re-delivering jobs, In Progress collapsed to 1–7 out of a configured 12 while hundreds waited up to 20 h (head-of-line blocking), and nothing in the API/observability surfaces pointed at it.
5) Workaround used (band-aid, mirrors your suggestion)
Stopped service → deleted the spinning rows from queue_messages (backup first) → restart: pending 184 / processing 7 → pending 8 / processing 6, service healthy, real commits start moving again. It recurs when new duplicate/no-message jobs arrive, so this is not production-viable.
6) On the suggested direction
Strongly agree with "keep one outstanding queue item per task_id / archive" and separating dependency-wait from error retries — plus the processed == False branch above, which needs a settle rather than a re-queue.
Two related data points from the same box, in case they help scope it: #5724 (serial chain stalls when the head task is stuck) was closed not_planned on 2026-10-16, and #6130 (task never reaches a terminal status) is still open — all three look like the same missing state machine for the session-commit lifecycle, and on a self-hosted deployment the observable outcome of all three is "queue stops moving and no error anywhere".
Happy to test a patch against this box — we can still reproduce (a session with 34 pending messages plus a steady arrival of no-message submissions).
Follow-up on 0.5.1.1: the processed == False branch from my previous comment is no longer the source, but the dependency wait still is — and the rate decouples from queue depth.
Environment: 0.5.1.1, self-hosted, single node, macOS, queue_workers.session_commit.max_concurrent = 4 (top-level, correctly read).
1) What changed since my v0.5.0 comment
On 0.5.1.1 an archive with no messages no longer requeues: Session.resume_queued_commit() writes .failed.json, calls tracker.fail() and returns True (the if not archive_messages: block). That is the settle behaviour I asked for in point 3 of my earlier comment — for the empty case it is fixed.
What remains is the live dependency-wait branch. resume_queued_commit() has exactly one return False exit:
# openviking/session/session.py
1907: if not await self._can_run_archive(self._archives.archive_index_from_uri(msg.archive_uri)):
1908: return False
and _can_run_archive() (line 2874) returns False while the predecessor archive is still non-terminal.
2) Queue shape here is much smaller than in the report — Pending stays at 0
The original report has 33 commits queued with depth stuck at 33-34. On this box only 1-4 entries exist and Pending is 0, so the loop is invisible in pending depth:
[02:41:19] SessionCommit | Pending 0 | In Progress 3 | Processed 26093 | Requeued 26005
[02:43:20] SessionCommit | Pending 0 | In Progress 4 | Processed 26093 | Requeued 26005
A 30-minute watchdog window on the same box: Processed +3126 / Requeued +3124 (99.94 %). Cumulative at read time: 26093 / 26005 (99.66 %).
3) One waiting commit alone produces thousands of requeues
One task, one archive, one predecessor:
| event | time |
|---|---|
task created (session_commit, starts waiting) |
00:08:21 |
predecessor archive_092 writes .done |
02:13:54 |
same task updated_at |
02:13:55 (+1 s) |
125.6 minutes of waiting, and the successor is only touched 1 second after the predecessor completes. Measured churn is 104 requeues/min (+3126 over 30 min), so a single waiting commit accounts for roughly 13 000 requeues over that wait. No duplicate jobs and no multi-commit pile-up are needed — which is why the storm does not require the 33-commit depth from the original report.
4) The wait is long because Phase 2 itself is long
Consecutive .done deltas on two sessions here: 39.3 / 62.9 / 13.3 / 17.8 / 3.2 min and 43.9 / 34.2 / 62.0 / 29.8 min — median 34.2 min, max 62.9 min (memory_diff.json up to 9.5 MB). Requeue volume scales with it: requeues ~= wait_minutes * 104.
The queue does not deadlock. Archives of one session complete strictly in order (00:09 -> 00:49 -> 01:52 -> 02:05 -> 02:23 -> 02:26) and the queue drained from 4 entries to 0 within 15 minutes (02:40 -> 02:55) once the current archive finished.
5) Not #6188
Every predecessor here has phase1.status == "ready" plus a .done marker, so this is the live dependency-wait branch, not the unmarked legacy archive case.
6) Two reasons this stays invisible in metrics
- Dependency wait is counted as
Processed. Each cycle increments bothProcessedandRequeued, soProcessedstops meaning "work done". Our own queue watchdog fired "requeue storm — clear the queue" while the queue was in fact processing archives normally at one per 3-63 minutes. - Two re-enqueue points for the same non-processed result.
_process_bound()re-enqueues directly (session_commit_processor.py:80-87) andon_dequeue()then returnsProcessResult.requeued()for the sameprocessed == False(line 133), so one wait cycle reads as one full process plus one requeue.
7) Impact on this box
5.1 % of one core sustained since server start (1818 s CPU over 35 578 s uptime), plus monitoring noise. No failed tasks, Errors: 0.
Suggested addition to the backoff / FIFO directions already in the report: report dependency waiting as its own counter (or exclude it from Processed), so operators can tell healthy serialization from a retry storm. Happy to test a patch against this box — we can still reproduce on 0.5.1.1.
Confirming this on 0.5.1.1 with local measurements, and adding the concrete numbers + the exact code path.
Code path (0.5.1.1)
openviking/session/session.py:1843resume_queued_commit()— its onlyFalseexit is at line 1907-1908:if not await self._can_run_archive(self._archives.archive_index_from_uri(msg.archive_uri)): return False(_can_run_archiveis atsession.py:2874, "Resolve an orphaned direct predecessor before this Archive runs.")openviking/storage/queuefs/session_commit_processor.py:79-86— onprocessed == Falseit re-enqueues the same message immediately:
No delay, no backoff, no dedupe, no retry ceiling.processed = await session.resume_queued_commit(msg) if not processed: await get_queue_manager().enqueue(QueueManager.SESSION_COMMIT, msg.to_dict())session_commit_processor.py:133return ProcessResult.success() if processed else ProcessResult.requeued()
Local observations (SessionCommit queue)
Cumulative counters on this instance before any manual intervention:
| processed | requeued | errors | pending | in progress |
|---|---|---|---|---|
| 48,954 | 48,865 | 0 | 25 | 4 |
→ requeue/processed = 99.82 %. Errors has never moved off 0.
One two-read window while a predecessor was still running (8.5 minutes apart):
| pending | in progress | processed | requeued | |
|---|---|---|---|---|
| read 1 | 24 | 4 | 48,923 | 48,845 |
| read 2 | 17 | 4 | 48,944 | 48,859 |
| delta | −7 | 0 | +21 | +14 |
- Same session had 11 pending session_commit tasks queued at once (repeated commits to one long session).
- Oldest pending task had been waiting 5.0 h with no
startedevent. in progressstayed pinned at 4/4 (the configuredmax_concurrent) the whole time, so raising the pool is not the fix here — the successors are not eligible to run.
Adjacent defects explicitly excluded
- The predecessor archive for the waiting chain has
phase1.status = "ready"and is not in a terminal state, so this is not the "legacy archive with no Phase 1 marker blocks forever" case. - No manual queue surgery was performed on this instance, so these requeues are not leftover rows from a previous cleanup.
- This is also not the "pending ≈ 0 and one zombie message spins" shape: here pending stays high and the retried messages are genuine successors.
One more amplifier worth noting: while the four in-progress slots are occupied by very long Phase 2 steps, the queue shows zero throughput for minutes at a time (I measured a 5-minute window with processed/requeued deltas of 0/0), and then the successors burst. So the storm is bursty and only visible while a predecessor transition happens — a single snapshot usually makes it look idle.
Suggested direction (same as the report): make the processed == False dependency-wait path settle or back off instead of immediately re-enqueuing (bounded retries with delay, and/or dedupe by session so only one successor per session is queued), and record a started event so the task ledger can distinguish "waiting" from "never dequeued".