Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(gateway): configure session expiry in seconds (#6651)
t0saki25b5a5e5c89a
diff --git a/deploy/helm/openviking-gateway/values.yaml b/deploy/helm/openviking-gateway/values.yamlindex c87603c17..83e52a2a8 100644--- a/deploy/helm/openviking-gateway/values.yaml+++ b/deploy/helm/openviking-gateway/values.yaml@@ -14,7 +14,7 @@ existingSecret: ""config:openviking_url: http://openviking:1933# Seven-day retention for sessions and Responses state.- session_ttl_days: 7+ session_ttl_seconds: 604800response_ttl_seconds: 604800storage:kernel: sqlitediff --git a/docs/en/about/02-changelog.md b/docs/en/about/02-changelog.mdindex 35f380241..9b666662f 100644--- a/docs/en/about/02-changelog.md+++ b/docs/en/about/02-changelog.md@@ -16,6 +16,9 @@ This changelog is automatically generated from [GitHub Releases](https://github.SQLite remains the default storage.- New `X-OpenViking-Upstream-URL` request header picks one of the allowed upstreams by itsBase URL; see [Pick the upstream per request](../gateway/07-upstreams.md#upstream-url-header).+ - `session_ttl_days` is replaced by `session_ttl_seconds` (at least 3600), so sessions can+ expire in under a day. The old setting is ignored with a startup warning; set the new one+ when upgrading.- Behavior changes with no configuration change: standalone keep-alive rises from 5 to 75seconds; a gateway bound to a public address waits and retries at startup whileOpenViking is unreachable or returns 5xx; idle SSE streams carry a comment heartbeat everydiff --git a/docs/en/gateway/06-manage-in-studio.md b/docs/en/gateway/06-manage-in-studio.mdindex 0b69bff18..6f399290b 100644--- a/docs/en/gateway/06-manage-in-studio.md+++ b/docs/en/gateway/06-manage-in-studio.md@@ -86,7 +86,7 @@ Saved changes to an upstream or a context profile apply to every gateway key thaA conversation records its context profile at its first request and keeps it, because changing what the model sees mid-conversation would break the provider's [prompt cache](01-how-it-works.md#replay). How soon a client picks up a profile change therefore depends on how often it starts a new conversation:- Clients that open a new conversation for every chat pick up changes quickly.-- Claude Code, Codex and clients that send a fixed session header can continue one conversation for days. They keep the old settings until they start a new conversation, or until the conversation has been idle for 30 days (`session_ttl_days`), when the gateway deletes its state.+- Claude Code, Codex and clients that send a fixed session header can continue one conversation for days. They keep the old settings until they start a new conversation, or until the conversation has been idle for 30 days (`session_ttl_seconds`), when the gateway deletes its state.How the gateway tells conversations apart is explained in [How conversations are recognized](03-connect-clients.md#how-conversations-are-recognized).diff --git a/docs/en/gateway/09-gateway-keys.md b/docs/en/gateway/09-gateway-keys.mdindex faf81dda9..be156544f 100644--- a/docs/en/gateway/09-gateway-keys.md+++ b/docs/en/gateway/09-gateway-keys.md@@ -31,7 +31,7 @@ With `tenancy: account` (the default), keys for the same OpenViking account andRotating an OpenViking key in key tenancy starts a new partition and new conversations. For troubleshooting, derive its partition without printing the key: `"k_" + hashlib.sha256(("openviking\0" + key).encode()).hexdigest()`. The OpenViking account identity is kept separately for revocation checks.-The stored OpenViking key and its user record expire after the configured `session_ttl_days`, measured from creation. Requests do not renew them. The next request confirms the key with OpenViking and recreates the records with the same partition and conversation scope. Issued gateway keys have no such TTL. See [Retention](11-security-and-data.md#retention) for pending capture and cleanup behavior.+The stored OpenViking key and its user record expire after the configured `session_ttl_seconds`, measured from creation. Requests do not renew them. The next request confirms the key with OpenViking and recreates the records with the same partition and conversation scope. Issued gateway keys have no such TTL. See [Retention](11-security-and-data.md#retention) for pending capture and cleanup behavior.Use gateway keys when clients need their own context profile, upstreams or allowed models, or must be revocable on their own.diff --git a/docs/en/gateway/11-security-and-data.md b/docs/en/gateway/11-security-and-data.mdindex 52d349ec2..3a51d3594 100644--- a/docs/en/gateway/11-security-and-data.md+++ b/docs/en/gateway/11-security-and-data.md@@ -69,8 +69,8 @@ Gateway data expires on its own. SQLite runs an hourly cleanup job; Redis uses k| Data | Kept for | Setting || --- | --- | --- |-| Conversation state | 30 days after last use | `session_ttl_days` |-| Cached OpenViking keys and their user records | Configured TTL from creation, without renewal | `session_ttl_days` |+| Conversation state | 30 days after last use | `session_ttl_seconds` |+| Cached OpenViking keys and their user records | Configured TTL from creation, without renewal | `session_ttl_seconds` || Stored request logs | 30 days | `log_retention_days` || Which upstream created each Responses response | 30 days | `response_ttl_seconds` || Sessions and memories in OpenViking | OpenViking's own rules | — |@@ -83,7 +83,7 @@ Minimums and where to set these are in [Gateway fields](13-configuration.md#gate## Redis conversation state {#redis-conversation-state}-With `storage.kernel: redis`, conversation state is a cache with a TTL of `session_ttl_days`. Writes renew it; reading a record alone does not.+With `storage.kernel: redis`, conversation state is a cache with a TTL of `session_ttl_seconds`. Writes renew it; reading a record alone does not.Eviction has observable effects:@@ -108,7 +108,7 @@ Revoking a gateway key, or the bound OpenViking key becoming invalid, does not d| Root | `DELETE /gateway/admin/account/data?account_id=<account>` | All gateway data of an account || Embedded deployment, automatically | Deleting a user or account in OpenViking | The matching gateway data |-A standalone deployment has no automatic step; its data stays until it is explicitly deleted or [expires](#retention). With [`management_api: false`](13-configuration.md#gateway-fields), the deletion API is also unavailable: deleting an OpenViking user does not notify the standalone gateway, so its conversation state remains until `session_ttl_days` expires. Request logs and response mappings follow their own retention settings. Embedded deployments retain the server's automatic deletion hook in account tenancy. In key tenancy, the hook cannot locate the `k_` partitions from the OpenViking account and user IDs; their cached data instead follows the retention settings above.+A standalone deployment has no automatic step; its data stays until it is explicitly deleted or [expires](#retention). With [`management_api: false`](13-configuration.md#gateway-fields), the deletion API is also unavailable: deleting an OpenViking user does not notify the standalone gateway, so its conversation state remains until `session_ttl_seconds` expires. Request logs and response mappings follow their own retention settings. Embedded deployments retain the server's automatic deletion hook in account tenancy. In key tenancy, the hook cannot locate the `k_` partitions from the OpenViking account and user IDs; their cached data instead follows the retention settings above.None of this touches memories and sessions already stored in OpenViking. The reverse also holds: after you delete a memory in OpenViking, the copy the gateway saved for an ongoing conversation is still replayed until that conversation expires. To clear it now, delete the user's gateway data.diff --git a/docs/en/gateway/13-configuration.md b/docs/en/gateway/13-configuration.mdindex a32136bc9..959ba640f 100644--- a/docs/en/gateway/13-configuration.md+++ b/docs/en/gateway/13-configuration.md@@ -41,7 +41,7 @@ An embedded and a standalone gateway share most fields; they differ in which fil| `default_upstreams` | Both | `{}` | Object mapping stable IDs to [upstream settings](#upstream-settings) | Upstreams for OpenViking keys when the account stores none; see [Deployment default upstreams](07-upstreams.md#deployment-default-upstreams) || `default_profile` | Both | Built-in profile defaults | [Context profile settings](#context-profile-settings) | Used when the account has no profile with the ID `default`; also the initial profile seeded in embedded dev mode || `min_server_version` | Both | `0.4.16` | Version string | Lowest OpenViking Server version a standalone gateway accepts |-| `session_ttl_days` | Both | `30` | 1 or more | Days of inactivity before a conversation expires; also the fixed lifetime of cached OpenViking keys and their user records |+| `session_ttl_seconds` | Both | `2592000` (30 days) | 3600 or more | Seconds of inactivity before a conversation expires; also the fixed lifetime of cached OpenViking keys and their user records. || `response_ttl_seconds` | Both | `2592000` (30 days) | 60 or more | Seconds to remember which upstream created a Responses response || `request_log_sink` | Both | `store` | `store`, `stdout` | Write request and background saving logs to storage or one flushed JSON line per record on stdout; see [Monitoring](../guides/22-gateway-operations.md#monitoring) || `log_retention_days` | Both | `30` | 1 or more | Days to keep request logs in storage; stdout retention is managed by the log collector |@@ -89,7 +89,7 @@ The default is local SQLite, with no external service. `storage.kernel` and `sto"command_timeout_ms": 5000}},- "session_ttl_days": 7+ "session_ttl_seconds": 604800}```@@ -134,7 +134,7 @@ OPENVIKING_GATEWAY_MANAGEMENT_KEY='<management-key>'| `tenancy` | `key` requires `management_api: false`; it has no effect when `openviking_keys` is off || `client_rules` | Every added pattern must be a valid Python regular expression; added tag names start with an ASCII letter and use only ASCII letters, digits, `_`, `.`, `:` and `-` || Unknown fields | Fail validation |-| Removed fields | Ignored, with a startup warning: `encryption_key_env`, and in `ov.conf` also the v0.5 fields listed in [Migration](../guides/22-gateway-operations.md#migration) |+| Removed fields | Ignored, with a startup warning: `encryption_key_env`, `session_ttl_days` (replaced by `session_ttl_seconds`), and in `ov.conf` also the v0.5 fields listed in [Migration](../guides/22-gateway-operations.md#migration) |## Client rules {#client-rules}diff --git a/docs/en/guides/22-gateway-operations.md b/docs/en/guides/22-gateway-operations.mdindex 7ddd223e2..ae52cbc35 100644--- a/docs/en/guides/22-gateway-operations.md+++ b/docs/en/guides/22-gateway-operations.md@@ -128,7 +128,7 @@ helm upgrade --install gateway ./deploy/helm/openviking-gateway \The default is one SQLite replica with a persistent volume and `Recreate` updates. A default StorageClass, or `persistence.storageClass`/`persistence.existingClaim`, must be available. Setting `persistence.enabled: false` loses SQLite state when a Pod is replaced; Helm NOTES warns about this. PVCs are retained on uninstall. Use both Redis providers before scaling; see [Scaling](#scaling).-The chart sets `session_ttl_days: 7` and `response_ttl_seconds: 604800`, shorter than the gateway's 30-day defaults; override `config.*` to change them. Each Pod requests 500m CPU and 1Gi of memory, with limits of 2 CPUs and 4Gi; set `resources` for your load.+The chart sets `session_ttl_seconds: 604800` and `response_ttl_seconds: 604800`, shorter than the gateway's 30-day defaults; override `config.*` to change them. Each Pod requests 500m CPU and 1Gi of memory, with limits of 2 CPUs and 4Gi; set `resources` for your load.The standalone chart's `existingSecret` accepts `management-key`, `redis-password` and `root-key`. The first two become `OPENVIKING_GATEWAY_MANAGEMENT_KEY` and `OPENVIKING_GATEWAY_REDIS_PASSWORD`; `config.storage.redis.password_env` names the latter. Local and KMS encryption mount `root-key` read-only at `/etc/openviking-gateway/keys/root-key` and set the provider's `key_file` to it. Generate the key before installing, as described under [Encryption](#encryption). For upstream credentials and KMS AK/SK, use `$VAR` in `config` and `extraEnv` with `secretKeyRef`; never put plaintext credentials in a ConfigMap.diff --git a/docs/zh/about/02-changelog.md b/docs/zh/about/02-changelog.mdindex ac9d5151a..5a1d8329a 100644--- a/docs/zh/about/02-changelog.md+++ b/docs/zh/about/02-changelog.md@@ -16,6 +16,8 @@ OpenViking 的所有重要变更都将记录在此文件中。默认存储仍是 SQLite。- 新增 `X-OpenViking-Upstream-URL` 请求头,按 Base URL 从允许的上游中选择一个,见[按请求指定上游](../gateway/07-upstreams.md#upstream-url-header)。+ - `session_ttl_seconds`(不低于 3600)取代 `session_ttl_days`,对话可以在一天内过期;+ 旧字段会被忽略并在启动时打印警告,升级时请改用新字段。- 无需修改配置的行为变化:独立网关 keep-alive 从 5 秒提高到 75 秒;绑定公网地址的网关在启动时遇到 OpenViking 不可达或返回 5xx 会等待并重试;空闲 SSE 流每 15 秒发送一条注释心跳;OpenViking 以 402 或 403 拒绝密钥的请求会被拒绝,diff --git a/docs/zh/gateway/06-manage-in-studio.md b/docs/zh/gateway/06-manage-in-studio.mdindex cef097d70..b060bf13f 100644--- a/docs/zh/gateway/06-manage-in-studio.md+++ b/docs/zh/gateway/06-manage-in-studio.md@@ -86,7 +86,7 @@ description: Studio 中 OpenViking 网关页面的使用方法:各标签页、对话在第一个请求时记下当时的上下文配置并一直沿用,因为中途改变模型看到的内容会破坏服务商的[提示词缓存](01-how-it-works.md#replay)。所以客户端多快能用上新的上下文配置,取决于它多久开始一次新对话:- 每次聊天都新开对话的客户端,很快就能用上新设置。-- Claude Code、Codex 以及发送固定会话请求头的客户端,会把一段对话延续很多天。它们一直沿用旧设置,直到开始新对话,或者这段对话闲置满 30 天(`session_ttl_days`),此时网关会删除这段对话的状态。+- Claude Code、Codex 以及发送固定会话请求头的客户端,会把一段对话延续很多天。它们一直沿用旧设置,直到开始新对话,或者这段对话闲置满 30 天(`session_ttl_seconds`),此时网关会删除这段对话的状态。网关如何区分不同的对话,见[网关如何识别对话](03-connect-clients.md#how-conversations-are-recognized)。diff --git a/docs/zh/gateway/09-gateway-keys.md b/docs/zh/gateway/09-gateway-keys.mdindex 4c61d66ca..0ad445b8e 100644--- a/docs/zh/gateway/09-gateway-keys.md+++ b/docs/zh/gateway/09-gateway-keys.md@@ -31,7 +31,7 @@ description: 签发把客户端接入 OpenViking 网关的网关密钥,并在按密钥隔离时,轮换 OpenViking 密钥会进入新分区并开始新对话。排障时可以不输出密钥,直接计算分区名:`"k_" + hashlib.sha256(("openviking\0" + key).encode()).hexdigest()`。OpenViking 的真实账号身份单独保存,用于吊销检查。-缓存的 OpenViking 密钥及其用户记录,从创建时起经过配置的 `session_ttl_days` 后过期,请求不会续期。下一个请求会向 OpenViking 重新确认密钥并重建记录,分区和对话 scope 保持不变。签发的网关密钥没有这项 TTL。待写回内容和清理行为见[保留期限](11-security-and-data.md#retention)。+缓存的 OpenViking 密钥及其用户记录,从创建时起经过配置的 `session_ttl_seconds` 后过期,请求不会续期。下一个请求会向 OpenViking 重新确认密钥并重建记录,分区和对话 scope 保持不变。签发的网关密钥没有这项 TTL。待写回内容和清理行为见[保留期限](11-security-and-data.md#retention)。如果客户端需要自己的上下文配置、上游或允许的模型,或者需要单独吊销,请使用网关密钥。diff --git a/docs/zh/gateway/11-security-and-data.md b/docs/zh/gateway/11-security-and-data.mdindex 056bfb863..c21261b77 100644--- a/docs/zh/gateway/11-security-and-data.md+++ b/docs/zh/gateway/11-security-and-data.md@@ -69,8 +69,8 @@ SQLite 文件只有运行网关的系统用户能读取;Redis 由网络和 ACL| 数据 | 保留时长 | 设置 || --- | --- | --- |-| 对话状态 | 最后一次使用后 30 天 | `session_ttl_days` |-| 缓存的 OpenViking 密钥及其用户记录 | 从创建时起经过配置的 TTL,不续期 | `session_ttl_days` |+| 对话状态 | 最后一次使用后 30 天 | `session_ttl_seconds` |+| 缓存的 OpenViking 密钥及其用户记录 | 从创建时起经过配置的 TTL,不续期 | `session_ttl_seconds` || 存储的请求日志 | 30 天 | `log_retention_days` || Responses 响应与上游的对应关系 | 30 天 | `response_ttl_seconds` || OpenViking 中的会话和记忆 | 遵循 OpenViking 自己的规则 | — |@@ -83,7 +83,7 @@ Redis 每个账号最多保留 10,000 条请求日志。读取时跳过早于 `l## Redis 对话状态 {#redis-conversation-state}-配置 `storage.kernel: redis` 后,对话状态按缓存保存,TTL 使用 `session_ttl_days`。写入会续期,只读记录不会续期。+配置 `storage.kernel: redis` 后,对话状态按缓存保存,TTL 使用 `session_ttl_seconds`。写入会续期,只读记录不会续期。驱逐会产生以下影响:@@ -108,7 +108,7 @@ Redis 异步主从切换可能丢失最近的写入或 lease,偶尔导致 capt| root | 调用 `DELETE /gateway/admin/account/data?account_id=<account>` | 整个账号的网关数据 || 嵌入部署,自动进行 | 在 OpenViking 中删除用户或账号 | 对应的网关数据 |-独立部署没有自动删除这一步,数据会一直保留,直到被显式删除或[过期](#retention)。设置 [`management_api: false`](13-configuration.md#gateway-fields) 后,删除 API 也不可用:在 OpenViking 中删除用户不会通知独立网关,对话状态只能等 `session_ttl_days` 到期后清理。请求日志和响应映射按各自的保留期限过期。按账号隔离的嵌入部署仍保留 Server 的自动删除钩子。按密钥隔离时,钩子无法根据 OpenViking 的账号和用户 ID 找到 `k_` 分区,其缓存数据按上述保留期限清理。+独立部署没有自动删除这一步,数据会一直保留,直到被显式删除或[过期](#retention)。设置 [`management_api: false`](13-configuration.md#gateway-fields) 后,删除 API 也不可用:在 OpenViking 中删除用户不会通知独立网关,对话状态只能等 `session_ttl_seconds` 到期后清理。请求日志和响应映射按各自的保留期限过期。按账号隔离的嵌入部署仍保留 Server 的自动删除钩子。按密钥隔离时,钩子无法根据 OpenViking 的账号和用户 ID 找到 `k_` 分区,其缓存数据按上述保留期限清理。已存入 OpenViking 的记忆和会话不受这些操作影响。反过来,在 OpenViking 中删除一条记忆后,网关为进行中的对话保存的那份副本仍会被原样放回,直到对话过期;要立即清除,删除该用户的网关数据。diff --git a/docs/zh/gateway/13-configuration.md b/docs/zh/gateway/13-configuration.mdindex 487bb99cf..77b42795a 100644--- a/docs/zh/gateway/13-configuration.md+++ b/docs/zh/gateway/13-configuration.md@@ -41,7 +41,7 @@ description: 查询 OpenViking 网关的配置字段、环境变量、上下文| `default_upstreams` | 两者 | `{}` | 稳定 ID 到[上游设置](#upstream-settings)的对象映射 | 账号没有存储上游时供 OpenViking 密钥使用,见[部署默认上游](07-upstreams.md#deployment-default-upstreams) || `default_profile` | 两者 | 内置上下文配置默认值 | [上下文配置设置](#context-profile-settings) | 账号没有 ID 为 `default` 的配置时使用,也是嵌入式 dev 模式初始化写入的配置 || `min_server_version` | 两者 | `0.4.16` | 版本号 | 独立网关要求的 OpenViking Server 最低版本 |-| `session_ttl_days` | 两者 | `30` | 1 及以上 | 对话闲置多少天后过期;也决定缓存的 OpenViking 密钥及其用户记录的固定寿命 |+| `session_ttl_seconds` | 两者 | `2592000`(30 天) | 3600 及以上 | 对话闲置多少秒后过期;也决定缓存的 OpenViking 密钥及其用户记录的固定寿命 || `response_ttl_seconds` | 两者 | `2592000`(30 天) | 60 及以上 | Responses 响应与上游的对应关系保留多少秒 || `request_log_sink` | 两者 | `store` | `store`, `stdout` | 将请求和后台保存日志写入存储,或以每条一行 JSON 写到 stdout 并立即刷新;见[观测](../guides/22-gateway-operations.md#monitoring) || `log_retention_days` | 两者 | `30` | 1 及以上 | 存储中的请求日志保留天数;stdout 的保留期限由日志采集系统管理 |@@ -89,7 +89,7 @@ description: 查询 OpenViking 网关的配置字段、环境变量、上下文"command_timeout_ms": 5000}},- "session_ttl_days": 7+ "session_ttl_seconds": 604800}```@@ -134,7 +134,7 @@ OPENVIKING_GATEWAY_MANAGEMENT_KEY='<management-key>'| `tenancy` | `key` 要求 `management_api: false`;`openviking_keys` 关闭时此字段不生效 || `client_rules` | 新增的模式必须是合法的 Python 正则表达式;新增的标签名以英文字母开头,只能包含英文字母、数字、`_`、`.`、`:` 和 `-` || 未知字段 | 校验失败 |-| 已删除的字段 | 忽略,启动时打印警告:`encryption_key_env`,以及 `ov.conf` 中[迁移](../guides/22-gateway-operations.md#migration)列出的 v0.5 字段 |+| 已删除的字段 | 忽略,启动时打印警告:`encryption_key_env`、`session_ttl_days`(已由 `session_ttl_seconds` 取代),以及 `ov.conf` 中[迁移](../guides/22-gateway-operations.md#migration)列出的 v0.5 字段 |## 客户端规则 {#client-rules}diff --git a/docs/zh/guides/22-gateway-operations.md b/docs/zh/guides/22-gateway-operations.mdindex 9e481d7a8..d01421f64 100644--- a/docs/zh/guides/22-gateway-operations.md+++ b/docs/zh/guides/22-gateway-operations.md@@ -128,7 +128,7 @@ helm upgrade --install gateway ./deploy/helm/openviking-gateway \默认使用单副本 SQLite、持久卷和 `Recreate` 更新策略。集群必须有默认 StorageClass,或配置 `persistence.storageClass`/`persistence.existingClaim`。设置 `persistence.enabled: false` 后,更换 Pod 会丢失 SQLite 状态,Helm NOTES 会显示警告。卸载会保留 PVC。扩容前必须把两个 provider 都改成 Redis,见[扩展](#scaling)。-chart 设置了 `session_ttl_days: 7` 和 `response_ttl_seconds: 604800`,比网关 30 天的默认值短;需要其他值时覆盖 `config.*`。每个 Pod 请求 500m CPU 和 1Gi 内存,上限为 2 CPU 和 4Gi;可按负载设置 `resources`。+chart 设置了 `session_ttl_seconds: 604800` 和 `response_ttl_seconds: 604800`,比网关 30 天的默认值短;需要其他值时覆盖 `config.*`。每个 Pod 请求 500m CPU 和 1Gi 内存,上限为 2 CPU 和 4Gi;可按负载设置 `resources`。独立 chart 的 `existingSecret` 接受 `management-key`、`redis-password` 和 `root-key`。前两项分别注入 `OPENVIKING_GATEWAY_MANAGEMENT_KEY` 和 `OPENVIKING_GATEWAY_REDIS_PASSWORD`;`config.storage.redis.password_env` 指向后者。local 和 KMS 加密把 `root-key` 只读挂载到 `/etc/openviking-gateway/keys/root-key`,并将 provider 的 `key_file` 指向它。安装前先按[加密](#encryption)生成密钥。上游凭证和 KMS AK/SK 在 `config` 中写 `$VAR`,通过 `extraEnv` 的 `secretKeyRef` 注入,不要将明文凭证写入 ConfigMap。diff --git a/openviking_gateway/app.py b/openviking_gateway/app.pyindex 809cb7ba1..c92509a20 100644--- a/openviking_gateway/app.py+++ b/openviking_gateway/app.py@@ -108,7 +108,7 @@ def open_stores(config: GatewayConfig, encryptor):handle.client, settings.key_prefix, AsyncCodec(encryptor))if settings.kernel == "redis":- store = redis_store.RedisKernelStore(backend, ttl=config.session_ttl_days * 86400)+ store = redis_store.RedisKernelStore(backend, ttl=config.session_ttl_seconds)else:store = SQLiteKernelStore(config.directory / "kernel.sqlite3", encryptor)# SQLite threads may still wait on this loop for the encryptor.@@ -196,7 +196,7 @@ def create_app(config: GatewayConfig, *, openviking_url: str, vlm_source=None, easync def cleanup_loop():while True:try:- await store.expire(time.time() - config.session_ttl_days * 86400)+ await store.expire(time.time() - config.session_ttl_seconds)await management.expire_logs(time.time() - config.log_retention_days * 86400)await asyncio.sleep(3600)except Exception:diff --git a/openviking_gateway/config.py b/openviking_gateway/config.pyindex fd74eec83..b8939df16 100644--- a/openviking_gateway/config.py+++ b/openviking_gateway/config.py@@ -94,7 +94,7 @@ class StorageConfig(BaseModel):class GatewayConfig(BaseModel):model_config = ConfigDict(extra="forbid")# Settings an upgraded configuration may still carry; rejecting them would stop the host.- removed_fields: ClassVar[frozenset[str]] = frozenset({"encryption_key_env"})+ removed_fields: ClassVar[frozenset[str]] = frozenset({"encryption_key_env", "session_ttl_days"})public_url: str = ""mcp_file_links: Literal["proxy", "direct"] = "proxy"@@ -109,7 +109,8 @@ class GatewayConfig(BaseModel):default_upstreams: dict[str, Upstream] = Field(default_factory=dict, repr=False)default_profile: Policy = Field(default_factory=Policy)min_server_version: str = "0.4.16"- session_ttl_days: int = Field(default=30, ge=1)+ # The 3600 floor keeps sessions alive past capture's default 600-second idle tail.+ session_ttl_seconds: int = Field(default=30 * 86400, ge=3600)response_ttl_seconds: int = Field(default=30 * 86400, ge=60)request_log_sink: Literal["store", "stdout"] = "store"log_retention_days: int = Field(default=30, ge=1)diff --git a/openviking_gateway/management.py b/openviking_gateway/management.pyindex ae5405cf2..4d48e34c4 100644--- a/openviking_gateway/management.py+++ b/openviking_gateway/management.py@@ -214,7 +214,7 @@ async def openviking_credential(app, key):account, user_id = identity["account_id"], identity["user_id"]if partitioned:account = "k_" + identifier- ttl = app.state.config.session_ttl_days * 86400+ ttl = app.state.config.session_ttl_secondsstored = {"source": "openviking","openviking_account": identity["account_id"],diff --git a/tests/gateway/e2e/test_resilience.py b/tests/gateway/e2e/test_resilience.pyindex ad6009fa5..6159adb27 100644--- a/tests/gateway/e2e/test_resilience.py+++ b/tests/gateway/e2e/test_resilience.py@@ -73,11 +73,23 @@ def test_02_default_grace_finishes_stream_and_other_pod_delivers(harness):)assert len(snapshot["libraries"]["library-a"]["sessions"]) == 1writes = [r for r in snapshot["requests"] if r["path"].endswith("/messages/batch")]- assert all(r["source_pod"] != victim_ip for r in writes), writesids = [source for r in writes for m in r["body"]["messages"] for source in m["source_message_ids"]]assert len(ids) == len(set(ids)) == 4+ # The next request confirms the first turn, so the victim may deliver it+ # immediately. Only the final, idle-delayed tail must survive on another Pod.+ tail_ids = {+ source+ for message in written_messages(snapshot)[-2:]+ for source in message["source_message_ids"]+ }+ tail_writes = [+ r+ for r in writes+ if any(tail_ids.intersection(m["source_message_ids"]) for m in r["body"]["messages"])+ ]+ assert tail_writes and all(r["source_pod"] != victim_ip for r in tail_writes), tail_writes@pytest.mark.standalonediff --git a/tests/gateway/test_gateway_config.py b/tests/gateway/test_gateway_config.pyindex 31f055379..5cb421423 100644--- a/tests/gateway/test_gateway_config.py+++ b/tests/gateway/test_gateway_config.py@@ -51,6 +51,13 @@ def test_removed_fields_are_ignored_with_one_warning(caplog):StandaloneGatewayConfig(openviking_url="http://localhost:1933", url="http://other")+def test_session_ttl_ignores_legacy_days_and_rejects_under_an_hour():+ assert GatewayConfig(session_ttl_days=7).session_ttl_seconds == 30 * 86400+ assert GatewayConfig(session_ttl_seconds=7200).session_ttl_seconds == 7200+ with pytest.raises(ValidationError):+ GatewayConfig(session_ttl_seconds=600)++def test_standalone_requires_own_url_and_rejects_server_config():with pytest.raises(ValidationError):StandaloneGatewayConfig()diff --git a/tests/gateway/test_management.py b/tests/gateway/test_management.pyindex 0179c4724..af75ae6f4 100644--- a/tests/gateway/test_management.py+++ b/tests/gateway/test_management.py@@ -856,7 +856,7 @@ async def test_revoked_capture_is_idle_until_ttl_expires(running_gateway):).fetchone()[0]== touched)- await app.state.store.expire(time.time() + app.state.config.session_ttl_days * 86400)+ await app.state.store.expire(time.time() + app.state.config.session_ttl_seconds)assert not (await app.state.store.capture.get(scope, session)).valuediff --git a/tests/gateway/test_storage_ports.py b/tests/gateway/test_storage_ports.pyindex 30d45870a..1ca1572f1 100644--- a/tests/gateway/test_storage_ports.py+++ b/tests/gateway/test_storage_ports.py@@ -881,7 +881,7 @@ async def test_open_stores_shares_redis_and_reads_across_instances(provider, tmpmonkeypatch.setattr(redis_store, "connect", opened)config = GatewayConfig(storage_path=str(tmp_path),- session_ttl_days=2,+ session_ttl_seconds=2 * 86400,log_retention_days=3,storage={"kernel": "redis",diff --git a/tests/gateway/test_tenancy.py b/tests/gateway/test_tenancy.pyindex 3c70c6096..e088cb6dc 100644--- a/tests/gateway/test_tenancy.py+++ b/tests/gateway/test_tenancy.py@@ -24,7 +24,7 @@ def gateway_config(request, gateway_backend):"default_upstreams": default_upstreams(gateway_backend[0]),"openviking_keys": True,"tenancy": "key",- "session_ttl_days": 7,+ "session_ttl_seconds": 7 * 86400,"default_profile": {"gateway_tools": False},**getattr(request, "param", {}),}