Repository navigation
fix: ops functions write through the wrapper's own __setitem__/__delitem__ (#3) - #4
Merged
Merged
Conversation
…tem__ (#3) The free functions in cosmodol.ops now perform the plain mapping write on the caller's store, with a one-shot ContextVar redirect (cosmodol.routing) telling the leaf how to execute the single write that reaches it. Every layer's write logic runs: write guards, preset hooks, write-through caches, and filt_iter scopes on keys an operation creates. Swallowed/deferred/multiplied writes raise RedirectError. batch_items patch on a wrapped or subclassed store needs unguarded_patch=True. Closes #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rrors Adversarial review of #3: a layer that writes another key first (companion container, audit record) received the operation's semantics; now the leaf refuses any write but the expected (method, key). Errors a layer catches are re-raised; subclasses scoping by __contains__ are checked; messages no longer claim a deferred write was not performed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3.
What changed
The free functions in
cosmodol.ops(replace_item,batch_items,add_container,delete_container(force=True),add_database,delete_database(force=True)) no longer write to the leaf directly. Each one performs the plain mapping write (store[k] = vordel store[k]) on the caller's outer store. First, it installs a one-shot redirect in the newcosmodol.routingmodule, held in aContextVarand pinned to the expected leaf key. The redirect tells the leaf how to execute the single write that reaches it: as a conditional replace, a batch entry, a cascade or a create. Every layer's own write logic therefore runs:mk_read_only,disable_setitem) refuse the operation.preset=hooks and write-through caches see the value, exactly as they would forstore[k] = v.filt_iterscopes now refuse keys that an operation creates (batch create/upsert,add_container,add_database). Thek in storecheck for existing resources is kept, and it now also applies to subclasses that override__contains__.RedirectError. This covers a layer that writes another key first, writes twice, or swallows the write. The leaf refuses any write other than the expected(method, key)before acting. An error that a layer catches is still re-raised to the caller.patchhas no mapping-write equivalent, so on a wrapped or subclassed store it now requiresunguarded_patch=True.Behaviour change:
add_database/add_containeron afilt_iterview now refuse a name outside the scope. Previously the resource was created. The old testtest_add_database_does_not_raise_after_creatingwas rewritten to cover this.Stated limits (in the
cosmodol/ops.pydocstring)batch_itemscollects its writes before committing them as one transaction. A layer that acts after the inner write returns has already acted, even if the commit fails.Adversarial review
A fresh Opus reviewer returned ship-after-fixes. All five confirmed defects are fixed, with a regression test for each:
inner_most_key, and mismatched calls are refused before anything is touched.__contains__was bypassed. It is now checked.Tests: 87 pass, including the doctests (16 new tests in
tests/test_ops_layers.py, 10 of which fail on master). No dependents.🤖 Generated with Claude Code