Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Retiring a Computer Use turn when the request that opened it finishes.
|
|
|
|
The host mints a fresh turn id for every request, in a request-setup hook. This
|
|
is the other half of that: a hook in the FINALLY phase, which the runtime runs
|
|
inside a `finally` block, so the turn is released whether the request
|
|
succeeded,
|
|
failed or was cancelled.
|
|
|
|
Without it nothing ever told the plugin a turn was over. A session that used
|
|
the
|
|
tool once went on claiming its turn -- holding the connection, and holding the
|
|
helper's screenshots and accessibility handles for that turn -- until some
|
|
later
|
|
request happened to arrive with a different id.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from qwenpaw.hooks.base import LifecycleHook
|
|
from qwenpaw.runtime.hooks import HookContext, HookResult
|
|
from qwenpaw.runtime.phases import Phase
|
|
|
|
from .client import end_computer_use_turn
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ComputerUseTurnEndHook(LifecycleHook):
|
|
"""Release the native turn a finished request was holding."""
|
|
|
|
phase = Phase.FINALLY
|
|
name = "computer_use_turn_end"
|
|
priority = 50
|
|
|
|
async def run(self, ctx: HookContext) -> HookResult:
|
|
session_id = getattr(ctx, "session_id", "") or ""
|
|
if not session_id:
|
|
return HookResult()
|
|
try:
|
|
await end_computer_use_turn(session_id)
|
|
except Exception: # noqa: BLE001 - cleanup must not fail a request
|
|
logger.debug(
|
|
"computer_use_turn_end: release failed session=%s",
|
|
session_id,
|
|
exc_info=True,
|
|
)
|
|
return HookResult()
|
|
|
|
|
|
__all__ = ["ComputerUseTurnEndHook"]
|