ReMe/reme/steps/proactive/data_connectors/resource_delivery.py
jinliyl ae55e2e570
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
feat!: split proactive runtimes and add Studio backend management (#776)
* refactor(proactive)!: separate runtime ownership and unify delivery

* refactor(proactive): finish runtime and Studio migration

* test(proactive): make scheduled skip coverage deterministic

* refactor(studio): unify navigation and notebook resource loading

* feat(studio): edit workspace documents and update proactive task names

* refactor(studio): simplify task settings and navigation

* feat(studio): secure and supervise backend settings

* feat(studio): unify workbench timelines and refine desktop updates

Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts.

Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view.

* fix(studio): support unsigned GitHub preview releases

* fix: verify container state and isolate proactive view errors

Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts.

Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history.

* fix(home): align candidate Docker context exclusions

* chore(deps): update openai-codex dependency to v0.172.0

- Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml
- Keep other dependencies unchanged
- Ensure compatibility with latest openai-codex features and fixes

* fix(daemon): discover parent dotenv and isolate listeners

Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
2026-11-25 21:33:16 +08:00

85 lines
3.9 KiB
Python

"""Recover event delivery from published resource packages."""
import asyncio
from hashlib import sha256
from ....schema import Event, ResourceMetadata
from ....schema.resource_metadata import RESOURCE_METADATA_FILENAME
from ....schema.proactive_agent import validate_task_names
from ....utils.async_utils import complete_in_thread
_DELIVERY_FILENAME = ".delivery.json"
def resource_event(workspace, directory, metadata, paths):
"""Derive a stable observation ID from its workspace-relative package directory."""
relative = directory.relative_to(workspace).as_posix()
return Event(
id=f"resource-{sha256(relative.encode()).hexdigest()}",
event_ts=metadata.created_at,
source=metadata.source,
description=metadata.description,
paths=[path.relative_to(workspace).as_posix() for path in paths],
)
class ResourceDelivery:
"""Freeze recipients before publishing and retain only unfinished deliveries."""
def __init__(self, connector, files, root, task_names):
self.connector = connector
self.files = files
self.root = root
self.task_names = task_names
def prepare(self, directory):
"""Stage the delivery beside the payloads before the manifest becomes visible."""
path = directory / _DELIVERY_FILENAME
self.connector.require_path(path)
self.files.write_json(path, {"pending": self.task_names})
async def flush(self):
"""Retry the original observation for each remaining recipient."""
pattern = f"*/*/{RESOURCE_METADATA_FILENAME}"
for manifest in await asyncio.to_thread(lambda: sorted(self.root.glob(pattern))):
try:
await self.deliver(manifest)
except (OSError, ValueError, RuntimeError) as error:
self.connector.logger.warning(f"Could not deliver resource package {manifest.parent}: {error}")
async def deliver(self, manifest):
"""Send one published package to its unfinished recipients."""
state_path = manifest.with_name(_DELIVERY_FILENAME)
self.connector.require_path(state_path)
state = await asyncio.to_thread(self.files.read_json, state_path, {"pending": []})
if not isinstance(state, dict) or not isinstance(state.get("pending"), list):
raise ValueError("Invalid pending resource recipients")
if not state["pending"]:
return
targets = validate_task_names(state["pending"])
previous_rejections = state.get("rejected", {})
if not isinstance(previous_rejections, dict):
raise ValueError("Invalid rejected resource recipients")
self.connector.require_path(manifest)
metadata = ResourceMetadata.model_validate_json(await asyncio.to_thread(self.files.read, manifest))
if metadata.source != self.connector.source:
raise ValueError(f"Unexpected resource source: {metadata.source}")
paths = [manifest.parent / name for name in self.connector.event_payloads(metadata)]
for path in paths:
self.connector.require_path(path)
if not path.is_file():
raise ValueError(f"Missing published resource payload: {path.name}")
event = resource_event(self.files.workspace, manifest.parent, metadata, paths)
result = await self.connector.proactive_manager.deliver_events(task_names=targets, events=[event])
rejected = result["rejected"]
if rejected:
self.connector.logger.warning(f"Resource event {event.id} rejected by tasks: {rejected}")
if result["deliveries"] or rejected:
await complete_in_thread(
self.files.write_json,
state_path,
{"pending": list(result["errors"]), "rejected": {**previous_rejections, **rejected}},
)
if result["errors"]:
raise RuntimeError(f"Resource event delivery failed: {result['errors']}")