Repository navigation
[ryoku] ryogami: workshop previews reuse cached clips and sweep orphan temps - #929
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 2 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| - **Night Light schedules now reconcile the running backend once when they are | ||
| enabled or restored, so a light left on during daylight turns off at the next | ||
| tick instead of waiting for the next sunrise edge (#919)** |
There was a problem hiding this comment.
🟡 minor · Maintainability · fix: medium effort
This PR also changes Night Light scheduling, independently of the Ryogami preview and temp cleanup work. Split the Night Light changes into a separate PR to keep one logical change per PR.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| if armed != 0 { | ||
| if want != n.running() { | ||
| var err error | ||
| if want { | ||
| err = n.intent("on") | ||
| } else { | ||
| err = n.intent("off") | ||
| } |
There was a problem hiding this comment.
🟠 major · Possible Bug · fix: medium effort
Disabling the schedule does not change schedArmed, so an in-flight armed tick can still apply its old want after the user turns scheduling off. Invalidate in-flight ticks on disable and synchronize the backend action with schedule changes so disabling leaves the current state alone.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
🦊 mika's reviewIncremental review: new commits since the last checkpoint. Summary
Change diagramflowchart LR
Workshop["Workshop video"] --> Identity["Size and head hash"]
Identity --> Preview["Preview reuse or render"]
Preview --> Metadata["Atomic identity record"]
Startup["Daemon startup"] --> Sweep["Cache temp sweep"]
Sweep --> Scan["Initial scan"]
Estimated review effort: 3/5 · risk: high 📁 Walkthrough details
|
| Severity | Category | Fix effort | File | Issue |
|---|---|---|---|---|
| 🟠 major | correctness | medium | ryoku/shell/ryogami/daemon/scan.go |
Possible Bug — A same-size workshop update that changes video data after the first 64 KiB leaves this identity unchanged, so the old preview is reused indefinitely. Hash the complete source or use another reliable content identity; add… |
| 🟡 minor | maintainability | low | ryoku/shell/ryogami/daemon/workshop_previews_test.go |
Maintainability — The new test comments include reviewer attribution, which the repository forbids in comments. Remove the parenthesized attribution references from these tests. |
⚡ Quick fixes by effort
Low effort (apply from the diff):
ryoku/shell/ryogami/daemon/workshop_previews_test.go:215 — Maintainability — The new test comments include reviewer attribution, which the repository forbids in comments. Remove the parenthesized attribution references from these tests.
Medium effort (a function-level change):
ryoku/shell/ryogami/daemon/scan.go:604 — Possible Bug — A same-size workshop update that changes video data after the first 64 KiB leaves this identity unchanged, so the old preview is reused indefinitely. Hash the complete source or use another reliable content identity; add…
🤖 Prompt for AI agents (click, copy, paste into Claude/Codex)
Fix the following issues found by mika-agent on Ryoku-dev/ryoku#929 (branch fix/ryogami-workshop-preview-reuse):
- ryoku/shell/ryogami/daemon/scan.go:604-610 — Possible Bug (major severity, medium effort): A same-size workshop update that changes video data after the first 64 KiB leaves this identity unchanged, so the old preview is reused indefinitely. Hash the complete source or use another reliable content identity; add…
- ryoku/shell/ryogami/daemon/workshop_previews_test.go:215-217 — Maintainability (minor severity, low effort): The new test comments include reviewer attribution, which the repository forbids in comments. Remove the parenthesized attribution references from these tests.
For each: verify it is real in the current code, apply the smallest correct fix, and run the repo's tests. Skip anything already resolved and say why.
🛠 Deterministic checks run
- golangci-lint: not installed (skip)
🚦 Merge recommendation: changes_required
🦊 Generated by Mika — the Ryoku org's self-hosted AI code reviewer. Machine findings: verify before merging.
| if armed != 0 { | ||
| if want != n.running() { | ||
| var err error | ||
| if want { | ||
| err = n.intent("on") | ||
| } else { | ||
| err = n.intent("off") | ||
| } | ||
| if err != nil { | ||
| log.Printf("ryoku-shell: night light schedule tick failed: %v", err) | ||
| return // retry on the next tick: do not record an action that did not land | ||
| } | ||
| } | ||
| n.schedMu.Lock() | ||
| if n.schedArmed == armed { | ||
| n.schedArmed = 0 | ||
| n.schedLastDesire = want |
There was a problem hiding this comment.
Boot restore bypasses the schedule. The first daylight tick clears
schedArmed when the backend is still off, but it leaves the saved enabled marker untouched. Login separately starts ryoku-cmd-nightlight restore, with no ordering against this tick. If restore runs afterward, it starts the light from that marker after the one-time check has finished. Later ticks see the same schedLastDesire and leave it on. Coordinate startup restore with the schedule check so this boot case is covered too.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/ipc/nightlight_schedule.go
Line: 294-310
Comment:
**Boot restore bypasses the schedule.** The first daylight tick clears `schedArmed` when the backend is still off, but it leaves the saved enabled marker untouched. Login separately starts `ryoku-cmd-nightlight restore`, with no ordering against this tick. If restore runs afterward, it starts the light from that marker after the one-time check has finished. Later ticks see the same `schedLastDesire` and leave it on. Coordinate startup restore with the schedule check so this boot case is covered too.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.9ec56fe to
812f03c
Compare
neur0map
left a comment
There was a problem hiding this comment.
🔍 Review findings — 1 blocking issue(s): see the inline comments and the walkthrough for details.
🧹 Nitpicks (1) — optional, not blocking
-
ryoku/shell/ryogami/daemon/scan.go:617-624— Suggestion: bug — Avoid globbing the cache directory pathSuggested change
func sweepTmpFiles(cacheDir string) {
for _, sub := range []string{"wallpaper/thumbs", "wallpaper/thumbs-sm", "wallpaper/video-thumbs", "wallpaper/anim"} {
dir := filepath.Join(cacheDir, sub)
entries, _ := os.ReadDir(dir)
for _, entry := range entries {
if strings.Contains(entry.Name(), ".tmp.") {
_ = os.Remove(filepath.Join(dir, entry.Name()))
}
}
}
}
|
All four findings addressed:
Ryogami module suite passes, gofmt and vet clean. |
|
Both round-2 findings addressed. The record-write window ( The crossed writers (greptile's P2, same family): each clip's render and publication is now serialized per preview path (a The glob nitpick for the sweep is noted and left as is: Workshop preview and sweep tests pass, gofmt and vet clean. |
neur0map
left a comment
There was a problem hiding this comment.
🔍 Review findings — 2 blocking issue(s): see the inline comments and the walkthrough for details.
|
Both round-3 findings addressed. The same-size update (scan.go:575): valid and the sharper of the two, because it is the failure my size-only fix traded in. The record beside each clip is now an identity, not a byte count: the source's size plus the SHA-256 of its first 64 KiB, stored as one line in The lock registry (scan.go:551): the per-clip render lock is now refcounted and releases its registry entry when nothing waits on it, so a library that churns videos does not grow it. The crossed-writers guarantee from the round-2 fix is unchanged. The two e2e failures in the module run are the same environmental pair from before my branch ( |
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| head := make([]byte, previewHeadBytes) | ||
| n, err := io.ReadFull(f, head) | ||
| if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { | ||
| return "" | ||
| } | ||
| sum := sha256.Sum256(head[:n]) | ||
| return strconv.FormatInt(size, 10) + ":" + hex.EncodeToString(sum[:8]) |
There was a problem hiding this comment.
🟠 major · Possible Bug · fix: medium effort
A same-size workshop update that changes video data after the first 64 KiB leaves this identity unchanged, so the old preview is reused indefinitely. Hash the complete source or use another reliable content identity; add a test that changes bytes beyond the hashed prefix.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| // A source whose identity cannot be computed, and a clip with no identity | ||
| // record, are not a match: two empty strings are not evidence the clip is | ||
| // current. This is the tail of the size-before-mtime fix (mika 3f8f5d83). |
There was a problem hiding this comment.
🟡 minor · Maintainability · fix: low effort
The new test comments include reviewer attribution, which the repository forbids in comments. Remove the parenthesized attribution references from these tests.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
7abd85e to
3e22fc6
Compare
|
I've reviewed 5 pushes on this PR automatically, so I'll stop doing full passes here and only check whether open threads get fixed. Add the |
|
Fixed the findings: workshop source identity now hashes the full file, records are written atomically, and reviewer attributions were removed from test comments. New head |
|
@ryoku-mika review |
Sipper1236
left a comment
There was a problem hiding this comment.
Good change, but hashing only the first 64 KiB misses same-size edits later in a video, so the old preview can stick around. Please key it to the full source.
Note: Fixed: Workshop previews hash the full source and write identity records atomically
3e22fc6 to
b0a59f2
Compare
|
Addressed the full-source identity finding (Sipper1236, mika-finding:6206e0b5, Greptile P2). Finding: Fix: Tests: added Head is b0a59f2, PR head matches it. @ryoku-mika please re-review. |
|
@ryoku-mika review Fresh pass requested on head |
Move the startup temp sweep before any generator can create cache files, match only real temp suffixes so finished thumbnails survive, and memoize source identity for unchanged files while keeping full-content hashing. Fixes current-head review findings on Ryoku-dev#929.
|
Pushed
Targeted tests pass with @ryoku-mika review Initial draft by me; final wording written with Hermes Agent. |
| if ok && memo.identity != "" && memo.size == it.filesize && memo.mtime == it.mtime { | ||
| return memo.identity |
There was a problem hiding this comment.
Changed videos keep old previews. The new cache trusts size and
mtime, but weVideoSource rounds the timestamp to whole seconds. If different source bytes arrive with the same size and timestamp second, this returns the old identity without reading the file. ensureVideoPreview then keeps the old clip on every later scan, even after the write finishes.
Use a stronger check for whether the file changed, including finer timestamps and file replacement, or clear its saved identity when the source changes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/ryogami/daemon/scan.go
Line: 628-629
Comment:
**Changed videos keep old previews.** The new cache trusts size and `mtime`, but `weVideoSource` rounds the timestamp to whole seconds. If different source bytes arrive with the same size and timestamp second, this returns the old identity without reading the file. `ensureVideoPreview` then keeps the old clip on every later scan, even after the write finishes.
Use a stronger check for whether the file changed, including finer timestamps and file replacement, or clear its saved identity when the source changes.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Thanks for the work here, merged with a cheaper login check on my side so it doesn't hash every video, it goes out with the next update |
Fixes #920.
Two changes, two commits.
1. Preview reuse keys on recorded source size, not Steam-managed mtimes.
The report's mechanism, traced in the code:
ensureVideoPreviewdoes skip whenwe--<id>-prev.mp4is newer than the source, so a finished clip is reused. What defeats that check is its comparison basis: Steam revalidation moves workshop source mtimes at every login, so a warm library reads as entirely stale and the daemon re-encodes all of it at every start. The login double start then kills the batch mid-encode, feeding part 2.Workshop clips now record the source size they were rendered from beside the clip (
<prev>.size), and a clip whose size record still matches is reused without a render. Local videos keep the unchanged mtime rule. The Entry wire contract is untouched.TestWorkshopPreviewReuseIgnoresSteamMtimedrives the realffmpegpath: source mtime pushed an hour into the future, clip replaced by a sentinel, scan, sentinel intact; then the source swapped for a different size, and only that re-renders.2. Startup sweeps orphan transcode temps.
A killed transcode never cleans its
.tmp.*file, and the login restart makes kills routine (the report measured ~840 MB of dead partials over three days).sweepTmpFilesruns once at daemon start, before the first scan, over the four cache media dirs, the only moment no generator can hold a live temp.TestSweepTmpFilesRemovesOnlyTempscovers keep and remove.On the concurrency observation in the report: renders already run on the
performance.maxThumbJobspool (default 16, 1 to 32, Hub-configurable). With reuse working, a warm boot renders nothing at all, so the pool stops being the bottleneck.Two e2e tests fail in my sandbox on the clean base tree as well (daemon socket never appears), so they are environmental rather than from this change; every other test in the ryogami module passes, gofmt and vet clean.
(Prepared with an AI agent as the AGENTS.md workflow invites; the mechanism was traced in the real code and every behaviour here is test-driven through the real ffmpeg path.)
The PR still has the blocking night light boot issue from the earlier review; the new preview issue is non-blocking.
Fix with agent prompt
Summary
Workshop previews now reuse saved content identities, and startup removes abandoned temporary files before cache jobs begin.
Reviews (8) · Last reviewed commit: "[global] ryogami: fix preview cleanup an..." · Reviewed by Greptile