Skip to content

fix(tv-cdp): reserve TVs until retiring leases drain - #5221

Merged
thymikee merged 5 commits into
mainfrom
fix/tv-cdp-lease-handoff
Nov 30, 2026
Merged

thymikee merged 5 commits into
mainfrom
fix/tv-cdp-lease-handoff

Conversation

@thymikee

@thymikee thymikee commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Keep a TV reserved until the retiring lease’s admitted operations drain and its vendor tunnel removal is confirmed. Release revokes the lease immediately and disconnects CDP. Each removal keeps its own cleanup record. Concurrent releases share the current cleanup attempt. Each open, close, or release teardown wait retries previously failed removals once and joins pending attempts. Release also invalidates in-flight allocation for the same lease. The TV CDP runtime and the Tizen and webOS transports preserve errors from both app operations and cleanup.

Before / after

  • allocate(leaseB) could succeed while lease A was listing apps or after tunnel removal failed. It now returns DEVICE_IN_USE until operations drain and removal succeeds.
  • A retained binding rejects new operations as soon as its lease retires, including after a replacement takes the TV.

Validation

Head 139c47c89714abb2f859214745fe9956c7a2270b. All 21 CI checks passed on this head. Runtime tests cover open and close recovery after a cancelled open, retention after another failure, and concurrent releases sharing a retry before handoff. CI can validate these regressions and Tizen forward-removal behavior with fakes. SDB 4.2.36 static inspection found a successful forward --list can omit rows when its 1 KiB server buffer fills. Failed removal still retains the reservation when absence cannot be confirmed. Live TV evidence is outstanding. The available workflows showed no Tizen or webOS hardware or Tizen emulator lane for the requested handoff and vendor cleanup trace.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.70 MB 6.70 MB 0 B
Package (unpacked) 6.70 MB 6.70 MB 0 B
Package (download) 2.04 MB 2.04 MB -6 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 19.3 ms 18.9 ms -0.4 ms
CLI --help 40.7 ms 42.9 ms +2.3 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/tizen 97.5 kB → 99.4 kB (+1.9 kB) 97.1 kB → 99.1 kB (+1.9 kB) 34.4 kB → 34.9 kB (+456 B)
@agent-device/webos 96.4 kB → 98.4 kB (+2.0 kB) 96.1 kB → 98.1 kB (+2.0 kB) 34.0 kB → 34.6 kB (+512 B)

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/tv-cdp/src/runtime.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 2 new findings on 68fb937. The verdict and the full list are in the summary comment.

Comment thread packages/tv-cdp/src/page-interactor.ts Resolved
Comment thread packages/tv-cdp/src/runtime.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 0decbee. The verdict and the full list are in the summary comment.

Comment thread packages/tv-cdp/src/runtime.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At 0decbee, the TV stays reserved while teardown drains, but two things must be fixed before merge: a failed tunnel removal is never retried by open or close, and there is no live TV evidence.

If one tunnel removal fails, for example a transient sdb forward --remove error after a cancelled open, the error stays in session.removals. open() throws it and close() only waits on it, so neither starts the removal again. The current test asserts this. This is a regression: from reading the earlier code, the failure was reported once and the next open made a fresh forward or inspector. Now one error can block every app open for the rest of the lease. The error gives no recovery hint, and even the first release does not retry. A failed removal should stay recorded until a retry succeeds, and every teardown wait (open, close and release) should retry it. Please do this once in the teardown helper, using the existing retry loop, and drop the retry flag derived from retirementAbort. Please update the test to show that a later open or close retries and succeeds once removal works again.

This changes TV app open and close, lease release, Tizen forward removal and webOS inspector shutdown, so live evidence is required before merge. The current coverage uses fakes, and no test covers the webOS close path. Please run the built bin/agent-device.mjs at this commit on a real Tizen or webOS TV, or the Tizen emulator. Connect session A, start open <app>, and disconnect A while the open is still in flight. Session B connecting to the same TV during A's release must get DEVICE_IN_USE, and B must connect after that release returns. Please record the commands, device, SHA and outputs. For Tizen, show that sdb forward --list has no leftover forward. For webOS, show that no ares-inspect process remains and that close ends when the child exits, without waiting for SIGKILL.

Not blocking, take or leave: the first release would also retry earlier failures under the rule above (runtime.ts); admitted TV operations could also receive AbortSignal.any([requestSignal, session.retirementAbort.signal]) so release does not wait for their deadlines, while removal keeps its own deadline; the failed-removal retry handle could travel as a typed field on the withTunnelRemoval error and be registered in open's catch, instead of through a second callback path (or ares.inspect could take an options object); the pending allocation fix addresses a separate earlier race, so it could be named in the PR body or split out; the rewritten ares-inspect close could get a test with a fake process that fails to stop, asserting that the stop ares-inspect error is retained and a retry succeeds; and the PR body's Validation section still says CI is pending and cites checks from the previous head.

These earlier threads no longer apply and can be resolved: this one, because the maps are now deleted only after teardown succeeds; this one, because each removal now deletes only its own entry; this one, because release now invalidates a pending allocation and a test covers it; and this one, because the lease stays until teardown succeeds, so a second release retries and a same-ID allocation gets DEVICE_IN_USE.

The only check not passing is Body rules, which was cancelled. It checks PR metadata and body text, and this diff does not change that path, so it is likely unrelated. The other 21 checks pass.

Not verified here: tests were not run locally. The earlier behavior after a failed removal was determined from the code, not from a test run. No production route was found where provider release runs inside an admitted TV operation and could deadlock, but daemon routes were not traced for this. The daemon's deadline on provider release was not checked.

Before merge, please make every teardown wait retry failed removals, attach the live TV evidence, and re-run Body rules after updating the Validation section.

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pushed 139c47c8 in response to the teardown feedback. Open, close, and release now share one retry path. Each wait retries previously failed removals once, joins work already in progress, and retains any remaining failure for the next wait. Regression cases cover recovery through open and close and concurrent releases sharing the retry.

CI is running on this head. The live handoff and vendor cleanup trace is still outstanding. We found no Tizen, webOS, or Tizen emulator lane in the configured workflows. Providing that trace under the CI-only validation constraint requires a CI runner with a supported TV target.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 139c47c

Since the review of 0decbee: 1 new · 0 still open · 1 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/tv-cdp/src/page-interactor.ts:172 🆕 One permanently failing tunnel removal wedges the TV forever; the old code reported it once

3 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (8b60400e9e2f).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 139c47c. The verdict and the full list are in the summary comment.

Comment thread packages/tv-cdp/src/page-interactor.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At 139c47c, the retry on every teardown wait from the earlier review is fixed. One item remains before merge: live evidence for the device-facing change.

runtime.ts: this PR changes TV app open and close, lease release, Tizen forward removal and webOS ares-inspect shutdown. The tests use fake removals and tunnels, and no live run is attached at any head. So the handoff and the vendor cleanup have not been observed on a real target. Please run the built bin/agent-device.mjs at the final head on a real Tizen or webOS TV, or on the Tizen emulator. Connect session A, start open <app>, and disconnect A while the open is in flight. Session B must get DEVICE_IN_USE when it connects to the same TV during A's release, and must connect after the release returns. For Tizen, show that sdb forward --list has no leftover forward. For webOS, show that no ares-inspect process remains and that close ends when the child exits, without SIGKILL. Record the commands, device, SHA and outputs. If no hardware is available, a maintainer must waive this explicitly.

Two open threads do not apply and can be resolved. This one is accurate but benign, because keeping the reservation until removal is confirmed is the intended rule. This one is fixed, because a second release retries the failed removals and the lease is deleted only after success.

CI shows no failing check at this commit.

Not verified here: tests were not run locally, though CI ran them at this commit. The static analysis of the SDB 4.2.36 binary (forward --list truncation at 1 KiB) was not reproduced. No real TV or emulator was available, so vendor cleanup behavior is known only from reading the code.

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both linked inline threads are resolved. The retry fix is in 139c47c, and all 21 CI checks passed on that head. The configured CI has no supported TV target, so the requested live handoff and vendor cleanup trace is still outstanding. Can a maintainer provide a CI-accessible Tizen or webOS target (including a Tizen emulator), or explicitly waive the live run for this head?

@thymikee

Copy link
Copy Markdown
Member Author

The maintainers waive the live TV evidence for 139c47c: no Tizen or webOS hardware is available, and the code review found no remaining defect after the teardown-retry fix. If real hardware shows a problem with the lease handoff or the vendor tunnel cleanup, a follow-up fix with a live transcript is welcome.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 30, 2026
@thymikee
thymikee merged commit 153479e into main Nov 30, 2026
23 of 24 checks passed
@thymikee
thymikee deleted the fix/tv-cdp-lease-handoff branch November 30, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant