Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### 新增
- 专家市场默认打开「精选」,用书签标出接入市场前随安装包提供的 22 个专家模板
- 通道卡片与 `/api/health` 展示每个通道的入站、出站、重连和丢弃计数;记忆存储页显示 checkpoint 保留窗口与 VACUUM 提示

### 修复
- 关机时会等正在进行的数据库查询结束再关闭连接,避免 Windows 上测试进程被访问冲突打断
Expand All @@ -20,6 +21,7 @@
- 供应商的默认模型可以清空并保持为空。对话里的模型名与选择时一致,能区分不同厂家的同名模型
- 服务端升级后,登录页和已登录页面都会提示刷新前端。PostgreSQL 备份缺少客户端工具时会说明原因,Docker 镜像带上该工具
- 专家配置文件改为文本框编辑,打开时不再停在编辑器加载中
- 飞书通道注册时改用持久化去重库,通道重建或服务重启后仍能识别重投事件

## [1.0.3b4] - 2026-11-06

Expand Down
5 changes: 5 additions & 0 deletions dashboard/src/api/modules/memoryDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ export interface MemoryStorageInspection {
wal_size: number | null;
reclaimable_bytes: number | null;
auto_vacuum_enabled: boolean | null;
checkpoint_retention_enabled?: boolean | null;
checkpoint_keep_last?: number | null;
checkpoint_keep_days?: number | null;
checkpoint_backup_before_prune?: boolean | null;
checkpoint_vacuum_recommended?: boolean | null;
tables: {
table: string;
exists: boolean;
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,8 @@
"configSaved": "Configuration saved successfully",
"configFailed": "Failed to save configuration",
"channelEnabled": "Channel enabled",
"lastInbound": "Last inbound {{time}}",
"channelHealth": "Reconnects {{reconnect}}, dropped stale {{stale}}, duplicate {{duplicate}}",
"channelDisabled": "Channel disabled",
"channelType": "Channel Type",
"status": "Status",
Expand Down Expand Up @@ -4990,6 +4992,10 @@
"inspectionTimingHint": "Server-side read-only inspection time, excluding network transfer. Data size, cache and concurrent work affect it; this is not a conversation or model benchmark. Count queries have a combined 5-second budget; timed-out counts are not shown as zero.",
"sharedCheckpointHint": "Multiple memory namespaces or experts share this file. Session checkpoints cannot be safely attributed, so only the current expert’s memory counts are shown. File maintenance is disabled.",
"checkpointCountHint": "Checkpoints restore sessions and are not message counts. Session IDs are deduplicated to count distinct sessions. Shared content blocks store deduplicated payloads; full-text indexes are not counted again.",
"checkpointRetention": "Checkpoint retention",
"checkpointRetentionValue": "Newest {{keep}}, age limit {{days}}. One backup is written before deletion.",
"checkpointRetentionNoDays": "none",
"vacuumRecommended": "Deleting old checkpoints does not shrink the file. Reclaimable space is large; run VACUUM on this SQLite file when the agent is idle.",
"comparisonHint": "Snapshots belong to this maintenance run. Deduplication preserves history and valid memories, so row counts may remain unchanged and shared blocks may increase. Background writes may affect counts. Backups consume separate space and are excluded from reclaimed bytes.",
"deleteBackup": "Delete backup",
"deleteBackupTitle": "Delete this backup for the current expert?",
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,8 @@
"configSaved": "配置保存成功",
"configFailed": "配置保存失败",
"channelEnabled": "频道已启用",
"lastInbound": "最近收到 {{time}}",
"channelHealth": "重连 {{reconnect}} 次,丢弃过期 {{stale}}、重复 {{duplicate}}",
"channelDisabled": "频道已停用",
"channelType": "通道类型",
"status": "状态",
Expand Down Expand Up @@ -4990,6 +4992,10 @@
"inspectionTimingHint": "耗时为服务端本次只读检查时间,不含网络传输;受数据量、缓存和同时运行的任务影响,不代表对话或模型性能。条数查询合计最多运行 5 秒,超时项不显示为 0。",
"sharedCheckpointHint": "当前文件由多个记忆命名空间或专家共享,无法安全归属会话检查点,仅展示当前专家的记忆分类条数。文件级维护已禁用。",
"checkpointCountHint": "检查点用于恢复会话,不等于消息条数;独立会话数按检查点中的会话 ID 去重。共享内容块用于去重存储,全文索引不重复计数。",
"checkpointRetention": "检查点保留",
"checkpointRetentionValue": "最近 {{keep}} 份,天数 {{days}}。删除前会先备份一份。",
"checkpointRetentionNoDays": "不限",
"vacuumRecommended": "删除旧检查点后文件不会马上变小。可回收空间已经不小,建议在空闲时对这个 SQLite 文件执行 VACUUM。",
"comparisonHint": "前后快照仅对应本次维护。去重维护保留会话历史和有效记忆,因此条数可能不变,共享内容块可能增加。后台写入也可能影响统计;备份单独占用空间,未计入释放量。",
"deleteBackup": "删除备份",
"deleteBackupTitle": "删除当前专家的这份备份?",
Expand Down
13 changes: 13 additions & 0 deletions dashboard/src/pages/Agent/Channels/components/ChannelCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ export function ChannelCard({
</p>

<div className={styles.cardBottom}>{renderStatusBadge()}</div>
{runtime?.last_inbound_at ? (
<p className={styles.cardDescription}>
{t("channels.lastInbound", {
time: new Date(runtime.last_inbound_at * 1000).toLocaleString(),
})}
{" · "}
{t("channels.channelHealth", {
reconnect: runtime.reconnect_count ?? 0,
stale: runtime.dropped_stale ?? 0,
duplicate: runtime.dropped_duplicate ?? 0,
})}
</p>
) : null}
</div>
);
}
6 changes: 6 additions & 0 deletions dashboard/src/pages/Agent/Channels/useChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export interface ChannelRow {
connected: boolean;
error?: string | null;
updated_at?: number;
last_inbound_at?: number | null;
last_outbound_at?: number | null;
reconnect_count?: number;
last_reconnect_at?: number | null;
dropped_duplicate?: number;
dropped_stale?: number;
};
}

Expand Down
19 changes: 19 additions & 0 deletions dashboard/src/pages/Agent/Memory/MemoryStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ export default function MemoryStorage({ agentId }: { agentId: string }) {
: "common.disabled",
),
},
{
key: "retention",
label: t("memory.storage.checkpointRetention"),
children: inspection.checkpoint_retention_enabled
? t("memory.storage.checkpointRetentionValue", {
keep: inspection.checkpoint_keep_last ?? "—",
days:
inspection.checkpoint_keep_days ??
t("memory.storage.checkpointRetentionNoDays"),
})
: t("common.disabled"),
},
]
: []),
]}
Expand All @@ -309,6 +321,13 @@ export default function MemoryStorage({ agentId }: { agentId: string }) {
{t("memory.storage.estimateHint")}
</Typography.Text>
)}
{inspection.checkpoint_vacuum_recommended && (
<Alert
type="warning"
showIcon
message={t("memory.storage.vacuumRecommended")}
/>
)}
{inspection.blocked_reason && (
<Alert
type="info"
Expand Down
7 changes: 7 additions & 0 deletions src/octop/api/routers/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ async def health(server: Any = Depends(get_server)) -> dict[str, Any]:
agents = (
len(server.app_runtime.agent_registry.list_rows()) if server.app_runtime is not None else 0
)
channels: list[dict[str, Any]] = []
runtime = getattr(server, "app_runtime", None)
gateway = getattr(runtime, "gateway", None) if runtime is not None else None
report = getattr(gateway, "channel_health", None)
if callable(report):
channels = report()
return {
"ok": True,
"started_at": server._started_at,
"db": bound,
"users_loaded": users,
"agents_running": agents,
"channels": channels,
}
5 changes: 5 additions & 0 deletions src/octop/api/routers/memory_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class StorageInspection(BaseModel):
wal_size: int | None = None
reclaimable_bytes: int | None = None
auto_vacuum_enabled: bool | None = None
checkpoint_retention_enabled: bool | None = None
checkpoint_keep_last: int | None = None
checkpoint_keep_days: int | None = None
checkpoint_backup_before_prune: bool | None = None
checkpoint_vacuum_recommended: bool | None = None
page_size: int | None = None
total_pages: int | None = None
freelist_pages: int | None = None
Expand Down
45 changes: 45 additions & 0 deletions src/octop/infra/agents/memory/sqlite_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
import sqlite3
import time
from contextlib import closing
Expand All @@ -23,6 +24,49 @@
)
CHECKPOINT_TABLES = ("checkpoints", "writes", "hm_checkpoint_blobs")
COUNT_BUDGET_SECONDS = 5.0
_VACUUM_RECOMMEND_BYTES = 32 * 1024 * 1024


def _env_flag(name: str, default: bool) -> bool:
raw = os.environ.get(name)
if raw is None or not str(raw).strip():
return default
return str(raw).strip().lower() not in {"0", "false", "off", "no"}


def _optional_positive_int(name: str) -> int | None:
if name not in os.environ:
return None
raw = os.environ.get(name, "").strip()
if not raw or raw == "0":
return None
try:
value = int(raw)
except ValueError:
return None
return value if value > 0 else None


def _checkpoint_policy(reclaimable_bytes: int) -> dict[str, Any]:
"""Retention window shown on the storage page.

Matches idle maintenance in octop-harness: keep the newest 20 checkpoints
unless ``OCTOP_CHECKPOINT_RETENTION`` is turned off.
"""
keep_last = _optional_positive_int("OCTOP_CHECKPOINT_KEEP_LAST")
keep_days = _optional_positive_int("OCTOP_CHECKPOINT_KEEP_DAYS")
if not _env_flag("OCTOP_CHECKPOINT_RETENTION", True):
keep_last = None
keep_days = None
elif "OCTOP_CHECKPOINT_KEEP_LAST" not in os.environ:
keep_last = 20
return {
"checkpoint_retention_enabled": keep_last is not None or keep_days is not None,
"checkpoint_keep_last": keep_last,
"checkpoint_keep_days": keep_days,
"checkpoint_backup_before_prune": _env_flag("OCTOP_CHECKPOINT_BACKUP_BEFORE_PRUNE", True),
"checkpoint_vacuum_recommended": reclaimable_bytes >= _VACUUM_RECOMMEND_BYTES,
}


def inspect_sqlite_storage(backend: Any, *, shared: bool) -> dict[str, Any]:
Expand Down Expand Up @@ -64,6 +108,7 @@ def inspect_sqlite_storage(backend: Any, *, shared: bool) -> dict[str, Any]:
"file_check_ms": (time.perf_counter() - started) * 1000,
"namespace": namespace,
"checkpoints_available": not shared,
**_checkpoint_policy(free * page_size),
}
deadline = time.perf_counter() + COUNT_BUDGET_SECONDS
conn.set_progress_handler(lambda: int(time.perf_counter() >= deadline), 1000)
Expand Down
44 changes: 44 additions & 0 deletions src/octop/infra/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,35 @@ def runtime_status_to_dict(
"error": error,
"updated_at": status.updated_at,
}
channel = self._channel_manager.get_channel(channel_id) if self._channel_manager else None
metrics = getattr(channel, "health_metrics", None)
if callable(metrics):
out.update(metrics())
if status.lease_owner:
out["lease_owner"] = status.lease_owner
if status.lease_until is not None:
out["lease_until"] = status.lease_until
return out

def channel_health(self) -> list[dict[str, Any]]:
"""Per-channel liveness counters. Message bodies are not included."""
if self._channel_manager is None:
return []
rows: list[dict[str, Any]] = []
for channel_id in self._channel_manager.channel_ids:
channel = self._channel_manager.get_channel(channel_id)
status = self.get_runtime_status(channel_id)
metrics = getattr(channel, "health_metrics", None)
row: dict[str, Any] = {
"id": channel_id,
"type": getattr(channel, "channel_type", ""),
"connected": bool(status.connected) if status is not None else False,
}
if callable(metrics):
row.update(metrics())
rows.append(row)
return rows

async def boot(self, *, serve_background: bool = True) -> None:
from octop.infra.gateway.process.channel_thinking import (
install_channel_thinking_clean,
Expand Down Expand Up @@ -814,6 +837,8 @@ async def _register_channel(self, row: ChannelRow) -> None:
if not self._channel_manager or not self._processor:
return
config = self._config_from_row(row)
if row.kind == "feishu":
config = self._with_feishu_dedup_path(config)
from octop.infra.agents.teams.service import is_team_agent # noqa: PLC0415

team_host = False
Expand Down Expand Up @@ -882,6 +907,25 @@ def _config_from_row(self, row: ChannelRow) -> dict[str, Any]:
)
return raw

def _with_feishu_dedup_path(self, config: dict[str, Any]) -> dict[str, Any]:
"""Point Feishu dedup at this install's data directory.

The channel library only opens a SQLite file when a path is set.
Restart and re-register then still recognize message ids Feishu redelivers.
An explicit ``dedup_db_path`` in the channel config is left as-is.
"""
if str(config.get("dedup_db_path") or "").strip():
return config
paths = getattr(self._agent_manager, "_paths", None)
root = getattr(paths, "root", None)
if root is None:
from octop.infra.utils.paths import PathLayout # noqa: PLC0415

root = PathLayout.from_env().root
updated = dict(config)
updated["dedup_db_path"] = str(root / "feishu-dedup.sqlite")
return updated

async def _unregister(self, channel_id: str) -> None:
"""Disconnect locally, then release only the lease this process holds."""
if self._channel_manager is not None:
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/gateway/test_gateway_runtime_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ async def test_register_success_sets_runtime_connected(tmp_path: Path) -> None:
assert status.reason is None
assert gw._channel_manager.add_channel.await_args is not None
assert gw._channel_manager.add_channel.await_args.kwargs["processor"] is not gw._processor
assert gw._channel_manager.add_channel.await_args.args[1]["dedup_db_path"] == str(
tmp_path / "feishu-dedup.sqlite"
)


@pytest.mark.asyncio
Expand Down
Loading