Skip to content

refactor(agents): type agent_scope without Any - #9585

Open
Duang777 wants to merge 1 commit into
loopx-project:mainfrom
Duang777:codex/agent-scope-zero-any-20261129
Open

Duang777 wants to merge 1 commit into
loopx-project:mainfrom
Duang777:codex/agent-scope-zero-any-20261129

Conversation

@Duang777

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: continuation of the zero-Any module campaign; no issue.
  • Goal/source and gap: loopx/control_plane/agents/agent_scope.py carried 13 AST Any (baseline ceiling 13), all dict[str, Any] payload annotations.
  • Observable before → after: module_metrics any_count 13 → 0; baseline ceiling lowered to 0.
  • Issue/task and intended base: none; base main at 811c1a1f6.

Author Declaration

  • Written by: model_agent (Claude Opus, Anthropic), operated by @Duang777

Implemented against

  • Specification and revision: no written specification; behavior of agent_scope.py at 811c1a1f6 is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Zero AST Any implemented agent_scope.py module_metrics() → 0
All imported and test-referenced names unchanged implemented importers across loopx/ and tests/ test suites below
Behavior unchanged implemented whole module AST parity below
  • Self-check before submission: every dict[str, Any] → dict[str, object]. The only runtime-visible edit wraps the _cleared_handoff_frontier sort key's int(...) argument in cast(int | float | str, ...); cast returns its argument unchanged. _int_value was not used there because it maps some int()-accepted inputs to 0.

Scope And Continuation

Validation

  • Tested revision: 1f0f9dc71
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
static passed mypy --strict --follow-imports=silent on the module and its 12 importers: 0 errors at base and head.
regression_parity passed AST of base vs head with annotations/typing imports stripped differs only by the cast(...) wrapper.
unit passed 120 test files touching agent scope / goal frontier / lane recommendation, plus goal terminal and ratchet tests: 3769 passed, 1 skipped, 2 failed. Both failures (`test_long_chain_projected_closeout.py::test_projected_vision_replan_settles_without_a_meta_successor[switch-paged
integration passed Smokes: agent-scope-projection-characterization, quota-agent-scoped-user-gate, quota-cleared-blocker-successor-gate, quota-resume-gated-open-todo, control-plane-risk-characterization.
real_entrypoint passed loopx quota should-run --codex-app --agent-id on a synthetic mixed-wait fixture in a temp directory: base and head both exit 0 with effective_action=agent_scope_wait; remaining JSON differences are per-run hashes, ids and timings.
static passed loopx canary premerge --from-git-diff --git-diff-base origin/main: 8/8, 0 failures.

Frontend / Visual Evidence

  • UI impact: none

Type of Change

  • Refactoring (no functional changes)

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

Shared-authority RFC fixture impact

N/A

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 unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • No paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

🤖 Generated with Claude Code

Replace the 13 `Any` uses in agent_scope.py with `object`:
`dict[str, Any]` becomes `dict[str, object]` in payload/candidate helper
signatures and two local annotations, and the `typing.Any` import is
dropped. Annotation-only apart from one no-op `cast(int | float | str, ...)`
wrapping the value passed to `int()` in `_cleared_handoff_frontier`'s sort
key, which narrows `object` for mypy --strict without changing behavior.

Lower the module's `any_count` ceiling in module_metric_baseline.json
from 13 to 0; line ceilings are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: duang777 <duangjl007@gmail.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.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

维护 Agent scope 与 quota 调度的开发者,以及使用 scoped Codex App 准入的操作者。 候选、当前阻塞和公开 quota 状态通过一组宽类型字典组合,模块里有 13 处 Any。 当前模块 Any 计数与上限同为 0,之前两者都是 13。忽略注解变化和唯一等值 cast 后,两版 AST 相同。 改动只涉及 Agent scope 的 Python 类型声明、一个等值 cast 和其 Any 基线行。 独立验证按改动范围运行,覆盖真实隔离 File/SQLite 和合成 Agent/Todo 数据。完整 Python 套件和远端 CI 未复跑。

改动思路 / Approach

将 JSON 投影的字典值约束为 object,沿原调用链保留字段读取和既有条件,测量后将 Any 上限改为 0。 改动只涉及 Agent scope 的 Python 类型声明、一个等值 cast 和其 Any 基线行。 Agent scope 继续投影 Todo、lease 与 gate,原 quota owner 继续作准入决定,Canary 只检查模块度量。 在 cleared gate 的排序点保留 int 原输入和转换,避免因收紧注解而改变历史输入。 Agent scope

具体改动 / Changes

精确提交 1f0f9dc710997b004b953345752fafbb0513f306,基线 811c1a1f66652d3fc3b9830d467e14b45b7423c1。两文件各有用途,共 +16/-16。

  • AGENT-SCOPE-PARITY。File/SQLite 的 scoped Stop、外部 gate 归属、准入和预算控制在两版实际 CLI 上结果一致,cleared gate 与延后工作具备相同路由。 实际 CLI 测试
  • SCOPE-TYPE-CEILING。只缩窄现有映射值型别。AST 结构对照确认唯一执行表达式改动为等值 cast,原排序仍走 int。度量和上限均实测从 13 降到 0。 基线文件
  • BASELINE-FAILURE-ATTRIBUTION。相同的拒绝原因在两提交复现,保留两项已知失败及原分页行为的归属。 分页对照

关键代码讲解

  • 身份关联与 operator gate 仍消费原 Agent、Todo 和用户状态,字典注解改为 object。 身份关联 用户 gate
  • cleared handoff 按原下降索引排序,cast 不改变输入。no-candidate 路径仍保留原能力和状态检查。 排序 无候选分支

对主干的风险 / Risks

140 项定向测试通过。基线和候选各跑 20 项原生 guard 测试与 4 个 smokes。Ruff、模块严格 mypy、Git diff 以及标准预合并 15 项通过。 switch-paged 和 grow-paged 两项在基线和候选都失败,命令依然拒绝。两头拒绝原因均从测试期待的 undelivered 提示偏离到要求重放原分页。

语义与验证

实际 File 与 SQLite CLI 用例包括外部 gate、明确 Stop、配额和身份隔离。相同 fixture 下基线和候选的 4 个 smokes 都通过。 真实路径验证契约

我的整体评价 / Verdict

APPROVE。 注解收紧与 Canary 上限相符,原守卫、历史排序及存储范围均有配对验证。两项分页用例在两头都复现同一错误提示,继续按已有分页契约跟踪。

English verdict: APPROVE at 1f0f9dc. Agent scope behavior matches the base across paired native File and SQLite tests. The measured Any count is zero and all 15 premerge checks passed. The two paged replan cases fail identically on both revisions.

This branch has not been deployed

No deployments
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