JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(skill): 修复新一轮 skill_tool 激活解除任务取消遗留的 main 熔断
CodehubTTG6c7240b01b4f
diff --git a/jiuwenswarm/agents/harness/common/rails/permissions/skill_authorization/file_store.py b/jiuwenswarm/agents/harness/common/rails/permissions/skill_authorization/file_store.pyindex 8167357365..4b02230d2f 100644--- a/jiuwenswarm/agents/harness/common/rails/permissions/skill_authorization/file_store.py+++ b/jiuwenswarm/agents/harness/common/rails/permissions/skill_authorization/file_store.py@@ -133,6 +133,20 @@ class _TransactionStore(SkillGrantStore):),}+ def revive_scope(self, session_id: str, agent_scope_id: str) -> None:+ """Drop the invalidation breaker for a scope; grants stay untouched.++ Task-termination paths (interrupt cancel/abort) invalidate the main+ scope so late callbacks cannot reopen the credential window. A+ fresh explicit skill_tool call is a new user intent and drops that+ stale breaker - aligned with ``activate_pending``'s discard when+ the dynamic-authorization feature is on. This never resurrects+ revoked grants or execution windows.+ """+ key = (str(session_id or "").strip(), str(agent_scope_id or "").strip())+ with self._lock:+ self._invalidated_scopes.discard(key)+def _open_at(directory: int | Path, name: str, flags: int, mode: int = 0o600) -> int:if isinstance(directory, int):@@ -525,19 +539,89 @@ class FileSkillGrantStore(SkillGrantStore):)return None+ def is_scope_invalidated(self, session_id: str, agent_scope_id: str) -> bool:+ """Read-only breaker probe for the fresh-activation pre-check.++ Never writes and never raises on missing sessions: an unreadable+ state simply reports no breaker, so the caller skips the revive+ marker and the ordinary pop guard stays in charge (fail-safe).+ """+ sid = str(session_id or "").strip()+ if not sid:+ return False+ try:+ if not self.session_directory(sid).is_dir():+ return False+ return bool(+ self.operate(+ sid,+ lambda store, doc: (+ str(agent_scope_id or "").strip()+ in doc.get("invalidated", [])+ ),+ write=False,+ )+ )+ except (+ OSError,+ ValueError,+ TypeError,+ RuntimeError,+ portalocker.exceptions.LockException,+ ):+ return False+def update_active_skill_state(- self, session_id: str, update: Callable[[dict], dict | None]+ self,+ session_id: str,+ update: Callable[[dict], dict | None],+ *,+ revive_main: bool = False,) -> dict | None:+ """Persist the active-skill record, optionally dropping the breaker.++ With ``revive_main=True`` a non-empty activation drops the stale+ main-scope invalidation breaker INSIDE this transaction, so the+ breaker is never absent while the activation is missing (atomic):+ a late callback from a cancelled round cannot slip between the+ drop and the persist. A completion-style update+ (``active_skill=None``) never revives.+ """+def action(store, doc):updated = update(dict(doc.get("active_skill") or {}))if updated is None:doc.pop("active_skill", None)else:doc["active_skill"] = updated+ if revive_main and updated.get("active_skill"):+ store.revive_scope(session_id, "main")return updatedreturn self.operate(session_id, action)+ def revive_scope(self, session_id: str, agent_scope_id: str) -> None:+ """Drop a task-cycle invalidation breaker on a fresh skill_tool call.++ A task cancel (interrupt/abort) writes ``main`` into the session+ file's invalidated list so late callbacks cannot restore the+ credential window; without a revival a fresh explicit skill_tool+ activation in the SAME session would also be dropped by+ ``operate`` forever. Missing sessions are skipped silently, like+ ``update_active_skill_state`` callers do.+ """+ sid = str(session_id or "").strip()+ if not sid:+ return+ try:+ if not self.session_directory(sid).is_dir():+ return+ except (OSError, ValueError):+ return+ self.operate(+ sid, lambda store, doc: store.revive_scope(sid, agent_scope_id)+ )+def configure_shared_skill_authorization(_config: dict) -> FileSkillGrantStore:"""Install session-file state before accepting requests; never fall back to memory."""diff --git a/jiuwenswarm/agents/harness/common/rails/skill_active_state.py b/jiuwenswarm/agents/harness/common/rails/skill_active_state.pyindex c03f75eda2..84675e2f5b 100644--- a/jiuwenswarm/agents/harness/common/rails/skill_active_state.py+++ b/jiuwenswarm/agents/harness/common/rails/skill_active_state.py@@ -31,6 +31,7 @@ _SESSION_ID_EXTRA_KEY = "__jiuwenswarm_session_id__"# 由 interface._build_inputs 写入 run_context.extra,before_invoke 读取,# 用于 CR-3a:HITL 恢复轮不计入过期计数。_CHAT_SEND_SOURCE_EXTRA_KEY = "__jiuwenswarm_chat_send_source__"+_SKILL_REVIVE_PENDING_KEY = "__jiuwenswarm_skill_revive_pending__"_current_session_var: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar("skill_active_session_id",@@ -70,7 +71,10 @@ def _shared_store(session_id: str):def _update_state(- session_id: str, update: Callable[[_SkillSessionState], None]+ session_id: str,+ update: Callable[[_SkillSessionState], None],+ *,+ revive_main: bool = False,) -> None:store = _shared_store(session_id)if store is None:@@ -90,7 +94,7 @@ def _update_state(if not store.session_directory(session_id).is_dir():logger.debug("[SkillActiveStateRail] session unavailable: %s", session_id)return- store.update_active_skill_state(session_id, mutate)+ store.update_active_skill_state(session_id, mutate, revive_main=revive_main)except (OSError, ValueError, TypeError, RuntimeError,portalocker.exceptions.LockException,@@ -421,6 +425,55 @@ class SkillActiveStateRail(DeepAgentRail):return session_idreturn self._owner_hint_for_default(ctx) or session_id+ async def before_tool_call(self, ctx: AgentCallbackContext) -> None:+ """Mark a fresh skill_tool call for deferred atomic revival (SF-1/SF-2).++ Task-termination paths (interrupt cancel/abort) invalidate the main+ scope so late callbacks from the cancelled round cannot reopen the+ credential window. A brand-new explicit skill_tool call is fresh+ user intent and may drop that stale breaker - but the drop is+ DEFERRED into the same transaction that persists this call's+ activation (after_tool_call), never performed here: reviving up+ front would let a late callback from the cancelled round slip past+ the pop guard, and listing-only / rejected calls would drop the+ breaker without any activation. Here we only probe (read-only) and+ stamp the marker with the current tool_call_id so after_tool_call+ can match it against the very same call.+ """+ inputs = getattr(ctx, "inputs", None)+ if inputs is None:+ return+ tool_name = getattr(inputs, "tool_name", "") or ""+ if tool_name != "skill_tool":+ return+ session_id = self._prefer_real_session_id(ctx, self._resolve_session_id(ctx))+ if not session_id or session_id == _DEFAULT_SESSION_ID:+ return+ self._bind_session_id(ctx, session_id)+ tool_call = getattr(inputs, "tool_call", None)+ tool_call_id = str(getattr(tool_call, "id", "") or "")+ if not tool_call_id:+ return+ store = _shared_store(session_id)+ if store is None:+ return+ try:+ invalidated = store.is_scope_invalidated(session_id, "main")+ except (+ OSError, ValueError, TypeError, RuntimeError,+ portalocker.exceptions.LockException,+ ) as exc:+ logger.warning(+ "[SkillActiveStateRail] breaker probe failed session=%s: %s",+ session_id,+ exc,+ )+ return+ if invalidated:+ extra = getattr(ctx, "extra", None)+ if isinstance(extra, dict):+ extra[_SKILL_REVIVE_PENDING_KEY] = tool_call_id+async def after_tool_call(self, ctx: AgentCallbackContext) -> None:inputs = getattr(ctx, "inputs", None)if inputs is None:@@ -435,28 +488,59 @@ class SkillActiveStateRail(DeepAgentRail):if tool_name not in {"skill_tool", "skill_complete"}:return+ skill_name = ""+ if tool_name == "skill_tool":+ meta = getattr(tool_msg, "metadata", None) or {}+ if meta.get("is_directory_listing"):+ return+ skill_name = (+ meta.get("skill_name") or _get_arg(tool_call, "skill_name", "") or ""+ ).strip()+ if not skill_name:+ return++ # 复活标记匹配:仅当本次调用是真正的 skill_tool 激活,且它的+ # before_tool_call 探测到 main 熔断并打上了同一 tool_call_id 的+ # 标记(框架保证同一工具调用的 before/after 共享 ctx)。匹配则+ # 把解熔断与激活持久化合并进同一事务(SF-1:迟到回调无标记,+ # 仍被 operate 的 pop 拦截)。值绑定 tool_call_id 防止 Agent 循环+ # 复用 ctx.extra 时残留标记误伤后续调用。+ #+ # 已知残留:若本调用成功完成后、after 派发前的微窗口内发生第二次 cancel(revoke 重写熔断),标记匹配仍会持久化本技能。+ revive_main = False+ if tool_name == "skill_tool":+ extra = getattr(ctx, "extra", None)+ if isinstance(extra, dict):+ tool_call_id = str(getattr(tool_call, "id", "") or "")+ if (+ tool_call_id+ and extra.get(_SKILL_REVIVE_PENDING_KEY) == tool_call_id+ ):+ revive_main = True+ extra.pop(_SKILL_REVIVE_PENDING_KEY, None)+def apply(state: _SkillSessionState) -> None:if tool_name == "skill_complete":- skill_name = (_get_arg(tool_call, "skill_name", "") or "").strip()- if skill_name and state.active_skill == skill_name:+ complete_name = (_get_arg(tool_call, "skill_name", "") or "").strip()+ if complete_name and state.active_skill == complete_name:logger.info("[SkillActiveStateRail] skill_complete(%s) session=%s -> idle",- skill_name,+ complete_name,session_id,)state.reset()elif (- skill_name+ complete_nameand state.active_skill- and state.active_skill != skill_name+ and state.active_skill != complete_name):# 激活名 ≠ 完成名:不清空(保持当前激活态),但留痕,# 防"状态挂死且无从排查"。logger.warning("[SkillActiveStateRail] skill_complete(%s) ignored: active is ""'%s' session=%s (complete only clears on name match)",- skill_name,+ complete_name,state.active_skill,session_id,)@@ -465,14 +549,6 @@ class SkillActiveStateRail(DeepAgentRail):if tool_name != "skill_tool":return- meta = getattr(tool_msg, "metadata", None) or {}- if meta.get("is_directory_listing"):- return- skill_name = (- meta.get("skill_name") or _get_arg(tool_call, "skill_name", "") or ""- ).strip()- if not skill_name:- returnprior_skill = state.active_skillif prior_skill and prior_skill != skill_name:# 切换到另一个 skill:旧 active_skill 在此清空(被新技能替换)。@@ -497,7 +573,7 @@ class SkillActiveStateRail(DeepAgentRail):state.source_session or "-",)- _update_state(session_id, apply)+ _update_state(session_id, apply, revive_main=revive_main)__all__ = [diff --git a/tests/unit_tests/agentserver/test_file_skill_grant_store.py b/tests/unit_tests/agentserver/test_file_skill_grant_store.pyindex 158bdb6e7d..89db6f12b1 100644--- a/tests/unit_tests/agentserver/test_file_skill_grant_store.py+++ b/tests/unit_tests/agentserver/test_file_skill_grant_store.py@@ -345,16 +345,18 @@ def test_corruption_never_serves_old_authorization(if corruption == "invalid-json":path.write_text("{")elif corruption == "bad-grant":- doc = json.loads(path.read_text())+ # state.json is UTF-8 (ensure_ascii=False); pin the encoding so+ # GBK-locale hosts run the assertion instead of UnicodeDecodeError.+ doc = json.loads(path.read_text(encoding="utf-8"))doc["grants"]["main"] = [{"unexpected": True}]path.write_text(json.dumps(doc))elif corruption == "bad-map":- doc = json.loads(path.read_text())+ doc = json.loads(path.read_text(encoding="utf-8"))doc["grants"] = []path.write_text(json.dumps(doc))else:replacement = tmp_path / "forged"- replacement.write_text(path.read_text())+ replacement.write_text(path.read_text(encoding="utf-8"), encoding="utf-8")path.unlink()path.symlink_to(replacement)assert b.get_active("session", "main") is None@@ -737,3 +739,118 @@ async def test_child_skill_approval_rechecks_persisted_session_version(assert (grant is not None) == (change == "allow")finally:file_store._session_file_context.reset(token)+++def test_fresh_activation_revives_task_cancelled_main_scope(stores):+ """One task cancel must not permanently kill skill_tool activation.++ Regression: interrupt(cancel) -> revoke_grants(sid, "main") writes+ ``main`` into the session file's invalidated list; ``operate`` then+ silently dropped every later ``update_active_skill_state`` activation+ in the SAME session (the "activated" log still printed), so+ SKILL_GATE kept blocking bash with active=None forever. This mirrors+ the production incident: the dynamic-authorization feature flag is+ off (no grants at all), so there is no approval path to drop the+ breaker. A fresh explicit skill_tool call must re-open the credential+ window, while a late callback without a fresh skill_tool call stays+ dropped.+ """+ a, b = stores+ # No grants exist (feature flag off, production incident shape).+ # Task cancel path invalidates the main scope (late-callback guard).+ b.revoke_grants("session", "main")+ # Late callback from the cancelled round cannot restore it (unchanged).+ a.update_active_skill_state(+ "session", lambda _: {"active_skill": "huawei-cloud-skill-submit"}+ )+ assert b.get_active_skill_state("session") is None+ # A fresh skill_tool call revives the scope before its after-callback.+ a.revive_scope("session", "main")+ # The fresh activation now persists for every reader.+ a.update_active_skill_state(+ "session", lambda _: {"active_skill": "huawei-cloud-skill-submit"}+ )+ assert b.get_active_skill_state("session") == {+ "active_skill": "huawei-cloud-skill-submit"+ }+++def test_revive_scope_never_resurrects_revoked_grants(stores, manifest):+ """revive_scope only drops the breaker; revoked grants stay revoked."""+ a, b = stores+ a.create_pending_grant(+ "session",+ "main",+ manifest,+ decision=GrantDecision.LOCAL,+ approval_tool_call_id="load-1",+ )+ assert a.activate_pending(+ "session",+ "main",+ manifest.skill_name,+ manifest,+ approval_tool_call_id="load-1",+ )+ # Task cancel revokes the grant and invalidates the scope.+ b.revoke_grants("session", "main")+ assert a.get_grant("session", "main", manifest.skill_name) is None+ assert a.get_active("session", "main") is None+ # Revival drops only the invalidation breaker.+ a.revive_scope("session", "main")+ assert a.get_grant("session", "main", manifest.skill_name) is None+ assert a.get_active("session", "main") is None+ # Yet a fresh activation persists again for every reader.+ a.update_active_skill_state(+ "session", lambda _: {"active_skill": manifest.skill_name}+ )+ assert b.get_active_skill_state("session") == {+ "active_skill": manifest.skill_name+ }+++def test_revive_scope_skips_missing_session_silently(stores):+ """A missing session directory is skipped silently, never created."""+ a, _ = stores+ a.revive_scope("officeclaw_ghost_session", "main")+ assert not (a.sessions_root() / "officeclaw_ghost_session").exists()+++def test_is_scope_invalidated_readonly_probe(stores):+ """The read-only probe reports breaker state without side effects."""+ a, b = stores+ assert a.is_scope_invalidated("session", "main") is False+ b.revoke_grants("session", "main")+ assert a.is_scope_invalidated("session", "main") is True+ assert a.is_scope_invalidated("officeclaw_ghost_session", "main") is False+++def test_atomic_revive_main_drops_breaker_and_persists_activation(stores):+ """update_active_skill_state(revive_main=True) is one transaction.++ The breaker drop and the activation persist atomically: a reader+ between two store instances never sees the breaker gone without the+ activation (or vice versa), and a non-activation (None skill) update+ never drops the breaker.+ """+ a, b = stores+ b.revoke_grants("session", "main")+ assert b.is_scope_invalidated("session", "main") is True+ # A completion-style update (active_skill=None) must NOT revive.+ a.update_active_skill_state(+ "session",+ lambda _: {"active_skill": None},+ revive_main=True,+ )+ assert b.is_scope_invalidated("session", "main") is True+ assert b.get_active_skill_state("session") is None+ # A real activation drops the breaker and persists in one transaction.+ a.update_active_skill_state(+ "session",+ lambda _: {"active_skill": "huawei-cloud-skill-submit"},+ revive_main=True,+ )+ assert b.is_scope_invalidated("session", "main") is False+ assert b.get_active_skill_state("session") == {+ "active_skill": "huawei-cloud-skill-submit"+ }diff --git a/tests/unit_tests/agentserver/test_skill_active_state.py b/tests/unit_tests/agentserver/test_skill_active_state.pyindex 5c30458719..23a58574f3 100644--- a/tests/unit_tests/agentserver/test_skill_active_state.py+++ b/tests/unit_tests/agentserver/test_skill_active_state.py@@ -43,7 +43,14 @@ def session_files(tmp_path, monkeypatch):context_token = file_store._session_file_context.set(None)sessions = tmp_path / "sessions"# Existing lifecycle cases use these session identifiers as real sessions.- for sid in set(re.findall(r'officeclaw_[A-Za-z0-9_]+', Path(__file__).read_text())):+ # The test module is UTF-8 (Chinese comments); read_text must pin the+ # encoding or every test errors out on GBK-locale Windows hosts.+ for sid in set(+ re.findall(+ r'officeclaw_[A-Za-z0-9_]+',+ Path(__file__).read_text(encoding="utf-8"),+ )+ ):(sessions / sid).mkdir(parents=True, exist_ok=True)monkeypatch.setattr(file_store, "get_agent_sessions_dir", lambda: sessions)monkeypatch.setattr(file_store, "get_user_workspace_dir", lambda: tmp_path)@@ -677,5 +684,163 @@ class TestAdoptDefaultActiveSkill(unittest.TestCase):assert "env" not in bash_ctx.inputs.tool_args+class TestCancelledScopeRevival(unittest.TestCase):+ """A fresh explicit skill_tool call reopens a task-cancelled window.++ Regression (SKILL_GATE false blocking): interrupt(cancel) ->+ revoke_grants(sid, "main") writes ``main`` into the session file's+ invalidated list; FileSkillGrantStore.operate then silently dropped+ every later update_active_skill_state activation in the SAME session+ (the "activated" log still printed), so the bash gate kept reading+ active=None forever - skill_tool then bash failed no matter the+ ordering (same batch, serial, strict serial barrier). Fix: the+ skill_tool before_tool_call drops the stale main breaker first+ (aligned with activate_pending's discard when the feature is on);+ the late-callback guard stays unchanged.+ """++ sid = "officeclaw_revive_sess"++ def tearDown(self):+ clear_session_skill_state(self.sid)++ def _skill_tool_ctx(self, skill_name="hwocr", listing=False):+ ctx = AgentCallbackContext(agent=MagicMock())+ tool_call = MagicMock()+ tool_call.arguments = {"skill_name": skill_name}+ tool_msg = MagicMock()+ if listing:+ tool_msg.metadata = {"is_directory_listing": True}+ else:+ tool_msg.metadata = {"skill_name": skill_name}+ ctx.inputs = ToolCallInputs(+ tool_call=tool_call,+ tool_name="skill_tool",+ tool_args={"skill_name": skill_name},+ tool_result=None,+ tool_msg=tool_msg,+ )+ ctx.extra = {}+ return ctx++ def _bash_ctx(self):+ ctx = AgentCallbackContext(agent=MagicMock())+ ctx.inputs = ToolCallInputs(+ tool_call=MagicMock(),+ tool_name="bash",+ tool_args={"command": "hwocr.exe general-text"},+ tool_result=None,+ tool_msg=None,+ )+ ctx.extra = {}+ return ctx++ def _store(self):+ from jiuwenswarm.agents.harness.common.rails import skill_active_state++ return skill_active_state._shared_store(self.sid)++ def test_late_callback_after_cancel_stays_dropped(self):+ # Control: no fresh skill_tool call after the cancel - a late+ # callback stays dropped (existing safety semantics, see+ # test_revocation_is_seen_by_original_process).+ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ asyncio.run(rail.after_tool_call(self._skill_tool_ctx()))+ assert get_session_active_skill(self.sid) is None++ def test_fresh_skill_tool_after_cancel_activates_and_gates_pass(self):+ # Fix target: a fresh explicit skill_tool call (before + after on+ # the SAME ctx, as the framework dispatches it) persists the+ # activation atomically with the breaker drop, and the bash gate+ # can read it and inject credentials.+ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ fresh_ctx = self._skill_tool_ctx()+ asyncio.run(rail.before_tool_call(fresh_ctx))+ asyncio.run(rail.after_tool_call(fresh_ctx))+ assert get_session_active_skill(self.sid) == "hwocr"+ inject = SkillCredentialInjectionRail(+ skill_envs={"hwocr": {"HWOCR_AK": "ak", "HWOCR_SK": "sk"}},+ preset_session_id=self.sid,+ )+ bash_ctx = self._bash_ctx()+ asyncio.run(inject.before_tool_call(bash_ctx))+ assert bash_ctx.inputs.tool_args["env"]["HWOCR_AK"] == "ak"++ def test_late_callback_between_fresh_before_and_after_stays_dropped(self):+ # SF-1 regression: a late after-callback from the cancelled round+ # lands after the fresh call's before but before its after. The+ # breaker drop is deferred into the fresh activation transaction,+ # so the stale write must still be dropped; the fresh call then+ # activates normally.+ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ fresh_ctx = self._skill_tool_ctx(skill_name="hwocr")+ asyncio.run(rail.before_tool_call(fresh_ctx))+ # Late after-callback from the cancelled round (stale skill, no+ # revive marker: its own before ran before the cancel).+ asyncio.run(+ rail.after_tool_call(self._skill_tool_ctx(skill_name="stale-skill"))+ )+ assert get_session_active_skill(self.sid) is None+ # The fresh call's after now persists atomically.+ asyncio.run(rail.after_tool_call(fresh_ctx))+ assert get_session_active_skill(self.sid) == "hwocr"++ def test_listing_only_call_does_not_revive(self):+ # SF-2 regression: a directory-listing skill_tool call activates+ # nothing, so it must not drop the breaker either (symmetry with+ # after_tool_call's listing skip).+ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ listing_ctx = self._skill_tool_ctx(listing=True)+ asyncio.run(rail.before_tool_call(listing_ctx))+ asyncio.run(rail.after_tool_call(listing_ctx))+ assert get_session_active_skill(self.sid) is None+ # Breaker still up: a late callback is still dropped...+ asyncio.run(rail.after_tool_call(self._skill_tool_ctx()))+ assert get_session_active_skill(self.sid) is None+ # ...while a fresh explicit call still activates.+ fresh_ctx = self._skill_tool_ctx()+ asyncio.run(rail.before_tool_call(fresh_ctx))+ asyncio.run(rail.after_tool_call(fresh_ctx))+ assert get_session_active_skill(self.sid) == "hwocr"++ def test_bash_or_other_tools_do_not_revive(self):+ # Only an explicit skill_tool call drops the breaker; bash and+ # other tools must not revive it.+ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ asyncio.run(rail.before_tool_call(self._bash_ctx()))+ asyncio.run(rail.after_tool_call(self._skill_tool_ctx()))+ assert get_session_active_skill(self.sid) is None++ def test_revive_marker_travels_the_real_callback_framework(self):+ # NTH-R2-1: pin the framework contract the marker relies on.+ # The revive marker is stamped in before_tool_call and consumed in+ # after_tool_call; it only works because the callback framework+ # dispatches both events on the SAME AgentCallbackContext+ # (ctx.extra persists across events). Drive both hooks through the+ # real AsyncCallbackFramework so a future per-event ctx copy fails+ # LOUDLY here instead of silently re-introducing the SKILL_GATE+ # false-blocking bug.+ from openjiuwen.core.runner.callback.framework import AsyncCallbackFramework++ rail = SkillActiveStateRail(session_id=self.sid)+ self._store().revoke_grants(self.sid, "main")+ ctx = self._skill_tool_ctx()++ async def run_through_framework():+ callbacks = AsyncCallbackFramework()+ await callbacks.register("before_tool", rail.before_tool_call)+ await callbacks.register("after_tool", rail.after_tool_call)+ await callbacks.trigger("before_tool", ctx)+ await callbacks.trigger("after_tool", ctx)++ asyncio.run(run_through_framework())+ assert get_session_active_skill(self.sid) == "hwocr"++if __name__ == "__main__":unittest.main()