Skip to content

fix(session): settle unexpected commit worker failures - #5772

Merged
qin-ctx merged 2 commits into
volcengine:mainfrom
akushonkamen:fix/5622-session-commit-guard
Oct 16, 2026
Merged

qin-ctx merged 2 commits into
volcengine:mainfrom
akushonkamen:fix/5622-session-commit-guard

Conversation

@akushonkamen

@akushonkamen akushonkamen commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

If loading a Session raises a JSON parsing error, the commit worker currently exits without settling its queue delivery. The task remains pending and later archives wait behind it.

Return a failed queue result for an unexpected processor exception. The existing task middleware persists the error and settles the delivery; the existing predecessor recovery then allows the next archive to run. The final change is one file, +4/-1 lines.

Before: a Session load error leaves the task pending, the delivery unacknowledged, and the next archive blocked.

After: the same error produces a failed task with the original error, the delivery is acknowledged, and the next archive proceeds through existing predecessor recovery.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #5622

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Convert unexpected _process exceptions into ProcessResult.failed, using the existing queue lifecycle to update task state and acknowledge the delivery.
  • Preserve cancellation propagation; no new task state, retry mechanism, or archive recovery helper.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

40 existing tests passed across the SessionCommit processor, QueueManager, commit resume, and task-work contracts. Ruff check and format check passed.

A focused before/after fault-injection probe used the real Session, NamedQueue, TaskWorkQueueMiddleware, TaskTracker, and PersistentTaskStore with in-memory storage transports. A load error leaves the baseline task pending and its successor blocked. With this change, the task fails with the original error, its delivery is acknowledged, and the next archive completes. Both a warm tracker and a tracker reloaded from persisted task records passed. No new test files or unit tests are added.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Not applicable.

Additional Notes

This settles the reported failure path. The concurrent torn-read cause has not been reproduced. Archive failure markers continue to be supplied by the existing predecessor recovery when the next archive checks the failed predecessor; this change does not introduce a second finalization mechanism.

…l task errors (volcengine#5622)

on_dequeue only guarded _parse_message; any exception raised inside
_process — e.g. the json.JSONDecodeError from Session.load() reading a
torn line of the live messages.jsonl during a compact commit — escaped
the handler. The queue layer then swallowed it: the delivery was never
acked, the queue row stayed in processing, and the task record stayed
pending until the client gave up with "Phase 2 timed out". A worker
restart replays the same payload into the same race, so recovery never
completes on its own.

Wrap the _process call and mirror the existing session-missing branch:
reuse the Phase-1 task record (tracker.create is idempotent for an
explicit task_id owned by the same user), record the real error via
tracker.fail, and settle the delivery as ProcessResult.failed so clients
see the underlying crash instead of a timeout.

Out of scope (noted in the PR): locking Session.load() against the
Phase-1 drain-rewrite, switching Phase 2 to the immutable archive, and
client timeout semantics.
@ynaamane

Copy link
Copy Markdown

I ran this branch through the production wiring (real QueueManager, NamedQueue, TaskWorkQueueMiddleware, TaskTracker, SessionCommitProcessor and Session, with in-memory stand-ins only for the AGFS queue backend, the task store and the viking fs), feeding the worker a torn messages.jsonl so that Session.load() raises inside Phase 2. The delivery is acked and the task ends failed in every scenario I tried (first delivery, redelivery after a restart with a cold tracker, delivery before Phase 1 created the task), which is the behaviour the issue asks for. Two observations from the same runs:

  1. No .failed.json marker is written next to the archive (files added: [] in all runs), so the archive directory stays in its pending shape on disk while the task record says failed. The session-missing branch a few lines above writes a marker through Session.finalize_failed_commit; reusing it here would keep the two views consistent.

  2. When the archive already carries .done (a message redelivered after the commit had completed) the task is still marked failed, so the task record contradicts the archive. Checking the persisted archive state before settling (fail only if the archive is still pending, otherwise treat the redelivery as already done) covers that case.

I have a branch with that state check and a test for the redelivered .done case; happy to share it or the reproduction script if either is useful here.

Reuse queue-owned failure settlement and predecessor recovery instead of duplicating task mutations in the processor.

Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
@qin-ctx qin-ctx changed the title fix(session): record SessionCommit Phase-2 worker failures as terminal task errors (#5622) fix(session): settle unexpected commit worker failures Oct 16, 2026
@qin-ctx
qin-ctx merged commit e24295f into volcengine:main Oct 16, 2026
8 of 9 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Oct 16, 2026
qin-ctx added a commit that referenced this pull request Oct 16, 2026
…l task errors (#5622) (#5772)

on_dequeue only guarded _parse_message; any exception raised inside
_process — e.g. the json.JSONDecodeError from Session.load() reading a
torn line of the live messages.jsonl during a compact commit — escaped
the handler. The queue layer then swallowed it: the delivery was never
acked, the queue row stayed in processing, and the task record stayed
pending until the client gave up with "Phase 2 timed out". A worker
restart replays the same payload into the same race, so recovery never
completes on its own.

Wrap the _process call and mirror the existing session-missing branch:
reuse the Phase-1 task record (tracker.create is idempotent for an
explicit task_id owned by the same user), record the real error via
tracker.fail, and settle the delivery as ProcessResult.failed so clients
see the underlying crash instead of a timeout.

Out of scope (noted in the PR): locking Session.load() against the
Phase-1 drain-rewrite, switching Phase 2 to the immutable archive, and
client timeout semantics.

Co-authored-by: qin-ptr <222410531+qin-ptr@users.noreply.github.com>
Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
(cherry picked from commit e24295f)
qin-ctx added a commit that referenced this pull request Oct 19, 2026
…l task errors (#5622) (#5772)

on_dequeue only guarded _parse_message; any exception raised inside
_process — e.g. the json.JSONDecodeError from Session.load() reading a
torn line of the live messages.jsonl during a compact commit — escaped
the handler. The queue layer then swallowed it: the delivery was never
acked, the queue row stayed in processing, and the task record stayed
pending until the client gave up with "Phase 2 timed out". A worker
restart replays the same payload into the same race, so recovery never
completes on its own.

Wrap the _process call and mirror the existing session-missing branch:
reuse the Phase-1 task record (tracker.create is idempotent for an
explicit task_id owned by the same user), record the real error via
tracker.fail, and settle the delivery as ProcessResult.failed so clients
see the underlying crash instead of a timeout.

Out of scope (noted in the PR): locking Session.load() against the
Phase-1 drain-rewrite, switching Phase 2 to the immutable archive, and
client timeout semantics.

Co-authored-by: qin-ptr <222410531+qin-ptr@users.noreply.github.com>
Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
(cherry picked from commit e24295f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Core server, runtime, storage, retrieval, SDK, and CLI.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Session Phase-2 worker crashes on torn live-messages read; commit task stuck pending forever, client reports misleading "Phase 2 timed out"

5 participants