Repository navigation
Fix Home rows after watched and dismissal actions - #84
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughHome item dismissal and watched-state updates now use injected async actions, local section/cache mutations, error reporting, and stale-fetch invalidation. Home rows and media cards propagate the new callback contract, while tests cover successful and failed mutations. ChangesHome item actions
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant HomeView
participant HomeViewModel
participant ContinuumAPI
participant ResponseCache
HomeView->>HomeViewModel: Start dismissal or watched update
HomeViewModel->>ContinuumAPI: Execute injected action
ContinuumAPI-->>HomeViewModel: Return success or failure
HomeViewModel->>ResponseCache: Apply successful section mutation
HomeViewModel-->>HomeView: Return result and update error state
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e29a29d38b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
iosApp/iosApp/Components/EpisodeThumbCard.swift (1)
317-336: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winDouble-tap can clobber optimistic
playedOverridestate.
HomeViewModel.setWatcheddedups by contentId and returnsfalseimmediately for a second concurrent call on the same item — not because the mutation failed, but because it's a duplicate in-flight request. Since this button has no pending/disabled state, a rapid double-tap starts a secondTaskthat getssucceeded == falsefrom the dedup guard and resetsplayedOverride = nil, which can stomp the correct optimistic state set by the first (possibly still-succeeding) tap.Consider disabling the control (or short-circuiting locally) while a request for this item is already in flight.
🔧 Proposed guard against re-entrant taps
`@State` private var playedOverride: Bool? + `@State` private var isTogglingWatched = falseif let onSetWatched { Button { + guard !isTogglingWatched else { return } let played = !isPlayed Task { `@MainActor` in + isTogglingWatched = true playedOverride = played let succeeded = await onSetWatched(played) if !succeeded { playedOverride = nil } + isTogglingWatched = false } } label: {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/iosApp/Components/EpisodeThumbCard.swift` around lines 317 - 336, Prevent re-entrant watched-state requests in the contextActions control: track whether the item’s onSetWatched operation is in flight, disable the Button or return early while pending, and clear the pending state when the request completes. Ensure a duplicate tap cannot reset playedOverride based on the deduplication result from HomeViewModel.setWatched.
🧹 Nitpick comments (1)
iosApp/Tests/HomeSectionsMutationTests.swift (1)
142-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the
played == falsebranch.All watched-update assertions use
played: true, so regressions in the non-removal path and the propagated callback value would go undetected. Add a successful unplayed test asserting the item remains in the relevant sections/cache and the callback receivesfalse.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/Tests/HomeSectionsMutationTests.swift` around lines 142 - 180, Add a successful `setWatched` test alongside `testSuccessfulWatchedUpdateRemovesItemFromNextUpAndCache` using `played: false`; configure cached sections and a callback, then assert the item remains unchanged in the relevant view-model sections and `ResponseCache`, the callback receives the expected content ID and `false`, and the operation succeeds without an action error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@iosApp/iosApp/Components/MediaCard.swift`:
- Around line 97-106: In the onSetWatched closure, ensure the failure-path
assignment playedOverride = nil after await handler(played) executes on the main
actor, either by wrapping it in MainActor.run or isolating the closure
appropriately; preserve the existing success behavior and return value.
In `@iosApp/Tests/HomeSectionsMutationTests.swift`:
- Around line 96-97: Update all four cache-backed tests, including the test
using ResponseCache.shared.set for CacheKey.homeSections, to snapshot the
existing cache entry before mutation and restore that exact entry in defer
teardown instead of unconditionally removing it; preserve the prior value when
present and remove the key only when no prior entry existed.
---
Outside diff comments:
In `@iosApp/iosApp/Components/EpisodeThumbCard.swift`:
- Around line 317-336: Prevent re-entrant watched-state requests in the
contextActions control: track whether the item’s onSetWatched operation is in
flight, disable the Button or return early while pending, and clear the pending
state when the request completes. Ensure a duplicate tap cannot reset
playedOverride based on the deduplication result from HomeViewModel.setWatched.
---
Nitpick comments:
In `@iosApp/Tests/HomeSectionsMutationTests.swift`:
- Around line 142-180: Add a successful `setWatched` test alongside
`testSuccessfulWatchedUpdateRemovesItemFromNextUpAndCache` using `played:
false`; configure cached sections and a callback, then assert the item remains
unchanged in the relevant view-model sections and `ResponseCache`, the callback
receives the expected content ID and `false`, and the operation succeeds without
an action error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3fcc94ae-f493-424a-820f-0a1a77a2bb08
📒 Files selected for processing (10)
iosApp/Tests/HomeSectionsMutationTests.swiftiosApp/iosApp/Components/EpisodeThumbCard.swiftiosApp/iosApp/Components/MediaCard.swiftiosApp/iosApp/Components/MediaRow.swiftiosApp/iosApp/Screens/Home/HomeSectionsMutation.swiftiosApp/iosApp/Screens/Home/HomeView.swiftiosApp/iosApp/Screens/Home/HomeViewModel.swiftiosApp/iosApp/Screens/Home/SectionRow.swiftiosApp/iosApp/Startup/StartupContentPrefetcher.swiftiosApp/iosApp/tvOS/Components/TVSkylineSectionFeed.swift
| onSetWatched: onSetWatched.map { handler in | ||
| { played in | ||
| playedOverride = played | ||
| handler(played) | ||
| let succeeded = await handler(played) | ||
| if !succeeded { | ||
| playedOverride = nil | ||
| } | ||
| return succeeded | ||
| } | ||
| }, |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Swift non-isolated async closure resumes on main actor after await MainActor function
💡 Result:
In Swift, a non-isolated async closure does not automatically resume execution on the MainActor after an await MainActor function call [1][2]. When an asynchronous function or closure is non-isolated (which is the default for @Sendable closures), it runs on a generic, non-actor executor [1]. If it calls an await expression targeting a MainActor function, the task suspends, hops to the MainActor to execute that function, and then—upon completion of the await—the task resumes execution [1][2]. Crucially, the task resumes on the same executor it was using before the suspension point [1]. Because the closure itself is non-isolated, it will resume on a generic executor, not the MainActor [1]. This behavior is a fundamental aspect of Swift concurrency's executor model, where execution context is tied to the isolation of the function or closure rather than the preceding await call [1][2]. If you require code to continue running on the MainActor after an await call, the closure itself must be marked with @MainActor or wrapped in a MainActor.run { ... } block [3][4]. Note that recent updates, such as those discussed in SE-0461, have refined how non-isolated async functions inherit isolation from their caller in certain contexts, but the fundamental rule remains that a non-isolated closure does not inherently "stick" to an actor just because it awaited a call to one [5][6][1].
Citations:
- 1: https://github.com/swiftlang/swift-evolution/blob/c8dbf85741736e07a2b0ad2662de0a7066cec93c/proposals/0338-clarify-execution-non-actor-async.md
- 2: https://forums.swift.org/t/await-closure-and-isolation/71752
- 3: https://forums.swift.org/t/determining-whether-an-async-function-will-run-on-the-main-actor/60749
- 4: https://developer.apple.com/forums/thread/710646
- 5: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md
- 6: https://github.com/swiftlang/swift-evolution/blob/4c523525549c2077307b7e4b7f1680e0a5d1511c/proposals/0461-async-function-isolation.md
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show the relevant portion of the file with line numbers
sed -n '1,260p' iosApp/iosApp/Components/MediaCard.swift | cat -n
printf '\n==== onSetWatched occurrences ====\n'
rg -n "onSetWatched" iosApp/iosApp -S
printf '\n==== MediaCard definition outline (if supported) ====\n'
ast-grep outline iosApp/iosApp/Components/MediaCard.swift --view expanded || trueRepository: Silo-Server/silo-apple
Length of output: 14616
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the relevant section around the cited lines with line numbers
nl -ba iosApp/iosApp/Components/MediaCard.swift | sed -n '80,125p'
printf '\n==== onSetWatched references ====\n'
rg -n "onSetWatched" iosApp/iosApp -S
printf '\n==== MediaCard outline ====\n'
ast-grep outline iosApp/iosApp/Components/MediaCard.swift --view expanded || trueRepository: Silo-Server/silo-apple
Length of output: 200
🏁 Script executed:
#!/bin/bash
set -euo pipefail
nl -ba iosApp/iosApp/Components/MediaCard.swift | sed -n '80,125p'
printf '\n==== onSetWatched references ====\n'
rg -n "onSetWatched" iosApp/iosApp -S
printf '\n==== MediaCard outline ====\n'
ast-grep outline iosApp/iosApp/Components/MediaCard.swift --view expanded || trueRepository: Silo-Server/silo-apple
Length of output: 200
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
path = Path('iosApp/iosApp/Components/MediaCard.swift')
lines = path.read_text().splitlines()
def show(start, end):
for i in range(start, min(end, len(lines)) + 1):
print(f"{i:4d}: {lines[i-1]}")
print("==== MediaCard.swift lines 430-540 ====")
show(430, 540)
print("\n==== MediaCard.swift lines 540-620 ====")
show(540, 620)
PY
printf '\n==== FocusableMediaCard references ====\n'
rg -n "FocusableMediaCard|Task \\{ `@MainActor`|MainActor" iosApp/iosApp/Components/MediaCard.swift -SRepository: Silo-Server/silo-apple
Length of output: 5813
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
path = Path('iosApp/iosApp/Components/MediaCard.swift')
lines = path.read_text().splitlines()
for start, end in [(430, 540), (540, 620)]:
print(f"==== MediaCard.swift lines {start}-{end} ====")
for i in range(start, min(end, len(lines)) + 1):
print(f"{i:4d}: {lines[i-1]}")
print()
PY
printf '\n==== FocusableMediaCard references ====\n'
rg -n "FocusableMediaCard|Task \\{ `@MainActor`|MainActor" iosApp/iosApp/Components/MediaCard.swift -SRepository: Silo-Server/silo-apple
Length of output: 5814
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
lines = Path('iosApp/iosApp/Components/MediaCard.swift').read_text().splitlines()
for start, end in [(430, 540), (540, 620)]:
print(f"==== MediaCard.swift lines {start}-{end} ====")
for i in range(start, min(end, len(lines)) + 1):
print(f"{i:4d}: {lines[i-1]}")
print()
PY
printf '\n==== FocusableMediaCard references ====\n'
python3 - <<'PY'
from pathlib import Path
for i, line in enumerate(Path('iosApp/iosApp/Components/MediaCard.swift').read_text().splitlines(), 1):
if 'FocusableMediaCard' in line or 'Task { `@MainActor`' in line or 'MainActor' in line:
print(f"{i:4d}: {line}")
PYRepository: Silo-Server/silo-apple
Length of output: 5825
Keep the failure-path playedOverride revert on the main actor. The closure starts on the Task { @mainactor in ... } call site, but after await handler(played) it can resume off-main because handler is non-isolated. That makes the playedOverride = nil branch a background @State mutation; wrap that write in MainActor.run or isolate the closure.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@iosApp/iosApp/Components/MediaCard.swift` around lines 97 - 106, In the
onSetWatched closure, ensure the failure-path assignment playedOverride = nil
after await handler(played) executes on the main actor, either by wrapping it in
MainActor.run or isolating the closure appropriately; preserve the existing
success behavior and return value.
| ResponseCache.shared.set(SectionsResponse(sections: sections), for: CacheKey.homeSections) | ||
| defer { ResponseCache.shared.remove(CacheKey.homeSections) } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the test file and nearby symbols first.
ast-grep outline iosApp/Tests/HomeSectionsMutationTests.swift --view expanded || true
# Show the file with line numbers, but only the relevant range.
sed -n '1,260p' iosApp/Tests/HomeSectionsMutationTests.swift | nl -ba | sed -n '1,260p'
# Find ResponseCache and CacheKey.homeSections usages in tests.
rg -n "ResponseCache\.shared|CacheKey\.homeSections|played:\s*false|played:\s*true" iosApp/Tests iosApp -g '*.swift' || true
# Inspect test configuration for parallelization hints.
rg -n "parallel|concurrent|testing" . -g '*.swift' -g 'Package.swift' -g '*.xcscheme' -g '*.xcconfig' -g '*.plist' || trueRepository: Silo-Server/silo-apple
Length of output: 820
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== HomeSectionsMutationTests.swift =="
sed -n '1,260p' iosApp/Tests/HomeSectionsMutationTests.swift | cat -n
echo
echo "== ResponseCache and CacheKey definitions/usages =="
rg -n "struct ResponseCache|class ResponseCache|enum CacheKey|homeSections" iosApp -g '*.swift' || true
echo
echo "== Parallelization / test execution hints =="
rg -n "parallel|concurrent|disabl|enabled" . -g '*.swift' -g 'Package.swift' -g '*.xcscheme' -g '*.xcconfig' -g '*.plist' || trueRepository: Silo-Server/silo-apple
Length of output: 50378
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== HomeSectionsMutationTests.swift (relevant lines) =="
sed -n '1,260p' iosApp/Tests/HomeSectionsMutationTests.swift | cat -n | sed -n '1,260p'
echo
echo "== ResponseCache definition =="
rg -n "ResponseCache" iosApp -g '*.swift' || true
echo
echo "== CacheKey.homeSections usages =="
rg -n "CacheKey\.homeSections" iosApp -g '*.swift' || true
echo
echo "== Test scheme/config parallel hints =="
rg -n "parallel|concurrent|disableParallel|enabledParallel" . -g '*.xcscheme' -g '*.plist' -g '*.xcconfig' -g 'Package.swift' -g '*.swift' || trueRepository: Silo-Server/silo-apple
Length of output: 29566
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 260:
print(f"{i:4d}: {line}")
PY
echo
echo "== ResponseCache definition =="
rg -n "ResponseCache" iosApp -g '*.swift' || true
echo
echo "== CacheKey.homeSections usages =="
rg -n "CacheKey\.homeSections" iosApp -g '*.swift' || true
echo
echo "== Test scheme/config parallel hints =="
rg -n "parallel|concurrent|disableParallel|enabledParallel" . -g '*.xcscheme' -g '*.plist' -g '*.xcconfig' -g 'Package.swift' -g '*.swift' || trueRepository: Silo-Server/silo-apple
Length of output: 29274
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 80 <= i <= 200:
print(f"{i:4d}: {line}")
PY
echo
echo "== Definitions/usages of ResponseCache and related cache key =="
rg -n "ResponseCache|CacheKey\.homeSections" iosApp -g '*.swift' || true
echo
echo "== Any test parallelization settings or config references =="
fd -a -t f '.+' . | rg 'xcscheme|xcconfig|Package\.swift|plist$' || trueRepository: Silo-Server/silo-apple
Length of output: 20013
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 80 <= i <= 205:
print(f"{i:4d}: {line}")
PY
echo
echo "== ResponseCache / CacheKey locations =="
rg -n "ResponseCache|CacheKey\.homeSections" iosApp -g '*.swift' || true
echo
echo "== test scheme / parallel execution hints =="
rg -n "parallel|concurrent|disableParallel|enabledParallel" . -g '*.xcscheme' -g '*.xcconfig' -g 'Package.swift' -g '*.plist' || trueRepository: Silo-Server/silo-apple
Length of output: 19522
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
text = p.read_text().splitlines()
for start, end in [(1, 85), (86, 140), (141, 205), (206, 260)]:
print(f"\n--- lines {start}-{end} ---")
for i in range(start, min(end, len(text)) + 1):
print(f"{i:4d}: {text[i-1]}")
PYRepository: Silo-Server/silo-apple
Length of output: 11097
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 85 <= i <= 205:
print(f"{i:4d}: {line}")
PY
echo
echo "== Search for cache mutation patterns in tests =="
rg -n "set\\(SectionsResponse\\(|remove\\(CacheKey\\.homeSections\\)|get\\(CacheKey\\.homeSections\\)" iosApp/Tests -g '*.swift' || trueRepository: Silo-Server/silo-apple
Length of output: 7929
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/Tests/HomeSectionsMutationTests.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 85 <= i <= 205:
print(f"{i:4d}: {line}")
PY
echo
echo "== ResponseCache definition and methods =="
rg -n "final class ResponseCache|class ResponseCache|struct ResponseCache|func set\\(|func remove\\(|func get\\(" iosApp -g '*.swift' || trueRepository: Silo-Server/silo-apple
Length of output: 7379
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the cache implementation for locking / global-state behavior.
sed -n '1,220p' iosApp/iosApp/Networking/ResponseCache.swift | cat -n
echo
echo "== XCTest setup/teardown or cache resets in tests =="
rg -n "setUp\\(|tearDown\\(|clearAll\\(|removeAll\\(|ResponseCache\\.shared\\.clearAll|ResponseCache\\.shared\\.remove\\(" iosApp/Tests -g '*.swift' || true
echo
echo "== Scheme/test-plan files mentioning XCTest parallelization =="
fd -a -t f . iosApp | rg 'xcscheme$|xctestplan$|xcworkspace$|xcodeproj$|Package\.swift$'Repository: Silo-Server/silo-apple
Length of output: 8351
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/iosApp/Networking/ResponseCache.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 220:
print(f"{i:4d}: {line}")
PYRepository: Silo-Server/silo-apple
Length of output: 6632
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('iosApp/iosApp/Screens/Home/HomeViewModel.swift')
for i, line in enumerate(p.read_text().splitlines(), 1):
if 90 <= i <= 180:
print(f"{i:4d}: {line}")
PYRepository: Silo-Server/silo-apple
Length of output: 4148
Restore the previous homeSections cache entry in teardown. ResponseCache.shared is process-wide, so remove(CacheKey.homeSections) can wipe out an existing value for the rest of the test run. Snapshot and restore the old entry instead; apply the same cleanup to the other three cache-backed tests.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@iosApp/Tests/HomeSectionsMutationTests.swift` around lines 96 - 97, Update
all four cache-backed tests, including the test using ResponseCache.shared.set
for CacheKey.homeSections, to snapshot the existing cache entry before mutation
and restore that exact entry in defer teardown instead of unconditionally
removing it; preserve the prior value when present and remove the key only when
no prior entry existed.
Summary
HomeViewModelTesting
xcodebuild test -project Silo.xcodeproj -scheme Silo -destination 'platform=iOS Simulator,id=5AEC2DBA-2CA4-4AA0-8EC8-333376BA51BC' -only-testing:SiloTests/HomeSectionsMutationTests CODE_SIGNING_ALLOWED=NO(9 tests passed)xcodebuild build -project Silo.xcodeproj -scheme Silo -destination 'platform=iOS Simulator,id=5AEC2DBA-2CA4-4AA0-8EC8-333376BA51BC' CODE_SIGNING_ALLOWED=NOxcodebuild build -project Silo.xcodeproj -scheme SiloTV -destination 'platform=tvOS Simulator,id=462E76D9-A6F7-4CBA-B8A8-1274FB2CB00B' CODE_SIGNING_ALLOWED=NOSilo Validation iPhoneSummary by CodeRabbit