Worker output batches ignore the JSON envelope size, and a 413 is retried forever

Open
#43 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, python

Research direction

Start with client/src/orcaster_worker/output_streamer.py, especially _peek_batch and _send_with_retry, then read client/src/orcaster_worker/api.py for response handling. Check the existing OutputStreamer tests and add coverage for batch limits, 413 splitting and single-event rejection; the issue also calls for a CHANGELOG entry under Unreleased. Done means bounded request bodies, ordered delivery, drained queue accounting, and no retry loop on an oversized event.

Written by the indexing model from the issue text.

Description

bug client P1

Problem

OutputStreamer._peek_batch limits a POST /v1/tasks/{id}/output batch by the sum of the UTF-8 bytes of the event texts (_DRAIN_BATCH_MAX_BYTES, 256 KiB; client/src/orcaster_worker/output_streamer.py:65, :119, :369-376). It does not count the JSON envelope of each event (seq, ts, stream, roughly 80 bytes). It also does not cap the number of events. The server schema does not cap the number of events per request either (server/orcaster_server/schemas/tasks.py:125).

A backlog of tiny events therefore makes a request body far larger than the 256 KiB budget suggests. For one-byte events the body is tens of MiB.

When the server answers 413, the worker does not treat it as permanent. _RETRY_STATUS does not contain 413 (client/src/orcaster_worker/api.py:35), and output() only maps 409 (api.py:362-364). The 413 becomes an exception, and _send_with_retry retries the same batch unchanged with backoff (output_streamer.py:401). Only a lost lease stops the loop. Events queued behind the batch are never delivered, and aclose() without a drain_deadline does not return.

The server limit for this route is MAX_OUTPUT_BODY_BYTES (server/orcaster_server/config.py:177, default 32 MiB).

Steps to reproduce

  1. A task writes unbuffered one-byte output.
  2. The worker builds a backlog of a few hundred thousand events (server unreachable for a while, or a refilled spill file).
  3. The next drain builds one very large batch.
  4. A server whose output body limit is lower than that batch answers 413. The worker retries the same batch forever.

Proposed change

  1. In _peek_batch, charge each event its text size plus a fixed envelope allowance (for example 128 bytes). Keep the queue byte accounting (_dequeue, _queue_bytes) on the real text bytes so it does not drift.
  2. Handle 413 explicitly:
    • If the batch has more than one event, split it in half and send the halves in order.
    • If a single event is rejected, log an error with the task id, the seq and the encoded size (never the text), then continue with the next event. Never drop silently.
  3. Keep the server output limit unchanged in this issue.

Acceptance criteria

  • A test feeds a few hundred thousand one-byte events through OutputStreamer with an API double. Every request body is below 4 MiB, every event is delivered exactly once, and seq order is kept.
  • A test with events whose JSON escaping is longest (control characters) keeps every request body below 4 MiB.
  • A test where the API double answers 413 above a size threshold shows the batch is split, all events are delivered, and aclose() returns without a drain_deadline.
  • A test where the API double always answers 413 for one event shows an error log with task id and seq, no event text in the log, and the rest of the stream delivered.
  • _queue_bytes is 0 after a full drain that included a split.
  • Existing workers keep working. The server output limit and its default are not changed in this issue, and the request format on the wire is unchanged.
  • CHANGELOG entry under Unreleased.

Open questions

  • Lowering MAX_OUTPUT_BODY_BYTES is out of scope. It should only be revisited once every deployed worker runs the fixed worker.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.