Skip to content

perf(dashboard): cache the tool-policy read by agents-directory revision - #12722

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/tool-policy-spec-scan
Sep 23, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/tool-policy-spec-scan

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

GET /api/session-tool-policy costs 750-965 ms per request on a host with ~2000 installed agent specs. Managed MCP servers call it at session start, so it runs on ordinary traffic. The read is offloaded to a worker, but it is pure Python holding the GIL, and a py-spy --gil profile of the live gateway attributes 6% of all GIL-holding samples (17 of 275) to this one call chain.

Why it matters

Those GIL stalls surface as event-loop lag. The adaptive concurrency controller reads the lag as pressure and pinned the subagent cap at 1 on an idle 128-core host, so every user with a large agents directory runs fewer subagents than the machine allows, and every other request on the loop waits behind the scan.

What changed (motivation → approach → change)

The handler resolves an agent's managedToolPolicy by declared name, parsing every spec in the directory through the hardened reader, and when nothing declares the name it parses every spec a second time so that "no match" is honest. Nothing is remembered between requests, so an unchanged directory pays 2N hardened reads per call.

The fix memoizes the resolved answer per agents directory and agent name in src/kiro_crew/dashboard/handlers/sessions.py, keyed on a stat-only revision: the directory mtime, (name, mtime_ns, ctime_ns, size, inode, device, mode) of every spec-suffixed entry, and the parsed-spec generation that agent_discovery.clear_list_agents_cache() already bumps, exposed as spec_cache_generation() in src/kiro_crew/agent_discovery.py. Every in-process writer that clears the catalog caches therefore also invalidates this memo, with no writer changes and no callback registry.

The memo steps aside wherever metadata cannot prove freshness, and the read then costs exactly what it costs on main: a symlinked spec entry (its metadata cannot see edits to the target; the stat itself is follow_symlinks=False); Windows (st_ctime_ns is creation time there; _TOOL_POLICY_MEMO_ENABLED); any entry whose mtime or ctime is younger than two seconds (_TOOL_POLICY_RACY_WINDOW_NS, the rule git applies to racy index entries, so a same-tick rewrite is never served stale); more than _TOOL_POLICY_REVISION_MAX_ENTRIES (4,096) entries, with one warning per process. An answer is stored only when the revision is identical before and after the read, so a write landing mid-read is never memoized under the old revision. At most _TOOL_POLICY_CACHE_MAX_AGENTS (256) names are retained per directory.

Only resolved answers are cached. ManagedToolPolicyUnreadable and AmbiguousAgentSpecError are re-derived on every call, so the fail-closed refusal and its per-request audit are byte-for-byte what they were; the readers and the path resolver are untouched. Scope: this covers the profiled route, GET /api/session-tool-policy; the KAS session-start projection in acp/kas_agents.py still parses per call and is tracked on #12721.

Backwards compatibility

Compatible: the route's responses, status codes and audit events are unchanged for every input; the only difference is that an unchanged directory is not re-read.

Tests

test/test_session_tool_policy_cache.py (new), each verified RED on main and GREEN here:

  • test_an_unchanged_directory_is_answered_without_reading_any_spec -- a second call opens no spec file.
  • test_an_in_place_edit_is_seen_and_the_new_policy_is_served -- an edited spec is read again and the new policy returned.
  • test_a_no_policy_answer_is_cached_until_a_spec_appears -- None is cached; a spec added afterwards is found.
  • test_a_refusal_is_re_derived_on_every_call -- an unreadable spec refuses and reads on every call.
  • test_the_cache_is_per_agent_and_per_directory.
  • test_the_revision_sees_content_and_permission_changes -- content/size on every platform, mode on POSIX.
  • test_the_memo_is_disabled_when_the_platform_cannot_prove_freshness -- with the memo switched off the route still answers correctly and reads on every call.
  • test_an_edit_during_the_read_is_not_memoized -- a spec rewritten while the uncached read is in flight leaves nothing in the cache; the next call serves the new policy.
  • test_a_directory_past_the_entry_cap_is_not_memoized -- above the entry cap there is no revision, the route still answers, and exactly one warning is logged.
  • test_a_fresh_spec_is_not_memoized_until_the_racy_window_expires -- a just-written spec yields no revision; once the clock passes the window it does.
  • test_a_symlink_entry_is_seen_without_creating_one -- the platform-independent counterpart: a fake directory entry reporting is_symlink() yields no revision.
  • test_the_catalog_invalidation_point_drops_cached_policy_answers_too -- with no filesystem change the revision is stable, and clear_list_agents_cache() alone changes it.
  • test_the_revision_ignores_files_the_spec_scans_ignore.
  • test_the_route_serves_a_repeat_request_without_spec_reads -- end to end through the handler.

test/test_session_tool_policy_off_loop.py, test_agent_discovery.py, test_agent_capabilities.py, test_member_memory_api.py, test_mcp_call_site_auth_coverage.py and test_agent_spec_hardened_reads.py still pass.

Manual verification

N/A -- unit coverage sufficient: the regression is a count of reads at the real filesystem seam, which the tests measure directly.

Related Issues

Part of #12721 -- the issue stays open for the KAS session-start sibling (acp/kas_agents.py) and the deferred follow-ups recorded there.

Pattern harvest

Rule candidate: review-prompt
Pattern: a per-request handler that scans a whole directory of files to find one entry, with no revision-keyed memo, on a directory that is user-installed and can hold thousands of entries.

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

Part of #12721 -- the issue stays open for the KAS session-start sibling (acp/kas_agents.py) and the deferred follow-ups recorded there.

@Pearcekieser
Pearcekieser requested review from a team and dwu96 September 22, 2026 05:39
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Intent: Make GET /api/session-tool-policy answer an unchanged agents directory from one scandir instead of re-reading and re-validating every spec (twice) per request, removing the second-largest GIL holder in the gateway profile while keeping every response, refusal and audit event identical.
Not a goal: Changing the hardened readers, the path resolver, spec_by_declared_name, the fail-closed refusal semantics, or the catalog caches in agent_discovery; no configuration knob.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of ce858d445c91cd26f4ba63c7b4ba388d16f261c7 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the agents directory can never live on a network mount — a stale NFS attribute cache defeats the stat revision beyond the 2-second racy window.

Suggestions

[DESIGN-REVIEWED] ce858d4

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed ce858d445c91cd26f4ba63c7b4ba388d16f261c7 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

The single candidate against sessions.py:200 claims the count cap (len(answers) >= _TOOL_POLICY_CACHE_MAX_AGENTS) leaves each retained field unbounded, invoking a-bound-bounds-every-field-it-retains. Falsified:

  • The retained policy nested container is NOT unbounded — every spec is read through agent_discovery._read_spec_bytes, which caps at hooks.MAX_FILE_BYTES (50 MB) and raises FileTooLargeError past it. The rule's condition is a field with "no length bound at all"; this field has one.
  • The retained agent_name is not an unbounded external string: it is a resolved agent identity from slot.agent / info.agent / state.sessions.get_agent(...), sanitized against traversal, and short in practice — not attacker-authored free text.
  • The count is bounded (256) and agent_name count is likewise bounded to 256 by the same guard, so the structure is bounded at 256 × (≤50 MB) — loose, but bounded, not the "unbounded" the rule targets.
  • The concrete input required (256 distinct real agents each carrying a ~50 MB managedToolPolicy) does not occur in practice; the observed policies are tiny ({"exclude": ["shell"]}). And the uncached path already JSON-parses every spec in the directory on every request, so any giant-spec directory is catastrophic before the memo retains anything — the cache introduces no new order-of-magnitude harm.

I could not re-derive a concrete-in-practice input plus an observable wrong outcome at the required bar, and found no other grounded defect in the caching logic (the before/after revision guard, racy-window skip, symlink/Windows/overflow disables, and shared spec-generation invalidation are all consistent).

[OPUS-REVIEWED] ce858d4

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of ce858d445c91cd26f4ba63c7b4ba388d16f261c7 via the fork AI-review pipeline — 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: PASS

Verify the 4,096-entry cap on a real large install: past it the fix silently switches off, and big directories are exactly who this PR is for.

What this change ships

Inventory (9 items) — 9 justified

Intent: stop an unchanged agents directory from costing ~1 s of GIL-holding spec parsing on every session-tool-policy request — a FIX (measured py-spy profile, issue #12721, tests verified red on base).

  1. A repeat policy request against an unchanged agents directory answers without reading any spec — justified
  2. New cross-module accessor agent_discovery.spec_cache_generation() — justified
  3. Windows never uses the memo; every request there still pays the full read — justified
  4. Specs written within the last two seconds are not memoized — justified
  5. Directories over 4,096 spec entries are never memoized, with one warning per process — justified
  6. A symlinked spec entry disables the memo for its directory — justified
  7. At most 256 agent answers are kept per directory — justified
  8. Refusals (unreadable or ambiguous spec) are re-derived and re-audited on every call — justified
  9. clear_list_agents_cache() docstring now names the cross-module generation — justified

The existing stat-signature cache (parsed_agent_specs / _dir_signature, agent_discovery.py:1317) does not do this job: the base's own spec_by_declared_name docstring records why the policy read must not filter over it (SEL attribution), and the new fingerprint's extra fields serve a stale-policy harm the catalog signature deliberately tolerates. The one unfixed sibling (acp/kas_agents.py:612, grep spec_by_declared_name, count 1) is declared and tracked on #12721.

[FIRST-PRINCIPLES-REVIEWED] ce858d4

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed ce858d445c91cd26f4ba63c7b4ba388d16f261c7 via the fork AI-review pipeline; updated in place on each push.

Review details

FINDING -- src/kiro_crew/dashboard/handlers/sessions.py:3610 -- replacing "st.st_ctime_ns" with mtime survives the added tests, leaving same-size rewrites with restored mtime stale -> Fix: add a same-size rewrite test that restores mtime and requires ctime to invalidate the cache.
[GPT-REVIEWED] ce858d4

@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
@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from 15528ca to 3fad276 Compare September 22, 2026 06:06
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • metadata-only revision can reuse a stale containment policy — fixed in 3fad276

Each spec's revision entry now carries (name, mtime_ns, ctime_ns, size, ino, dev, mode), and every in-process spec writer (dashboard fork/publish/edit/delete/reset, package mutation, capability publication) calls the new clear_tool_policy_cache() beside clear_list_agents_cache(), so an in-process rewrite invalidates unconditionally.
The stat-only fast path is kept on purpose: hashing ~2,000 files per request is the cost this PR removes.
The residual window — an out-of-process rewrite that preserves size, mtime, ctime, inode and mode within one filesystem tick — is now documented at the revision function; it is the same window the sibling catalog caches accept.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • platform skip weakens the invalidation ratchet — fixed in 3fad276

The skipif marker is removed; test_the_revision_sees_content_and_permission_changes mutates content/size on every platform and additionally asserts the recorded mode changes on POSIX inside the same test body.
No newly added skip or xfail remains in the diff.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • docstring contradicts the directory-mtime term — fixed in 3fad276

The revision docstring now states that stray files are omitted from entry tuples but still invalidate through directory mtime when added or removed.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • sibling caches are cleared by in-process spec writers; this one was not — fixed in 3fad276

Added clear_tool_policy_cache() in sessions.py and a _clear_agent_spec_caches() helper in handlers/agents.py and agent_capabilities.py that drops both the catalog cache and the tool-policy cache at every existing clear_list_agents_cache() call site.
The tool-policy cache therefore closes the same sub-tick in-process write window the catalog caches close; test_explicit_invalidation_drops_cached_policy_answers pins the clear.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • memo covers one of two spec_by_declared_name callers; re-spells _dir_signature — accepted-and-deferred

The second caller, acp/kas_agents.py at session start, is a different path (KAS session boot, not the per-request containment read) and sharing the memo there is not a one-line reuse; widening it here would move this PR past its stated intent (request-path containment read).
The deferral is recorded on the linked issue #12721 with owner and due date; the invalidation duplication is bounded to one stat-revision helper in sessions.py and is called out there.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Note on the deferral above: the task and Due: 2026-10-06 line are recorded on #12721, but as a fork contributor I cannot set the deferred-finding label or the assignee on that issue (gh issue edit is refused). A maintainer will need to add both, or tell me to fold the KAS caller into this PR instead.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_pending_boundary_consumer_semantics.py (#12718 fixes the shard-4 slot-reader tripwire) since this head (0a80050 -> 194f6d5); CI re-running.

@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from 3fad276 to a127bcc Compare September 22, 2026 06:09
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from a127bcc to 2504a38 Compare September 22, 2026 07:26
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • new cache sits outside clear_list_agents_cache's one invalidation point — fixed in 2504a38

agent_discovery.clear_list_agents_cache() is again the single entry point: it gains register_agent_spec_cache_clearer(fn) and iterates the registered clearers after dropping its own caches; handlers/sessions.py registers clear_tool_policy_cache at import. No import cycle (sessions imports agent_discovery, never the reverse).
The docstring now states the promise covers registered spec-derived caches.
test_the_catalog_invalidation_point_drops_cached_policy_answers_too pins that clear_list_agents_cache() alone empties _TOOL_POLICY_CACHE.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • _clear_agent_spec_caches defined twice — fixed in 2504a38

Both copies are deleted. With the tool-policy cache registered into clear_list_agents_cache(), the writer modules need no wrapper: handlers/agents.py and agent_capabilities.py are byte-identical to origin/main again.
The one line that knows about the extra cache is the registration next to the cache it clears, in sessions.py.

@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from 28f964f to 172e911 Compare September 22, 2026 13:01
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Metadata-only cache can preserve a removed tool restriction (same-tick rewrite) — fixed in 172e911

Closed with the racy-git rule: an entry (or the directory) whose mtime or ctime is younger than _TOOL_POLICY_RACY_WINDOW_NS (2 s) yields no revision and the read bypasses the memo, so a same-size rewrite in the same filesystem timestamp tick as the compared stat can never be served stale, on any timestamp granularity up to 2 s. Covered by test_a_fresh_spec_is_not_memoized_until_the_racy_window_expires. With ctime + generation + symlink bypass + Windows bypass + racy window, there is no remaining metadata path to a stale relaxed policy.

  • Entry count does not bound retained policy data — rebutted

Same as on 5fa7f82: the memo holds at most 256 resolved policy dicts per directory; the 50 MB figure is the spec-file parse cap, not the policy size, and reaching it requires an operator to author 255 distinct ~50 MB policy objects into their own trusted directory. Downgraded by the adjudicator as a disproportionate remedy.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • generation test passes even without generation invalidation — fixed in 172e911

test_the_catalog_invalidation_point_drops_cached_policy_answers_too takes the revision twice with no filesystem change and asserts equality, then asserts clear_list_agents_cache() alone changes it; removing the generation from the tuple fails the test.

@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
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Re-pushed the identical tree as 2c1f072: on 172e911 the CI run's Await Fast Gate step read the fork Fast Gate as action_required (it was still awaiting approval) one minute before that gate was approved and went green, so CI failed closed and the fork review lanes skipped. Nothing in the tree changed; CI re-running.

@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from 172e911 to 2c1f072 Compare September 22, 2026 13:15
@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
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 1974dad: fixes the Windows shard failures on 2c1f072, which were this PR's own tests assuming the memo engages on a platform where it is deliberately off. The platform decision is a module constant (_TOOL_POLICY_MEMO_ENABLED) the test fixture forces on, the fake-entry test no longer touches sys.platform (that crashed the xdist worker), and test_the_memo_is_disabled_when_the_platform_cannot_prove_freshness covers the disabled path on every OS. Also rebased: main moved cbdfa74 -> 87553ba (no overlap). CI re-running.

@Pearcekieser
Pearcekieser force-pushed the perf/tool-policy-spec-scan branch from 2c1f072 to 1974dad Compare September 22, 2026 13:43
@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
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Revision retains an unbounded spec population — rebutted

Same finding as on 28f964f and c916c8b, same answer: one (name, 7 ints) per spec-named entry (~300 KB at the profiled 2,000 specs), bounded by the directory the operator installs, and the same population agent_discovery._dir_signature already retains for the catalog caches. Capping it would silently restore the 2N-read path for exactly the large directories this PR exists for. Downgraded by the adjudicator as a disproportionate remedy for the third time.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • New ratchet test can skip — rebutted

The skip fires only when symlink_to raises on unelevated Windows, and it is paired exactly as testing-conventions.md requires: test_a_symlink_entry_is_seen_without_creating_one asserts the symlink-disables-memo branch deterministically on every platform with a fake directory entry. The adjudicator FLAGged the finding on that basis ("the skip only drops a redundant integration assertion, not the freshness guarantee").

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • needs-a-decision: GPT lane convergence on _agents_dir_revision — needs-a-decision

Since round 3 the GPT lane has raised one finding per round against the same span (sessions.py|gpt/BLOCKING) under a new framing each time: follow-symlinks (fixed), symlink-target staleness (fixed: symlinked specs bypass the memo), Windows ctime (fixed: memo off on Windows), same-tick rewrite (fixed: 2 s racy window, the git rule), and three times an "unbounded" revision tuple that the adjudicator has downgraded as disproportionate on each occasion. Design, First Principles and Opus are PASS/clean; every stale-policy path named so far is closed by construction.
Maintainer decision requested: if the remaining "unbounded revision" item is judged not a defect, please record /ai-review override gpt 1974dad4083a577add807e0be9a9b56ea77753fe: revision tuple is one stat record per installed spec, the same population _dir_signature already retains; capping it would restore the 2N-read path this PR removes. If instead a cap is wanted, name the number and I will add it in one push.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed d768ffb (test-only): test_a_symlink_entry_is_seen_without_creating_one replaced the process-wide os.scandir with a MagicMock for its whole body, which handed a mock to pytest's own scandir callers on Windows and crashed the xdist worker (shard 3 on 1974dad, taking three unrelated tests on sibling workers with it). The fake scan applies to the test directory only; every other path delegates to the real os.scandir. No production change; CI re-running.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 73b00c0 (test-only): the fake os.scandir result implements the iterator protocol as well as the context-manager one (Windows pathlib iterates it directly -- '_FakeScan' object is not an iterator on d768ffb shard 3), and interception is active only around the single production call. The fork review lanes on d768ffb never ran (GitHub App rate limit at 14:31 UTC); this push re-triggers them. No production change.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Cache hit can bypass a concurrent policy tightening — rebutted

Unreachable, as the adjudicator's FLAG records: a tightening rewrites the spec, the kernel advances that entry's st_ctime_ns to now, no POSIX API backdates it, and any entry with ctime inside the 2 s racy window yields no revision, so the memo cannot answer during or immediately after the write; the revision is also compared on every hit, and the memo is off entirely on Windows. In-process writers additionally bump the generation in the revision tuple.
This is the seventh framing of one span since round 3; every stale-policy path named has been closed by construction (symlink bypass, Windows bypass, ctime, generation, racy window). The maintainer decision requested on 1974dad stands: /ai-review override gpt 73b00c030cc3c382ac3c4b1d5196a8084458d068: no metadata path to a stale relaxed policy remains; the adjudicator flagged this finding as unreachable.

GET /api/session-tool-policy resolved an agent's managedToolPolicy by
parsing every spec in the agents directory to match its declared name,
then, on a miss, parsing every spec again strictly to prove the miss
honest. Each pass ran the hardened reader per file (symlink resolve,
sensitive-path fence, pinned open, JSON parse). With ~2000 installed
specs a request cost 750-965 ms on a worker thread, most of it holding
the GIL, and the py-spy GIL profile attributed 6% of all GIL-holding
samples to this chain; the stalls fed the loop-lag signal that pinned
the adaptive subagent cap at 1 on an idle host.

The read is now answered from a per-directory cache keyed on a
stat-only revision: the directory's mtime plus (name, mtime, ctime,
size) of every spec entry. An unchanged directory costs one scandir.
Only resolved answers are cached; unreadable and ambiguous refusals
are re-derived on every call so the fail-closed semantics and their
per-request audit are unchanged.
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Cache hit can bypass a concurrent policy tightening — fixed in ce858d4

Implemented the store-side half of the proposed fix: the revision is recomputed after the uncached read and the answer is stored only if it equals the revision taken before the read; a write landing mid-read is never memoized under the preceding revision (the hit path already recomputes the revision on every call). Covered by test_an_edit_during_the_read_is_not_memoized.

  • Revision retains an unbounded spec population — fixed in ce858d4

Implemented the proposed cap: above _TOOL_POLICY_REVISION_MAX_ENTRIES (4,096) spec entries _agents_dir_revision returns None, the read bypasses the memo, and one warning is logged per directory per process. Covered by test_a_directory_past_the_entry_cap_is_not_memoized.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • New ratchet test can skip — fixed in ce858d4

The real-symlink test is removed, so no pytest.skip remains in the module. The property is held by test_a_symlink_entry_is_seen_without_creating_one (a symlink entry yields no revision, on every platform) and test_the_memo_is_disabled_when_the_platform_cannot_prove_freshness (no revision means every call reads).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased: main moved 87553ba -> c701a5e (52 commits, no overlap with this PR's files); CI re-running.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • ctime in the revision is not pinned by a test — rebutted

A same-size rewrite with os.utime-restored mtime advances ctime to now, which on this head lands inside the 2 s racy window, so the revision is None and the memo is bypassed whether or not ctime is in the tuple; the property the finding wants to pin is already guaranteed one layer earlier by test_a_fresh_spec_is_not_memoized_until_the_racy_window_expires. Pinning ctime specifically would need the test to fake a clock past the window while keeping ctime fresh, i.e. patch the same time.time_ns the guard reads, and a mutation that drops ctime would still be caught by the racy window in every real deployment. Removing st_ctime_ns would also fail test_the_revision_sees_content_and_permission_changes on POSIX (chmod changes ctime only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants