Skip to content

fix(longlive): add logger + warning when KV cache write is skipped (#921)#924

Open
livepeer-tessa wants to merge 1 commit intomainfrom
fix/kv-cache-write-skip-warning-921
Open

fix(longlive): add logger + warning when KV cache write is skipped (#921)#924
livepeer-tessa wants to merge 1 commit intomainfrom
fix/kv-cache-write-skip-warning-921

Conversation

@livepeer-tessa
Copy link
Copy Markdown
Contributor

Summary

Addresses #921.

The if write_len > 0 guards on both KV cache write paths in CausalWanSelfAttention.forward() already prevent the RuntimeError that caused 310+ chunk failures per session (empty tensor slice when write_start_index == local_end_index). However, silent skips made it impossible to detect cache-state drift from Grafana logs.

Changes

  • Add import logging and logger = logging.getLogger(__name__) to causal_model.py
  • Add else: logger.warning(...) on both the roll_and_insert and direct_insert write paths

The WARNING message includes write_start_index, local_end_index, and a reference to #921.

Why this matters

When rapid video↔text mode transitions leave the cache index in a stale state, the skip now surfaces in logs as a WARNING instead of silently passing through. This:

  1. Confirms the guard is firing in production
  2. Provides the index values needed to diagnose root-cause cache drift
  3. Allows Grafana alert rules to key on KV cache write skipped if this starts happening frequently

Testing

  • Syntax check: python3 -c 'import ast; ast.parse(...)'
  • Ruff lint: no new violations introduced ✅

cc @mjh1 @emranemran

)

The `if write_len > 0` guards in `CausalWanSelfAttention.forward()` already
prevent the RuntimeError (empty tensor slice when write_start_index ==
local_end_index), but the skip was silent, making it impossible to diagnose
cache-state drift from Grafana logs.

Changes:
- Add `import logging` and `logger = logging.getLogger(__name__)`
- Add `else: logger.warning(...)` branch on both the roll_and_insert and
  direct_insert write paths so that stale-index events are surfaced as
  WARNING-level log entries (rather than ~310 silent skips/session)

The WARNING includes write_start_index, local_end_index, and a reference to
#921 to aid future investigation of cache index drift after rapid
video↔text mode transitions.

Fixes #921

Signed-off-by: Tessa (livepeer-tessa) <tessa@livepeer.org>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f84b177-48d5-471f-8a30-9d752415519b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/kv-cache-write-skip-warning-921

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 fal.ai Preview Deployment

App ID daydream/scope-pr-924--preview
WebSocket wss://fal.run/daydream/scope-pr-924--preview/ws
Commit d9f8e0d

Livepeer Runner

App ID daydream/scope-livepeer-pr-924--preview
WebSocket wss://fal.run/daydream/scope-livepeer-pr-924--preview/ws
Auth private

Testing Livepeer Mode

SCOPE_CLOUD_MODE=livepeer SCOPE_CLOUD_APP_ID="daydream/scope-livepeer-pr-924--preview/ws" uv run daydream-scope

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.

1 participant