Skip to content

Self-hosted AI workspace.

Python

fix(calendar): accept list event range aliases

Ocean Bennett503e281be90b
diff --git a/src/agent_loop.py b/src/agent_loop.py
index f3bab9d41..1f70ca2a5 100644
--- a/src/agent_loop.py
+++ b/src/agent_loop.py
@@ -328,6 +328,7 @@ Bulk delete/archive/mark emails. Use this for "delete all those" after listing e
{"action": "create_event", "summary": "<event title>", "dtstart": "<natural language or ISO datetime>"}
```
Calendar event management (CalDAV). Actions: `list_events`, `create_event`, `update_event`, `delete_event`, `list_calendars`. \
+For `list_events`: {start?, end?, calendar?}; prefer `start`/`end` for the range, though start_date/end_date and from/to aliases are accepted. \
For `create_event`: {summary, dtstart, dtend?, duration?, calendar?, location?, description?, reminder_minutes?, rrule?}. \
`dtstart` accepts natural language ("tomorrow at 1pm", "in 2 hours", "next monday 9am") or ISO ("2026-05-12T13:00:00"). \
If `dtend` omitted, defaults to dtstart+1h (or +1d when `all_day: true`). \
diff --git a/src/tool_implementations.py b/src/tool_implementations.py
index 2b0fe372f..62ac23a08 100644
--- a/src/tool_implementations.py
+++ b/src/tool_implementations.py
@@ -2111,6 +2111,13 @@ async def do_manage_calendar(content: str, owner: Optional[str] = None) -> Dict:
"""Parse agent event datetimes in the user's timezone when available."""
return _parse_dt_pair(parse_due_for_user(raw))
+ def _first_nonempty_arg(*names: str):
+ for name in names:
+ value = args.get(name)
+ if value not in (None, ""):
+ return value
+ return None
+
def _create_calendar_reminder(summary: str, location: str, dtstart: datetime,
all_day: bool, minutes_before: int,
is_utc: bool = False) -> tuple[Optional[str], Optional[str]]:
@@ -2168,12 +2175,18 @@ async def do_manage_calendar(content: str, owner: Optional[str] = None) -> Dict:
elif action == "list_events":
try:
- if args.get("start"):
- start_dt = _parse_dt(args["start"])
+ start_raw = _first_nonempty_arg(
+ "start", "start_date", "range_start", "from", "dtstart", "since"
+ )
+ end_raw = _first_nonempty_arg(
+ "end", "end_date", "range_end", "to", "dtend", "until"
+ )
+ if start_raw:
+ start_dt = _parse_dt(start_raw)
else:
start_dt = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
- if args.get("end"):
- end_dt = _parse_dt(args["end"])
+ if end_raw:
+ end_dt = _parse_dt(end_raw)
else:
end_dt = start_dt + timedelta(days=14)
except ValueError as e:
diff --git a/src/tool_schemas.py b/src/tool_schemas.py
index 311184c43..307a3516a 100644
--- a/src/tool_schemas.py
+++ b/src/tool_schemas.py
@@ -545,8 +545,8 @@ FUNCTION_TOOL_SCHEMAS = [
"uid": {"type": "string", "description": "Event UID (for update/delete)"},
"calendar_href": {"type": "string", "description": "Specific calendar URL (optional; defaults to first calendar)"},
"calendar": {"type": "string", "description": "Filter list_events by calendar name or href"},
- "start": {"type": "string", "description": "list_events range start (ISO datetime); defaults to today"},
- "end": {"type": "string", "description": "list_events range end (ISO datetime); defaults to +14 days"},
+ "start": {"type": "string", "description": "list_events range start (ISO datetime); defaults to today. Prefer start; backend also accepts start_date, range_start, from, dtstart, since."},
+ "end": {"type": "string", "description": "list_events range end (ISO datetime); defaults to +14 days. Prefer end; backend also accepts end_date, range_end, to, dtend, until."},
"event_type": {"type": "string", "description": "Tag / category for the event. Common values: work, personal, health, travel, meal, social, admin, other. Aliases accepted: tag, category, type."},
"importance": {"type": "string", "enum": ["low", "normal", "high", "critical"], "description": "Priority level (defaults to 'normal')"},
"reminder_minutes": {"type": "integer", "description": "For create_event: create an Odysseus reminder this many minutes before the event, e.g. 5 for 'reminder 5 min before'."},
diff --git a/tests/test_calendar_list_range_aliases.py b/tests/test_calendar_list_range_aliases.py
new file mode 100644
index 000000000..669c8e009
--- /dev/null
+++ b/tests/test_calendar_list_range_aliases.py
@@ -0,0 +1,80 @@
+"""manage_calendar list_events should honor common range aliases.
+
+The agent prompt and schema prefer start/end, but model calls can emit
+start_date/end_date or from/to. Those aliases used to be ignored, causing the
+tool to fall back to its default 14-day window.
+"""
+
+import json
+import sys
+import tempfile
+import uuid
+
+import pytest
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.pool import NullPool
+
+from tests.helpers.import_state import clear_fake_database_modules
+
+clear_fake_database_modules()
+
+import core.database as cdb
+
+_TMPDB = tempfile.NamedTemporaryFile(suffix=".db", delete=False)
+_ENGINE = create_engine(
+ f"sqlite:///{_TMPDB.name}",
+ connect_args={"check_same_thread": False},
+ poolclass=NullPool,
+)
+cdb.Base.metadata.create_all(_ENGINE)
+_TS = sessionmaker(bind=_ENGINE, autoflush=False, autocommit=False)
+
+
[email protected](autouse=True)
+def _bind_temp_db(monkeypatch):
+ monkeypatch.setitem(sys.modules, "core.database", cdb)
+ parent = sys.modules.get("core")
+ if parent is not None:
+ monkeypatch.setattr(parent, "database", cdb, raising=False)
+ monkeypatch.setattr(cdb, "SessionLocal", _TS)
+ yield
+
+
+ ("start_key", "end_key"),
+ [
+ ("start_date", "end_date"),
+ ("from", "to"),
+ ("range_start", "range_end"),
+ ],
+)
+async def test_list_events_honors_range_aliases(start_key, end_key):
+ from src.tool_implementations import do_manage_calendar
+
+ owner = "calendar-alias-" + uuid.uuid4().hex[:8]
+
+ inside = await do_manage_calendar(json.dumps({
+ "action": "create_event",
+ "summary": "Late June planning",
+ "dtstart": "2126-06-25T10:00:00Z",
+ }), owner=owner)
+ assert inside.get("exit_code", 0) == 0, inside
+
+ outside = await do_manage_calendar(json.dumps({
+ "action": "create_event",
+ "summary": "Outside July planning",
+ "dtstart": "2126-07-10T10:00:00Z",
+ }), owner=owner)
+ assert outside.get("exit_code", 0) == 0, outside
+
+ res = await do_manage_calendar(json.dumps({
+ "action": "list_events",
+ start_key: "2126-06-01T00:00:00Z",
+ end_key: "2126-07-01T00:00:00Z",
+ }), owner=owner)
+
+ assert res.get("exit_code", 0) == 0, res
+ summaries = [event["summary"] for event in res["events"]]
+ assert summaries == ["Late June planning"]
+ assert "between 2126-06-01 and 2126-07-01" in res["response"]