Skip to content

Commit ebc2366

Browse files
committed
feat(config): add github_sync.poll_interval_seconds with validation and restart-required reload (OX-55)
Signed-off-by: Eli Ma <eli@patch.sh>
1 parent 15144db commit ebc2366

12 files changed

Lines changed: 133 additions & 8 deletions

File tree

‎config/config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ ssh_receive_pack = false
403403
# report_timeout_seconds = 60
404404
# exit_timeout_seconds = 15
405405
# diagnostic_budget_bytes = 4096
406+
# poll_interval_seconds = 60 # range 10..=3600; restart-required
406407
# [[github_sync.bindings]]
407408
# id = "core"
408409
# path = "/project/core"

‎docs/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ One line of purpose and the key entries per section; full comments and defaults
110110
- **`[oci]`**: `enabled` switch (double-gated with storage-only for `/v2`, otherwise a bare 404) and `accept_user_tokens` (default `false`). In storage-only mode, `/api/v1/user/token*` routes and website session resolution (`WebsiteSessionStore`) are mounted only when `oci.enabled = true`, `oci.accept_user_tokens = true`, and `[oauth].website_api_base_url` is non-empty; enabling `oci.enabled` alone does not mount token routes or switch sessions, and `accept_user_tokens` does not change whether `/v2` accepts `access_token`. Review mode keeps its existing `/api/v1/user/ssh` and user routes. See the [User Guide](./user-guide.md) for product surfaces.
111111
- **`[agent_capture]` (removed)**: the legacy Capture HTTP ingestion section was retired. A config that still carries it is rejected with an explicit removal error instead of being silently ignored; `MEGA_AGENT_CAPTURE__*` environment keys are rejected too. Upload agent history through scoped traces Git and query it through `/api/v1/traces` (see the [traces protocol](./refactoring/traces.md)).
112112
- **`[storage_events]`**: outbound events for committed writes (default off). `enabled` (requires storage-only), `installation_id` (required, never auto-generated), numeric bounds for concurrency / timeouts / graceful shutdown, `[[storage_events.targets]]` (id / https url / `secret_ref` HMAC / events / filter lists). The commented sample and `config validate` describe supported values and validation.
113-
- **`[github_sync]`**: GitHub outbound sync (default off). `enabled`, `ssh_host` / `ssh_user` / `ssh_host_key`, `ssh_key_ref` (a SecretRef string — never put the private key itself here), four timeouts, `[[github_sync.bindings]]` (id / path / remote), and optional `[[github_sync.operator_tokens]]` (`name` / `token` / `bindings` / `actions`; `bindings = ["*"]` never implies any action, empty `actions` or empty token list denies all operator commands without blocking startup; validation and startup fail closed on duplicate/empty `name`, empty `token`, unknown binding IDs, or unknown actions; `config validate --show-sources`, logs, and error paths display only token `name` and config source, never raw token values; changes are restart-required and never hot-reloaded). See [`config.toml`](../config/config.toml) for the full schema.
113+
- **`[github_sync]`**: GitHub outbound sync (default off). `enabled`, `ssh_host` / `ssh_user` / `ssh_host_key`, `ssh_key_ref` (a SecretRef string — never put the private key itself here), four timeouts, `poll_interval_seconds` (periodic Q4 poll interval in seconds: default `60`, valid range `10..=3600`, restart-required on reload; legacy configs omitting it default to `60`), `[[github_sync.bindings]]` (id / path / remote), and optional `[[github_sync.operator_tokens]]` (`name` / `token` / `bindings` / `actions`; `bindings = ["*"]` never implies any action, empty `actions` or empty token list denies all operator commands without blocking startup; validation and startup fail closed on duplicate/empty `name`, empty `token`, unknown binding IDs, or unknown actions; `config validate --show-sources`, logs, and error paths display only token `name` and config source, never raw token values; changes are restart-required and never hot-reloaded). See [`config.toml`](../config/config.toml) for the full schema.
114114
- **`[traces]`**: traces archive switch, default `enabled = false` in every sample profile.
115115
- **Identity and label:** `server_id` is an operator UUID and is required only when enabled; the process never generates it. Reloading config or starting the process again keeps that UUID. Rotating TLS certificates or credentials does not replace it. `scope` is an optional operator label. Changing any of these requires a restart.
116116
- **Protocol budgets:** Protocol budgets are not config fields; the code now fixes them at the values below. Those are all 22 constants in the contract table. The contract is [`refactoring/traces.md`](./refactoring/traces.md).

‎docs/configuration.zh.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mega2 --config /etc/mega2/config.toml config secret check redis.url \
110110
- **`[oci]`**:`enabled` 开关(`/v2` 双重门:storage-only + enabled,缺一只返回裸 404)与 `accept_user_tokens`(默认 `false`)。在 storage-only 形态下,只有 `oci.enabled = true`、`oci.accept_user_tokens = true` 且 `[oauth].website_api_base_url` 非空同时成立时,才挂载 `/api/v1/user/token*` 三条路由并切换到 website 会话;只打开 `oci.enabled` 不挂这些路由,也不切换会话,且 `accept_user_tokens` 不改变 `/v2` 对 `access_token` 的接受。review 形态继续保留既有 `/api/v1/user/ssh` 等路由。见 [`refactoring/oci.md`](./refactoring/oci.md) 与 [`deploy-trunk.md`](./deploy-trunk.md) §10。
111111
- **`[agent_capture]`(已移除)**:旧 Capture HTTP 写入配置已退场。仍携带该节的配置会被显式拒绝而不是静默忽略,`MEGA_AGENT_CAPTURE__*` 环境变量同样被拒绝。Agent 历史改经 scoped traces Git 上传、经 `/api/v1/traces` 查询(见 [traces 协议](./refactoring/traces.md))。
112112
- **`[storage_events]`**:已提交写入的出站事件(默认关)。`enabled`(要求 storage-only)、`installation_id`(必填、不自动生成)、并发 / 超时 / 优雅关闭数值界、`[[storage_events.targets]]`(id / https url / `secret_ref` HMAC / events / 过滤器列表)。冻结校验规则见 [`refactoring/config.md`](./refactoring/config.md) 与 [`refactoring/storage-events.md`](./refactoring/storage-events.md)。
113-
- **`[github_sync]`**:GitHub 出站同步(默认关)。`enabled`、`ssh_host` / `ssh_user` / `ssh_host_key`、`ssh_key_ref`(SecretRef 字符串,勿写私钥本体)、四个超时、`[[github_sync.bindings]]`(id / path / remote),以及可选 `[[github_sync.operator_tokens]]`(`name` / `token` / `bindings` / `actions`;`bindings = ["*"]` 不暗授权任何 action,`actions = []` 或空 token 列表默认拒绝所有操作且不妨碍启动;重复或空 `name`、空 `token`、未知 binding ID 或未知 action 会在校验与启动阶段直接失败;`config validate --show-sources`、日志与错误诊断仅显示 token `name` 与配置来源,永不输出密值;变更属 restart-required,永不热替换,须重启生效)。见 [`refactoring/github-sync.md`](./refactoring/github-sync.md)。
113+
- **`[github_sync]`**:GitHub 出站同步(默认关)。`enabled`、`ssh_host` / `ssh_user` / `ssh_host_key`、`ssh_key_ref`(SecretRef 字符串,勿写私钥本体)、四个超时、`poll_interval_seconds`(Q4 周期轮询间隔秒数:默认 `60`,合法范围 `10..=3600`,热加载属 restart-required 须重启生效;旧配置未设置该字段时按默认 `60` 加载)、`[[github_sync.bindings]]`(id / path / remote),以及可选 `[[github_sync.operator_tokens]]`(`name` / `token` / `bindings` / `actions`;`bindings = ["*"]` 不暗授权任何 action,`actions = []` 或空 token 列表默认拒绝所有操作且不妨碍启动;重复或空 `name`、空 `token`、未知 binding ID 或未知 action 会在校验与启动阶段直接失败;`config validate --show-sources`、日志与错误诊断仅显示 token `name` 与配置来源,永不输出密值;变更属 restart-required,永不热替换,须重启生效)。见 [`refactoring/github-sync.md`](./refactoring/github-sync.md)。
114114
- **`[traces]`**:traces 归档开关。所有示例 profile 的 `enabled` 都是 `false`。
115115
- **身份与标签:**`server_id` 是操作者写入的 UUID,只在启用时必填,进程不会自行生成。配置重载和新进程重新初始化都保留这个 UUID。轮换 TLS 证书或凭据不会替换它。`scope` 是可选的操作者标签。这三项变更都需要重启。
116116
- **协议预算:**协议预算不是配置字段,代码目前把它们固定为下列值。这是契约表里的全部 22 个常量,契约见 [`refactoring/traces.md`](./refactoring/traces.md)。

‎docs/plan/plan-20260920.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,14 +3654,14 @@ docker.yml tag build 双矩阵与 docker manifest job;本计划 REL-OX-01 全
36543654
### Task OX-55:轮询频率配置(implementation)
36553655

36563656
**Task type:** `implementation`
3657-
**Lifecycle / Acceptance:** `pending` / 空
3657+
**Lifecycle / Acceptance:** `in-progress` / `locally-accepted`
36583658
**Description:** 为 OX-61 的单轮 poll 提供有界频率配置,调度/停机由 OX-59 承接。自原 OX-01 的轮询轴拆出。
36593659
**Current evidence:** `src/config/model.rs:78-103` 当前无 interval;`src/config/validate.rs:910-931` 校验 deadline;`src/server/http_server.rs:545-675` 管理服务任务。
36603660
**Acceptance criteria:**
3661-
- [ ] AC-1:`github_sync.poll_interval_seconds` 在 sync enabled 时默认 60,范围 10..=3600;非法值配置失败,reload 为 restart-required。
3662-
- [ ] AC-2:配置样例、模板及英文/中文配置指南注明默认值、上限与 restart-required;旧配置在未设置该字段时仍可加载。
3661+
- [x] AC-1:`github_sync.poll_interval_seconds` 在 sync enabled 时默认 60,范围 10..=3600;非法值配置失败,reload 为 restart-required。
3662+
- [x] AC-2:配置样例、模板及英文/中文配置指南注明默认值、上限与 restart-required;旧配置在未设置该字段时仍可加载。
36633663
**Verification:**
3664-
- [ ] VER-1:`source .env.test && cargo test -p mega2 --lib 'config::tests::github_sync_poll_interval_validation' -- --exact`(new)。
3664+
- [x] VER-1:`source .env.test && cargo test -p mega2 --lib 'config::tests::github_sync_poll_interval_validation' -- --exact`(new)。
36653665
**Dependencies:** `OX-132`。
36663666
**Implementation write set:** `src/config/model.rs`、`src/config/validate.rs`、`src/config/reload.rs`、`src/config/template.rs`、`config/config.toml`(注释)、`docs/refactoring/github-sync.md`、`docs/refactoring/integration.md`、`docs/configuration.md`、`docs/configuration.zh.md`、`docs/plan/plan-20260920.md`。
36673667
**Release write set:** `N/A`(REL-OX-01 plan release child;版本面只由 OX-284 修改)

‎docs/plan/plan-status.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
**2026-11-30 `plan-20260920.md` `OX-55`(轮询频率配置)本地验收完成:** `in-progress / locally-accepted`(G-12)。在 `src/config/{model,validate,reload,template}.rs`、`config/config.toml` 与中英文配置指南新增 `github_sync.poll_interval_seconds`(默认 `60`,合法范围 `10..=3600`,超界校验 fail-closed,热加载纳入 `restart_required_fields` 保持快照不变,旧配置缺省自动加载为 `60`),同步更新 `docs/refactoring/github-sync.md` 与 `docs/refactoring/integration.md`;VER-1(`github_sync_poll_interval_validation`)、全部 6 项 `config::tests::github_sync_*` 回归与 `fmt --check` 全绿。下一卡:`OX-95`。
2+
13
**2026-11-30 `plan-20260920.md` `OX-132`(Q4 unchanged 恢复分派)本地验收完成:** `in-progress / locally-accepted`(G-12)。在 `src/ceres/github_sync/poller.rs` 扩展 `PollRoundDispatchOutcome` 与 `dispatch_poll_verdict` 补齐两条已 parked 的 `RemoteUnchanged` 恢复分支(无 `in_flight` → `OX-63` 无事件 `RecoveredToIdle`,有 `in_flight` → `OX-94` + `OX-116` `PromotedParkedIntent`),其余非 parked `RemoteUnchanged`/`FirstCreate` 保持 `NoTransition`,advertise 错误与 CAS 冲突均终态返回不切换分支且零 Git 写,同步更新 `docs/refactoring/github-sync.md` 与 `docs/refactoring/integration.md`;双 VER(`poll_round_unchanged_recovery_dispatch`、`poll_round_error_no_git_write`)、`OX-121` 回归与 `fmt --check` 全绿。下一卡:`OX-55`。
24

35
**2026-11-30 `plan-20260920.md` `OX-121`(Q4 单轮结果分派)本地验收完成:** `in-progress / locally-accepted`(G-12)。在 `src/ceres/github_sync/poller.rs` 新增 `PollRoundError`、`PollRoundDispatchOutcome`、穷尽式分派器 `dispatch_poll_verdict` 与单轮入口 `run_poll_round`(单次穷尽 `match` 至多执行一条状态转换:`SelfComplete` → `OX-100` + `OX-93`,`RemoteDiverged { has_in_flight: true }` → `OX-92` + `OX-93`,`RemoteDiverged { has_in_flight: false }` → `OX-127` + `OX-93`,其余分类暂返 `NoTransition` 零 cursor 写,零 Git 写句柄),同步更新 `docs/refactoring/github-sync.md` 与 `docs/refactoring/integration.md`;VER-1(`poll_round_dispatch_self_and_diverged`)与 `fmt --check` 全绿。下一卡:`OX-132`。

‎docs/refactoring/github-sync.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ GitHub 出站同步状态变更复用既有 `storage_events` version-1 envelope
16131613
- **`OX-116`(parked intent 原命令重试 CAS):** 在 `src/jupiter/storage/github_sync_cursor.rs` 新增单 SQL identity/generation CAS `poll_promote_parked_intent_cas`(严格要求 `state = 'parked'`、精确 `generation` 与原 `in_flight` 4-tuple 且存在匹配 `github_sync_intent` 行,原子提升为 `in_flight`、清除 `park_reason`、递增 `generation` 并保留原 `in_flight_*` tuple),在 `src/ceres/github_sync/poller.rs` 新增 `PollRetryPromoteOutcome` 与 `apply_poll_parked_intent_retry(&RetryCandidate, &GithubSyncCursorStorage)`(仅接受 `OX-94` 封闭候选,陈旧 CAS 返回 `CasConflict` 不覆盖并发更新,重复 poll 不新建 intent 行,零 Git/SSH 写句柄)。
16141614
- **`OX-121`(Q4 单轮结果分派):** 在 `src/ceres/github_sync/poller.rs` 新增 `PollRoundError`、`PollRoundDispatchOutcome`、穷尽式单轮分派器 `dispatch_poll_verdict` 与组合入口 `run_poll_round`(单次穷尽 `match` 至多执行一条状态转换:`SelfComplete` → `OX-100` + `OX-93`,`RemoteDiverged { has_in_flight: true }` → `OX-92` + `OX-93`,`RemoteDiverged { has_in_flight: false }` → `OX-127` + `OX-93`,其余分类暂返 `NoTransition` 待 `OX-132` 扩展,零 Git 写句柄)。
16151615
- **`OX-132`(Q4 unchanged 恢复分派):** 在 `src/ceres/github_sync/poller.rs` 扩展 `PollRoundDispatchOutcome` 与 `dispatch_poll_verdict` 的 `RemoteUnchanged` 两条已 parked 分支:无 `in_flight` → `OX-63`(`RecoveredToIdle`,无事件),有 `in_flight` → 先 `OX-94` 资格判定再 `OX-116`(`PromotedParkedIntent`,保留原 intent tuple);其余非 parked `RemoteUnchanged` 与 `FirstCreate` 保持 `NoTransition`,advertise 错误或 CAS 冲突即终态返回、不在同轮改选另一分支且零 Git 写。
1616+
- **`OX-55`(轮询频率配置):** 在 `src/config/{model,validate,reload,template}.rs`、`config/config.toml` 与中英文配置指南新增 `github_sync.poll_interval_seconds`(默认 `60`,有效范围 `10..=3600`,超界 fail-closed 拒载,热加载记录为 `restart_required_fields` 保持快照不变,旧配置省略该字段自动按默认 `60` 加载)。
16161617

16171618
## 模板漂移(GAP-07)
16181619

0 commit comments

Comments
 (0)