Skip to content

fix: gapped custom-enum child scope (B-3) + drop per-resolve CacheItem alloc (P-1)#218

Merged
lesnik512 merged 2 commits into
mainfrom
fix/audit-fixes-batch2
Jun 14, 2026
Merged

fix: gapped custom-enum child scope (B-3) + drop per-resolve CacheItem alloc (P-1)#218
lesnik512 merged 2 commits into
mainfrom
fix/audit-fixes-batch2

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

Batch 2 of the 2026-06-14 deep audit — the two real, low-risk code fixes.

  • B-3build_child_container(scope=None) derived the next scope as self.scope.value + 1, assuming contiguous values. A gapped custom IntEnum (TENANT=6, JOB=10) raised MaxScopeReachedError despite a deeper member existing. Now derives the smallest member > self.scope. The stock contiguous Scope enum is unaffected.
  • P-1fetch_cache_item used setdefault(id, CacheItem(...)), whose default is evaluated eagerly, so every cache hit (every resolve after the first) constructed and discarded a CacheItem (+2 dicts). Switched to behavior-identical get-then-set, removing the per-resolve allocation.

Bundle (plan-only, spec = the audit report): planning/changes/active/2026-06-14.04-audit-fixes-batch2/.

Test Plan

  • New B-3 tests (gapped auto-derive returns next member; deepest member still raises MaxScopeReachedError) — gapped case failed on main, passes here
  • P-1 is behavior-identical (no new test; full suite + 100% coverage exercise miss + hit paths)
  • 208 passed, 100% coverage (just test-ci); just lint-ci clean

🤖 Generated with Claude Code

lesnik512 and others added 2 commits June 14, 2026 15:08
- B-3: build_child_container derives the next scope as the smallest enum member
  deeper than the current one, so non-contiguous custom IntEnums (TENANT=6,
  JOB=10) work instead of raising MaxScopeReachedError on value+1.
- P-1: fetch_cache_item uses get-then-set instead of setdefault, removing the
  throwaway CacheItem (+2 dicts) constructed on every cache hit.

Spec: planning/audits/2026-06-14-deep-audit-report.md

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… path

The initial P-1 get-then-set broke setdefault's atomicity, which is load-bearing:
fetch_cache_item runs outside the container lock, so concurrent first-resolvers of
a singleton must share one CacheItem (the cache + double-checked lock live on it).
Restore atomic setdefault on the creation path; keep a get fast path so the common
hit case still avoids the throwaway allocation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 7624d89 into main Jun 14, 2026
7 checks passed
@lesnik512 lesnik512 deleted the fix/audit-fixes-batch2 branch June 14, 2026 12:17
lesnik512 added a commit that referenced this pull request Jun 14, 2026
Move bundle to archive (status: shipped, pr: 218); update README Index; mark
B-3/P-1 resolved in the 2026-06-14 audit report Status line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant