mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
* feat(agent): unify persistent sessions and native fork settings
* fix(agent): preserve continuation and rejected session settings
* feat(event_stream): add bounded durable event streams
* fix(agent): preserve session guards and execution policies
* Revert "fix(agent): preserve session guards and execution policies"
This reverts commit 02188565dc.
* refactor(agent)!: unify file-native proactive runtimes
Coordinate named cron and event agents through an application-owned runtime,
with per-agent memory, native session registries and Markdown reminders.
Initialize Chat and task memories once under reme_agents and remove the old
PA delivery APIs and duplicated session state.
Serialize temporary query ownership with collection, recover incomplete
session-registry appends, and migrate benchmark plugins to public file helpers.
Split model providers into registered modules without changing their behavior.
* feat(proactive): add speech and scheduled observation collectors
Add DashScope ASR/TTS components, restart-safe finance collectors and
five-minute screenshot/Codex dialogue observations with bilingual docs.
Use response receipt time for stock freshness and recover interrupted
work-observation cleanup without replaying committed dialogue.
* refactor(core)!: unify execution cleanup and remove legacy contracts
Track queued Agent operations through shutdown and deletion, keep retry
backoff bounded, and reuse the local process runner for Shell steps.
Reject BASE registrations and remove duplicate config/path helpers.
BREAKING CHANGE: plugin discovery requires package-only entry points
and plugin.yaml; FileLink.predicate and the dream.ProactiveResult alias
are removed. Rebuild old derived graph indexes from workspace notes.
* feat(agent)!: add desktop workspace and isolated inbox delivery
* chore(desktop): remove one-click restart launcher
* fix(agent): guard session content and persist incremental display history
* test(home): verify host network isolation across platforms
* refactor(agent)!: unify durable inbox components
* docs: illustrate personal and proactive agent runtimes
* Refactor agent streaming and durable reminder delivery
Project formal turns through one ordered transcript, with live snapshots until native history catches up. Render localized activity groups, stable Markdown blocks and paged conversation history.
Bound proactive batches and preserve retries, persist reminder links before delivery, and synchronize explicit user-read receipts across sessions. Remove the obsolete desktop receipt format.
* Align desktop streaming activity with Codex
Keep assistant progress in the conversation and fold reasoning into activity details. Normalize native command actions into file, directory, search and command summaries with localized disclosure and explicit completion.
Match user bubbles and activity styling while preserving streaming anchors, links and expansion state.
* docs: explain proactive agents and personal runtime
* Align proactive runtime settings and documentation
* Unify agent runtime APIs and resource collection
* Deduplicate proactive observations and respect market sessions
* Refine proactive sessions and screenshot filtering
* Add desktop background transparency and tab transitions
* Tighten observation validation and task prompts
* Align streaming tool display with canonical item snapshots
* Unify Agent identity, task memory, and session workflows
Use agent_name and agent_type across the runtime, APIs, collectors and Desktop.
Initialize task_memory into MEMORY.md and return memory paths for native edits.
Keep task questions in read-only forks and automatic runs in validated file stages.
Document current behavior and cover default conversation rendering and SDK forks.
* Unify active sessions and task files; remove prompt wording tests
* Refine proactive jobs and fix coverage reporting
* Remove unused desktop artifacts and protocol probe
* Simplify proactive runs and commit validated artifacts after model failures
* Allow daily summaries for new records without reminders
* refactor(proactive): improve proactive and cron agent prompts and workflow steps
- Update cron agent description to emphasize recording what happened and reporting results
- Change sleep reminder rule to be specifically tagged for proactive agent
- Rename query fields to proactive_query for clarity
- Streamline and clarify proactive agent workflow steps in English and Chinese versions
- Enhance task analysis and reminder decision logic with clearer instructions
- Revise today's summary update format and examples with time stamps and consistent headings
- Provide separate detailed steps for cron agent execution and reporting
- Ensure reminder generation logic is more precise and avoid assumptions about user knowledge
* Add notebook and task management with resilient agent cleanup
* Improve search accounting and desktop conversation controls
* Guard conversation reset against endpoint changes
* refactor(proactive): simplify session options and improve markdown link warnings
- Remove unused failure status detection and associated UI styling in activity component
- Simplify session_options method by removing unnecessary parameters and excessive prompt formatting
- Enhance _query method to handle task content and event inputs conditionally based on agent type
- Add static method to extract and decode markdown links ignoring code blocks
- Introduce _warn_local_links to log warnings on broken local links without failing artifact validation
- Integrate local link warnings into artifact reading flow for proactive and cron agents
- Modify tests to reflect session_options signature changes and verify local link warning behavior
- Ensure TASK.md is non-empty before task execution, enforcing content validation
- Refactor CSS to remove deprecated broken activity state styles
- Improve test coverage with parameterized tests for broken local link warnings under various scenarios
* fix(agent): preserve user edits and recover durable commits
* fix(agent): guard outbox writes and defer full inbox delivery
* fix(agent): preserve reminder eligibility and serialize lifecycle transitions
* Simplify proactive task storage and desktop protocol
* Make proactive timeline limits configurable
* test(proactive): remove prompt checks and redundant cases
* Unify proactive task APIs and documentation
* fix(proactive): preserve incomplete triggers and skip oversized reminders
* fix(proactive): preserve queued trigger types across task updates
* docs(proactive): improve instructions for recording scheduled task results
- Clarify steps to follow after completing the scheduled task work
- Specify writing `action: write` in frontmatter when overwriting the record file
- Simplify description of what to include in the record body
- Emphasize using only necessary tools for the task and writing the record
- Align English and Chinese instructions for consistency
* fix(proactive): keep scheduled time and bypass event cooldown for cron
187 lines
7.6 KiB
Python
187 lines
7.6 KiB
Python
"""Codex snapshot forks and native append acceptance while generation owns its lease."""
|
|
|
|
# pylint: disable=missing-function-docstring,protected-access,redefined-outer-name
|
|
|
|
import asyncio
|
|
from types import SimpleNamespace
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from reme.components.agent_wrapper import CodexAgentWrapper
|
|
from . import test_agent_session_api
|
|
from . import test_codex_agent_wrapper
|
|
|
|
runtime = test_agent_session_api.runtime
|
|
codex_wrapper = test_agent_session_api.codex_wrapper
|
|
system = test_codex_agent_wrapper.system
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("ephemeral", [False, True])
|
|
async def test_created_fork_stays_loaded_until_its_first_query(system, monkeypatch, ephemeral):
|
|
wrapper, _, server, _ = system
|
|
source = (await wrapper.reply("Source"))["session_id"]
|
|
child = await wrapper.create_session(resume=source, fork_session=True, ephemeral=ephemeral)
|
|
native = test_codex_agent_wrapper._Codex.instances[0]
|
|
assert child not in native.unsubscribed
|
|
assert server._threads[child].pending is native.threads[child]
|
|
read = AsyncMock(
|
|
return_value=SimpleNamespace(
|
|
thread=SimpleNamespace(
|
|
id=child,
|
|
turns=[],
|
|
path=None,
|
|
status=SimpleNamespace(root=SimpleNamespace(type="idle")),
|
|
),
|
|
),
|
|
)
|
|
monkeypatch.setattr(native._client, "thread_read", read)
|
|
await wrapper.read_session(child)
|
|
read.assert_awaited_once_with(child, include_turns=not ephemeral)
|
|
monkeypatch.setattr(native, "thread_resume", AsyncMock(side_effect=AssertionError("Ephemeral fork was unloaded")))
|
|
result = await wrapper.reply("Child query", resume=child)
|
|
assert result["status"] == "completed" and result["session_id"] == child
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("role", ["user", "assistant"])
|
|
async def test_immediate_append_submits_while_generation_runs_and_waits_only_for_persistence(codex_wrapper, role):
|
|
wrapper, native = codex_wrapper
|
|
received = asyncio.Event()
|
|
queued = []
|
|
request = native.client._client.request.side_effect
|
|
|
|
async def enqueue(method, params, **kwargs):
|
|
if method == "thread/inject_items":
|
|
queued.append(params)
|
|
received.set()
|
|
return SimpleNamespace()
|
|
return await request(method, params, **kwargs)
|
|
|
|
native.client._client.request.side_effect = enqueue
|
|
async with wrapper.app_server.thread("session-1"):
|
|
native.thread.status.root.type = "active"
|
|
pending = asyncio.create_task(
|
|
wrapper.append_session("session-1", "queued", message_id="one", role=role, delivery="immediate"),
|
|
)
|
|
try:
|
|
await asyncio.wait_for(received.wait(), 1)
|
|
assert not pending.done() and not native.injections
|
|
assert native.client.thread_resume.await_count == 1
|
|
assert (await wrapper.read_session("session-1")).state.status == "active"
|
|
await request("thread/inject_items", queued[0])
|
|
result = await asyncio.wait_for(pending, 1)
|
|
assert result.content == "queued" and result.role == role
|
|
assert len(queued) == len(native.injections) == 1
|
|
assert native.thread.status.root.type == "active"
|
|
assert not wrapper.app_server._threads["session-1"].appends
|
|
finally:
|
|
native.thread.status.root.type = "idle"
|
|
pending.cancel()
|
|
await asyncio.gather(pending, return_exceptions=True)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("outcome", ["timeout", "cancelled", "lost_receipt"])
|
|
async def test_accepted_but_unpersisted_append_is_not_resubmitted_on_retry(codex_wrapper, outcome):
|
|
wrapper, native = codex_wrapper
|
|
received = asyncio.Event()
|
|
queued = []
|
|
request = native.client._client.request.side_effect
|
|
|
|
async def enqueue(method, params, **kwargs):
|
|
if method == "thread/inject_items":
|
|
queued.append(params)
|
|
received.set()
|
|
if outcome == "lost_receipt":
|
|
raise OSError("lost receipt")
|
|
return SimpleNamespace()
|
|
return await request(method, params, **kwargs)
|
|
|
|
native.client._client.request.side_effect = enqueue
|
|
pending = asyncio.create_task(
|
|
wrapper.append_session("session-1", "once", message_id="one", delivery="immediate", timeout=0.1),
|
|
)
|
|
await asyncio.wait_for(received.wait(), 1)
|
|
if outcome == "cancelled":
|
|
pending.cancel()
|
|
error = {"timeout": TimeoutError, "cancelled": asyncio.CancelledError, "lost_receipt": OSError}[outcome]
|
|
with pytest.raises(error):
|
|
await pending
|
|
assert "reme-proactive-one" in wrapper.app_server._threads["session-1"].appends
|
|
restarted = CodexAgentWrapper(app_context=wrapper.app_context)
|
|
try:
|
|
with pytest.raises(ValueError, match="different content"):
|
|
await restarted.append_session("session-1", "different", message_id="one", delivery="immediate")
|
|
retry = asyncio.create_task(
|
|
restarted.append_session(
|
|
"session-1",
|
|
"once",
|
|
message_id="one",
|
|
delivery="immediate",
|
|
expected_revision="stale",
|
|
),
|
|
)
|
|
try:
|
|
await asyncio.sleep(0.02)
|
|
assert not retry.done() and len(queued) == 1
|
|
await request("thread/inject_items", queued[0])
|
|
message = await asyncio.wait_for(retry, 1)
|
|
assert message.content == "once" and len(queued) == 1
|
|
finally:
|
|
retry.cancel()
|
|
await asyncio.gather(retry, return_exceptions=True)
|
|
finally:
|
|
await restarted.close()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_native_rejection_does_not_leave_an_uncertain_receipt(codex_wrapper):
|
|
wrapper, native = codex_wrapper
|
|
|
|
class Rejected(ValueError):
|
|
"""A definitive protocol rejection before native acceptance."""
|
|
|
|
code = -32600
|
|
|
|
native.client._client.request.side_effect = Rejected("invalid request")
|
|
with pytest.raises(Rejected):
|
|
await wrapper.append_session("session-1", "rejected", message_id="one", delivery="immediate")
|
|
assert not wrapper.app_server._threads["session-1"].appends
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_immediate_append_restores_an_unloaded_session(codex_wrapper):
|
|
wrapper, native = codex_wrapper
|
|
native.thread.status.root.type = "notLoaded"
|
|
|
|
async def resume(_session_id, **_options):
|
|
native.thread.status.root.type = "idle"
|
|
return native.handle
|
|
|
|
native.client.thread_resume.side_effect = resume
|
|
message = await wrapper.append_session("session-1", "restored", message_id="one", delivery="immediate")
|
|
assert message.content == "restored"
|
|
native.client.thread_resume.assert_awaited_once()
|
|
assert len(native.injections) == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_simultaneous_immediate_appends_share_retry_identity(codex_wrapper):
|
|
wrapper, native = codex_wrapper
|
|
messages = await asyncio.gather(
|
|
*(wrapper.append_session("session-1", "once", message_id="one", delivery="immediate") for _ in range(3)),
|
|
)
|
|
assert messages[0] == messages[1] == messages[2]
|
|
assert len(native.injections) == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pending_receipts_survive_loaded_thread_pruning(codex_wrapper):
|
|
wrapper, native = codex_wrapper
|
|
native.client._client.request.side_effect = AsyncMock(return_value=SimpleNamespace())
|
|
with pytest.raises(TimeoutError):
|
|
await wrapper.append_session("session-1", "queued", message_id="one", delivery="immediate", timeout=0.05)
|
|
await wrapper.app_server._prune_threads(native.client)
|
|
assert "reme-proactive-one" in wrapper.app_server._threads["session-1"].appends
|