Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Governed Model Turn V3 Actual Boundary

## 冻结目标

本切片只把已存在的 `GovernedModelTurnV3` 与 `InvocationMaterialV2` 串进 routegateway 的可逆 pre-invoke 路径。由于 credential exact current、实际 Provider request canonical 和 durable Provider Attempt 尚未冻结,它在 `prepareAt` 后、任何 Boundary 写入前确定性 Fail Closed。

## 固定顺序

```text
exact Turn
→ historical Boundary early Inspect
→ authoritative Context/Tool pair S1
→ Prepared/Current/ACK S1/S2
→ reversible Provider prepare
→ deterministic Fail Closed
```

历史 Boundary 通过同一复合 Store 在 Binding、Secret 和 Factory 前 early Inspect;所有新调用都保持 Boundary、Provider 与 Observation 写入为零。

## 边界

- `ContextFrame/ContextMaterial`与`ToolInjectionMaterial/ToolSurface`必须通过`InvocationMaterialAuthorizerV2`的paired-reader ports再次验证。
- caller传入的非零`ModelBoundary`必须与历史winner exact一致;只有零值可由历史winner补全。
- S1/S2分别用一次权威paired-reader读取同时生成Authorization与完整Context/Tool projection;每条source的Ref、Checked、TTL、Digest及projection body必须exact一致,不能二次读取拼接快照,也不能只比较聚合最短TTL。
- Commit ACK在S1/S2都必须重新验证current、Prepared/Current绑定和完整body;expiry equality、same-Ref body splice及重封后的Ref漂移均在Provider prepare前拒绝。
- exact Turn Reader返回值必须同时通过完整`Validate`和Ref equality,不能用保持Ref的State/Created/Updated/Expires splice绕过。
- routegateway不生成Context、Tool、Runtime或Harness事实。
- Provider prepare可逆;确定性 Fail Closed 必须释放adapter lease。
- adapter lease的release/retire终态与调用顺序无关;最终stale且refs为零时Closer恰执行一次,release错误保留在返回因果链。
- 当前切片不跨 Runtime guard、不调用 Provider,也不产生 Provider Observation。
- 同版本、同expiry但credential material generation变化不能由现有`SecretResolver`证明,因此不得通过二次Resolve解锁Provider。
- direct `Invoke`、V1、V2路径不因本切片获得V3治理语义。

## Production NO-GO

当前同时缺少:

- 将`prepareAt`产生的实际Provider request形状重算并闭合到`ActualProviderInjectionDigest`的公开canonical;
- V3 Provider Attempt/Observation的持久化与exact Inspect合同。
- Model-owned exact `CredentialMaterialCurrentRef`、`ResolvedCredentialHandle`与`CurrentReader`,并让pool key和`preparedCall`绑定该exact ref,在invoke前fresh exact Inspect。

所以本切片只能证明pre-invoke读取、准备与Fail Closed;测试中的工具alias和compiled digest仍是fixture材料,不是Tool Owner authoritative compiled material。Host availability只能由Runtime guard的权威reader提供,caller不得伪造。
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Governed Model Turn V3 Actual Boundary 施工中

## 当前事实

- worktree已rebase基线:`origin/main@5e491e9450b76a3f488cf14703b9d4396dc670bc`
- 分支:`agent/governed-model-turn-v3-routegateway-actual-boundary`
- V3 routegateway pre-invoke路径已形成未提交候选。
- authoritative Context/Tool pair会在S1/S2各读取一次,并由同次读取同时产生Authorization与完整projection;非min source TTL/Checked漂移不会被二次读取TOCTOU或聚合最短TTL掩盖。
- Commit ACK在S1/S2按完整body与currentness复检;exact Turn保持Ref的body splice也会Fail Closed。
- 现有`SecretResolver`无法证明同version/expiry下的material generation exact current,因此本切片在prepare后、Boundary前Fail Closed。
- caller Boundary exact匹配/冲突、source TTL缩短/延长与Checked漂移、ACK expiry/body漂移、Turn body splice、S2 clock regression、Runtime draft preflight与Provider lease release error chain均已补门禁。
- adapter lease release/retire改为顺序无关终态,stale且refs为零时Closer恰一次。
- 已有64并发、same-coordinate material drift与重放门禁测试,Boundary/Provider均为0。

## NO-GO

尚无credential exact current/handle/reader、实际Provider request→`ActualProviderInjectionDigest`公开canonical,也无V3 Provider Attempt/Observation持久化与exact Inspect;当前仅证明Boundary/Provider/Observation=0的pre-invoke reference路径。
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Module: Governed Model Turn V3 Actual Boundary

## 作用

该模块是Model Invoker中V3 pre-provider facts到routegateway物理调用的窄接线。它复用公开Owner ports,不复制Context、Tool、Runtime或Harness语义。

## Public surface

- `InspectCurrentInvocationMaterialAuthorizationV2`
- `InspectCurrentInvocationMaterialAuthorizationClosureV3`
- `ValidateModelProviderActualPointRequestDraftV3`
- `GovernedModelTurnProviderBoundaryTurnAttemptReaderV3`
- `routegateway.GovernedModelTurnActualBoundaryDependenciesV3`
- `routegateway.GovernedModelTurnActualBoundaryCommandV3`
- `routegateway.GovernedModelTurnActualBoundaryResultV3`
- `routegateway.WithGovernedModelTurnActualBoundaryV3`
- `routegateway.Gateway.InvokeGovernedModelTurnActualBoundaryV3`

## Current status

Owner-local pre-invoke candidate。它以完整Context/Tool paired projection、完整ACK snapshot和已验证Turn body执行S1/S2;在adapter prepare后、Boundary写入前确定性Fail Closed。无credential exact current、实际Provider request canonical闭包与持久Provider Observation,Provider调用固定为0,production仍为NO-GO。
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Governed Model Turn V3 Actual Boundary Plan

## 实施

1. 增加已持久化`InvocationMaterialV2`的authoritative pair复读helper;Authorizer每个阶段只读每个Pair一次,并从同次读取同时生成Authorization与完整current projection。
2. 为Gateway增加独立V3 dependencies与Option,不修改V1/V2。
3. 实现S1/S2与可逆Provider prepare。
4. 在任何Boundary写入前因credential exact current合同缺失而确定性Fail Closed。
5. 在任何Provider prepare前校验Runtime actual-point draft;历史replay拒绝caller Boundary splice。
6. 增加64并发、same-version/same-expiry material drift、非min source TTL/Checked漂移、ACK current/body漂移、Turn body splice、pair unavailable、clock drift和replay测试。
7. 收紧adapter lease终态:release/retire并发或任意先后顺序不丢失Closer与错误。

## 验收

- Boundary、Provider与Observation写入均为0。
- 64并发同Turn/attempt保持Boundary=0、Provider=0。
- 同版本同expiry但material generation变化仍Provider=0。
- 任一authoritative source或ACK在S1/S2发生完整projection/body漂移时,Binding、Secret、Factory、Boundary、Provider与Observation均为0。
- 交替Reader不能利用同阶段二次读取制造Authorization/Pair混合快照;每个Pair在每个阶段恰读一次。
- exact Turn保持Ref但修改State/Created/Updated/Expires时,Provider prepare为0。
- authoritative pair未配置时Gateway无法启用。
- V1/V2、direct Invoke、Provider实现、Runtime/Harness/Context/Tool目录零修改。
- ordinary、race、vet、diff/import boundary通过。

## 后续

另行冻结Provider request canonical→`ActualProviderInjectionDigest`闭包、V3 Provider Attempt/Observation history与lost-reply exact Inspect,以及credential exact current/handle/reader;本计划不生成production Outcome。
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package modelinvoker

import (
"context"
"time"
)

// InvocationMaterialCurrentAuthorizationClosureV3 freezes the complete
// authoritative Context and Tool pair projections observed with one current
// material authorization check. Aggregate authorization expiry alone cannot
// prove that a non-minimum source did not drift between S1 and S2.
type InvocationMaterialCurrentAuthorizationClosureV3 struct {
Authorization InvocationMaterialAuthorizationV2
ContextPair InvocationMaterialContextPairProjectionV2
ToolPair InvocationMaterialToolPairProjectionV2
}

// InspectCurrentInvocationMaterialAuthorizationV2 replays the five exact
// Model-owned reader checks for an already persisted InvocationMaterialV2.
// It does not create another material, cross a commit gate, prepare a Provider,
// or grant dispatch authority. Route gateways use it at S1/S2/S3 so the stored
// RouteCall bytes cannot outlive their authoritative Context and Tool pairs.
func InspectCurrentInvocationMaterialAuthorizationV2(
ctx context.Context,
authorizer *InvocationMaterialAuthorizerV2,
prepared PreparedModelInvocationFactV1,
current PreparedModelInvocationCurrentProjectionV1,
material InvocationMaterialV2,
now time.Time,
) (InvocationMaterialAuthorizationV2, error) {
if ctx == nil || ctx.Err() != nil || authorizer == nil || now.IsZero() ||
material.ValidateAgainstPreparedV2(prepared, current, now) != nil {
return InvocationMaterialAuthorizationV2{}, governedInvalidV1(
"invocation material V2 current authorization inputs are invalid",
)
}
closure := InvocationMaterialExactClosureV2{
SourceLineage: material.Authorization.SourceLineage,
ProviderInjection: material.Authorization.ProviderInjectionRef,
Route: material.Authorization.RouteRef,
Profile: material.Authorization.ProfileRef,
}
observed, err := authorizer.authorizeV2(
ctx,
prepared,
current,
material.Call,
closure,
now,
)
if err != nil {
return InvocationMaterialAuthorizationV2{}, err
}
if !sameInvocationMaterialAuthorizationClosureV2(
observed,
material.Authorization,
) ||
observed.AuthorizedUnixNano < material.Authorization.AuthorizedUnixNano ||
observed.ExpiresUnixNano != material.Authorization.ExpiresUnixNano {
return InvocationMaterialAuthorizationV2{}, governedConflictV1(
"invocation material V2 current authorization drifted",
)
}
return observed, nil
}

// InspectCurrentInvocationMaterialAuthorizationClosureV3 additionally freezes
// the full paired Context and Tool current projections. It performs no writes,
// gate crossing, Provider preparation, or dispatch authorization.
func InspectCurrentInvocationMaterialAuthorizationClosureV3(
ctx context.Context,
authorizer *InvocationMaterialAuthorizerV2,
prepared PreparedModelInvocationFactV1,
current PreparedModelInvocationCurrentProjectionV1,
material InvocationMaterialV2,
now time.Time,
) (InvocationMaterialCurrentAuthorizationClosureV3, error) {
var closure InvocationMaterialCurrentAuthorizationClosureV3
if ctx == nil || ctx.Err() != nil || authorizer == nil || now.IsZero() ||
material.ValidateAgainstPreparedV2(prepared, current, now) != nil {
return closure, governedInvalidV1(
"invocation material V3 current authorization closure inputs are invalid",
)
}
expected := InvocationMaterialExactClosureV2{
SourceLineage: material.Authorization.SourceLineage,
ProviderInjection: material.Authorization.ProviderInjectionRef,
Route: material.Authorization.RouteRef,
Profile: material.Authorization.ProfileRef,
}
observed, err := authorizer.authorizeClosureV3(
ctx,
prepared,
current,
material.Call,
expected,
now,
)
if err != nil {
return closure, err
}
authorization := observed.authorization
if !sameInvocationMaterialAuthorizationClosureV2(
authorization,
material.Authorization,
) ||
authorization.AuthorizedUnixNano <
material.Authorization.AuthorizedUnixNano ||
authorization.ExpiresUnixNano !=
material.Authorization.ExpiresUnixNano {
return closure, governedConflictV1(
"invocation material V2 current authorization drifted",
)
}
closure = InvocationMaterialCurrentAuthorizationClosureV3{
Authorization: authorization,
ContextPair: observed.contextPair,
ToolPair: observed.toolPair,
}
return closure, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ type GovernedModelTurnProviderBoundaryRepositoryV3 interface {
) (GovernedModelTurnProviderBoundaryFactV3, error)
}

// GovernedModelTurnProviderBoundaryTurnAttemptReaderV3 exposes the immutable
// winner for an original V3 Turn attempt. It lets a physical gateway reject a
// replay before resolving credentials or preparing a Provider adapter.
type GovernedModelTurnProviderBoundaryTurnAttemptReaderV3 interface {
InspectGovernedModelTurnProviderBoundaryTurnAttemptV3(
context.Context,
GovernedModelTurnAttemptRefV3,
) (GovernedModelTurnProviderBoundaryFactV3, error)
}

func GovernedModelTurnProviderBoundaryOwnerV3() core.OwnerRef {
return core.OwnerRef{
Domain: governedModelTurnProviderBoundaryOwnerDomainV3,
Expand Down Expand Up @@ -321,7 +331,7 @@ func DeriveGovernedModelTurnProviderBoundaryRefV3(
"governed model turn provider boundary V3 lineage drifted",
)
}
if err := validateRuntimeRequestWithoutBoundaryV3(request); err != nil {
if err := ValidateModelProviderActualPointRequestDraftV3(request); err != nil {
return GovernedModelTurnProviderBoundaryRefV3{}, err
}
operationDigest, err := request.Operation.DigestV3()
Expand Down Expand Up @@ -422,9 +432,9 @@ func BuildGovernedModelTurnProviderBoundaryFactV3(
if err != nil {
return GovernedModelTurnProviderBoundaryFactV3{}, err
}
if turn.RefV3() != draft.TurnRef {
if turn.Validate() != nil || turn.RefV3() != draft.TurnRef {
return GovernedModelTurnProviderBoundaryFactV3{}, governedConflictV1(
"governed model turn provider boundary V3 Turn exact Reader drifted",
"governed model turn provider boundary V3 Turn exact Reader returned invalid or drifted content",
)
}
if _, err := validateCurrentGovernedModelTurnWinnerV3(
Expand Down Expand Up @@ -690,7 +700,10 @@ func validateGovernedModelTurnProviderBoundaryLineageV3(
return nil
}

func validateRuntimeRequestWithoutBoundaryV3(
// ValidateModelProviderActualPointRequestDraftV3 validates every Runtime
// actual-point coordinate that exists before Model derives ModelBoundary. It
// performs no reads and does not grant dispatch authority.
func ValidateModelProviderActualPointRequestDraftV3(
request runtimeports.InspectCurrentModelProviderActualPointRequestV1,
) error {
boundary := request.ModelBoundary
Expand Down
Loading
Loading