Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .silo-translations
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
platform=web
version=2026.12.04-0b3cec1
sha256=c6d8d85b1b97fad7089f605a524389e0780913bad094c09cffbebf2fea9e442a
version=local-624cb84cf70e
sha256=-

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug medium

Local translation pin prevents reproducible synchronization

A normal scripts/sync-translations invocation fails because it rejects local-* pins without --local or --version. Restore a published release version and checksum so the repository can reproduce the translation assets.

Prompt for LLM
File .silo-translations, lines 2-3:

Local translation pin prevents reproducible synchronization

The committed local version makes a normal `scripts/sync-translations` invocation fail because the script explicitly rejects `local-*` pins without `--local` or `--version`. Restore a published release version and its checksum so the translation assets can be reproduced from the repository alone.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is expected while Silo-Server/silo-translations#228 is unmerged. Silo's translation rules have a client pull request sync with --local until the catalog change merges, then re-sync with --version <release> before it merges. That re-sync replaces this pin with the published release and its checksum. The PR body says so under Translations.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the clarification. I agree the local-* pin is expected while the catalog PR is unmerged, so my suggestion does not account for the documented workflow.

The remaining merge prerequisite is to re-sync with the published release and checksum after Silo-Server/silo-translations#228 merges. I can also save this workflow as a repository convention if you’d like.

4 changes: 2 additions & 2 deletions contracts/api/v2/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -266420,7 +266420,7 @@
}
}
],
"description": "Signed direct-play token required despite public outer middleware. Committed routing must select this proxy and direct-play recipe; legacy empty routing retains only bounded original method authority. Delegates to ServeDirectPlay with file-derived strong ETag, standard conditional/range handling, rolling write deadlines and viewer tracking. Partial routing returns 409; wrong egress or recipe family returns 503. Read interruption may truncate a committed response; no durable transfer or reconstruction guarantee.",
"description": "Signed direct-play token required despite public outer middleware. Committed routing must select this proxy and direct-play recipe; legacy empty routing retains only bounded original method authority. Delegates to ServeDirectPlay with an ETag computed from size, modification time and sampled file bytes (it does not prove byte equality), standard conditional/range handling, rolling write deadlines and viewer tracking. Partial routing returns 409; wrong egress or recipe family returns 503. Read interruption may truncate a committed response; no durable transfer or reconstruction guarantee.",
"listener": "proxy",
"method": "GET",
"path": "/stream/direct/{token}",
Expand Down Expand Up @@ -267006,7 +267006,7 @@
}
}
],
"description": "Signed direct-play token required despite public outer middleware. Committed routing must select this proxy and direct-play recipe; legacy empty routing retains only bounded original method authority. Delegates to ServeDirectPlay with file-derived strong ETag, standard conditional/range handling, rolling write deadlines and viewer tracking. Partial routing returns 409; wrong egress or recipe family returns 503. Read interruption may truncate a committed response; no durable transfer or reconstruction guarantee. HEAD suppresses response bytes but retains existing viewer tracking.",
"description": "Signed direct-play token required despite public outer middleware. Committed routing must select this proxy and direct-play recipe; legacy empty routing retains only bounded original method authority. Delegates to ServeDirectPlay with an ETag computed from size, modification time and sampled file bytes (it does not prove byte equality), standard conditional/range handling, rolling write deadlines and viewer tracking. Partial routing returns 409; wrong egress or recipe family returns 503. Read interruption may truncate a committed response; no durable transfer or reconstruction guarantee. HEAD suppresses response bytes but retains existing viewer tracking.",
"listener": "proxy",
"method": "HEAD",
"path": "/stream/direct/{token}",
Expand Down
19 changes: 8 additions & 11 deletions docs/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3568,17 +3568,14 @@ uncertain persistence before another explicit submission.
debounce_seconds is the window in which autoscan drops repeat reports of a path.
A report is dropped only when the same reported path in the same library was
claimed within the window and still looks as it did at that claim: still missing,
or a regular file with the same size, modification time and, on Unix, inode. A
deleted file, or one whose size, modification time or inode changed, queues a
scan. A rewrite that keeps the size and inode within the filesystem's timestamp
resolution, or that a network mount's attribute cache hides, can still be
dropped, as can a same-size, same-time replacement on filesystems that derive
inode numbers from the path. Reports of existing directories are never dropped.
Repeats do not extend the window, and 0 disables it. Claims live in Redis and
are shared by all nodes; on mounts where each node assigns its own inode numbers
(some FUSE and SMB setups), a repeat handled by a different node does not match
and scans again. Without Redis, or when a Redis call fails, every report is
processed.
or a regular file with the same size and the same modification time to the
microsecond. A deleted file, or one whose size or modification time changed,
queues a scan. A same-size replacement that keeps the modification time is
dropped too, as is a rewrite that keeps the size and the modification time
within the microsecond, or that a network mount's attribute cache hides.
Reports of existing directories are never dropped. Repeats do not extend the
window, and 0 disables it. Claims live in Redis and are shared by all nodes.
Without Redis, or when a Redis call fails, every report is processed.

The web enable switch and advanced form capture body and authority, disable retry
and authentication replay, and invalidate the canonical reader only for the active
Expand Down
59 changes: 47 additions & 12 deletions docs/architecture/direct-stream-resume.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,56 @@ Original-file responses follow the HTTP byte-range contract:
`416 Requested Range Not Satisfiable` with `Content-Range: bytes */<size>`.
- `HEAD` returns the same representation headers as `GET` without a body.

On Linux, macOS, and Windows, each response carries a strong, opaque `ETag`
derived from the open file's filesystem identity, change time, modification
time, and size. The validator is stable while the playback plan's original-file
entity is unchanged, but changes for same-size replacements even when their
modification time is preserved. Platforms that cannot expose a durable
filesystem revision omit the validator instead of hashing an entire media file
before each request. On those platforms an ETag-based `If-Range` request cannot
match and safely falls back to a full `200 OK` response.
On every platform, each response that carries a representation has a
strong-form, opaque `ETag`: a SHA-256 over the file's size, its modification
time to the microsecond, and its first and last 64 KiB (the whole file when it
is under 128 KiB). The tag holds no device, inode, or change time, so it
survives inode churn on a FUSE mount, `chmod`, a hardlink removal, and a switch
between API servers. The exception is a rolling upgrade from a build that sends
Comment thread
Quick104 marked this conversation as resolved.
Resolved
the older `dsr1` tag: old and new servers send different tags for the same
file, so a resume that crosses them gets `200 OK`. Status-specific header rules
stay as they are: for example, `http.ServeContent` strips the tag from a `416`.

The server samples the file only on a cache miss. A process-wide cache of 4,096
entries, least recently used evicted, maps the path, the platform's filesystem
revision, and the size and modification time to the tag. A miss happens on the
first request for a file in a process, after a change of the local stat or the
path, after an eviction or a restart, and on every request where the platform
gives no usable local revision. The local stat decides only when to read again;
the bytes, size, and modification time decide whether the tag changes. A failed
read of the sampled bytes answers `500`, and nothing is cached.

Two origins comparing fresh samples send the same tag only when both see the
same size, modification time to the microsecond, and sampled bytes. API servers
agree under the operator requirement in
[transcode-nodes.md](transcode-nodes.md), while a node or proxy mount that
dates files differently sends another tag, and a resume that switches to it
gets `200 OK`. A warm cache entry can also differ from a fresh sample after a
write the stat hides.

The tag does not prove byte equality. Two changes keep the old tag:

- A same-size edit that keeps or restores the modification time and leaves both
sampled ends unchanged.
- On a mount whose stat hides a write, an edit at a sampled end, until the next
Comment thread
Quick104 marked this conversation as resolved.
Resolved
stat change, restart, or eviction.

For either, a stale matching `If-Range` gets `206` with the requested range of
the current file, which a client may append to bytes it received from the
previous version; `If-Match` passes (`206`); `If-None-Match` answers `304`.

The tag leaves out the inode, device, and change time, because they differ
between hosts and change without the bytes changing. It leaves out a hash of the
whole file, because that makes each request cost the file's size. It leaves out
a stored version or digest, which would be exact but needs the server to record
one for each file.

A client resuming a transfer sends both `Range` and `If-Range` with the
validator. When it still matches, the server returns the requested `206`
response. When the entity changed, the server ignores the range and returns the
entire current entity as `200 OK`, preventing bytes from different revisions
from being combined. `If-None-Match` uses the same validator for ordinary
conditional requests.
response. When the entity changed in a way the tag detects, the server ignores
the range and returns the entire current entity as `200 OK`, preventing bytes
from different revisions from being combined. `If-None-Match` uses the same
validator for ordinary conditional requests.

For a bounded chunk read, a client can instead send `Range` and `If-Match`.
When the validator matches, the server returns the requested `206` interval.
Expand Down
6 changes: 4 additions & 2 deletions docs/architecture/worker-http-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ claims must select the committed proxy and recipe family; partial routing return
method authority only within their token lifetime. Download, remux and transcode
tokens are not interchangeable with direct-file authority.

Both methods use the existing ServeDirectPlay path and viewer tracking. File
identity supplies the strong ETag used by conditional resume; local file media
Both methods use the existing ServeDirectPlay path and viewer tracking. The
ETag used by conditional resume is a hash of the file's size,
modification time and sampled bytes, described in
[direct-stream-resume.md](direct-stream-resume.md); local file media
comes from the owning extension map. Single/multipart ranges, 304, 412 and 416
retain standard conditional behavior. HEAD suppresses bytes. Rolling write
deadlines and stream accounting remain unchanged; a later read failure can
Expand Down
25 changes: 10 additions & 15 deletions internal/autoscan/debounce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ func TestDebounceScansReplacementAtSamePath(t *testing.T) {
state string // "" removes the file
scan bool
}{
{name: "import", state: "file:100:1:10", scan: true},
{name: "duplicate import", state: "file:100:1:10", scan: false},
{name: "replacement with new size and mtime", state: "file:200:2:11", scan: true},
{name: "rewrite with new mtime only", state: "file:200:3:11", scan: true},
{name: "replacement with same size and mtime", state: "file:200:3:12", scan: true},
{name: "duplicate of the replacement", state: "file:200:3:12", scan: false},
{name: "import", state: "file:100:1", scan: true},
{name: "duplicate import", state: "file:100:1", scan: false},
{name: "replacement with new size and mtime", state: "file:200:2", scan: true},
{name: "rewrite with new mtime only", state: "file:200:3", scan: true},
{name: "delete", state: "", scan: true},
{name: "re-import of the original file", state: "file:100:1:10", scan: true},
{name: "re-import of the original file", state: "file:100:1", scan: true},
}
for _, step := range steps {
if step.state == "" {
Expand Down Expand Up @@ -273,18 +271,15 @@ func TestObservePathStateReplacementWithSameSizeAndMtime(t *testing.T) {
}

writeAt(path, "abc")
if info, err := os.Stat(path); err != nil {
t.Fatal(err)
} else if fileIdentity(info) == "" {
t.Skip("no file identity on this platform; the state is size and mtime only")
}
original, ok := observePathState(path)
if !ok || original == stateAbsent {
t.Fatalf("existing file = (%q, %v), want a file state", original, ok)
}

// An importer writes the new file beside the old one and renames it into
// place: same path, same size, same modification time, different file.
// place: same path, same size, same modification time, different file. The
// scan a report queues decides change by size and modification time, so
// this reads as the same state.
tmp := filepath.Join(dir, "movie.mkv.partial")
writeAt(tmp, "xyz")
if err := os.Rename(tmp, path); err != nil {
Expand All @@ -294,8 +289,8 @@ func TestObservePathStateReplacementWithSameSizeAndMtime(t *testing.T) {
if !ok {
t.Fatalf("replaced file = (%q, false), want debounceable", replaced)
}
if replaced == original {
t.Fatalf("replacement kept state %q", replaced)
if replaced != original {
t.Fatalf("same-size, same-mtime replacement state = %q, want the original state %q", replaced, original)
}
if again, _ := observePathState(path); again != replaced {
t.Fatalf("unchanged replacement state %q != %q", again, replaced)
Expand Down
9 changes: 0 additions & 9 deletions internal/autoscan/fileidentity_other.go

This file was deleted.

20 changes: 0 additions & 20 deletions internal/autoscan/fileidentity_unix.go

This file was deleted.

25 changes: 14 additions & 11 deletions internal/autoscan/suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"github.com/redis/go-redis/v9"

"github.com/Silo-Server/silo-server/internal/models"
)

// Suppressor debounces repeated reports of the same observed change. A claim
Expand All @@ -19,7 +21,8 @@ import (
// The window drops a report only when the path still looks exactly as it did
// at the live claim: a duplicate delivery of a change that a scan has already
// been queued for. A report that observes a different state (the file was
// deleted, replaced, or re-imported since the claim) claims again and scans.
// deleted, or its size or modification time changed since the claim) claims
// again and scans.
type Suppressor interface {
// ShouldScan atomically claims key for the observed state. It returns
// true, recording state with a ttl expiry, when no claim is live or the
Expand Down Expand Up @@ -91,11 +94,15 @@ const stateUnobserved = "unobserved"

// observePathState returns the debounce state of a local path and whether a
// repeated report of it may be debounced at all. A missing path is "absent";
// a regular file is identified by its size, modification time, and (on Unix)
// inode number, as "file:<size>:<mtimeNs>:<inode>". A delete, a rewrite, or a
// replacement at the same path reads as a new state, including a replacement
// that keeps the old size and modification time. Claims recorded in an older
// token format never match, so they only ever cause an extra scan.
// a regular file is identified by its size and modification time to the
// microsecond, as "file:<size>:<mtimeUs>". A delete, or a change of either,
// reads as a new state. A replacement with the same size and the same
// microsecond modification time reads as the same state, so a repeat report of
// it inside the window is dropped: the scan it would queue also decides change
// by size and microsecond modification time (internal/scanner). A claim
// recorded in an older token format can match only when its old nanosecond
// value equals the new microsecond value, which no real file reaches; any other
// old claim never matches, so it only causes an extra scan.
//
// Anything else is never debounced. A directory's own metadata does not
// change when a file deeper in its tree does, so a repeated directory report
Expand All @@ -110,11 +117,7 @@ func observePathState(path string) (string, bool) {
case err != nil:
return "", false
case info.Mode().IsRegular():
state := fmt.Sprintf("file:%d:%d", info.Size(), info.ModTime().UnixNano())
if id := fileIdentity(info); id != "" {
state += ":" + id
}
return state, true
return fmt.Sprintf("file:%d:%d", info.Size(), models.NormalizeFileModifiedAt(info.ModTime()).UnixMicro()), true
default:
return "", false
}
Expand Down
12 changes: 6 additions & 6 deletions internal/downloads/serve_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ func notifyServeAuthorized(ctx context.Context, target FileTarget) {

// WithServeEntityTag makes local file serving send tag(file, info) as the
// response ETag, computed from the descriptor it serves. Without it no ETag
// is sent.
func WithServeEntityTag(ctx context.Context, tag func(*os.File, os.FileInfo) string) context.Context {
// is sent. An error from tag fails the serve before any header is set.
func WithServeEntityTag(ctx context.Context, tag func(*os.File, os.FileInfo) (string, error)) context.Context {
if ctx == nil || tag == nil {
return ctx
}
return context.WithValue(ctx, serveEntityTagContextKey{}, tag)
}

func serveEntityTag(ctx context.Context, file *os.File, info os.FileInfo) string {
func serveEntityTag(ctx context.Context, file *os.File, info os.FileInfo) (string, error) {
if ctx == nil {
return ""
return "", nil
}
tag, _ := ctx.Value(serveEntityTagContextKey{}).(func(*os.File, os.FileInfo) string)
tag, _ := ctx.Value(serveEntityTagContextKey{}).(func(*os.File, os.FileInfo) (string, error))
if tag == nil {
return ""
return "", nil
}
return tag(file, info)
}
7 changes: 6 additions & 1 deletion internal/downloads/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,17 @@ func (s *Service) serveLocalFile(ctx context.Context, w http.ResponseWriter, r *
return fmt.Errorf("stat file: %w", err)
}

etag, err := serveEntityTag(ctx, f, stat)
if err != nil {
return fmt.Errorf("entity tag: %w", err)
}

if name == "" {
name = path
}
w.Header().Set("Content-Disposition", attachmentDisposition(name))
w.Header().Set("Content-Type", playback.MimeFromExtension(path))
if etag := serveEntityTag(ctx, f, stat); etag != "" {
if etag != "" {
w.Header().Set("ETag", etag)
}

Expand Down
34 changes: 34 additions & 0 deletions internal/downloads/service_read_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@ func TestLocalDownloadCanceledWritePersistsFailureDB(t *testing.T) {
}
}

// An entity tag that cannot be computed fails the serve before the download
// headers are set, so a browser never saves the error page under the media
// file's name.
func TestServeLocalFileEntityTagErrorServesNothing(t *testing.T) {
path := filepath.Join(t.TempDir(), "fixture.mp4")
if err := os.WriteFile(path, []byte("synthetic media"), 0600); err != nil {
t.Fatal(err)
}
injected := errors.New("sample read failed")
ctx := WithServeEntityTag(context.Background(), func(*os.File, os.FileInfo) (string, error) {
return "", injected
})
svc := &Service{}
w := httptest.NewRecorder()

err := svc.serveLocalFile(ctx, w, httptest.NewRequest("GET", "/file", nil), path, "movie.mkv", 2)

if !errors.Is(err, injected) {
t.Fatalf("error = %v, want one wrapping %v", err, injected)
}
if errors.Is(err, ErrResponseCommitted) {
t.Fatalf("error = %v, want it not marked as a committed response", err)
}
if got := w.Header().Get("Content-Disposition"); got != "" {
t.Errorf("Content-Disposition = %q, want none", got)
}
if got := w.Header().Get("ETag"); got != "" {
t.Errorf("ETag = %q, want none", got)
}
if w.Body.Len() != 0 {
t.Errorf("body length = %d, want 0", w.Body.Len())
}
}

// Only a response that delivered the whole file completes an account-level
// row: a HEAD probe or a partial range leaves it transferring (#4219).
func TestEphemeralDownloadCompletesOnlyOnWholeFileDB(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion internal/playback/directplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ func ServeDirectPlay(w http.ResponseWriter, r *http.Request, filePath string) er
}

w.Header().Del("ETag")
etag := DirectPlayEntityTag(f, stat)
etag, err := DirectPlayEntityTag(f, stat)
if err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)
Comment thread
Quick104 marked this conversation as resolved.
Resolved
return fmt.Errorf("direct play entity tag: %w", err)
Comment thread
Quick104 marked this conversation as resolved.
Resolved
}
if etag != "" {
w.Header().Set("ETag", etag)
}
Expand Down
Loading
Loading