Skip to content

fix(context): preserve native continuity across command workdirs - #7481

Merged
huangruiteng merged 1 commit into
mainfrom
codex/native-context-command-workdir-20261027
Oct 27, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/native-context-command-workdir-20261027

Conversation

@huangruiteng

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

同一原生 Codex Session 完整读取上下文后,把下一条 CLI 命令放在子目录或另一 checkout 执行,会被误判成原生工作区变化:投影退回全量,并删除恢复 journal。结果是正常跨仓库工作丢失差分基线和原始恢复选择器。

本改动让原生生命周期事件继续拥有工作区与 epoch 的判定;CLI 的临时工作目录不再代替该事实。Session、Goal、Agent、完整分页、捕获内容校验和真实工作区变化的隔离保持有效。

Author Declaration

  • Written by: model_agent; OpenAI Codex.
  • Specification: existing native lifecycle ownership in loopx/control_plane/quota/native_context_lifecycle.ts and the native context section of docs/heartbeat-automation-prompt.md, at the baseline above. The defect reproduction distinguishes a command cwd from a native workspace event.
Criterion Disposition Implementation / evidence
Ordinary tool execution preserves continuity implemented Two fresh-process cases move to a nested directory or sibling checkout, retain delta, read the pinned recovery through real CLI, then continue another delta.
Actual native workspace change retires old state implemented SessionStart with a different native workspace clears candidate and recovery, rotates epoch, and the next projection is full.
Recovery stays scoped and read-only implemented Existing different-Session/Goal/Agent, missing identity, private-file, corruption, compaction and incomplete-page cases remain; recovery reads preserve journal bytes.
Presentation does not readmit or spend implemented Real File/SQLite quota integration moves the warm replay to another checkout and retains exact original Turn receipt and spend counts.

Scope And Continuation

Changes the existing Python native IO adapter and its tests/docs. No new owner, state store, protocol vocabulary, configuration, lifecycle rule or permission grant. The old process-cwd negative is replaced by an actual native-workspace transition; malformed workspace metadata remains a negative case. The docs also distinguish qualified native resume from an unqualified SessionStart.

This proposal completes the source repair. Actual installed host adoption and whole-turn cost measurement remain separate acceptance work; this PR does not claim long-horizon effectiveness or measured model retention. An already deleted journal is not recreated by this patch; it needs a genuine native lifecycle boundary and complete current read.

Validation

  • Tested revision: 85d2d252f.
  • Run state: finished for the source suite; supplemental native suite stopped after repeated prerequisite failures.
  • Input classes: synthetic, public_fixture.
Check kind Result Evidence / limitation
regression_parity passed Identical fresh-process nested/sibling regressions fail on immutable main with full fallback; both pass with the fix.
integration / real_backend passed Six Python modules covering lifecycle, resume, boundary, native capture, capture reader and CLI: 262 passed / 66 opt-in native cases skipped. Includes real File and SQLite receipt continuity.
unit passed TypeScript context-delivery suite: 27 passed.
static passed Ruff, Python compilation, bilingual diff check, diff check, and public-boundary scan over all four changed files. Scan used an isolated empty registry; its missing optional runtime is one warning.
real_entrypoint failed Enabling the native suite with Codex 0.153.4 produced 8 failures before the guard could return JSON; stopped further repetition. The first actual tool output contains EffectRuntimeNodeProbeError requiring Node.js 22.22.3+. The same native case fails on immutable main. This is a retained prerequisite failure, not native qualification of this head.
manual / cost passed Three local trials per version, identical 50,000-character synthetic context: full fallback 17 pages / 58,981 response bytes → delta 2 pages / 5,852 bytes; journal survives only after the fix. Local projection+reads median 9.27 ms → 57.35 ms. This measures transport calls/bytes, not model tokens or complete host latency.
integration not_run Full repository CI and live model adoption remain unqualified here.

The native prerequisite failure occurs upstream of the changed projection path. The passing source suite does not waive that native gap or CI/review requirements.

Frontend / Visual Evidence

UI impact: none. Existing CLI transport and lifecycle hooks; no screen or activation control changes. Screenshots are not applicable.

Type of Change / LoopX Area

  • Bug fix
  • Test and documentation update
  • Host or runtime integration

Shared-authority RFC fixture impact: N/A; no provider routing or authority schema change.

Boundary Checklist

  • Only public-safe code, synthetic fixtures and aggregate evidence; no private traces, endpoints, local paths or credentials.
  • No benchmark settings, scoring, running jobs or host scheduling changed.
  • No paired RFC changed; bilingual diff check passed.
  • UI impact is none.
  • Commit is DCO signed off.

Signed-off-by: huangruiteng <huangrt01@163.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max

动机 / Motivation

在同一原生 Codex 会话中跨子目录或 checkout 执行 LoopX 命令的用户会遇到此问题。此前仅改变命令的工作目录就会丢失已完整读取的差分基线及原始恢复入口;现在保留原会话连续性,真正的原生工作区切换仍清除旧恢复状态。这会中断正常跨仓库工作,让用户重新寻找原上下文,而不是继续已授权的任务。同一夹具在 base 的三项场景均失败、head 三项通过;原生 CLI 的完整读取、差分与压缩恢复路径通过。本 PR 只修复现有可选上下文传输的目录识别,不改变准入、配额、权限或默认激活,也不证明安装态、模型记忆或总体成本收益。

改动思路 / Approach

生命周期判断沿用 TypeScript owner,Python 仅负责提供方私有文件与传输;删去重复目录条件比新增状态或适配层更合适。当前 PR 边界是恢复同一原生会话的跨命令目录连续性,并保留真实工作区变化、失去上下文和恢复的既有边界。原生事件提供 session、workspace 与 epoch;单条 shell 命令的目录只是执行位置。投影和恢复读取都删除这项错误比较,仍检查会话、Goal/Agent、完整分页、私有文件和捕获摘要。只修其中一个入口会留下另一处失败;提高超时或强制所有命令回到同一目录也无法修正身份来源。正向检查跨目录继续,反向检查真正工作区切换后不能借用旧状态。

具体改动 / Changes

完整审阅 base 17b2a0f9b818dc6e6fe77ccc567b20ff91b3bc40 → head 85d2d252fefb6a9fe1e50f3df2dad66a261d14bd,4 文件 +98/-22:生产适配 +5/-6,两处集成测试与一份运行说明;没有新增状态、配置、协议或权限规则。

关键代码讲解

  • read_codex_context_reference:187:失去上下文后,只从同一原生 session 和匹配 Goal/Agent 的 journal 选择原始捕获。此读操作不写 journal;后续页固定原始路径与 digest,不跟随移动选择器。删除 cwd 相等条件使子目录和 sibling checkout 都能读取同一原始恢复材料。
  • project_codex_context:448:在锁内验证原生身份和 epoch,先提交当前原始恢复,再尝试差分。命令目录变化不再删除 journal;真实生命周期变化仍由现有 TypeScript owner 清理,缺失或不安全状态仍拒绝或全量回退。
  • test_native_workspace_change_retires_previous_recovery:228:用实际 SessionStart 工作区事件验证 epoch 变化、旧 candidate/recovery 消失、旧入口拒绝,随后即使命令目录仍旧,也能准备新的全量材料。不是把真实工作区隔离测试改成不再检查。

规范 spec_ref=docs/heartbeat-automation-prompt.md#opt-in-native-context-delivery、spec_revision=17b2a0f9b818dc6e6fe77ccc567b20ff91b3bc40:native lifecycle owns continuity 对应两处入口及跨目录正例;actual context loss and original recovery 对应原生工作区、压缩恢复与原 Turn 结算;explicit opt-in and authority boundary 对应关闭路径和不受支持 host 反例,三项均 implemented。文档的 qualified same-session resume 只是明确原有已验证 checkpoint 例外;完整读取、证据来源、恢复次序、停止条件和权限边界没有删除。

对主干的风险 / Risks

未发现阻塞问题。同一冻结夹具只切换实际源码根目录,不改变断言或 30 秒超时:base 三项失败,head 三项通过。第三个 base 失败发生在真实失效后准备新全量材料,前面的旧状态清除断言已经通过;不能把它误报成 base 的安全隔离失败。默认关闭与配置往返的 base/head 各 46 项通过,完整输出一致。

独立专项 278 通过、66 个可选原生场景跳过;另以 Codex 0.163.0-alpha.11.1 实际执行一项 native exec 全量→差分→压缩→原始恢复用例,通过。它使用隔离的源码 CLI 与确定性本地模型观察器,不等于真实模型理解。27 项 TS 上下文协议测试、Ruff、配置中的 17 文件 mypy、control-plane typecheck、语义检查和四文件公共边界扫描通过。语义检查首次因本地生成清单缺失未执行,生成后原检查通过,首次结果保留。Standard premerge 的 6 项 direct、14 项 selected(5 catalog、8 risk、1 boundary)全部 PASS,无失败或 manual hold;严格变更质量回执也与本 head 的完整 diff 匹配。

作者记录的旧原生二进制失败及延迟反例仍按原条件保留;本轮单一当前原生通过不把历史失败改成通过,也不建立总体 token、延迟或成本收益。未查询或等待远端 CI。

我的整体评价 / Verdict

APPROVE;交付判断 goal_achieved,仅指这个可复验的目录识别修复。long_horizon=preserved、user_experience=improved:原始承诺和结算身份不变,跨命令目录继续不需要额外确认,真实上下文失效仍有完整恢复路径。逐文件检查仅涉及 Python 传输适配、测试与运行说明,没有渲染组件、布局或样式变化;CLI 结果已实际读回。安装态 App、页面视觉、全部原生组合与真实模型采纳仍未验证。

代码量必要,同域简化已在这次删除重复条件中落实;无需再建一套生命周期或抽象。源码与所选原生路径通过不等于部署、安装或合并授权。

English verdict: APPROVE 85d2d25; command workdir changes preserve native continuity while real workspace invalidation and original-capture recovery remain enforced.

@huangruiteng
huangruiteng merged commit 05e85ec into main Oct 27, 2026
29 of 43 checks passed
@huangruiteng
huangruiteng deleted the codex/native-context-command-workdir-20261027 branch October 27, 2026 10:33
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.

2 participants