Skip to content

Implement configurable seamless file-size segment rotation for live recording#4

Draft
Copilot wants to merge 9 commits intomainfrom
copilot/implement-stop-restart-recording
Draft

Implement configurable seamless file-size segment rotation for live recording#4
Copilot wants to merge 9 commits intomainfrom
copilot/implement-stop-restart-recording

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 13, 2026

This PR starts implementation of file-size based recording segmentation with a configurable threshold, while preserving continuous stream capture (no recovery-style reconnect path for normal splits).
When enabled, recording now rotates to a new file as soon as the active segment reaches the configured size.

  • Config: add size-based split threshold

    • Added MAX_RECORDING_FILE_SIZE_BYTES (0 = disabled) to runtime config.
    • Wired the new env var into app config defaults and runtime loading.
    • Updated .env, Dockerfile, and README config tables/examples.
  • Recorder: in-stream segment rotation (no stream disconnect)

    • Added per-segment byte tracking alongside total bytes.
    • Added rotation trigger segmentBytes >= MaxRecordingFileSizeBytes.
    • Rotation now swaps writer pipeline to a new file on the same live stream read loop.
    • Closed segments are finalized independently (including existing conversion enqueue behavior).
  • Recorder: safer output path handling

    • Made output-path reads/writes concurrency-safe in Recorder.
    • Updated stats reporting to read output path via synchronized accessor.
  • Segment naming: deterministic collision handling

    • Added next-segment path generation from current file prefix + timestamp.
    • Added bounded collision retry and fallback naming with warning log.
  • Focused unit coverage

    • Added tests for:
      • split trigger threshold logic (shouldRotateSegment)
      • next-segment path generation and collision suffix behavior.
// disabled by default
MaxRecordingFileSizeBytes: utils.MustAtoi64(
    utils.EmptyOrElse(os.Getenv("MAX_RECORDING_FILE_SIZE_BYTES"), "0"),
)

// split trigger in recording loop
if r.shouldRotateSegment(info) {
    if err := r.rotateSegment(roomId, info, ctx, &currentPipe); err != nil {
        l.Errorf("failed to rotate segment by size: %v", err)
    }
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.bilibili.com
    • Triggering command: /tmp/go-build1955602642/b325/bilibili.test /tmp/go-build1955602642/b325/bilibili.test -test.testlogfile=/tmp/go-build1955602642/b325/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� user 2DfD_wGQN ux-amd64/pkg/tool/linux_amd64/vet credential.helpe/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/too-o/tmp/go-build1955602642/b363//_cgo_.o 0.1-go1.25.0.lin-unsafeptr=false (dns block)
  • api.live.bilibili.com
    • Triggering command: /tmp/go-build1955602642/b325/bilibili.test /tmp/go-build1955602642/b325/bilibili.test -test.testlogfile=/tmp/go-build1955602642/b325/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� user 2DfD_wGQN ux-amd64/pkg/tool/linux_amd64/vet credential.helpe/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/too-o/tmp/go-build1955602642/b363//_cgo_.o 0.1-go1.25.0.lin-unsafeptr=false (dns block)
    • Triggering command: /tmp/go-build1955602642/b355/room.test /tmp/go-build1955602642/b355/room.test -test.testlogfile=/tmp/go-build1955602642/b355/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 0.1-go1.25.0.linux-amd64/src/run-c --global ux-amd64/pkg/tool/linux_amd64/vet credential.usern/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/too/tmp/go-build1955602642/b363/ (dns block)
    • Triggering command: /tmp/go-build1955602642/b352/recorder.test /tmp/go-build1955602642/b352/recorder.test -test.testlogfile=/tmp/go-build1955602642/b352/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 0.1-go1.25.0.linux-amd64/src/run. d9zbPST-B ux-amd64/pkg/tool/linux_amd64/vet credential.usern/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.lin/tmp/go-build1955602642/b325/_testmain.go (dns block)
  • www.bilibili.com
    • Triggering command: /tmp/go-build1955602642/b325/bilibili.test /tmp/go-build1955602642/b325/bilibili.test -test.testlogfile=/tmp/go-build1955602642/b325/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� user 2DfD_wGQN ux-amd64/pkg/tool/linux_amd64/vet credential.helpe/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/too-o/tmp/go-build1955602642/b363//_cgo_.o 0.1-go1.25.0.lin-unsafeptr=false (dns block)
    • Triggering command: /tmp/go-build1955602642/b352/recorder.test /tmp/go-build1955602642/b352/recorder.test -test.testlogfile=/tmp/go-build1955602642/b352/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 0.1-go1.25.0.linux-amd64/src/run. d9zbPST-B ux-amd64/pkg/tool/linux_amd64/vet credential.usern/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.lin/tmp/go-build1955602642/b325/_testmain.go (dns block)
    • Triggering command: /tmp/go-build1955602642/b355/room.test /tmp/go-build1955602642/b355/room.test -test.testlogfile=/tmp/go-build1955602642/b355/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 0.1-go1.25.0.linux-amd64/src/run-c --global ux-amd64/pkg/tool/linux_amd64/vet credential.usern/home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/too/tmp/go-build1955602642/b363/ (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Start implementation

[Chronological Review: The conversation began with the user requesting the implementation of a feature that stops and restarts recording when a specific file size is reached. The user emphasized the need for this implementation to ensure that recording does not lose any live content during the process. The user then reiterated the request to start the implementation, indicating a desire to move forward with the coding task.]

[Intent Mapping:

  • "幫我實作一個隔特定檔案大小(configurable)時停止並重新錄製(類似分割檔案)" - User requests implementation of a feature to stop and restart recording based on a configurable file size.
  • "你能確保你的規劃能讓錄製無斷切割,而不是像recovery重連丟失部分直播内容嗎" - User seeks assurance that the implementation will not result in loss of content during recording interruptions.
  • "Start implementation" - User expresses readiness to begin coding the requested feature.]

[Technical Inventory:

  • Language: Go (Golang)
  • File: d:\Projects\mine\bilirec\internal\services\recorder\stats.go
  • Key concepts: File size monitoring, recording management, seamless transitions in live content recording.]

[Code Archaeology: No specific code changes or functions have been discussed or modified yet, as the user is in the initial stages of implementation.]

[Progress Assessment: The user has not yet begun coding the requested feature but has expressed a clear intent to start. There is a focus on ensuring that the implementation meets the requirement of seamless recording.]

[Context Validation: The conversation has established the need for a feature that allows for configurable file size limits while ensuring no loss of content during recording interruptions. The user is ready to start the implementation.]

[Recent Commands Analysis:

  • Last Agent Commands: The user issued commands to start the implementation of the recording feature and requested assurance regarding the seamlessness of the recording process.
  • Tool Results Summary: No tool results are available as the implementation has not yet begun.
  • Pre-Summary State: The agent was actively preparing to assist the user in implementing the requested feature when the token budget was exceeded.
  • Operation Context: The commands were executed in direct relation to the user's goal of implementing a file size-based recording feature without losing live content.]
1. Conversation Overview: - Primary Objectives: The user requested the implementation of a feature to stop and restart recording based on a configurable file size and sought assurance that this would not result in loss of live content. - Session Context: The conversation has focused on the user's desire to implement a recording feature in Go, with an emphasis on seamless operation during interruptions. - User Intent Evolution: The user has consistently expressed a need for a specific feature and has shown readiness to begin implementation while seeking confirmation of its effectiveness.
  1. Technical Foundation:
  • Go: The programming language being used for the implementation.
  • File: d:\Projects\mine\bilirec\internal\services\recorder\stats.go, which is the current working file for the user.
  1. Codebase Status:
  • File Name: stats.go
  • Purpose: This file is intended to manage recording statistics and functionality.
  • Current State: No modifications have been made yet as the user is preparing to start the implementation.
  • Key Code Segments: Not applicable yet as no code has been discussed or modified.
  1. Problem Resolution:
  • Issues Encountered: The user is concerned about potential content loss during recording interruptions.
  • Solutions Implemented: No solutions have been implemented yet as the coding process has not started.
  • Debugging Context: No ongoing troubleshooting efforts have been initiated.
  • Lessons Learned: The importance of seamless recording during interruptions has been highlighted.
  1. Progress Tracking:
  • Completed Tasks: No tasks have been completed yet.
  • Partially Complete Work: The user is ready to start the implementation of the recording feature.
  • Validated Outcomes: No features have been validated yet.
  1. Active Work State:
  • Current Focus: The user is focused on implementing a feature to manage recording based on file size.
  • Recent Context: The user has requested to start the implementation and has sought assurance regarding the seamlessness of the recording process.
  • Working Code: No code snippets have been discussed yet.
  • Immediate Context: The user is preparing to implement the requested feature in the stats.go file.
  1. Recent Operations:
  • Last Agent Commands: The user requested to start the implementation and sought assurance regarding the recording process.
  • Tool Results Summary: No tool results are available as the implementation has not yet begun.
  • Pre-Summary State: The agent was preparing to assist with the implementation when the token budget was exceeded.
  • Operation Context: The commands were executed to align with the user's goal of...

Created from VS Code.

Copilot AI and others added 8 commits April 13, 2026 10:11
Agent-Logs-Url: https://github.com/eric2788/bilirec/sessions/881c531d-f8b3-4dd1-a432-66ead9323421

Co-authored-by: eric2788 <6276840+eric2788@users.noreply.github.com>
Agent-Logs-Url: https://github.com/eric2788/bilirec/sessions/881c531d-f8b3-4dd1-a432-66ead9323421

Co-authored-by: eric2788 <6276840+eric2788@users.noreply.github.com>
Agent-Logs-Url: https://github.com/eric2788/bilirec/sessions/881c531d-f8b3-4dd1-a432-66ead9323421

Co-authored-by: eric2788 <6276840+eric2788@users.noreply.github.com>
Agent-Logs-Url: https://github.com/eric2788/bilirec/sessions/881c531d-f8b3-4dd1-a432-66ead9323421

Co-authored-by: eric2788 <6276840+eric2788@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature to stop and restart recording by file size Implement configurable seamless file-size segment rotation for live recording Apr 13, 2026
Copilot AI requested a review from eric2788 April 13, 2026 10:20
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