Repository navigation
Description
DONE. Closed before these files carried a status word. The .done
suffix is the record; this line is that same answer in the second place
the check reads, and no new judgement.
Carl, 2026-08-25: "As soon as the server sends or receives a valid
handle to a client it should be lifetime tracked against that client,
preferably entirely automatic by scanning inbound and outgoing
messages recursively."
What already happens
Outbound is already automatic, one level deep. codec.encode calls
the proxy_id callback for every proxy-typed field, and the server
passes a callback that mints a handle and leases it to the caller's
connection:
self.codec.encode(resp, "result", m["return_type"], result,
lambda obj: self.put(obj, _tok(stream), parents=[req.self.id]))
Inbound resolves but does not grant, which is right: the client already
holds the lease for a handle it is able to name.
The real gap: nesting
value_to_msg recurses into nested wire-VALUES and nothing else:
if self.kind(ftype) == "value":
self.value_to_msg(ftype, val, getattr(msg, fname))
else:
setattr(msg, fname, val) # a proxy lands here and breaks
check_wire_contract does not forbid a _wire_fields entry naming a
proxy type, so declaring one is accepted and then fails at the first
call that touches it. Broken by omission, not by design.
Nothing declares one today, which is why nobody has hit it. 030 makes
it certain: an attribute set carrying store paths or values is exactly
a collection with proxies inside.
Opinion: yes outbound, no inbound, and not by scanning
Outbound recursion: unreservedly. It is a bug fix. Extend the
codec's existing walk so a proxy anywhere in a message gets minted and
leased the same way a top-level one does.
Walk the declared shape, not the message. A generic descriptor
scan for Handle fields would work without the manifest, but it is
less precise - it cannot tell a live proxy from a Handle used as an
opaque id in some future control message - and it puts a second thing
in this codebase that knows what a handle is. The codec already walks
the declared shape and already knows which fields are proxies.
Inbound auto-granting: no. lifecycle.py draws a deliberate line -
"The handle ID remains the access capability; the token decides
LIFETIME." Granting on receipt blurs it twice over:
- a client passing back a handle it already holds gets a SECOND lease
and then owes two releases. This repo has had exactly one
lease-inflation bug (024) and it stayed green for a long time,
because nothing released after claiming; - a client passing a handle it does not hold becomes an owner by using
it. That may be desirable - it is close to what share(copy) does -
but it is a semantics decision, not a mechanical one.
Either way the lease count becomes a function of how many times an
object was passed as an argument, which a caller cannot reason about.
The scaling problem the two ideas create together
put() mints a fresh handle per call, so the same object returned
twice is two handles with two leases. Harmless today. With recursive
tracking and nested collections it stops being harmless: one Value
appearing in a hundred map entries becomes a hundred handles and a
hundred leases, and the client's finalizers then have to release a
hundred times to free one object.
Identity-mapping - one handle per object per connection, refcounted -
is the fix, and it wants doing BEFORE nested proxies land rather than
after. It also simplifies the client: 028's per-handle refcount exists
partly because the server can hand out several handles for one thing.
Order
- identity-mapping in HandleTable: put() returns the existing handle
for an object this connection already holds, and bumps its lease. - recursive proxy encode/decode in the codec, driven by the declared
shape. - check_wire_contract stops accepting a proxy field it cannot carry,
until (2) lands.
Done 2026-08-25: step 1
put() indexes each connection's objects by identity. A repeat put
returns the handle that connection already has and adds a lease.
share() indexes the target, bind() re-indexes what it claims from
escrow, and both a drop and a connection death clear their rows.
test_handles.py drives the table directly and calls audit() after
every step. audit() existed and nothing called it, so the invariant
it holds proved nothing.
Revised 2026-08-25: step 3 is the answer for _wire_fields, not step 2
Step 2 said "recursive proxy encode/decode in the codec". Writing it
turned up the reason it cannot exist for a _wire_fields value.
A wire-value is rebuilt on the far side by _from_parts, which builds
a real C++ object and needs a real local object for every part:
@classmethod
def _from_parts(cls, StorePath path, str output):
d._ptr = new CDerivedPath(deref(path._ptr), ...)
A proxy is exactly the thing that has NO object on the far side. So a
value carrying a proxy is reconstructible only in the process that
already holds the proxy, which is the one process that never needs to
decode it. The schema would carry it - _msg_arg_type turns a proxy
into a Handle field wherever it appears - and the encode half is easy.
The decode half has nowhere to land.
That is a design boundary, not a missing feature: a wire-value
copies all the way down. check_wire_contract now says so at build
time, naming the field and the reason.
Nesting is still coming, through 030 rather than here. NixValue is a
union of the wire KINDS, and its proxy arm decodes to a client-side
proxy object rather than to a binding class - which is a target a
handle can actually land on. The primitive that work needs is the same
one drafted here: a proxy callback pair that carries the declared type
alongside the value, so a handle minted at depth knows what class to
adopt into. It belongs in the 030 codec, where the decode side is
coherent.
Which leaves the server-side half of step 2 for 030 as well: a proxy
nested in a message arrives as a bare SYNC binding object, and the
handle table holds async wrappers (it resolves handles for method
calls and calls aclose on a drop). Minting one needs the producing
runner, so the mint callback has to reach the target wrapper. Affine
returned types can only attach to their producer's thread, so a free
function that yields a nested affine proxy has no home for it and must
fail loudly.
Decided 2026-08-25: inbound grants, idempotently
Carl: "The reason for these is when you're sharing handles between
processes against the same server. The new client would make requests
against these handles and then it holds them as well."
That answers the second of my two objections rather than dodging it: a
client becoming an owner by using a handle it was not given IS the
point. A handle id is the access capability, so passing one between
two processes out of band is a legitimate way to share an object, and
the second process should keep it alive by calling through it.
The first objection - that a client passing back a handle it already
holds would owe two releases - dissolves once the grant is
IDEMPOTENT. touch() grants at most one lease per connection per
handle, however many times the connection names it. A counted grant
would make the lease total a function of how often an object was
passed as an argument, which no caller can reason about and no client
could balance: the client releases once per client-side object, not
once per call.
Every inbound path goes through Dispatcher.resolve: the request's
own self handle, every proxy parameter, and a constructor's proxy
arguments alike.
Two smaller consequences, both tested:
- an unknown or dropped id grants nothing and raises, so naming a
handle cannot mint a holder for one that never existed; - a connection that detached a handle and then calls through it takes
ownership back. Detach says "I am done owning this"; calling says
otherwise.
That closes 031. The recursive half became #567.
Migrated from tasks/031-recursive-handle-tracking.md.done.
Assisted-By: Opus 5
Activity