Repository navigation
fix(chat): avoid global registry timestamp churn failing bound steward prep - #9265
Conversation
…d prep Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
There was a problem hiding this comment.
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);以下对照问题验收约束列出具体改动与关键符号:
关键代码讲解
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 导致的全局注册表高频重写。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供上层范围校验使用。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的并发触碰。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。- 单测补充:新增
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 个修改文件):PASSpytest -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
Summary
loopx/global_registry.py): When syncing a singlegoal_idfrom a multi-goal source registry,merge_goal_entriespreviously refreshedsynced_aton every unchanged sibling unconditionally, causing everyrefresh-statecall to rewrite the global registryupdated_atand siblingsynced_attimestamps even when nothing changed. Only advance unchanged siblingsynced_atwhen an incoming goal actually changed (or the sibling lackssynced_at), preservingtest_sqlite_archive_and_registry_healthstaleness semantics while eliminating no-op global-registry churn.bound_stewardcontext recollection resilient to sync-timestamp-only touches (loopx/goal_portfolio.py,loopx/chat_manager_context.py): On the local recollection retry (attempt > 0forbound_stewardwithout inline SSH grants), ignore top-levelupdated_atand per-goalsynced_atchurn when verifyinginventory_semantic_revisionwhile keeping all exact Goal identity/instance/metadata checks,attempt == 0recollection, and non-bound_stewardfail-closed guarantees intact.commit_execution_loss_closeout(loopx/control_plane/quota/execution_preparation.py): PassCANONICAL_AUTHORITY_WRITE_TIMEOUT_SECONDS(45s) instead of relying on the default 10s RPC budget when closing out large file authority logs.Verification
ruff checkon 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 checkpublic 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/3catalog canaries passed,failures: 0).