Repository navigation
fix: class-endpoint objects belong to their creator and are bounded in size (#22) - #29
Merged
Merged
Conversation
…n size (#22) - obj_owner handler hook: (request) -> owner. Objects are kept per owner (OwnedObjStore): another owner's id is simply not found, an unidentified request is refused, obj_quota (100) evicts only the owner's own least recently used objects, max_owners (1000) bounds the owners. - Safe default: a class endpoint without obj_owner is refused at build time; obj_owner=shared_objects is the named opt-in to the old capability-id behaviour (obj_store still applies there). - max_obj_size (10 MB, None disables) measured by obj_sizeof (default bounded_deep_sizeof, which stops at the limit) after creation and after every dispatched call; an object over it is dropped. - current_request ContextVar, set around every handler call, so per-request hooks can read the request. Closes #22 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rial review of #29) - The size check runs in a finally: a call that grows the object and then raises is measured too (it grew 50 MB past a 10 KB limit). - Byte budgets: max_owner_bytes (20 MB) and max_total_bytes (256 MB) on top of max_obj_size (now 1 MB, which also bounds the per-call walk). Evicted objects release their bytes (LRUObjStore on_evict). - OwnedObjStore takes a lock (an eviction race raised KeyError under threads). - obj_owner returning '' is refused like None; an unhashable owner names the hook; docs say the owner must be authenticated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thorwhalen
added a commit
that referenced
this pull request
Oct 13, 2026
An instance endpoint (an object exposed through attr_names) is one object every client shares. Like class endpoints (#29), it now needs obj_owner: a (request) -> owner hook that refuses unidentified requests, or the named opt-in obj_owner=shared_objects. Module endpoints are unchanged. max_obj_size / obj_sizeof bound it: checked when the service is built and after every call; once over, the object is kept and calls are refused until it is back under. AuthorizationError now maps to 401 (its subclasses ForbiddenError and OverwritesNotAllowed to 403) in the Bottle and aiohttp error handlers, which share one status table. The aiohttp handler resets current_request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thorwhalen
added a commit
that referenced
this pull request
Oct 13, 2026
* fix: instance endpoints need an obj_owner and are bounded in size (#30) An instance endpoint (an object exposed through attr_names) is one object every client shares. Like class endpoints (#29), it now needs obj_owner: a (request) -> owner hook that refuses unidentified requests, or the named opt-in obj_owner=shared_objects. Module endpoints are unchanged. max_obj_size / obj_sizeof bound it: checked when the service is built and after every call; once over, the object is kept and calls are refused until it is back under. AuthorizationError now maps to 401 (its subclasses ForbiddenError and OverwritesNotAllowed to 403) in the Bottle and aiohttp error handlers, which share one status table. The aiohttp handler resets current_request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: review of #31: obj_shrinkers, sizeof follows bound methods/partials/closures - obj_shrinkers: names still callable while an instance endpoint is over its limit, so a client can bring it back under (one client could otherwise lock everyone out). - bounded_deep_sizeof follows what bound methods, partials and closures hold. - Document what is not measured and the per-call cost; fix the 401/403 comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: second review of #31: checked obj_shrinkers, atomic measure+flag, guarded traversal - obj_shrinkers: a str is refused, every name must be dispatched. - Measuring and setting/clearing the over-limit flag happen under one lock. - bounded_deep_sizeof follows MethodType.__func__, function attributes and defaults, static/class methods; an object whose attributes raise is measured plainly instead of failing the call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- 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 #22. Follows the convention of #18 / #23: a safe default plus a named opt-in.
Ownership
obj_owner:(request) -> owner(e.g. the authenticated user id). Objects live in anOwnedObjStore, keyed per owner:Noneis refused with anAuthorizationError;obj_quota(100 per owner) evicts only that owner's least recently used objects;max_owners(1000) bounds how many owners hold objects at once.obj_owneris refused when the service is built, with an error naming both options.obj_owner=shared_objectsrestores the old behaviour, where an object id is the only access control and all clients share one LRU store.obj_store=still applies in that mode only.current_requestContextVar, set around every handler call on both the sync and aiohttp paths. Dispatched functions do not have to take the request.Size
None:max_obj_size: 1 MB per object;max_owner_bytes: 20 MB across one owner's objects;max_total_bytes: 256 MB across the whole endpoint.InputError. Evicted objects free their bytes.obj_sizeof, which defaults tobounded_deep_sizeof. That function walks containers,__dict__and__slots__, counts each object once, and stops as soon as the limit is passed, so measuring costs at most about the limit.max_obj_size, so it costs at most about 1 MB of objects per call. As documented, a single call can still allocate before it is measured, and an object that references large shared data counts that data: raisemax_obj_size, or pass anobj_sizeofthat skips it.OwnedObjStoreis thread-safe.Noneor""is refused. The docs say the owner must come from authentication.Breaking
Class-endpoint handlers must now set
obj_owner. No package in the fleet uses class endpoints. The existing tests were migrated by addingobj_owner=shared_objectsin their helper. The decision is recorded for the user in #28, with the recommendation to keep it.Tests
py2http/tests/test_obj_ownership.pycovers:shared_objectsopt-in;sizeof;pytest --doctest-modules py2http: 119 passed. Dependents gate (priv test-dependents py2http --transitive): py2http and extrude pass.Adversarial review
A fresh Opus reviewer read the diff and the issue and tried to break it. Across everything it tried, ownership held: one owner never reached another owner's object. Verdict: ship-after-fixes. It confirmed 6 defects. The fixes are in the second commit, and the reviewer's repro scripts now fail as intended:
finally.max_owner_bytesandmax_total_bytesare added, and the per-object default drops to 1 MB.max_obj_size, now 1 MB, so it costs about a tenth of that.KeyError(665 times in 8 threads). Fixed: the store takes a lock, and a test stresses it.max_obj_size,obj_sizeof). This is the price of a default that is safe.Plausible concerns also taken:
""is refused;TypeError;Not taken, because they are pre-existing or unreachable:
AuthorizationErrormaps to 400;_get_frameworkrefuses;🤖 Generated with Claude Code