Skip to content

fix(chat): avoid global registry timestamp churn failing bound steward prep - #9265

Merged
loopx-agent merged 1 commit into
mainfrom
codex/fix-steward-context-prep-20261122
Nov 22, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/fix-steward-context-prep-20261122

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Stop redundant multi-goal global registry rewrites on unchanged syncs (loopx/global_registry.py): When syncing a single goal_id from a multi-goal source registry, merge_goal_entries previously refreshed synced_at on every unchanged sibling unconditionally, causing every refresh-state call to rewrite the global registry updated_at and sibling synced_at timestamps even when nothing changed. Only advance unchanged sibling synced_at when an incoming goal actually changed (or the sibling lacks synced_at), preserving test_sqlite_archive_and_registry_health staleness semantics while eliminating no-op global-registry churn.
  • Keep bound_steward context recollection resilient to sync-timestamp-only touches (loopx/goal_portfolio.py, loopx/chat_manager_context.py): On the local recollection retry (attempt > 0 for bound_steward without inline SSH grants), ignore top-level updated_at and per-goal synced_at churn when verifying inventory_semantic_revision while keeping all exact Goal identity/instance/metadata checks, attempt == 0 recollection, and non-bound_steward fail-closed guarantees intact.
  • Match canonical write RPC timeout on commit_execution_loss_closeout (loopx/control_plane/quota/execution_preparation.py): Pass CANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS (45s) instead of relying on the default 10s RPC budget when closing out large file authority logs.

Verification

  • ruff check on all 7 modified files: passed.
  • pytest -q tests/test_global_registry_write_serialization.py tests/control_plane/test_sqlite_archive_and_registry_health.py tests/test_chat_manager_context.py tests/control_plane/test_execution_loss_closeout_cli.py tests/test_manager_preparation_recovery.py: 105 passed.
  • loopx check public boundary scan (7 files): ok: true, zero boundary warnings/errors.
  • loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main: ok: true (3/3 catalog canaries passed, failures: 0).

…d prep

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gemini-4-carbon-high · google_antigravity (self_reported, high)

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

Reviewed exact head: ad5ab9abae96bdd052e9f4e9097e7dfc696b95f3

动机 / Motivation

当多 Goal 同仓项目定期执行状态刷新与 sync-global 同步时,global_registry 会把来源未变的 sibling synced_at 与全局 updated_at Timestamp(同步时间戳)一并重写,导致全局注册表文件字节哈希每分钟都在发生非语义变动。与此同时,绑定管家在轮次前通过 collect_manager_turn_context 并发读取多 Goal 组合状态与证据历史,只要两次重试期间全局注册表的同步时间戳再次被刷新,原本授权作用域并未改变,本轮也会因原始哈希不一致而连续两次失败并抛出 manager_authorization_unavailable,使用户正常提问与自愈指令在模型调用前直接中断。此外,commit_execution_loss_closeout 在读取大型文件权威日志时沿用了默认 10 秒 RPC 超时,容易在落盘前误报响应不确定。不做本修复则会持续造成多 Goal 场景下的并发准备失败与失租收口误判;本 PR 以最小侵入修复上述三处根因并补充单测验证,剩余低频状态采集耗时优化可在后续独立切片推进。

改动思路 / Approach

本 PR 在既有状态所有权和 fail-closed 授权边界内,按“抑制无意义写入 + 区分同步时间戳抖动与真实语义变更 + 对齐写入 RPC 超时”的最小边界收口,不新增平行状态所有者或公共协议字段:

  • 写入端去抖(loopx/global_registry.py):在 merge_goal_entries 中显式追踪 incoming_changed,仅当本次导入的目标 Goal 真正新增或内容变化、或 sibling 尚无 synced_at 时才推进未改动 sibling 的 synced_at;当整次同步无任何语义变化时,结合已有 updated_at 保留逻辑,使 _mutate_global_registry_locked 命中 wrote=False 跳过磁盘覆写。
  • 读取端语义校验(loopx/goal_portfolio.py、loopx/chat_manager_context.py):复用 decode_registry_snapshot 提取 registry_semantic_revision,仅剥离顶层 updated_at 与 goals[*].synced_at 两个同步时间戳字段,保留 goal_instance_id、activation、route 与其余全部字段。重采集参数 ignore_sync_timestamp_churn 默认关闭,仅在 collect_manager_turn_context 的第二次本地重试且会话为 bound_steward(无 inline SSH 授权)时启用。
  • 失租收口超时对齐(loopx/control_plane/quota/execution_preparation.py):commit_execution_loss_closeout 改用控制面已定义的 CANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS(45s),匹配权威写入锁与大日志加载耗时窗口,保持单次提交语义与幂等边界不变。

具体改动 / Changes

无独立书面设计规格/RFC(no written specification exists for this internal fix);以下对照问题验收约束列出具体改动与关键符号:

关键代码讲解

  1. merge_goal_entries(loopx/global_registry.py):
    在扫描 incoming 列表时记录 incoming_changed;仅当存在新增 Goal 或除 synced_at 外任意字段变化时设为 True。随后处理 unchanged_siblings 时要求 incoming_changed or not item.get("synced_at"),既保持 stale_source_registry 健康检查对真实变更后 sibling 时间戳推进的既有语义,又消除无变化 heartbeat 导致的全局注册表高频重写。
  2. registry_semantic_revision 与 build_goal_portfolio(loopx/goal_portfolio.py):
    新增内部辅助函数 registry_semantic_revision,使用 decode_registry_snapshot 解析并在捕获畸形/异常输入时返回 None(fail-closed);在 build_goal_portfolio(..., ignore_sync_timestamp_churn=False) 中当显式开启 ignore_sync_timestamp_churn=True 时,采集前后字节不同但 registry_semantic_revision 一致则判定 changed = False,并返回 inventory_semantic_revision 供上层范围校验使用。
  3. manager_authorization_scope_id_for_registry、manager_turn_context 与 collect_manager_turn_context(loopx/chat_manager_context.py):
    为 manager_authorization_scope_id_for_registry 与 manager_turn_context 增加可选 expected_inventory_semantic_revision / ignore_sync_timestamp_churn=False 参数;仅在 collect_manager_turn_context 的 attempt > 0 and bound_steward and not inline_remote 条件成立时传入 ignore_sync_timestamp_churn=True,使绑定管家在重采集阶段容忍外部仅刷新 updated_at/synced_at 的并发触碰。
  4. commit_execution_loss_closeout(loopx/control_plane/quota/execution_preparation.py):
    向 effect_runtime_result("quota.execution_loss_closeout.commit", ...) 显式传入 timeout=CANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS。
  5. 单测补充:新增 test_single_goal_sync_with_unchanged_siblings_skips_redundant_write、test_bound_steward_survives_repeated_sync_timestamp_churn_but_rejects_semantic_changes 与 test_execution_loss_closeout_uses_canonical_write_timeout 覆盖上述行为与反例。

对主干的风险 / Risks

  • 默认隔离与 fail-closed 保真(default_off_isolation / authority_semantics):ignore_sync_timestamp_churn 默认值为 False,首次尝试(attempt == 0)、非 bound_steward 外部通道及 inline_remote(SSH)通道行为完全保持原样;即便是 bound_steward 的 attempt == 1,一旦 observation_generation、goal_instance_id、Goal 增删或任意非时间戳字段变化,或者快照解码失败,registry_semantic_revision 比对与 manager_authorization_scope_id_for_registry 仍严格 fail-closed 并返回 external_authorization_changed。上述正反例已在 test_chat_manager_context.py 与现有 test_sqlite_archive_and_registry_health.py 中直接验证。
  • 验证结果汇总:
    • ruff check(7 个修改文件):PASS
    • pytest -q tests/test_global_registry_write_serialization.py tests/control_plane/test_sqlite_archive_and_registry_health.py tests/test_chat_manager_context.py tests/control_plane/test_execution_loss_closeout_cli.py tests/test_manager_preparation_recovery.py:105 passed(PASS)
    • loopx check(7 文件公开边界扫描):ok: true,0 错误 0 警告(PASS)
    • loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main:ok: true,3/3 canaries 通过(PASS)

我的整体评价 / Verdict

本改动对长程自主执行(long_horizon)与终端用户体验(user_experience)均具有直接正向收益:消除多 Goal 周期刷新导致的 registry.global.json 高频无效落盘,并根除绑定管家上下文采集阶段因并发同步时间戳触碰引发的假阳性失败,同时修复 execution-loss-closeout 10s RPC 超时问题。未新增公共 schema 或词汇表(仅复用现有注册表解码器并增加局部语义摘要 helper),改动体量收敛可逆,所有既有授权与健康检查回归测试全量通过,残留风险低。

English verdict: APPROVE

@loopx-agent
loopx-agent merged commit c563a47 into main Nov 22, 2026
10 of 12 checks passed
@loopx-agent
loopx-agent deleted the codex/fix-steward-context-prep-20261122 branch November 22, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant