Skip to content

fix(cluster): align InitCache timeline and sticky delete markers - #208

Merged
AlexanderWagnerDev merged 4 commits into
mainfrom
cursor/fix-initcache-timeline-and-delete-markers
Sep 10, 2026
Merged

fix(cluster): align InitCache timeline and sticky delete markers#208
AlexanderWagnerDev merged 4 commits into
mainfrom
cursor/fix-initcache-timeline-and-delete-markers

Conversation

@AlexanderWagnerDev

@AlexanderWagnerDev AlexanderWagnerDev commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remap before InitCache staging so keyframe timestamps share the MediaFrame timeline_ts domain (avoids remapper poisoning / jumps on failover).
  • Inject InitCache headers at the remapped timestamp instead of hard-coded 0.
  • Saturate the timeline remapper at u32::MAX instead of wrapping to ~0.
  • Stop auto-pruning deleted_streams by live session presence so sticky markers survive Raft begin_delete timeouts.

Test plan

  • CI: librtmp2-server with cluster feature (media hub / timeline)
  • CI: HTTP delete sticky-marker / Raft timeout paths
  • Failover/resubscribe: no large player timeline jumps after InitCache

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Improved live media initialization so metadata, codec headers, and keyframes use consistent timeline timestamps.
    • Prevented timeline timestamps from wrapping back to zero at the maximum value.
    • Preserved deleted-stream status markers until they are explicitly cleared, improving consistency across streaming and cluster operations.

Stage remapped timestamps for InitCache, inject headers at the remapped ts, saturate the remapper at u32::MAX, and stop pruning deleted_streams by live session presence during Raft delete ambiguity.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fc5e6665-af9e-4462-bb59-8640da343070

📥 Commits

Reviewing files that changed from the base of the PR and between 473c9d1 and 89f0c75.

📒 Files selected for processing (3)
  • src/http.rs
  • src/server.rs
  • src/test_support.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: acfaeb14-298f-4a88-afb9-065dd34b81a2

📥 Commits

Reviewing files that changed from the base of the PR and between 90de14f and 473c9d1.

📒 Files selected for processing (4)
  • src/cluster/media/hub.rs
  • src/cluster/media/timeline.rs
  • src/server.rs
  • src/test_support.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change unifies remapped timestamps for media cache injection, prevents timeline wraparound at u32::MAX, and stops live-session polling from removing deleted stream markers.

Changes

Media timing and cache injection

Layer / File(s) Summary
Timeline remapping and cache updates
src/cluster/media/timeline.rs, src/cluster/media/hub.rs
TimelineRemapper::map preserves u32::MAX during encoder-reset correction. Local frame caching now receives the remapped timestamp.
Shared live cache injection
src/cluster/media/hub.rs
Both InitCache paths store the cache entry and call inject_init_cache_live. The helper injects metadata, AVC, AAC, and keyframe data with one remapped timestamp.

Deleted marker lifecycle

Layer / File(s) Summary
Deleted marker retention
src/server.rs, src/test_support.rs
The RTMP poll loop and test harness no longer prune deleted_streams markers based on live connections. The live-stream lookup is now test-only.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MediaSession
  participant MediaCache
  participant TimelineRemapper
  participant LiveOutput
  MediaSession->>MediaCache: Store InitCache entry
  MediaSession->>TimelineRemapper: Remap keyframe timestamp
  TimelineRemapper-->>MediaSession: Return one timeline timestamp
  MediaSession->>LiveOutput: Inject metadata and codec headers
  MediaSession->>LiveOutput: Inject keyframe using the same timestamp
Loading

Suggested reviewers: claude, cursoragent

Merge Risk: ⚪ Minimal · up to 473c9

The change aligns media timestamps, prevents timeline wraparound, and preserves delete markers for timeout recovery. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the two primary changes: aligning InitCache timestamps with the cluster timeline and preserving delete markers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-initcache-timeline-and-delete-markers

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.

AlexanderWagnerDev and others added 2 commits September 10, 2026 19:15
Co-authored-by: Cursor <cursoragent@cursor.com>
…d helper

Collapse inject_init_cache_live parameters for Sonar/clippy, and gate live_stream_ids_for_deleted_markers behind cfg(test) after removing production retain.

Co-authored-by: Cursor <cursoragent@cursor.com>
@AlexanderWagnerDev
AlexanderWagnerDev marked this pull request as ready for review September 10, 2026 17:24
@AlexanderWagnerDev

Copy link
Copy Markdown
Contributor Author

@codex review

@cursor

cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_815756b6-67ca-43c3-9799-1edab4020cab)

@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: 473c9d139d

ℹ️ 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 src/server.rs Outdated
Comment on lines +1185 to +1189
// `deleted_streams` markers are owned by HTTP/cluster delete
// paths (insert on begin_delete, remove on finalize/rollback).
// Do not prune by live session presence — that drops sticky
// markers during Raft begin_delete ambiguity when the node has
// no local RTMP sessions for the stream.

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 Restore cleanup for transient drain markers

When ownership moves away while this node still has a local publisher, sync_ownership_from_db calls force_unpublish_and_drain, which inserts the stream into this same set without scheduling a delete finalize or ClearDrainStream. Removing the live-session pruning therefore leaves that marker forever after the publisher is kicked, and the checks in rtmp_bridge.rs reject every later publish and play attempt for the stream on this node, including after ownership returns. Keep explicit cleanup for these transient force-unpublish markers, or separate them from sticky delete markers.

Useful? React with 👍 / 👎.

Codex finding: ownership force_unpublish inserts deleted_streams without finalize, so disabling live-session prune left permanent publish/play blocks. Track HTTP deletes in sticky_deleted_streams and only prune non-sticky markers after local sessions drain.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@AlexanderWagnerDev
AlexanderWagnerDev merged commit 6f5340c into main Sep 10, 2026
19 checks passed
@AlexanderWagnerDev
AlexanderWagnerDev deleted the cursor/fix-initcache-timeline-and-delete-markers branch September 10, 2026 17:49
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