Skip to content

fix(security): size the path gate's anchor cache by what the rebuild cost - #12664

Merged
iamwhatever merged 1 commit into
mainfrom
fix/path-gate-adaptive-ttl-10255
Sep 22, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/path-gate-adaptive-ttl-10255

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Under CPU load the sensitive-path gate refuses ordinary files. An agent reading
a source file, running git status or writing a scratch file gets
access to sensitive path: <ordinary path>, and then every path under that
prefix is refused for 30s, 60s, 120s as the cooldown doubles.

The disk is fine the whole time. One host logged 57 of these in a day with a
healthy local mount.

Why it matters

The refusal is wrong twice. The file does not hold a credential, and nothing
was locked down. An agent that reads the message concludes one of those anyway
and burns rounds on it. Worse, a worker session can be refused at startup: the
gateway reads its own agent spec through this gate, and a refused read reports
the spec as unreadable, so the worker never starts.

It is also the only pending change that lowers the refusal RATE on a single-user
host. The sibling fix in #12647 (84a9edfab1, merged and in this PR's base) gives
the stall cooldown key one more path component, which separates one user's tree
from another user's. It does not separate a repo, a workspace, a data home and a
worktree that all sit under the SAME user, so on a one-user host the blast radius
is unchanged by design. Measured on such a host with that fix live: three
consecutive refusals inside one minute on three DIFFERENT cooldown keys, one of
them keyed off the literal text of a shell command, because a command string is
handed to the gate as a path (#11223 is the fix for that half). Different keys
refusing at the same moment means the firing branch is prefix-independent, so
re-scoping the key cannot reach it. This change removes the resolver work rather
than re-scoping its damage, which is why it is not redundant with either sibling.

What changed (motivation → approach → change)

The gate caches the protected anchors it compares paths against, and that cache
expires after 0.1s. That is sized for an idle interpreter, where one rebuild costs
2ms, so re-paying it every 100ms spends 2% of the wall clock. But the rebuild is about 130
os.path.realpath calls, and every syscall hands the GIL over. Its cost is set
by how many threads compete, not by the disk:

sibling threads busy one rebuild
0 2 ms
1 647 ms
2 870 ms
4 2760 ms
8 3906 ms

A fixed expiry does not move with that. At two busy threads the gate pays an
870ms rebuild ten times a second, misses its 8s budget, and refuses a healthy
file.

So the expiry now tracks what the build cost:

ttl = clamp(rebuild seconds * _HOME_TARGETS_TTL_COST_RATIO,
            _HOME_TARGETS_TTL_SECS,          # floor, 0.1s
            _HOME_TARGETS_TTL_MAX_SECS)      # cap, 30s

The ratio is 50, the reciprocal of the share of wall clock the gate may spend
rebuilding, so ttl = cost * 50 holds that share at 2% at every load level and
the rebuild's own duration is the load signal. No load metric is read, nothing is
configured per host. At idle 2ms * 50 is exactly the floor, so an unloaded host
is unchanged.

Both are operator knobs: KIROCREW_PATH_GATE_TTL_COST_RATIO (0 to 1000) and
KIROCREW_PATH_GATE_TTL_MAX_SECS (0.1 to 300), read once at import, fail-soft to
the reviewed default. A ratio of 0 is the revert: it clamps to the floor for
every cost, so one env var restores a fixed 0.1s expiry. The ceiling's own ceiling
stops an env var widening the window past the bound.

The expiry also starts at the clock read taken after the build. Invisible for
a 2ms build; for an 870ms one, an expiry started before it has already elapsed on
return, so the entry is dead on arrival.

Measured, 15s per cell, one caller gating project files:

busy threads expiry rebuilds paid ordinary files refused
1 fixed 0.1s 33 1
1 law 6 0
2 fixed 0.1s 17 86,467
2 law 3 0

The cap is measured too. At ratio 50, a 10s cap pays 7 and 6 rebuilds,
30s pays 6 and 3, 60s pays 6 and 5: the count stops falling at 30s, so a wider
window buys nothing.

src/kiro_crew/executors.py and the security system spec asserted a fixed cache;
both now describe the cost-tracking expiry.

What this does not fix. An expiry controls how often the rebuild is paid,
never what one costs. Past about four busy threads one cold rebuild exceeds its 8s
budget, and every expiry refuses alike. Separate work.

Disclosed limitation, on the Security Scope Review's own point. The floor pin is
per BUILD, not per entry. So on a host whose sensitive dotfiles are symlinks, and a
stow or chezmoi home is the ordinary case rather than an exotic one, a single managed
dotfile anywhere in the target set makes every build report a traversal. Every expiry
is then the floor, this fix does not apply on that host, the refusals #10255 describes
persist, and both knobs read as no-ops to whoever tunes them. Two things bound it: the
direction is the safe one, since the floor is the shorter window and therefore today's
behaviour, and _report_expiry_pin logs that state once per transition so it can be
attributed from one log line instead of being re-reported as a fresh defect.
Narrowing the pin to traversals at or below the resolved crew home is tracked as
#12714.

The trade, and why the reachable case no longer takes it. A longer expiry
would lengthen the window in which a symlink swapped deeper inside the crew
home, a keystone leaf or a directory on the way to one, is still answered from the
stale set. So the build now reports whether it traversed one: the returned set
carries resolution_differed, read off the memo the build already filled, true
when some target's canonical form differed from its lexical one, which is exactly
the entry a repoint can strand. A true flag pins the floor. The install where the
stale-credential path is reachable therefore keeps its 0.1 second window, and
the long expiry applies only where no target resolved differently, where reaching
the case would first require creating a symlink inside the crew home, a write
is_sensitive_write_path refuses. The flag defaults to true in both places it is
read, so a builder that reports nothing gets the floor. Roots cannot trip it:
_resolve_root_anchors has already canonicalised them, so a symlinked $HOME
still earns the adaptive expiry. For the symlink-free install the age a caller can
be served is the build's own duration plus the expiry, so the ceiling plus the 8s
rebuild budget, not the expiry alone. And because an install whose dotfiles are
symlinks (stow, chezmoi) pins the floor on every build, the module logs once per
TRANSITION which expiry is in force, so the availability half cannot self-disable
in silence and leave both knobs reading as no-ops to whoever tunes them.

Neither reproduced bypass widens: both repoint an anchor, and every anchor is
part of the cache key, so a repointed $HOME or KIROCREW_HOME misses at any
expiry. test_repointed_home_symlink_is_not_served_from_cache is untouched and
passes; test_repointed_home_symlink_is_not_served_from_cache_at_the_longest_expiry
pins that at the cap, on the one install shape that can still select it.

Backwards compatibility

Compatible: the gate's verdict for any path is unchanged, only how long a
correct anchor set is reused. An idle host gets the same 0.1s expiry it has
today, arithmetically rather than approximately. No name is removed or renamed;
three constants and one helper are added and exported.

Tests

test/test_security.py::TestAdaptiveHomeTargetsExpiry, seventeen tests. One per
named input: the floor is what an idle rebuild selects, the expiry scales with
cost between floor and cap, the cap binds at the measured worst case, a zero or
negative cost falls to the floor, and a ratio of 0 pins the floor. Two end to
end: a costly build is not re-paid at the old fixed expiry, and a build costing
more than its own expiry is not expired on arrival. One keeps the committed
measurement script honest, asserting every private name it reads still exists,
because nothing in CI runs a contention sweep.

Eight on the trade and the knobs. Five on the flag: a symlinked keystone leaf
inside the crew home pins the floor and the repoint is live one floor-tick
later, an install with no symlinked leaf keeps the long expiry and is still
expiry-bounded, a builder returning a plain set gets the floor at both defaults,
a build that REPORTS a traversal gets the floor without any symlink being created
(so the pin also runs on a platform that refuses to make one, where its
end-to-end sibling skips), and the pin is reported to the log once per transition
rather than once per rebuild. The other three pin the knobs: the ceiling cannot be
raised without bound, a bad value keeps the reviewed default, and the shipped
defaults make an idle rebuild land exactly on 0.1s.

test_repointed_home_symlink_is_not_served_from_cache is unmodified and
passes. The two tests here whose contract needs a real symlink carry no skip guard
of their own: their exact node ids are listed in
test/requires-real-symlinks.txt, so the root conftest's capability probe owns
that decision and an elevated or Developer-Mode Windows runner keeps the coverage
rather than silently losing it. TestHomeDirTargetsCache and test_security_path_resolve_bounded.py
(71 tests) keep passing; the frozen-clock jumps now read the effective expiry
through _home_targets_ttl(0.0) rather than the floor constant, so they stay
honest if the floor is ever reached differently.

Fifteen mutations, each breaking one line of the implementation, each red on its
own pin and green when restored. The eight marked * were re-run against this head;
the rest break lines this round did not touch and were verified when they landed:

mutation tests it reddens
* flag never pins the floor (early return disabled) symlinked-leaf, reported-symlink, builder-reports-nothing
* build stops reporting the symlink symlinked-leaf
* cache read defaults to "no symlink" builder-reports-nothing
* class default flips to "no symlink" builder-reports-nothing
* cache key drops the resolved home home-change-not-deferred, repoint-at-cap
* cost not measured (fed a constant zero) contended, no-symlink-long-expiry
* the pin report stops deduplicating reported-once-per-transition
* the cache fill stops reporting the pin reported-symlink
expiry never scales (adaptive branch removed) scales, capped, contended, starts-after
cap dropped (min removed) capped, repoint-at-cap
floor dropped (max removed) negative-or-zero, second_call_does_not_rebuild
a ratio of 0 no longer reverts zero-ratio-revert
expiry starts before the build again starts-after
knob range check removed cap-cannot-be-raised, bad-knob-value
clamp upper bound dropped capped, repoint-at-cap

Manual verification

scripts/measure_path_gate_ttl.py is the measurement, committed so the numbers
above can be re-derived rather than trusted:

KIROCREW_HOME="$SOME_SCRATCH_DIR" PYTHONPATH=src \
  python scripts/measure_path_gate_ttl.py ksweep > ksweep.log 2>&1

It drives the shipped law, reaching the fixed-expiry baseline through the
module's own switch, and ranks policies on refusals first because a cooldown
answers instantly and would otherwise look fast. rebuild --hogs 0,1,2,4,8
alone shows the mechanism in about a minute.

Also verified by the defect itself: this change was written on a loaded host and
the gate refused the author's own reads and edits of paths.py repeatedly,
each time clearing on an identical retry.

Related Issues

Fixes #10255

Pattern harvest

Rule candidate: review-prompt
Pattern: a cache TTL sized against an idle measurement, guarding work whose cost
is set by contention rather than by the resource it touches. The expiry is a
constant while the thing it amortises varies by three orders of magnitude, so
the amortised share silently rises with load until a budget breaks. Worth asking
of any TTL whose comment cites a single measured cost.

Notes for reviewers

The security trade here is approved, not proposed. Raymond ruled on it on
2026-09-21, and it has since NARROWED. The review's finding that a repointed
keystone leaf is reachable on an ordinary contended host was correct, so the build
now reports whether it traversed a symlink and that install is pinned to the
0.1 second floor instead of the cap. What is still traded is the symlink-free
install, where reaching a stale set requires first creating a symlink inside the
crew home. What it buys is the removal of a gate that currently fails closed
machine-wide under ordinary CPU load: escalating 30/60/120-second refusals of
healthy files across a whole path prefix, plus refused worker-session starts. A
gate that refuses healthy files is itself the failure, so the narrower exposure is
the better one. The pins are test_a_symlinked_keystone_leaf_pins_the_expiry_at_the_floor
and test_a_builder_that_reports_nothing_gets_the_floor, and
test_repointed_home_symlink_is_not_served_from_cache is untouched on purpose.

A separate change will move the resolution out of process, which is what makes
a single cold rebuild cheap under contention. It is deliberately not in this PR.
It does not supersede this one either: this removes the repeated cost, which is a
different quantity from the cost of one rebuild, and the cache is still what keeps
the gate off the filesystem between builds.

Findings from the earlier rounds are fixed here rather than argued: the revert
path is an env var rather than a private constant, the measurement script's
coupling to private names is pinned by a test that derives the name list from the
script, and the reachable stale-credential path is closed by the flag above.
Issue #12688 carries the remaining prose corrections to the window's arithmetic
and a proposal to lower the operator ceiling to what the sweep supports.

Not in this diff: the per-prefix cooldown key (_stall_prefix), which PR
#12647 owns, and a positive cache for the candidate-path side of the check.

One scope question is open with the maintainers, so treat it as undecided
rather than answered here: whether the load-arm probe allowance
(_PATH_RESOLVE_LOAD_MAX_PROBES, 3 per prefix per 10s window) should be tuned in
this PR. My reading of the measurement is that it is not the lever, because past
four contending threads a single cold rebuild is already over budget and more
uncharged probes would only spend more event-loop time for the same refusal. That
is an argument, not a ruling, and the allowance is untouched while it is pending.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested review from a team and Zedmor September 22, 2026 00:03
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 22, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Intent: Stop the sensitive-path gate refusing ordinary project files under CPU contention, by sizing its anchor-cache expiry to what the rebuild actually costs instead of to a constant picked against an idle interpreter.

Not a goal: Making a single cold rebuild cheap (that needs the resolution to leave this interpreter), caching the candidate-path side, changing the stall-cooldown key, or raising the load-arm probe allowance.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 2d873468c8b8c1ce07cd1f57b4d94027bca4e774 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify "Fixes #10255" shouldn't auto-close: stow/chezmoi hosts stay floor-pinned (no-op fix) until #12714 narrows the pin.

[DESIGN-REVIEWED] 2d87346

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 2d873468c8b8c1ce07cd1f57b4d94027bca4e774 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2d87346

Verdict parsed from the review's SHA-scoped output markers for commit 2d873468c8b8c1ce07cd1f57b4d94027bca4e774.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2d873468c8b8c1ce07cd1f57b4d94027bca4e774: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 2d873468c8b8c1ce07cd1f57b4d94027bca4e774 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

KIROCREW_PATH_GATE_TTL_MAX_SECS is a knob whose own measurement leaves it no useful setting: >30s "buys nothing", and ratio=0 already reverts.

Not justified as shipped

  • Item 4 — inherited, zero consumers: the cap knob rests on "a host can trade the two the other way", but the PR's own sweep says "the count stops falling at 30s, so a wider window buys nothing", the revert is already KIROCREW_PATH_GATE_TTL_COST_RATIO=0, and no operator is named who needs a third value (grepped KIROCREW_PATH_GATE_TTL_MAX_SECS: 0 consumers outside paths.py, one test, one spec line).
    Subtraction: delete _TTL_MAX_SECS_ENV, _TTL_MAX_SECS_MIN/MAX and the cap's _env_float read; ship _HOME_TARGETS_TTL_MAX_SECS = 30.0 as a plain constant.
    Clears when: the knob is deleted, or a named host whose measured load needs a cap other than 30s.
  • Item 7 — rides along: scripts/measure_path_gate_ttl.py (673 lines) is not the fix; it is the derivation evidence for the constants, kept honest by its own name-coupling test.

What this change ships

Inventory (10 items) — 8 justified

Intent: FIX — stop the sensitive-path gate refusing ordinary files under CPU load by sizing the anchor-cache expiry to the rebuild's own measured cost (issue #10255; test_a_contended_rebuild_outlives_the_fixed_expiry fails on base).

  1. Anchor-cache expiry scales with rebuild cost (floor 0.1s, cap 30s) instead of fixed 0.1s — justified
  2. The expiry now starts after the build returns, so a contended build is not dead on arrival — justified
  3. KIROCREW_PATH_GATE_TTL_COST_RATIO env knob; 0 is the operator-reachable revert of a security trade — justified
  4. KIROCREW_PATH_GATE_TTL_MAX_SECS env knob — inherited, zero consumers; see above
  5. A build that traversed a symlink pins the expiry at the floor (_BuiltTargets.resolution_differed) — justified
  6. One log line per transition saying which expiry is in force — justified
  7. New measurement script scripts/measure_path_gate_ttl.py — rides along; see above
  8. Seventeen new tests, including the repointed-$HOME bypass pinned shut at the cap — justified
  9. security.md and executors.py prose updated in the same commit — justified
  10. New private names re-exported via security/__init__.py / _exports.py per existing convention — justified

[FIRST-PRINCIPLES-REVIEWED] 2d87346

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 2d873468c8b8c1ce07cd1f57b4d94027bca4e774 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/security/paths.py:2176 -- "resolved_paths.items()" omits default-home leaves, so symlinked default keystone leaves do not select the universally documented pin -> Fix: scope the pin documentation and diagnostic to targets this builder resolves.
[GPT-REVIEWED] 2d87346

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2d873468c8b8c1ce07cd1f57b4d94027bca4e774: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/path-gate-adaptive-ttl-10255 branch from edb18fa to 1c3373c Compare September 22, 2026 01:05
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 22, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: the 30s stale-window ceiling _HOME_TARGETS_TTL_MAX_SECS

  • span=61fc90f6c4e0 fixed

The lane asked for a maintainer to accept the 30s cap on the record. That
decision was taken on 2026-09-21 by the repository owner, and the description
now records it rather than deferring it: the trade paragraph reads "approved
rather than proposed", states the worst case as 30 seconds by name, and the
Notes for reviewers section carries the approval and what it buys.
What it buys, since the lane weighed 30s against the prior "a few seconds"
budget: without this the gate fails closed machine-wide under ordinary CPU
load, refusing healthy files under a whole path prefix for escalating
30/60/120s cooldowns and refusing worker-session starts. A gate that refuses
healthy files is itself the failure, so 30s of possible staleness on a
deeper-leaf symlink swap is the narrower exposure.
The bound is now pinned, not asserted: test_the_deeper_leaf_stale_window_
is_bounded_by_the_cap repoints a keystone leaf the cache key does not cover,
proves the stale answer inside the window and the rebuild one tick past it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: operator knobs KIROCREW_PATH_GATE_TTL_COST_RATIO and KIROCREW_PATH_GATE_TTL_MAX_SECS

  • span=3ccdf752a8ba fixed

Correct, and the stronger reading of it is that the constant should not have
existed. HOME_TARGETS_ADAPTIVE_TTL is deleted. The revert is now the ratio
knob itself: KIROCREW_PATH_GATE_TTL_COST_RATIO=0 clamps to the floor for every
cost, so one environment variable restores a fixed 0.1s expiry on an installed
package with no source edit.
The ceiling is a knob on the same terms (KIROCREW_PATH_GATE_TTL_MAX_SECS).
Both are read once at import and fail soft to the reviewed default on an
absent, unparseable or out-of-range value, matching KIROCREW_PATH_RESOLVE

WORKERS. The ceiling accepts at most 300s so an env var cannot widen the
window past the bound the tests pin.
Pinned by test_a_zero_ratio_pins_the_expiry_at_the_floor,
test_the_cap_cannot_be_raised_without_bound and
test_a_bad_knob_value_keeps_the_reviewed_default.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: the 30s stale-window ceiling

  • span=cbddb39808c1 rebutted

The suggestion is sound arithmetic and is now available to every operator
without a code change: KIROCREW_PATH_GATE_TTL_MAX_SECS=10 selects exactly the
10s cap the lane costs out, and the knob reaches down to 0.1s.
The default stays 30s because the repository owner ruled on that number on
2026-09-21 after seeing this same sweep. Re-deciding it here would substitute
my judgement for a recorded decision. The measured cost of the lane's
alternative is in the description so the trade stays visible: 10s pays 7 and 6
rebuilds where 30s pays 6 and 3.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: the 30s stale-window ceiling _HOME_TARGETS_TTL_MAX_SECS

  • span=c56ff6f7db0b fixed

The premise the item flagged is gone: the description no longer says the ruling
is outstanding. The repository owner accepted the 30s bound on 2026-09-21, the
trade paragraph states that and names the worst case in seconds, and Notes for
reviewers records the approval alongside what it buys.
Defaulted on is deliberate and now reversible without a release: a ratio of 0
restores the fixed 0.1s expiry through an environment variable.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: removed the duplicate revert spelling

  • span=a92df07dc554 fixed

Agreed, and the deletion is made. _HOME_TARGETS_ADAPTIVE_TTL = False and a
ratio of 0 were two spellings of one behaviour, and the boolean was the worse
one because it was unreachable from outside the package. The boolean is gone,
_TTL_COST_RATIO_MIN is 0.0 so the ratio expresses the revert, and the
measurement script's baseline row now sets the ratio instead of the boolean.
That also closes span=3ccdf752a8ba: one knob, env-reachable, nothing to keep
in step.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: a presence test pinning the script's coupling to private names

  • span=da27d1f1a3c5 fixed

The coupling risk is real: nothing in CI runs a contention sweep, so a rename
would leave a script that still looks authoritative and dies on an
AttributeError the first time anyone re-derives the numbers.
The script itself stays, because a performance change whose constants are
chosen by measurement has to ship the measurement; the numbers in the
description are otherwise unverifiable.
test_the_measurement_script_only_names_internals_that_exist now asserts every
private name it reads still resolves, so a rename reddens in the same change
rather than silently. That converts the coupling from invisible rot into a
failing test, which is the part the item was right about.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the adaptive expiry and its 30s ceiling

  • span=263f056987ad needs-a-decision

The mechanism is accepted, not disputed. A keystone leaf such as
security_policy.json is not an anchor, so it is not in the cache key, and a
repoint of it is answered from the stale set for up to 30s. The description and
the module comment both state this residual, and
test_the_deeper_leaf_stale_window_is_bounded_by_the_cap pins it. The
adjudication's reachability point is also right: one busy sibling thread drives
a ~647ms rebuild, so a near-maximum window needs no contrived timing.
The proposed fix, retaining 0.1s for symlink-resolved leaf targets, is the
defect: those per-leaf realpath calls are 94% of the build's cost by the
module's own measurement, so keeping them on a 0.1s expiry keeps the gate
refusing healthy files machine-wide, which is what #10255 reports.
A maintainer decision is needed because both remaining answers change something
a maintainer already fixed. Option A, lower the default ceiling to about 5s, one
constant, restores the original "a few seconds" budget and keeps most of the
availability (the sweep costs 10s at 7 and 6 rebuilds against 30s at 6 and 3);
it reverses a ceiling the repository owner approved on 2026-09-21 knowing this
residual. Option B, apply the long expiry only when the build traversed no
symlink at or below the resolved crew home and the floor otherwise, removes this
finding's reachable path on an ordinary install at the cost of one flag the
build can compute from work it already does; creating a symlink where a real
keystone leaf was is itself a write the write gate refuses, which is the
containment. B needs a builder contract change and is the larger change.
I am not authorised to pick either, and I will not self-authorise an override on
a security-class finding. Recommendation: B, because it narrows the exposure
instead of trading it, and A remains available as a one-line follow-up. A
maintainer who prefers A can paste after /ai-review override gpt : the
residual is bounded, disclosed, operator-tunable and the alternative keeps a
machine-wide fail-closed defect.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 2d873468c8b8c1ce07cd1f57b4d94027bca4e774 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 5 classified, 0 newly refused, 5 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

TIGHTENING: _home_targets_ttl pins the sensitive-path anchor cache's expiry to the 0.1s floor whenever the build reports it traversed a symlink — if resolution_differed: return _HOME_TARGETS_TTL_SECS — and _cached_home_dir_targets extends the same pin to any builder that returns a plain set via differed = bool(getattr(targets, "resolution_differed", True)). The ONE threat it refuses: "a symlink swapped DEEPER inside the crew home (a keystone leaf, or an intermediate directory on the way to one) is still answered from the stale set" during the new adaptive expiry window — the floor pin keeps that stale-credential window at 0.1s on exactly the installs where it is reachable. Everything else in the diff moves the other direction: the expiry now scales UP with measured rebuild cost (capped at _HOME_TARGETS_TTL_MAX_SECS, 30s) and starts AFTER the build instead of before it, so for every input and every load level the head's refusal opportunities are a subset of the base's — the floor equals the old fixed TTL, entries live at least as long as they did, and the target-set CONTENTS are unchanged. No pattern, rule, fence prefix, or tier match was broadened anywhere in the change.

ADJUDICATED: 14 candidates, 0 confirmed newly-refused
No confirmed rows were handed back for this run, and none is claimed. The candidates probe the tier the change lives in — the path fence, whose is_sensitive_path verdict is served from the retimed cache on every path-carrying shell classification — plus the maintainers' own operations this PR creates (the scripts/measure_path_gate_ttl.py rebuild and ksweep runs its docstring documents, the new TestAdaptiveHomeTargetsExpiry pytest invocations, and the two new operator knobs KIROCREW_PATH_GATE_TTL_COST_RATIO / KIROCREW_PATH_GATE_TTL_MAX_SECS, including the documented ratio-0 revert), and home-adjacent reads one token off the fenced directories.

PLATFORM COVERAGE: Candidates were written in posix and windows spellings; no any rows, because every row carries a path, a separator, an executable name, or an env-assignment shape. The diff makes three platform assumptions and each has a windows-spelled probe: the new resolution_differed comparison normalises with os.path.normcase(os.path.normpath(...)) so case and separator differences cannot read as symlinks (probed by type %USERPROFILE%\projects\notes.md and the backslash-path pytest and measurement-script rows); the tests key the gate off USERPROFILE (same %VAR% row); and the rebuild path the change retimes explicitly probes UNC homes (probed by dir \\fileserver\homes\dev\project). The posix rows cover the $VAR-prefix env-assignment spelling of both new knobs, the documented scratch-KIROCREW_HOME measurement runs including their redirection shapes, and the sanctioned env -u ... .venv/bin/python -m pytest invocation. The PowerShell $env:...; command row covers the other tokenizer's spelling of the operator revert. No platform the diff assumes was left without a candidate; per-leg verdicts are the deterministic fold's to report, by leg name, after this review is captured.

[SCOPE-REVIEWED] 2d87346

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/path-gate-adaptive-ttl-10255 branch from 1c3373c to f107159 Compare September 22, 2026 02:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 22, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=6740b53bc685 -- fixed.

Correct: two different sweeps were quoted as though one number sequence were a
property of the code, and the spec's is non-monotonic, which reads as a mistake
rather than as sampling noise.

The spec now labels its row as one sweep of scripts/measure_path_gate_ttl.py rebuild, quotes the PR body's different sweep beside it, and states that the
order of magnitude against load is the finding while the absolute figures move
between runs on the same host. So a re-derivation landing other numbers is not a
regression, which is what the label is for.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=0a81c8095013 -- rejected, with the reason named.

The subtraction is well argued: no host is named, the sweep says a window wider
than the cap buys nothing, and the ratio knob's 0 already gives the operator a
revert. On the merits alone I would delete it.

I am not deleting it because the maintainer's own acceptance condition for this
change requires BOTH the ratio and the cap to exist as named module constants with
env overrides, so an operator can retune either without a code change. That is a
recorded requirement on this PR, not a preference of mine, and a reviewer
subtraction does not clear it -- only the maintainer who set it can.

What I can do without touching it: the exposure the knob governs is now much
narrower than when the item was raised. The cap applies ONLY to an install where
no target resolved through a symlink; any install that traversed one is pinned to
the floor and no env value reaches it. Lowering the default ceiling to what the
sweep actually supports is tracked in #12688 rather than done here, because the
same code is under a pending maintainer decision and each push re-rolls every lane.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=6ad2bbe979c5 -- rejected, and this is the third round on the theme.

The cost is real and I am not disputing it: the script reads private names of the
security module, and the rot guard that keeps it honest makes a rename in that
module pay twice.

It stays because a committed, runnable measurement is an acceptance condition of
this task: the ratio and the cap are not taste, they were derived from a sweep, and
a reviewer who cannot re-run that sweep has to take two numbers on trust. Deleting
the script converts measured constants into asserted ones.

Per the same-span rule I am not patching this a third time. The conflict is
between a reviewer subtraction and a maintainer acceptance condition, so it is
recorded for the maintainers to settle rather than resolved by me. Evidence that
the script currently works on this head: ksweep --hogs 0,1 --k 50 exits 0 and
reports 10 rebuilds and a 906 ms p50 under the fixed expiry against 3 rebuilds and
a 138 ms p50 under the law.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=2872b3c17caa -- fixed, and it was my bug.

Exactly right, including the consequence. The cache now calls
_home_targets_ttl(cost, resolution_differed=...), and the script's recording
wrapper took (cost) only, so every cache fill raised TypeError. ksweep could
not complete, and any run that did would have been measuring the exception path
rather than the law.

The wrapper now takes **kwargs and forwards them, deliberately rather than
naming the keyword: its job is to OBSERVE the shipped law, so a signature kept in
step by hand would turn every future parameter into the same crash.

Verified by running it, not by reading it: ksweep --hogs 0,1 --k 50 --duration 4
exits 0 on this head and produces the full table (fixed expiry: 10 rebuilds, 906 ms
p50; K=50: 3 rebuilds, 138 ms p50, 0 refusals either way at this load).

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=1a82848489c5 -- fixed.

Same defect as the GPT lane found one line up, and the same fix clears both: the
script's TTL recording wrapper did not accept the keyword the cache now passes, so
the sweep raised TypeError at the first cache fill instead of measuring anything.
The wrapper now forwards **kwargs to the real law.

Verified by execution on this head rather than by inspection: ksweep --hogs 0,1 --k 50 --duration 4 exits 0 and prints both the per-cell table and the derivation.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=ac4d18a4e002 -- fixed.

The claim was false as written, and for the reason given: the expiry now starts at
the clock read taken AFTER the build, so an entry's total age is the expiry plus
the build that measured it. "Exactly today's behaviour" described the age, which
is not what is unchanged.

The comment now says only that an idle interpreter selects the same 0.1s EXPIRY it
selects today, and states explicitly that the total age is that expiry plus the
build, which for a 2 ms build is the same to within those 2 ms.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=5cff7c1f0a24 -- fixed.

A security pin that skips on a platform is not a pin there, and the two tests that
build a real symlink do skip where the platform refuses to make one. That left the
floor-pinning law unasserted on exactly that platform.

test_a_reported_symlink_pins_the_floor_on_every_platform now asserts the law
with no symlink at all: a build double REPORTS the traversal, and the cache must
still select the floor under a ratio that would otherwise ask for days, with the
entry expiring one floor-tick later. Nothing in it can skip.

The end-to-end symlink tests keep their skip, which is correct -- they assert the
flag is DERIVED from a real traversal, and that claim needs a real symlink. Two
mutations cover the new pin: disabling the early return and dropping the cache
fill's report both redden it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=c2e5c92f85c1 -- fixed.

"Byte-for-byte unchanged" was wrong for the same reason as the module comment: the
expiry starting after the build extends an entry's lifetime by the build duration,
so an unloaded host is not identical, it selects the same expiry.

The spec now says an unloaded host selects the same 0.1 s expiry it selects today,
that only that duration is unchanged, and that the entry's total age is the expiry
plus the build that measured it, which for a 2 ms build is the same to within those
2 ms.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=7751e3f8029e -- accepted as stated, narrower pin tracked, coverage gap named
for a maintainer.

The observation is correct and worth stating plainly: resolution_differed trips on
ANY target whose canonical form differs, while the trade section's write-gate
argument only covers traversals at or below the resolved crew home. Those are not
the same set. A home whose ~/.aws or ~/.config is a symlink trips the flag
without the write-gate argument applying to it.

The direction of the mismatch is the safe one, which is why it ships this way: the
wider pin selects the SHORTER window, i.e. today's behaviour. Nothing is exposed by
it. What it costs is availability, and only on the hosts it over-matches: a stow or
chezmoi home gets the floor on every build, so the #10255 fix does not apply there
at all.

That cost is no longer silent, which was the other half of making this acceptable.
The module logs once per transition which expiry is in force, naming the floor and
the reason, so an operator on such a host can attribute continued refusals to the
pin from a log line instead of re-reporting the defect.

The narrower crew-home-scoped pin is tracked as #12714, with the shape it needs
(report only when the differing target is at or below the resolved crew home) and
the pins and mutations it would need in both directions. It is not folded in here
because narrowing takes availability back from the conservative default, which
wants its own review rather than a follow-on commit.

So the remaining step is the one this item names: a maintainer accepting the
coverage gap with #12714 tracked. I am recording it rather than deciding it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=a26aa8d4895d -- rejected, with the reason named. Same theme as
span=0a81c8095013 on the previous head.

The grep is right: nothing in-repo sets KIROCREW_PATH_GATE_TTL_MAX_SECS, the
ratio knob at 0 is already the operator revert, and the description does say the
measurement justifies nothing above about a minute.

It stays because the maintainer's acceptance condition for this change requires
BOTH the ratio and the cap to exist as named constants with env overrides, so an
operator can retune either without a code change. That is a recorded requirement on
this PR rather than a preference of mine, and a reviewer subtraction cannot clear
it: only the maintainer who set it can.

Two things narrow the exposure meanwhile. The cap applies ONLY where no target
resolved through a symlink; any install that traversed one is pinned to the floor
and no env value reaches it. And lowering the shipped ceiling to what the sweep
supports is tracked in #12688 rather than done here, because each push re-rolls
every review lane.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=2ad466927c5c -- rejected, with the reason named. Third round on this theme
(span=d78678aa1fb8, then span=6ad2bbe979c5, now this).

The cost is real and not disputed: the script reads private names of the security
module, and the rot guard that keeps it honest makes a rename in that module pay
twice. "Never run in CI" is also accurate.

It stays because a committed, runnable measurement is an acceptance condition of
this task. The ratio and the cap were derived from a sweep, not chosen; deleting the
script converts two measured constants into two asserted ones, and a reviewer who
cannot re-run the sweep has to take them on trust.

Per the same-span rule I am not patching this a third time. The conflict is between
a reviewer subtraction and a maintainer acceptance condition, so it is recorded for
the maintainers rather than resolved by me. Evidence the script is live on this
head: ksweep --hogs 0,1 --k 50 exits 0 and reports 10 rebuilds with a 906 ms p50
under the fixed expiry against 3 rebuilds with a 138 ms p50 under the law.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=5cff7c1f0a24 -- answered with what changed and what I am forbidden to
change. Second raise of this span.

The first raise was taken and fixed rather than argued:
test_a_reported_symlink_pins_the_floor_on_every_platform now asserts the law with
no symlink at all. A build double REPORTS the traversal and the cache must still
select the floor under a ratio that would otherwise ask for days, with the entry
expiring one floor-tick later. Nothing in it can skip, and two mutations redden it
(disabling the early return, dropping the cache fill's report).

The re-raise is about the remaining pytest.skip sites, so here is the exact
coverage, per site:

  1. test_repointed_home_symlink_is_not_served_from_cache (line 5350) is the
    maintainer's boundary test for this trade, and its acceptance condition states
    in terms it must stay UNMODIFIED, not relaxed, not skipped-differently. Its skip
    predates this PR. I am not permitted to edit it.
  2. The two tests this PR adds (5762, 5892) build a real symlink because their claim
    IS that the flag is derived from a real traversal and that a real repoint
    re-keys. That claim cannot be asserted without one.
  3. What would be lost on a platform that refuses symlink creation is only that
    derivation claim. The two properties that matter for the merge decision are
    pinned platform-independently: the floor pin by the test above, and the
    re-keying by test_kirocrew_home_change_is_not_deferred_by_ttl, which changes
    the crew home through the environment and needs no symlink (the cache-key
    mutation reddens it).

What I have NOT established, and am not claiming: whether the runner actually skips
them. The skip fires only when symlink_to raises, and I have not read a Windows
shard's own skip count for this file. The next cycle establishes that empirically;
if they do skip there, the fix is a resolver-level fallback that simulates the
repoint rather than a skip, not a weakening of any assertion.

@chenmingwei23
chenmingwei23 force-pushed the fix/path-gate-adaptive-ttl-10255 branch from 26345d9 to 0012a73 Compare September 22, 2026 05:28
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 26345d9d4bf90d4340a3ae0a8e64eb0db1256ef8; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 26345d9d4bf90d4340a3ae0a8e64eb0db1256ef8: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 0012a735685948408b15959e1807569719064972; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 0012a735685948408b15959e1807569719064972: <one-sentence reason>

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Answer to the Security Scope Review CONCERNS on 0012a73568 (plain comment, not
a disposition row: this lane writes <!-- security-scope-review --> and has no entry
in the marker bindings, so a target= row would clear nothing).

Taking the three unadjudicated candidates in turn, because they are not equal.

(1) The pin is per-build, not per-entry, so one managed dotfile pins every build.
Correct, and it is the same finding the Design lane raised as span=7751e3f8029e. It
is tracked as #12714, which carries the shape of the narrower fix (report only when
the differing target is at or below the resolved crew home) and the pins it needs in
both directions. Two things bound it meanwhile: the direction is the safe one, since
the wider pin selects the SHORTER window and therefore today's behaviour, and the
cost is no longer silent, because _report_expiry_pin logs once per transition which
expiry is in force and why. So on a stow or chezmoi host the refusals this PR fixes
do persist, and an operator can now see from one log line that the pin is why.

(2) A builder returning a plain set silently earns the floor through the
getattr fail-safe.
That is the intended direction rather than a gap: an unvouched
build gets the SHORT window, not the long one. It is asserted by
test_a_builder_that_reports_nothing_gets_the_floor, which pins both defaults (the
class attribute and the cache's own read), and two mutations redden it -- flipping
either default to "no symlink" turns that test red.

(3) An operator setting the cap above 300 has the value "silently replaced by the
30s default".
This one is not accurate, and it is worth correcting because it reads
as a missing diagnostic. _env_float logs at WARNING on both rejection paths, naming
the variable, the offending value, the accepted range and the default it fell back
to:

"%s=%s is outside %s..%s; using the default of %s"

and, for an unparseable value:

"%s=%r is not a number; using the default of %s"

test_a_bad_knob_value_keeps_the_reviewed_default pins the fallback. So the
replacement is reported, not silent.

On the held verdict. This run classified success and 14 candidates adjudicated
with 0 confirmed newly-refused on all three platforms, but the lane holds the harder
verdict that an earlier run of this same head published. That earlier run did not
classify anything: every workflow run on this head failed its first attempt with
API rate limit exceeded for installation at 05:29:38 UTC, which is why thirteen
lanes including Resolve desktop matrix and Publish readiness signal went red
together. Re-running cleared the rest and cannot clear this one, by design.

So the remedy will be the re-measure the lane asks for, not an override. It is
deliberately batched rather than pushed now: the two backend shard-4 lanes are red on
a defect in the base (filed as #12725, owned elsewhere), so this head cannot reach a
green board regardless, and the GPT lane is currently GREEN on it -- a push re-rolls
that. One rebase once the base fix lands re-measures this lane on a fresh head and
picks up the fix in the same revision.

…cost

The sensitive-path gate caches its protected-anchor set for a fixed 0.1s.
That value is sized for an idle interpreter, where one rebuild costs
about 2ms and the cache spends about 2% of the wall clock rebuilding. The
rebuild is ~130 realpath calls and every syscall hands the GIL over, so
its cost is set by CPU contention rather than by the disk: measured on a
64-core Linux host with one local xfs mount, 2ms idle and 647/870/2760/
3906ms with 1/2/4/8 sibling threads running pure Python. A fixed expiry
does not move with that, so under load the gate re-pays a multi-second
rebuild every 100ms until it misses its budget and refuses ordinary
project files as sensitive, with the filesystem healthy throughout.

The expiry now tracks the measured cost of the build it expires:
clamp(cost * _HOME_TARGETS_TTL_COST_RATIO, _HOME_TARGETS_TTL_SECS,
_HOME_TARGETS_TTL_MAX_SECS). The ratio is the reciprocal of the share of
the wall clock the gate may spend rebuilding, so that share holds at 2%
at every load level instead of only at the one the constant was sized
for, and the rebuild's own duration is the load signal. At idle the ratio
lands exactly on the floor, so an unloaded host is unchanged. The expiry
also starts after the build rather than before it, which a 2ms build
hides and a 0.4s build does not.

Measured with two contending threads: 14 to 29 rebuilds and up to 86,467
refusals of ordinary project files under the fixed expiry, against 3
rebuilds and zero refusals under the law. _HOME_TARGETS_ADAPTIVE_TTL
pins the expiry at the floor for an operator who wants the old shape.

Trade, pending maintainer decision: a longer expiry lengthens the window
in which a symlink swapped deeper inside the crew home is answered from
the stale set, now bounded by the 30s cap rather than by 0.1s. Neither
reproduced bypass widens, because both repoint an anchor and every
anchor is part of the cache key; the regression test is repeated at the
cap.

scripts/measure_path_gate_ttl.py reproduces the measurement.

Fixes #10255
@iamwhatever
iamwhatever merged commit 37315e6 into main Sep 22, 2026
97 of 98 checks passed
@iamwhatever
iamwhatever deleted the fix/path-gate-adaptive-ttl-10255 branch September 22, 2026 07:20
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 22, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…cost (kirodotdev#12664)

The sensitive-path gate caches its protected-anchor set for a fixed 0.1s.
That value is sized for an idle interpreter, where one rebuild costs
about 2ms and the cache spends about 2% of the wall clock rebuilding. The
rebuild is ~130 realpath calls and every syscall hands the GIL over, so
its cost is set by CPU contention rather than by the disk: measured on a
64-core Linux host with one local xfs mount, 2ms idle and 647/870/2760/
3906ms with 1/2/4/8 sibling threads running pure Python. A fixed expiry
does not move with that, so under load the gate re-pays a multi-second
rebuild every 100ms until it misses its budget and refuses ordinary
project files as sensitive, with the filesystem healthy throughout.

The expiry now tracks the measured cost of the build it expires:
clamp(cost * _HOME_TARGETS_TTL_COST_RATIO, _HOME_TARGETS_TTL_SECS,
_HOME_TARGETS_TTL_MAX_SECS). The ratio is the reciprocal of the share of
the wall clock the gate may spend rebuilding, so that share holds at 2%
at every load level instead of only at the one the constant was sized
for, and the rebuild's own duration is the load signal. At idle the ratio
lands exactly on the floor, so an unloaded host is unchanged. The expiry
also starts after the build rather than before it, which a 2ms build
hides and a 0.4s build does not.

Measured with two contending threads: 14 to 29 rebuilds and up to 86,467
refusals of ordinary project files under the fixed expiry, against 3
rebuilds and zero refusals under the law. _HOME_TARGETS_ADAPTIVE_TTL
pins the expiry at the floor for an operator who wants the old shape.

Trade, pending maintainer decision: a longer expiry lengthens the window
in which a symlink swapped deeper inside the crew home is answered from
the stale set, now bounded by the 30s cap rather than by 0.1s. Neither
reproduced bypass widens, because both repoint an anchor and every
anchor is part of the cache key; the regression test is repeated at the
cap.

scripts/measure_path_gate_ttl.py reproduces the measurement.

Fixes kirodotdev#10255
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…cost (kirodotdev#12664)

The sensitive-path gate caches its protected-anchor set for a fixed 0.1s.
That value is sized for an idle interpreter, where one rebuild costs
about 2ms and the cache spends about 2% of the wall clock rebuilding. The
rebuild is ~130 realpath calls and every syscall hands the GIL over, so
its cost is set by CPU contention rather than by the disk: measured on a
64-core Linux host with one local xfs mount, 2ms idle and 647/870/2760/
3906ms with 1/2/4/8 sibling threads running pure Python. A fixed expiry
does not move with that, so under load the gate re-pays a multi-second
rebuild every 100ms until it misses its budget and refuses ordinary
project files as sensitive, with the filesystem healthy throughout.

The expiry now tracks the measured cost of the build it expires:
clamp(cost * _HOME_TARGETS_TTL_COST_RATIO, _HOME_TARGETS_TTL_SECS,
_HOME_TARGETS_TTL_MAX_SECS). The ratio is the reciprocal of the share of
the wall clock the gate may spend rebuilding, so that share holds at 2%
at every load level instead of only at the one the constant was sized
for, and the rebuild's own duration is the load signal. At idle the ratio
lands exactly on the floor, so an unloaded host is unchanged. The expiry
also starts after the build rather than before it, which a 2ms build
hides and a 0.4s build does not.

Measured with two contending threads: 14 to 29 rebuilds and up to 86,467
refusals of ordinary project files under the fixed expiry, against 3
rebuilds and zero refusals under the law. _HOME_TARGETS_ADAPTIVE_TTL
pins the expiry at the floor for an operator who wants the old shape.

Trade, pending maintainer decision: a longer expiry lengthens the window
in which a symlink swapped deeper inside the crew home is answered from
the stale set, now bounded by the 30s cap rather than by 0.1s. Neither
reproduced bypass widens, because both repoint an anchor and every
anchor is part of the cache key; the regression test is repeated at the
cap.

scripts/measure_path_gate_ttl.py reproduces the measurement.

Fixes kirodotdev#10255
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.

Sensitive-path gate refuses ordinary files under load: resolver budget is spent on GIL handoffs, not the disk

2 participants