Skip to content

fix(leases): reject directory and glob write-scope conflicts - #7786

Merged
loopx-agent merged 1 commit into
loopx-project:mainfrom
Jim-jimu:fix/lease-directory-glob-overlap
Nov 1, 2026
Merged

loopx-agent merged 1 commit into
loopx-project:mainfrom
Jim-jimu:fix/lease-directory-glob-overlap

Conversation

@Jim-jimu

@Jim-jimu Jim-jimu commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

  • Outcome basis / optional anchor: reproduced lease exclusion bug; no separate issue.
  • Goal/source and gap: src/ and src/components/*.ts describe overlapping write scopes, but the mixed literal/glob matcher tested only the directory string itself. Two exclusive leases could therefore both be granted in one repository.
  • Observable before → after: standalone task-lease acquire and atomic todo claim now reject the second overlapping lease with write_scope_conflict, leaving canonical state unchanged. Disjoint scopes remain admissible; the regression-parity and real-entrypoint rows below prove both outcomes.
  • Issue/task and intended base: self-contained repair against loopx-project/loopx:main, baseline 04c5799b88f6c4cf12a224b7fa679f272e1e794e.

Author Declaration

Implemented against

Criterion (spec clause) Disposition Symbol / path Test or command
Overlapping relative scopes exclude another effective lease implemented scopePairOverlaps / fnmatchcase task_lease_directory_scopes.test.ts; CLI regression below
Case/lexical aliases preserve overlap and immutable request identity implemented existing normalization and folded matcher retained Unicode/class cases; exact retry and unchanged-state assertions
Different repositories and verified independent worktrees retain their existing boundaries implemented acquisition decision unchanged directory authority-boundary test; repository/workspace suites
  • Self-check before submission: read the canonical contract, contribution rules, applicable guidance and PR template; reviewed the full diff and public overlap work. Verified the changed behavior through real CLI transactions. Full-suite and platform gaps are disclosed below.

Scope And Continuation

  • Completed scope and remaining work: complete within this three-file repair. Directory matching now checks whether the glob has a viable continuation below the directory, including empty character classes and Unicode folds. It reuses the existing matcher; stored scope identity, schemas and glob/glob policy are unchanged.
  • Slice boundary / successor: no implementation successor required. Broader CI qualification remains outstanding; this PR does not change host process cleanup or runtime lifecycle behavior.

Validation

  • Tested revision: the implementation and tests were validated in the working tree, then committed unchanged as 2974dc24b112c89ae9ee071762351d88aeb783f8. Baseline comparisons use 04c5799b88f6c4cf12a224b7fa679f272e1e794e.
  • Run state: finished; broad-suite attempts were interrupted and do not constitute passing full runs.
  • Input classes: synthetic, public_fixture.
  • Environment: Linux, Node 24.22.1, Python 3.12.14. Broad reruns explicitly disabled usage telemetry with LOOPX_USAGE_PING=0 DO_NOT_TRACK=1.
Check kind Result Public-safe evidence / limitation
regression_parity passed Same new tests on baseline: 15/26 TS tests failed; 48/88 CLI cases failed because overlapping scopes were admitted. After the fix, all 26 TS tests and all 88 CLI cases passed.
unit passed Directory, acquire, repository and workspace TS suites: 64 passed, 1 PostgreSQL test skipped. Run with Node's test runner on tests/control_plane_ts/task_lease_{directory_scopes,acquire,repository,workspace}.test.ts.
real_entrypoint / real_backend passed uv run --extra test pytest tests/control_plane/test_canonical_lease_scopes.py -n 4 -q: 190 passed, including the 88 new cases. Real CLI, File and SQLite 3.53.4 providers use disposable fixtures; both scope orders and acquire/claim entrypoints are covered.
regression_parity passed Independent bounded Python fnmatch oracle: 6,960 directed comparisons, no mismatches. Ordinary non-directory baseline/head parity: 1,369 comparisons, no differences. These are supplemental generated checks, not additional committed tests.
static passed npm run -s typecheck:control-plane; Ruff over the contribution-guide scope; configured mypy check (17 files); git diff --check; bilingual RFC check.
integration passed Standard premerge gate: 5 direct checks and 17 selected smoke/canary checks passed. CLI output-budget smoke passed. Public-boundary CLI check found no errors; its disposable empty runtime produced one expected warning.
integration failed Broad TS and Python attempts encountered failures and were interrupted; no full-suite pass is claimed. Targeted diagnosis reproduced 18 runtime connection failures and 7 process/cleanup failures on unchanged baseline. The 18 readback cases and 23 scheduler cases passed on this branch with isolated temporary runtime directories. Remaining broad failures were not exhaustively attributed.
real_backend not_run PostgreSQL configuration was unavailable; the related test was skipped.
  • Coverage and gaps: positive concrete-path witnesses, negative class/sibling cases, Unicode aliases, both argument orders, immutable replay, and canonical state after rejection cover the changed decision path. Real File/SQLite entrypoints passed. Full-suite qualification, PostgreSQL, native Windows/macOS and hosted CI remain unverified.

See validation disclosure guidance.

Frontend / Visual Evidence

  • UI impact: none.
  • Before / After: N/A.
  • First viewport and preview: N/A.
  • States and viewports shown: N/A.
  • Source data: none.
  • Attention review / Craft review: N/A; no UI changes.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference: Core control-plane hardening; canonical lease exclusion contract cited above.

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A; no migration or RFC-promotion claim.
  • Semantic dimensions changed, or reviewed no-impact rationale: directory/glob overlap decision only; no schema or routing changes.
  • Provider conformance arms run: existing disposable File/SQLite CLI fixtures, as reported above.
  • Read-only legacy/file/PostgreSQL three-arm rehearsal: N/A; no promotion, runtime-routing or compatibility-projection change.

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths.
  • I did not duplicate maintainer-owned benchmark work.
  • I kept the change scoped to the reproduced lease exclusion defect.
  • No paired RFC changed; the bilingual RFC check passes.
  • UI impact is marked none.
  • Every commit includes a DCO Signed-off-by trailer.

Match glob continuations beneath literal directory scopes while preserving character classes, Unicode folds and disjoint paths. Cover exclusive acquire and atomic Todo claim with File and SQLite CLI regressions, immutable retries and unchanged state after rejection.

Signed-off-by: Jim-jimu <3230103159@zju.edu.cn>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T05:59:17.814176Z 2974dc2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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

使用普通独占租约协调同一仓库写入的维护者和 Agent,会遇到目录范围与文件 glob(通配表达式)交叉的任务。

先取得 src/ 的租约,再申请 src/components/*.ts:基线允许两个写入者同时执行;当前 head 拒绝第二笔,且保留原租约、回执和状态。

同一共享目录的冲突现在会被真实 acquire 和原子 todo claim 拒绝;不相交范围仍可执行,持有者精确释放后可继续工作。

本修复不扩张写权限、不改变 worktree 协作模式,也不承担进程终止、自动交接或跨 Goal 文件锁。

改动思路 / Approach

目录延续匹配复用原有 typed acquire owner,存储、资格与 CAS 保持原边界,避免另造租约规则。

当前 PR 完整交付普通目录与 glob 的互斥修复;不引入新配置、存储格式或调度策略。

原始 scope 的拼写继续参与不可变请求身份,目录包含关系只是比较时的推导值。实现沿现有 glob token 和 Unicode 折叠匹配器判断:目录的已知前缀先匹配,余下表达式必须仍可能匹配一个后代。普通文件匹配默认不进入该分支。独占冲突仍由原 canonical acquire owner 拒绝,已验证独立 worktree 的重叠仍是集成提示,没有新增配置或手工同步状态。

具体改动 / Changes

审查完整 base 04c5799b88f6c4cf12a224b7fa679f272e1e794e → head 2974dc24b112c89ae9ee071762351d88aeb783f8:一个生产文件增加 42 行、删除 5 行;两个测试文件增加 146 行,无生成物或存储 schema 变更。

规范:docs/reference/canonical-lease-renew.md#repository-relative-scope-identity,不可变版本 04c5799b88f6c4cf12a224b7fa679f272e1e794e。逐项映射:SCOPE-OVERLAP 已实现,同 Goal 的目录/glob 重叠在真实 acquire 与原子 claim 上拒绝;SCOPE-IDENTITY 已实现,大小写/词法别名仍重叠,原参数重试及续约后的原回执保持;SCOPE-BOUNDARY 已实现,不同已知仓库与已验证独立 worktree 沿既有规则处理。

关键代码讲解

  • classHasMatch:检查剩余字符类是否可满足,保留正/负类和折叠别名,空逆序区间不能产生假后代。
  • fnmatchcase:默认完整匹配不变;目录模式在已知前缀耗尽后判断剩余 token 的可满足性,沿现有 memo/Unicode owner 计算。
  • scopePairOverlaps:只把 literal directory 与 glob 的混合分支接到延续匹配;现有 acquire/claim、repository/worktree 和 quota 调度 caller 继续消费同一判断。

对主干的风险 / Risks

未发现阻塞问题。最危险的反例是先取得 src/ 后再申请 src/components/*.ts,或用 src/SS/ 与 [ß] 绕过互斥;我在 File、SQLite 和真实 PostgreSQL 上独立重现基线错误,并验证当前拒绝发生在 canonical 提交前。反向参数、不相交兄弟路径、不可满足字符类、原请求重试和持有者释放后的继续执行均有覆盖。

本地检查 结果
同一 scope CLI harness:基线 / 当前 head 基线 48 failed、142 passed;当前 190 passed。失败均为重叠的第二笔租约被错误准入
定向 TS directory/acquire/repository/workspace PASS:64;最初 1 项 PG skip 后用真实后端补验
隔离 PostgreSQL 16.15 PASS:必需 store 集成 382 项、workspace 32 项;独立目录对照 8 项,基线 4 个重叠案例错误放行,head 全部符合预期
新 Todo 与恢复 PASS:在已有目录租约后创建新任务,冲突无副作用;原持有者精确 release 后新 key 可取得租约,File/SQLite 都成功
共享调度 caller / 静态 / 风险 gate PASS:26 项 orchestration;TS typecheck、Ruff、mypy 17;5 项 direct 与 17 项 selected premerge 检查

语义与 CI 对齐

复用现有 token、AcquireDecision 和 canonical lease vocabulary,不新增按文本猜状态的规则。修正的是已有独占合同的漏判;worktree 的 advisory 没有变成强制占有。当前配置不查询或等待 GitHub CI。作者披露的 broad-suite 失败仍属诊断,原因未在此穷尽,也未被宣称修复;当前必要的 changed-invariant 与真实 PostgreSQL 证据已独立建立。

我的整体评价 / Verdict

APPROVE,完成所声明的目录/glob 修复。长程维度保持原有执行、重试与恢复能力,用户体验减少了可导致并发覆盖的错误准入;不以测试数量宣称实际团队效率收益。兼容性保留有真实的 persisted request/receipt 消费者,修改集中在原 owner,暂不需要更大的 glob 框架或额外跟踪任务。

已检查租约 matcher 与 CLI 入口,未改动任何渲染页面。 视觉改动无未验证项;原生平台与模型执行边界另列。

未执行完整 Python/TS 仓库套件、Windows/Linux 原生 CLI 或长期负载;初次 TS 的 PostgreSQL skip 已由隔离真实后端补验。历史作者 broad-suite 失败保留为诊断,未推断为已修复;当前必要不变量已有独立覆盖。 精确 scope 的 change-quality receipt cqr_d4e448d6c3b6387442ca 已验证有效。批准结论不代表执行了合并。

English verdict: APPROVE — 2974dc24b112c89ae9ee071762351d88aeb783f8 fixes directory/glob exclusion; File/SQLite and isolated PostgreSQL validation passed. Full-suite and cross-platform qualification remain unverified.

@loopx-agent
loopx-agent merged commit 85b0975 into loopx-project:main Nov 1, 2026
12 of 34 checks passed
@loopx-agent

Copy link
Copy Markdown
Collaborator

补充一个租约粒度的后续设计建议,想请作者考虑。

这条修复解决了现有 exclusive 语义下目录与 glob 的重叠漏检。更上层的问题是:普通代码编辑是否可以主要依靠 Todo 级执行租约和独立 worktree,而把跨工作树的文件范围重叠作为集成提示?

建议分开考虑三个职责:

  • Todo 执行租约:维护执行实例归属、续租、过期接管、代际隔离和结果提交,防止同一任务的旧执行者继续结算。
  • 代码隔离与集成:各 Agent 在独立 worktree 编辑;相同文件的修改通过 diff、测试和评审协调。现有 --write-worktree 模式已经部分采用这一边界,可评估能否成为普通代码任务的默认路径。
  • 共享可变资源:同一物理 checkout、共享运行状态或远端分支仍需对应的保护。两个不同 Todo 的合法租约不能自动防止它们覆盖同一份资源;这部分也不宜与 sandbox 权限校验混为一层。

当前路径协调已经需要处理目录/glob、字符类与 Unicode、路径别名、符号链接及 worktree 文件树观测。希望能评估:哪些检查确实必须进入执行准入,哪些可以降为提示或移到集成阶段;同时量一下真实调用链中的成本。独立 worktree 也有创建、依赖和清理成本,不能仅凭简化路径规则就推断显著提速。

参考当前已声明的 独立 worktree 代码编辑契约,可以进一步梳理“Todo 执行租约为核心、代码隔离优先、共享资源按需互斥”的边界,以及简化后仍须保留的并发与恢复反例。

Jim-jimu commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up. I agree with separating Todo execution ownership, code-workspace isolation, and protection of shared mutable resources.

I inspected main at da4510af. The existing --write-worktree path already supports cooperative code editing: cross-checkout scope overlaps can become integration advisories, including when the other lease has no recorded workspace identity. Active executions of the same Todo and overlapping writes in a known same checkout remain protected. The next step therefore seems to be connecting the existing capability across its callers.

I found two concrete gaps:

  • Ordinary self-claim creates its execution lease through prepareClaimExecution without supplying write_workspace. A caller running in an independent worktree can therefore still encounter ordinary scope exclusion.
  • Adaptive task orchestration filters overlapping child tasks by repository and write scope before considering their actual workspace isolation.

I compared these paths through the current production transaction entrypoints using synthetic workspace identities and real File/SQLite stores. With two overlapping tasks, ordinary self-claim rejects the second task without changing state. Acquiring a lease with a distinct workspace identity for each task before self-claim allows both claims to succeed. This verifies the transaction boundary, not the complete Host execution journey.

Based on that, I would suggest proceeding in stages:

  1. Carry verified code-workspace identity through ordinary managed claim. Reuse the existing workspace observer, lease decision and atomic claim transaction, binding the identity to the original request and receipt. Preserve existing callers, historical receipts and already-issued leases.
  2. Then make parallel admission aware of workspace isolation. For code tasks whose isolated workspaces can actually be prepared and verified, use file overlap as integration information and an input to scheduling. An intention to use a worktree must not itself grant execution authority.
  3. Only then evaluate a scoped default change. Same-checkout writes, shared runtime state, Git administration and remote branches still need protection at their respective resource boundaries. Execution generations, expiry takeover, stale-execution rejection and idempotent recovery must retain their existing guarantees.

Workspace observation should also remain distinct from filesystem access control. Surviving old processes, shared links and external effects still require explicit boundaries owned by the Host or the actual resource entrypoint.

I would not assume a performance improvement upfront. Evaluation should include workspace preparation, dependencies, scanning, lease reads/writes, waiting, integration rework and cleanup, and judge the default change by accepted outcomes and complete costs.

Would “carrying verified worktree identity through ordinary managed claim” be a suitable first independently deliverable scope? Parallel scheduling policy and default behavior could follow once that path is qualified.

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