Skip to content

[Draft] feat: Delegation depth tracking — max_delegation_depth (Phase 2) #108

@watari-ai

Description

@watari-ai

Status: Draft

This is a design draft for Phase 2 of delegation-aware effects.
Phase 1 (delegation=explicit + grants) is tracked in #107.

Feedback and design discussion welcome — nothing is frozen here.


Motivation

Phase 1 introduces a static friction mechanism: callers must explicitly declare grants to invoke delegation=explicit effects. This stops silent propagation at one hop.

But in long delegation chains (A→B→C→D), an explicit grant at each hop still allows the permission to travel arbitrarily far. For highly sensitive or irreversible effects, you may want to limit how many hops a permission can travel, regardless of explicit grants.

This is the dynamic complement to Phase 1's static mechanism.


Proposed Addition

Add optional max_delegation_depth to EffectQualifier:

{
  "op": "NET:http_post",
  "reversible": false,
  "delegation": "explicit",
  "max_delegation_depth": 1
}

Semantics:

  • depth=0: only the declaring module may invoke this effect directly
  • depth=1: the declaring module + one level of delegation
  • No field (default): unlimited depth (current behavior)

Open Design Questions

1. Static or dynamic?

The core challenge: delegation depth is often determined at runtime (which agent calls which), not at compile time.

  • Static approach: define "depth" as the number of module boundaries crossed in the static call graph. Checkable by L2 at compile time, but may be too conservative — a module that conditionally delegates would always be counted.
  • Dynamic approach: thread a delegation_context through runtime execution. More precise, but requires runtime support (executor, or mcp-fw enforcement layer).
  • Hybrid: static checker warns, runtime enforces.

2. Who enforces it?

  • NAIL checker (static): can detect obvious violations at compile time
  • mcp-fw (runtime): can track actual delegation chain length per call

This is the primary reason Phase 2 is deferred — the enforcement boundary between NAIL (language) and mcp-fw (runtime) needs to be decided first.

3. Interaction with grants

Does max_delegation_depth=1 mean:

  • (a) grants can only be declared at depth ≤ 1, or
  • (b) the effect can only be executed within depth ≤ 1 of its origin?

These have different implications for the checker and the runtime.


Relationship to mcp-fw

mcp-fw already sits in the delegation chain between Claude and MCP servers. Phase 2 would likely be primarily enforced there — tracking delegation_chain per request and blocking calls that exceed max_delegation_depth.

See: https://github.com/zyom45/mcp-fw


References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions