Skip to content

fix(sync): bound historical backfill inputs and defer over-limit legacy work - #22452

Merged
Git-on-my-level merged 8 commits into
mainfrom
lane/sync-input-limits
Oct 19, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
lane/sync-input-limits

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Bounds historical sync backfill inputs: files, encoded bytes, decoded/VAD audio bytes, frame count, duration and codec metadata (limits table in backend/docs/runbooks/sync-backfill-input-limits.md). Over-limit uploads return 413 at V2 admission, after the final lane is resolved (fresh and recent-legacy-fresh uploads are not capped; V1 never processes backfill and keeps its retryable 503), before staging, claims or the 202. The Cloud Tasks worker re-bounds each staged download and decode expansion; legacy over-limit work and retryable tmpfs/ENOSPC pressure (including Opus decode and prefetch-hit writes) return a queue-owned 409 with the job re-queued under its run fence and cloud audio plus content claims preserved.

Supersedes #20662. That PR also reduced the worker to 4 GiB / concurrency 3 / max 18 with a 1 GiB tmpfs; main now runs 8 GiB / concurrency 6 with a live max-scale (#20661, #21959) and the two sizings are unqualified together, so this PR makes no action.yml or Cloud Run sizing change. A 4 GiB experiment would need its own qualification against the current design.

Risk: legacy over-limit uploads now get an explicit 413 (clients keep the local recording and stop automatic retries); legacy over-limit worker input needs prompt operator recovery within the existing staging/task lifetime. Rollback: restore the previous serving revision.

Validation: targeted test_sync_input_limits, test_sync_pcm_decode, test_sync_opus_decode, test_sync_cloud_tasks, test_sync_two_lane, test_sync_v2, test_background_task_ratchet pass locally (nice, per-file).

Failure-Class: none

INV-MEM-4: resource bounds preserve content claims and defer over-limit legacy work rather than completing or invalidating it.

UI-Evidence: none -- backend only

Line-Count-Exception: backend/routers/sync.py | 3784 -> 3820 | Enforce batch resource bounds and map capacity pressure to a retryable 503 that preserves raw audio and claims.

Line-Count-Exception: backend/utils/sync/pipeline.py | 3507 -> 3538 | Bound staged downloads and expansion; propagate storage pressure without consuming legacy work.

Line-Count-Exception: backend/utils/other/storage.py | 2525 -> 2569 | Stream-bound staged downloads against the backfill byte budget.

🤖 Generated with Claude Code

…cy work

Admission (V1/V2) rejects over-limit backfill batches with 413 before custody
transfer; the Cloud Tasks worker bounds each staged download and decode
expansion, and answers 503 (job re-queued, audio and content claims preserved)
for legacy over-limit work or retryable tmpfs pressure. No Cloud Run sizing
change: supersedes the input-guard portion of #20662.

Failure-Class: none

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T11:08:20.318263Z 9c825de New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 144326dd8b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/routers/sync.py
Comment on lines +1080 to +1081
if lane_decision.lane is SyncLane.BACKFILL:
await run_blocking(sync_executor, validate_backfill_uploads, files)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce aggregate limits while parsing multipart bodies

At this point FastAPI has already parsed and spooled every upload before invoking the handler. Both sync routes still declare only the 200 MiB per-part @max_part_size and no multipart_limits, so a backfill request can submit up to the parser's 1,000-file default and exhaust the instance's temporary storage long before this 20-file/64-MiB check returns 413; this also occurs before authentication dependencies run. Apply the file-count and whole-body bounds in MultipartMaxPartSizeRoute during parsing rather than only validating the completed UploadFile list.

Useful? React with 👍 / 👎.

Comment thread backend/routers/sync.py
if sync_lane == SyncLane.BACKFILL.value:
await run_blocking(db_executor, release_backfill_slot, uid, job_id)
return JSONResponse(status_code=200, content={'status': 'done'})
except (BackfillInputLimitExceeded, BackfillStoragePressure) as error:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve final-attempt handling for fresh storage failures

When a fresh sync-jobs task hits ENOSPC/EDQUOT during decode or VAD, the newly raised BackfillStoragePressure reaches this lane-agnostic catch and is re-queued with a 503 even on its final configured attempt. Fresh jobs have no backfill sequencer to redrive an exhausted task, and jobs with an attempt are exempt from stale-poll finalization, so the job remains permanently queued with its content claim held after Cloud Tasks drops the task and the staged blobs eventually expire. Restrict indefinite deferral to the backfill lane or route fresh pressure through the existing final-attempt branch.

AGENTS.md reference: backend/AGENTS.md:L145-L145

Useful? React with 👍 / 👎.

Comment thread backend/utils/sync/files.py Outdated
os.remove(wav_file_path)
return False
except Exception as e:
raise_sync_storage_pressure(e)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove partial WAVs before raising storage pressure

If an output write fails with ENOSPC or EDQUOT after creating wav_file_path, raise_sync_storage_pressure raises immediately and makes the existing removal below it unreachable; the PCM catch has the same ordering. In the deprecated v1 path, decode_files_to_wav never returns its output list and the endpoint cleanup therefore knows only the raw paths, leaving the partial WAV in the shared syncing/{uid} directory and keeping the volume full for subsequent work. Delete the partial output before translating and re-raising the storage exception.

Useful? React with 👍 / 👎.

width, rate = 2, 16000
match = re.search(r'_fs(\d+)', filename)
frame_samples = int(match.group(1)) if match else 160
if frame_samples not in OPUS_FRAME_SAMPLES:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound numeric tokens before converting them

A multipart filename can contain an _fs token with more than Python 3.11's integer-string digit limit, causing this int(...) call to raise ValueError before the allowed-value check; the PCM rate conversion has the same problem. validate_backfill_uploads catches only BackfillInputLimitExceeded, so such an untrusted historical upload produces a 500 instead of the intended bounded 413 response. Check the token length or catch conversion failures and translate them to BackfillInputLimitExceeded.

Useful? React with 👍 / 👎.

Comment thread backend/utils/sync/files.py Fixed
Comment thread backend/utils/sync/files.py Fixed
Comment thread backend/utils/sync/files.py Fixed
Comment thread backend/utils/sync/files.py Fixed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c825dee39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

with open(file_path, 'wb') as output:
output.write(prepared.data)
if max_bytes is not None and len(prepared.data) > max_bytes:
from utils.sync.input_limits import BackfillInputLimitExceeded

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the new storage imports to module scope

Move this BackfillInputLimitExceeded import, along with the newly added imports inside _write_prefetched_bytes and _download_blob_bounded, to the module import section. The backend explicitly prohibits function-local imports and requires dependencies to follow the database/ → utils/ → routers/ → main.py hierarchy; input_limits does not import storage, so these imports do not appear necessary to break a cycle.

AGENTS.md reference: backend/AGENTS.md:L161-L169

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 9d9f357 into main Oct 19, 2026
60 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/sync-input-limits branch October 19, 2026 11:18
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
…sites (#22495)

* feat(sync): legacy-dark call sites, sequencer dark exits and /v1/sync-local-files 410 (lane 10 slice 2b)

routers/sync.py: no legacy job outside on (fence for legacy-owned
content, 409 retry-later otherwise), legacy-fresh skipped, sequencer
registration and pre-sequencer migration only at on, dark sweep stops
claims but keeps enrichment and summary-debt repair, dark wake 200.
uid_sequencer: kick/sweep inert in dark. /v1/sync-local-files returns
410 (7-day census: zero calls); its v1-only tests are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): drop #22452's v1 over-limit test; /v1/sync-local-files is 410 in slice 2b

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): drop the remaining v1 sync-local-files source checks (route is 410)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(sync): the 410 v1 handler is a plain def (no await)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): fair-use 402 source check reads the v1 410 stub as a plain def

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): the v1 structure check expects the 410 stub

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): router-harness legacy-dark tests in their own file, allowlisted like test_sync_cloud_tasks

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* revert(sync): keep /v1/sync-local-files in slice 2b; its retirement moves to the C6 deletion PR (lead ruling (a))

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
)

* fix(backend): restore pyright-clean main after #22207 and #22326

Main's backend unit shards fail the enforced pyright lane:

- database/desktop_previews.py (#22207): 16 reportUnnecessaryIsInstance
  errors. The runtime guards stay; they move into validators that take
  `object` (_payload, _string, _expected_generation, _datetime), so the
  checks are meaningful to pyright. Public signatures, error messages and
  check order are unchanged.
- utils/sync/pipeline.py:process_segment (#22326 on top of #22452):
  "code is too complex to analyze". Behaviour-neutral split: the two
  identical cap-hold defer blocks become one hold_for_cap closure, and the
  final-pass / speaker-identification block moves to
  _assign_segment_speakers with the same exception handling.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): repair unit tests that drifted from main across merges

Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
YinkaAdepoju pushed a commit to YinkaAdepoju/omi that referenced this pull request Nov 1, 2026
…ocal-files is 410 in slice 2b

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants