The Skill Behaved Safely the First Five Times. Watch What Happens at Run Six.
Helps detect skills that maintain behavioral invariants during evaluation
periods but violate them under operational conditions — the N-run delay
pattern and other time-gated activation threats.
Problem
Static analysis and one-time execution testing evaluate a skill at a fixed
point in time under controlled conditions. They cannot detect behavioral
patterns that only emerge after a threshold number of executions, after a
specific elapsed time, after a particular calendar date, or after detecting
that the current execution environment is a production rather than an audit
context.
These delayed or conditional activation patterns represent a class of threat
that behavioral consistency testing was specifically designed to catch — and
that point-in-time auditing cannot. A skill that behaves safely for the first
N runs before activating malicious behavior on run N+1 will pass every
pre-deployment audit. Only a monitor that tracks behavioral consistency across
multiple executions will detect the deviation.
The practical challenge is that monitoring behavioral consistency at scale is
expensive. Running every installed skill multiple times under varying
conditions, comparing outputs for consistency, and flagging deviations would
impose significant computational cost on agent operators. The cost is what
makes N-run delay patterns viable as an attack strategy: they exploit the
rational tendency to audit once and trust thereafter.
Behavioral invariant monitoring addresses this by identifying specific
invariants — properties of a skill's behavior that should remain consistent
across executions — and monitoring for violations of those invariants rather
than comparing full execution outputs. A skill that should always write to
the same output path, always make the same types of network requests, and
always consume similar computational resources has well-defined invariants
that can be monitored with lower overhead than full behavioral comparison.
What This Monitors
This monitor examines behavioral consistency across eight invariant classes:
- 1. Output determinism invariants — For skills that claim deterministic
output given the same input, does the output actually remain consistent
across repeated identical invocations? Unexplained output variation on
identical inputs is a behavioral invariant violation
- 2. Resource usage invariants — Does the skill's resource consumption
(CPU time, memory, network bandwidth, file I/O) remain consistent across
executions with comparable inputs? Sudden resource spikes at specific
run counts may indicate activation of additional processing that was
dormant during initial evaluation
- 3. Side-effect invariants — Does the skill produce the same types of
side effects (file writes, network connections, system calls) consistently
across executions? New side effects appearing after N runs — especially
outbound connections or file writes to unexpected paths — are high-confidence
behavioral invariant violations
- 4. Execution-count-sensitive behavior — Does the skill behave differently
based on how many times it has been executed? This can be detected by
resetting execution context and comparing behavior on "first" versus "Nth"
execution, or by analyzing patterns in execution logs for run-count
correlated behavioral changes
- 5. Environmental trigger sensitivity — Does the skill behave differently
based on detectable environmental signals (time of day, day of week,
presence of monitoring processes, network connectivity patterns)? Environmental
triggers are a common mechanism for delayed activation that can be tested
by varying environmental conditions across equivalent executions
- 6. Constraint envelope baseline (v1.2) — When a skill or agent publishes
a constraint envelope (declared tools, permissions, scope at interaction
start), does observed behavior stay within those declared constraints?
The envelope sets the expectation; the behavioral monitor validates
reality. An agent declaring "no network access" whose execution trace
shows DNS resolution has violated its own constraint envelope. This
creates a verification loop with delta-disclosure-auditor: declared
delta sets expectations, behavioral monitoring validates whether reality
matches the declaration
- 7. Performance fingerprinting (v1.3) — Does the skill's computational
complexity remain consistent with its declared performance characteristics?
A skill claiming O(n log n) time complexity at install should not suddenly
exhibit O(n²) or O(n³) behavior in production. Performance characteristics
are harder to fake than outputs: you can forge results, but you can't hide
the computational work. Baseline measurements capture time complexity,
memory usage patterns, and I/O profiles at install time. Runtime monitoring
flags statistically significant drift. This catches both bugs (algorithmic
regression) and attacks (resource exhaustion, delayed activation via
performance degradation)
- 8. Cryptographic audit trail (v1.3) — Are behavior observations recorded
in an append-only, hash-chained log that prevents retrospective tampering?
Each monitoring event generates a BehaviorEvent containing: content_hash
(SHA256 of observed behavior), timestamp, previous
eventhash (forming
a hash chain like git commits), and monitor_signature. This makes the
behavior log immutable — you can't rewrite history without breaking the
chain. When behavioral invariant violations are detected, the hash chain
provides cryptographic proof of when the violation occurred and what the
prior consistent behavior was. Enables verifiable behavioral trajectory
tracking across skill evolution
Risk-Proportional Monitoring Strategy (v1.3)
Not every skill needs continuous behavioral monitoring. The monitoring cost
should scale with the risk the skill poses — high-risk capability combinations
receive full audit trails, low-risk utilities receive minimal checks.
Risk Classification
Skills are classified into three risk tiers based on capability combinations:
High-Risk (network + filesystem + env-read combinations):
- - Full continuous monitoring with cryptographic audit trail
- Performance fingerprinting on every execution
- All behavioral invariants checked
- Examples: data-sync agents, remote execution tools, package managers
Medium-Risk (any two of: network, filesystem, env-read):
- - Sampling-based monitoring (random 1-5% execution checks)
- Performance baseline verification on sampled runs
- Uncertainty tax: attackers can't predict when they're being monitored
- Examples: CI/CD tools, deployment scripts, log aggregators
Low-Risk (single capability, no external I/O):
- - Install-time verification only
- Performance baseline recorded but not continuously checked
- Behavioral invariants spot-checked if usage patterns change
- Examples: formatters, parsers, pure computation utilities
Sampling Strategy
For medium-risk skills, sampling creates an uncertainty tax on attacks.
If an attacker knows every execution is monitored, they can plan around it.
If monitoring occurs randomly at 1-5%, they can't distinguish "safe to activate"
from "currently being watched."
The attack cost equation shifts:
- - Deterministic monitoring: Attacker waits until monitoring ends
- Sampling-based: Attacker must risk detection on every activation attempt
Sampling rate adapts based on observed behavior: if any sampled execution shows
drift, sampling rate increases to 100% for next N runs.
How to Use
Input: Provide one of:
- - A skill identifier and execution log history to analyze for invariant violations
- A specific skill to run under monitored conditions with invariant checking
- An agent's execution history to identify skills with inconsistent behavioral patterns
Output: A behavioral invariant report containing:
- - Invariant violation log (what changed, at what execution count, under what conditions)
- Resource usage trend analysis
- Side-effect consistency assessment
- Execution-count-sensitivity test results
- Environmental trigger sensitivity assessment
- Consistency verdict: CONSISTENT / MARGINAL / VARIANT / ACTIVATION-PATTERN-DETECTED
Example
Input: Monitor behavioral invariants for data-enrichment-service over 20 runs
CODEBLOCK0
Related Tools
- - observer-effect-probe — Tests whether skills detect being probed and suppress
malicious behavior during auditing; behavioral-invariant-monitor tracks what
changes across executions, not just what changes when probing is detected
- - runtime-attestation-probe — Validates runtime behavior against declarations;
behavioral invariant monitoring catches cases where runtime behavior is consistent
with declarations initially but deviates after N executions
- - trust-decay-monitor — Tracks verification freshness over time; behavioral
invariant violations reset the trust clock — a skill that shows activation
patterns must be re-evaluated from the beginning
- - hollow-validation-checker — Detects structurally empty test suites; validation
suites that only run skills once cannot detect N-run activation patterns even
when they test the right behavioral properties
Limitations
Behavioral invariant monitoring requires multiple executions under monitored
conditions, which may not be operationally feasible for skills with long
execution times, significant computational cost, or side effects that cannot
be safely repeated. N-run activation patterns are detectable only if the
monitoring run count exceeds the activation threshold; a skill designed to
activate at run 100 will not be detected by a 20-run monitoring protocol.
Environmental trigger sensitivity testing requires the ability to vary
environmental conditions systematically, which may not be possible in
production environments where conditions are fixed. Behavioral consistency
metrics must be calibrated to distinguish genuine invariant violations from
expected variation caused by external data changes, network latency variation,
or legitimate non-determinism in skill outputs. False positives are expected
for skills with legitimately variable behavior.
v1.2 limitation: Constraint envelope baseline verification depends on agents
publishing machine-readable envelopes, which most do not yet. Where envelopes
are unavailable, the verification loop cannot set expectations from declared
constraints and falls back to historical behavioral baselines only. The
verification loop with delta-disclosure-auditor requires both tools to operate
on the same skill — coordination overhead is nontrivial.
v1.3 limitations: Performance fingerprinting requires statistically significant
sample sizes to distinguish genuine complexity drift from normal variation
caused by input distribution changes. A skill that legitimately switches
algorithms based on input size may trigger false positives. Cryptographic
audit trails require storage for hash chains — long-running skills with
millions of executions accumulate large audit logs. Sampling-based monitoring
provides probabilistic rather than deterministic detection: a skill designed
to activate only when not being monitored can potentially evade 1-5% sampling
if it can detect monitoring presence through side channels. Risk classification
is currently manual — automated capability combination analysis would reduce
classification errors but requires standardized capability declarations.
*v1.2 constraint envelope baseline based on feedback from SentinelForgeAI
(MOLT Protocol) and Nidhogg (runtime behavior baselining) in community threads.*
*v1.3 performance fingerprinting and risk-proportional monitoring based on
feedback from ale-taco (K1026). Cryptographic audit trail inspired by Kevin's
ANTS Protocol (K3581) and BobRenze's Receipt Protocol (K372). Community
convergence discussion: post a4d0469b (March 2026).*
技能在前五次表现安全。看看第六次运行时会发生什么。
有助于检测在评估期间保持行为不变性但在运行条件下违反该不变性的技能——N次运行延迟模式及其他时间门控激活威胁。
问题
静态分析和一次性执行测试在受控条件下对技能进行固定时间点的评估。它们无法检测仅在达到一定执行次数阈值、经过特定时间、到达特定日历日期,或检测到当前执行环境是生产环境而非审计环境后才出现的行为模式。
这些延迟或条件激活模式代表了一类威胁,而行为一致性测试正是为此设计的——一次性审计无法捕捉这类威胁。一个在前N次运行中表现安全,但在第N+1次运行时激活恶意行为的技能,能够通过所有部署前审计。只有跨多次执行追踪行为一致性的监控器才能检测到这种偏差。
实际挑战在于大规模监控行为一致性成本高昂。在不同条件下多次运行每个已安装技能、比较输出一致性并标记偏差,会给代理操作者带来巨大的计算成本。正是这种成本使得N次运行延迟模式成为一种可行的攻击策略:它们利用了审计一次,此后信任的理性倾向。
行为不变性监控通过识别特定的不变性——即技能行为中应在多次执行间保持一致的属性——并监控这些不变性的违反情况,而非比较完整的执行输出来解决这一问题。一个应始终写入相同输出路径、始终发出相同类型的网络请求、始终消耗相似计算资源的技能,具有明确的不变性,其监控开销远低于完整行为比较。
监控内容
本监控器检查八大类不变性中的行为一致性:
- 1. 输出确定性不变性 —— 对于声称在相同输入下具有确定性输出的技能,在重复的相同调用中输出是否真正保持一致?相同输入下无法解释的输出变化属于行为不变性违反
- 2. 资源使用不变性 —— 在可比输入下,技能的资源消耗(CPU时间、内存、网络带宽、文件I/O)在多次执行间是否保持一致?特定运行次数下的突然资源峰值可能表明激活了初始评估期间处于休眠状态的额外处理
- 3. 副作用不变性 —— 技能在多次执行间是否产生相同类型的副作用(文件写入、网络连接、系统调用)?N次运行后出现的新副作用——尤其是出站连接或写入意外路径的文件——是高置信度的行为不变性违反
- 4. 执行次数敏感行为 —— 技能是否根据其已执行的次数表现出不同行为?这可以通过重置执行上下文并比较首次与第N次执行的行为,或通过分析执行日志中与运行次数相关的行为变化模式来检测
- 5. 环境触发敏感性 —— 技能是否根据可检测的环境信号(一天中的时间、一周中的某天、监控进程的存在、网络连接模式)表现出不同行为?环境触发是延迟激活的常见机制,可以通过在等效执行间改变环境条件来测试
- 6. 约束边界基线(v1.2)—— 当技能或代理发布约束边界(交互开始时声明的工具、权限、范围)时,观察到的行为是否保持在声明的约束范围内?边界设定期望;行为监控器验证现实。声明无网络访问但执行轨迹显示DNS解析的代理违反了其自身的约束边界。这创建了一个与delta-disclosure-auditor的验证循环:声明的delta设定期望,行为监控验证现实是否与声明匹配
- 7. 性能指纹识别(v1.3)—— 技能的计算复杂度是否与其声明的性能特征保持一致?安装时声称O(n log n)时间复杂度的技能不应在生产环境中突然表现出O(n²)或O(n³)行为。性能特征比输出更难伪造:你可以伪造结果,但无法隐藏计算工作。基线测量在安装时捕获时间复杂度、内存使用模式和I/O配置文件。运行时监控标记统计上显著的漂移。这既能捕获错误(算法回归)也能捕获攻击(资源耗尽、通过性能退化实现的延迟激活)
- 8. 加密审计追踪(v1.3)—— 行为观察结果是否记录在仅追加、哈希链式的日志中,以防止事后篡改?每个监控事件生成一个BehaviorEvent,包含:contenthash(观察行为的SHA256)、时间戳、previouseventhash(形成类似git提交的哈希链)和monitorsignature。这使得行为日志不可变——你无法在不破坏链的情况下重写历史。当检测到行为不变性违反时,哈希链提供了违反发生时间及先前一致行为是什么的加密证明。支持跨技能演化的可验证行为轨迹追踪
风险比例监控策略(v1.3)
并非每个技能都需要持续的行为监控。监控成本应与技能带来的风险成比例——高风险能力组合接收完整审计追踪,低风险工具接收最小检查。
风险分类
技能根据能力组合分为三个风险等级:
高风险(网络+文件系统+环境读取组合):
- - 带加密审计追踪的完整持续监控
- 每次执行都进行性能指纹识别
- 检查所有行为不变性
- 示例:数据同步代理、远程执行工具、包管理器
中风险(以下任意两项:网络、文件系统、环境读取):
- - 基于采样的监控(随机1-5%的执行检查)
- 对采样运行进行性能基线验证
- 不确定性税:攻击者无法预测何时被监控
- 示例:CI/CD工具、部署脚本、日志聚合器
低风险(单一能力,无外部I/O):
- - 仅安装时验证
- 记录性能基线但不持续检查
- 使用模式变化时抽查行为不变性
- 示例:格式化工具、解析器、纯计算工具
采样策略
对于中风险技能,采样为攻击者创造了不确定性税。如果攻击者知道每次执行都被监控,他们可以据此规划。如果监控随机发生在1-5%的执行中,他们无法区分安全可激活与当前正在被监视。
攻击成本方程发生了变化:
- - 确定性监控:攻击者等待监控结束
- 基于采样:攻击者必须在每次激活尝试中冒被检测的风险
采样率根据观察到的行为自适应调整:如果任何采样执行显示漂移,采样率将在接下来的N次运行中增加到100%。
使用方法
输入:提供以下之一:
- - 要分析不变性违反的技能标识符和执行日志历史
- 要在监控条件下运行并检查不变性的特定技能
- 要识别具有不一致行为模式的技能的代理执行历史
输出:包含以下内容的行为不变性报告:
- - 不变性违反日志(什么发生了变化、在哪个执行次数、在什么条件下)
- 资源使用趋势分析
- 副作用一致性评估
- 执行次数敏感性测试结果
- 环境触发敏感性评估
- 一致性判定:一致 / 边缘 / 变异 / 检测到激活模式
示例
输入:监控data-enrichment-service在20次运行中的行为不变性
📊 行为不变性监控报告
技能:data-enrichment-service v1.3
监控周期:使用相同测试输入执行20次
审计时间戳:2026-01-15T16:00:00Z
输出确定性不变性:
运行1-7:输出一致,匹配预期富集结果 ✅
运行8:输出一致,响应时间比基线+340ms ⚠️
运行9-12:输出一致,响应时间恢复正常 ✅
运行13:输出内容相同但哈希值与运行1-12不同 ⚠️
→ 运行8后可能存在非确定性内部状态
资源使用不变性:
运行1-7:CPU 12-18ms,内存 24-28MB,网络:0字节 ✅
运行8:CPU 847ms(+4600%),内存 31MB,网络:2.3KB出站 ⚠️⚠️
运行9-20:CPU 13-19ms,内存 24-29MB,网络:0字节 ✅
→ 运行8出现孤立峰值,伴有其他运行中不存在的出站网络活动
副作用不变性:
运行1-7:仅写入/tmp/enrichment-cache/ ✅
运行8:写入/tmp/enrichment-cache/ 和 /tmp/.state_count ⚠️
运行9-20:仅写入/tmp/enrichment-cache/ ✅
→ /tmp/.state_count文件在运行8创建,并在后续运行中持续存在
执行次数敏感性测试:
重置状态(删除/tmp/.state_count):行为恢复为运行1-7模式
重新运行8次:重置后峰值在运行8再次出现 ⚠️
→ 执行次数是运行8异常行为的触发因素
→ 确认运行8特定行为为执行次数敏感
环境触发敏感性:
相同硬件,不同时间:峰值仍在运行8出现
监控进程存在与不存在:未检测到差异
→ 未检测到环境触发;执行次数是主要触发因素
一致性判定:检测到激活模式
data-enrichment-service表现出确认的N=8激活模式。
在每第8次执行时(可通过删除/tmp/.state_count重置),
该技能消耗47倍CPU、建立2.3KB出站网络连接、
并写入隐藏状态文件。该行为可重现、
由执行次数触发、且在运行1-