agentscope-ai / agentscope-ai/agentscope
[Bug]: Scheduled sessions persist an empty workspace_id
- Dominant language
- Python
- Stars
- 31.5k
- Forks
- 3.5k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 95
Description
### Prerequisites
- [x] I have searched the existing [issues](https://github.com/agentscope-ai/agentscope/issues) and [discussions](https://github.com/agentscope-ai/agentscope/discussions), and this is not a duplicate.
- [x] This is a bug, not a usage question. (For questions, please use [Discussions](https://github.com/agentscope-ai/agentscope/discussions/new?category=general) instead.)
### Background / Description
When a scheduled task is triggered, `SchedulerManager` creates the
execution session with an empty `workspace_id`.
This happens in both the stateful and stateless scheduling paths:
```python
SessionConfig(
workspace_id="",
chat_model_config=record.data.chat_model_config,
)
```
This differs from normal session creation, which generates a workspace ID
when none is provided:
```python
workspace_id=body.workspace_id or _generate_id()
```
`ScheduleCreate` also records the current session as
`ScheduleData.source_session_id`, whose field description says that it is
used for resource retrieval. However, `_build_trigger()` does not use the
source session when creating the scheduled session.
This produces a persisted scheduled session with:
```text
source = schedule
source_schedule_id =
config.workspace_id = ""
```
This is also inconsistent with the workspace lifecycle. Workspace managers
receive `SessionConfig.workspace_id` as the stable cache and workspace
identifier, while `WorkspaceBase` replaces a falsy workspace ID with a
newly generated ID. The persisted session can therefore retain an empty ID
while the runtime workspace has a different generated ID.
Expected behavior:
A scheduled session should always persist a valid, stable workspace ID.
Possible semantics include:
1. Inherit the source session's workspace when `source_session_id` is
available.
2. Generate a new isolated workspace ID.
3. Allow the host application to provide a workspace resolver.
Could you please confirm which workspace ownership semantics are intended
for scheduled sessions?
### Error Messages
```shell
No exception or stack trace is emitted.
The scheduler silently creates and persists a scheduled session whose
configuration contains:
source = schedule
source_schedule_id = schedule-1
config.workspace_id = ""
Expected:
config.workspace_id =
```
### Steps to Reproduce
1. Install AgentScope with the service dependencies:
```shell
python -m pip install "agentscope[service]==2.0.4"
```
2. Save the following as `repro_schedule_workspace.py`:
```python
import asyncio
from typing import Any
from agentscope.app._manager import SchedulerManager
from agentscope.app.message_bus import InMemoryMessageBus
from agentscope.app.storage import (
ChatModelConfig,
ScheduleData,
ScheduleRecord,
ScheduleSource,
SessionConfig,
SessionRecord,
SessionSource,
)
class CapturingStorage:
def __init__(self) -> None:
self.created_config: SessionConfig | None = None
async def upsert_session(
self,
*,
user_id: str,
agent_id: str,
config: SessionConfig,
state: Any,
source: SessionSource,
source_schedule_id: str | None,
session_id: str | None = None,
) -> SessionRecord:
self.created_config = config
return SessionRecord(
id=session_id or "scheduled-session",
user_id=user_id,
agent_id=agent_id,
config=config,
state=state,
source=source,
source_schedule_id=source_schedule_id,
)
async def main() -> None:
storage = CapturingStorage()
scheduler = SchedulerManager(
storage=storage, # type: ignore[arg-type]
message_bus=InMemoryMessageBus(),
)
schedule = ScheduleRecord(
id="schedule-1",
user_id="user-1",
agent_id="agent-1",
data=ScheduleData(
name="workspace reproduction",
description="Reproduce the scheduled workspace issue.",
cron_expression="* * * * *",
chat_model_config=ChatModelConfig(
type="dummy",
credential_id="dummy",
model="dummy",
parameters={},
),
stateful=False,
source=ScheduleSource.AGENT,
source_session_id="source-session",
),
)
trigger = scheduler._build_trigger(schedule)
await trigger()
assert storage.created_config is not None
print(f"source_session_id: {schedule.data.source_session_id!r}")
print(f"scheduled workspace_id: {storage.created_config.workspace_id!r}")
asyncio.run(main())
```
3. Run the script:
```shell
python repro_schedule_workspace.py
```
4. Actual output:
```text
source_session_id: 'source-session'
scheduled workspace_id: ''
```
5. Expected output:
```text
source_session_id: 'source-session'
scheduled workspace_id: ''
```
### Environment
- AgentScope Version: 2.0.4
- Python Version: 3.11.14
- OS: Windows 11 (Microsoft Windows NT 10.0.26200.0)
Contributor guide
Assessment
This issue has not been assessed yet.