Skip to content

feat(agent): enforce control-plane session execution grants - #7233

Merged
M4n5ter merged 5 commits into
apache:mainfrom
MicroGery:codex/rust-session-execution-main
Nov 24, 2026
Merged

M4n5ter merged 5 commits into
apache:mainfrom
MicroGery:codex/rust-session-execution-main

Conversation

@MicroGery

Copy link
Copy Markdown
Contributor

Summary

A published checkpoint does not authorize a Host to continue its Session. Add an optional, control-plane-independent execution grant so a trusted embedding can bind one native Session to an execution generation, enforce its permission ceiling, and fence checkpoint publication. The default local Host remains unchanged.

The file-backed reference authority durably arbitrates claims and renewals, and commits generation validation, Head CAS, and the original receipt in one transaction. Revocation or expiry closes admission and autonomously drains the Host; a successor remains blocked until the supervisor supplies confirmed cleanup. Grant fields alone are not credentials, and lease expiry alone does not authorize takeover.

This replaces #7085, which closed when rust-preview was deleted. GitHub rejects reopening or retargeting that closed PR, so this continuation targets main and addresses its review:

  • Scope startup recovery, queued input and mutation RPCs to the granted Session. Reject unauthorized recovery without changing the original facts or queue; keep Root-wide producers and cross-Session mutations outside this bootstrap mode.
  • Check authority at actual model/tool admission; keep ordinary configuration reads local. Active observations no longer acquire a write lock, grant policies are shared through Arc, and checkpoint commits avoid redundant authority round trips.
  • Replace internal-control/SQL-trigger/dummy-process tests with persisted Host restart, real file/network/permission denial, and autonomous revoke/expiry shutdown scenarios. Bound the final stopped acknowledgement and make SQL/state matching explicit.

Migration 0003_execution.sql adds the reference authority's tables without rewriting published migrations; its digest is sealed in the migration lock. The upgrade capsule now preserves and cold-replays claims, renewals, publication receipts, the Head and an unacknowledged draining generation. Historical capsules without this optional scenario remain readable.

Scope is one existing native Session in its existing Root/deployment/namespace. Cross-Root activation, external executors, cloud adapters and user-facing configuration remain separate work. This does not promise isolation from unmanaged workspace writers.

Refs #2370.

Verification

Rust builds and tests ran on a Mac mini with two build jobs and one test thread:

  • Checkpoint execution/repository: 30 passed; one existing manual I/O baseline ignored.

  • Managed Host execution/recovery: 3 passed.

  • State stop/steering recovery: 10 passed.

  • Existing Host permission boundaries: 4 passed; unmanaged queued recovery: 1 passed.

  • CLI upgrade capsule round trip: 1 passed.

  • The CLI background HTTP-service regression that failed in the old PR CI: 1 passed on this macOS run.

  • Strict Clippy (--lib --tests --no-deps -- -D warnings) passed for event-log, agent-state, host-runtime and agent-native.

  • cargo fmt checks passed for the five affected packages; migration lock validation and git diff --check passed. The remote full-workspace cargo fmt --all attempt was blocked by the nested checkout making an excluded vendored crate discover the parent checkout's workspace, so the scoped format check was used instead.

Total: 50 passed, plus one ignored manual baseline. This is targeted macOS validation, not a claim that the new PR's cross-platform CI has passed. The tested main baseline is b5c50b10a5; the subsequent Windows namespace change in dd4c1581ea touches no PR files.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex assisted with implementation, review fixes, tests, documentation and validation. Commits retain Generated-by: Codex trailers.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally (validation ran on the Mac mini)

Does this PR entail a breaking change or persisted-data migration?

  • Yes — described under Summary, including in-place schema migration and upgrade capsule coverage
  • No

Does this PR entail a change in behavior?

  • Yes — described under Summary
  • No

@github-actions github-actions Bot added the effort/XXL Over 2500 readable lines label Nov 24, 2026

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

English

The follow-up fixes from #7085 look solid — recovery scoping, central mutation gating in service.rs, read-first FileRepository::observe, Arc<Grant>, bounded stopped acknowledgement, migrations.lock.json + upgrade_compat coverage, and the rewritten behavioral Host tests all address the earlier findings cleanly.

I pushed one small follow-up commit to finish two remaining edges:

  • Moved live require_execution() out of RunAccess::check_tool() into NativeDriver::validate_tool, NativeCellPort::invoke, and around interactive approval waits in tools.rs. This covers non-Service tools (MCP, todo, Recall, Code Mode exec/wait) at live admission while eliminating redundant 3–4x observe() calls per native Service tool call.
  • Disabled goals, scheduled_tasks, and bot settings in Owner::open under managed execution so in-process CreateGoal/GoalStatus/ScheduledTask/Bot tools match the single-Session boundary enforced by service.rs and Owner::activated.
  • Trimmed the redundant permission/checkpoint loop from the lease-expiry test and added assertions for both fixes above.

Verified locally with cargo fmt --check, strict cargo clippy -p maka-agent-native --lib --tests --no-deps -- -D warnings, and all 3 model_recovery::execution tests passing. LGTM!

简体中文

针对 #7085 的改动都很扎实:恢复范围收口、service.rs 统一 mutation 拦检、FileRepository::observe 先读后写、Arc<Grant>、stopped 超时保护、migrations.lock.json + upgrade_compat 胶囊验证,以及重写后的端到端行为测试都到位了。

我顺手补推了一个小 commit 把最后两处边角收干净:

  • 把实时 require_execution() 从 RunAccess::check_tool() 移到 NativeDriver::validate_tool、NativeCellPort::invoke 以及 tools.rs 的交互式审批前后——这样非 Service 工具(MCP、todo、Recall、Code Mode exec/wait)都能走实时 authority 校验,同时消掉了原生 Service 工具单次调用 3–4 次重复 observe()。
  • 受管模式下在 Owner::open 直接关闭 goals / scheduled_tasks / bot,让进程内的 CreateGoal / GoalStatus / ScheduledTask / Bot 工具和 service.rs 及 Owner::activated 的单 Session 边界保持一致。
  • 顺手去掉了租约过期用例里重复跑的那段写文件/网络/checkpoint 套件,并补上了上面两处改动的断言。

本地跑过 cargo fmt --check、maka-agent-native 严格 clippy 以及 3 个 model_recovery::execution 实测用例全部通过。LGTM!

MicroGery and others added 5 commits November 24, 2026 23:12
Add a durable execution authority, generation-fenced checkpoint commits,
Host admission and permission ceilings, and confirmed stop-before-handoff.
Cover concurrent claims, lost replies, expiry, cleanup failures and real Host
model/tool/checkpoint behavior.

Refs apache#2370

Generated-by: Codex
Reject captured sandbox and approval ceilings that exceed the active execution grant. Cover the restore boundary in the real Host fixture and document it in both guides.

Generated-by: Codex
Gate Session mutations centrally and reject foreign or overprivileged recovery
before claims, queue consumption, or preflight failure writes. Keep global
producers outside the single-Session execution scope.

Remove redundant authority observations, share grant policy ownership, avoid
write locks for active observations, and bound stopped acknowledgement.
Replace internal test hooks with persisted Host recovery, real permission
boundaries and autonomous drain tests; cover execution state in the upgrade
capsule and seal the appended repository migration.

Refs apache#7085

Generated-by: Codex
Check live execution authority once per top-level tool in NativeDriver::validate_tool (and per nested Code Mode tool in NativeCellPort::invoke, plus around interactive approval waits) so non-Service tools like MCP, todo, Recall and exec cells cannot slip past revocation while avoiding 3-4x redundant observe() calls on native Service tools.

Disable Goal, ScheduledTask and Bot tool registration in managed execution mode so in-process tools match the single-Session boundary enforced by service.rs and Owner::activated.
@M4n5ter
M4n5ter force-pushed the codex/rust-session-execution-main branch from 55a89e0 to 4f28629 Compare November 24, 2026 15:14
@M4n5ter
M4n5ter merged commit 16e3a77 into apache:main Nov 24, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants