Skip to content

Who Gets to Make the Next Change?

S5·E18 ·rootweaver · postgres · reliability · agent-governance

A Checkpoint Is an Intake Receipt ended with evidence in quarantine. I could recover a piece of what a session had done. When another session took over a task, I had a different question. What gave it the right to make the next change, and how would I know the previous session had lost that right?

In late July I set out to make that decision explicit. A coding agent could be implementing a change, advising the implementer or starting from an old conversation that still described it as the owner. A parent conversation gives me the objective and the reasons for delegating. It cannot arbitrate two concurrent claims on a shared resource. I wanted one place to decide who could change that resource, a record of why, and a way to inspect the decision before it started blocking tools. I set those boundaries and reviewed the evidence. Coding agents helped implement the kernel, service, adapters and console.

An engineer stands by the main control wheel of a coastal flood barrier

The shared wheel makes the ownership decision visible. Conceptual illustration.

Start with a decision the database can own

A task assignment can stay useful for hours. Permission to act needs a shorter lifetime and a scope. The first package modelled those separately. A scope says which work is covered, who owns it and which effects it permits. An effect describes a kind of action, such as a change to repository state. A resource selector identifies the resource the effect would touch. A lease binds temporary authority to a principal, the identity the control plane recognises, and a particular session acting as that principal.

Canonical selectors let the service compare resources consistently before deciding whether they overlap. The grant then runs in a database transaction. If two claimants both read “available” and only lock after choosing an outcome, they can reason correctly about the same stale state. Taking the authority lock before checking conflicting leases forces the second claimant to evaluate the decision after the first finishes. The source uses SQLAlchemy to express transactions and row locks against PostgreSQL.

Exact excerpt from the private implementation. repository.py at 05dca0c, lines 473–478, inside _acquire

        now = self._now()
        with self._engine.begin() as connection:
            scope, orchestration = self._lock_scope_authority(
                connection, request.scope_id
            )
            self._expire_due_leases(connection, orchestration["id"], now)
Explain this code line by line
  1. Read the repository clock once for this acquisition attempt.
  2. Start the database transaction. Operations on this connection share its commit boundary.
  3. Call the internal method that obtains the relevant authority locks and returns the task scope and its containing orchestration.
  4. Supply the transaction connection and the scope ID from the request.
  5. Close the method call. The returned scope and orchestration remain available to the following statements.
  6. Mark leases in that orchestration whose time has run out, using the same connection and clock reading.

The next part of the source examines previous results for the same principal, operation and idempotency key. Idempotency means an exact retry does not create a second grant. If the key arrives with a different request hash, the repository raises a conflict. A fresh claim must pass authority checks and the resource-conflict check. The check includes recently expired leases inside a bounded takeover grace period. When the claim succeeds, the epoch is one more than the highest prior epoch on that scope. The implementation report records a test with 64 concurrent acquisition requests, producing one grant and 63 denials. The retained test source makes the setup precise. One seeded principal and session sent distinct acquisition requests for the same resource. The test isolates concurrent claim handling on one scope. Multi-host lifecycle checks came later, and this test supplies no throughput or fairness measurement.

A handover has to invalidate the previous generation

A lease expires unless it is renewed through heartbeats. Time handles absence. A fencing epoch handles succession. It is a generation number that identifies which version of authority a caller is using. A session can remember the previous generation after a pause or reconnect. A validator can check that number against the current lease instead of relying on the session to notice a handover.

The repository validates the lease, principal, session, scope, token hash, epoch, effect and requested resource. The token is a secret held by the claimant. The stored hash lets the service check it without storing the bearer token itself. The epoch still matters because holding a once-valid token is compatible with having lost ownership.

Exact excerpt from the private implementation. repository.py at 05dca0c, lines 1075–1080, inside transfer

            scope, orchestration = self._lock_scope_authority(
                connection, old["scope_id"]
            )
            old = self._locked_active_lease(connection, request.lease_id)
            if old["fencing_epoch"] != request.expected_epoch:
                raise LeaseConflict("stale transfer compare-and-swap epoch")
Explain this code line by line
  1. Take the authority locks for the transfer and load the relevant scope and orchestration.
  2. Use the same transaction connection and the scope recorded on the outgoing lease.
  3. Close the call after passing those two values.
  4. Load the currently active lease under lock. This is the authoritative read after taking the scope lock.
  5. Compare the stored fencing epoch to the generation the requester expected to transfer.
  6. Stop with a conflict when they differ. A request prepared for an earlier generation cannot transfer the currently observed lease through this branch.

This is part of a compare-and-swap. The repository compares current state with an expected version before applying the change. The rest of the transfer checks the matching approved request and its revision, the outgoing lease and scope, and the proposed successor’s session and identity. It changes the old lease to transferred, changes the owner of the scope, inserts the successor lease at the incremented epoch and appends an event inside the transaction. A consultant session can contribute advice without receiving mutation authority through this transfer.

Gloved hands exchange blank metal tags at a weathered interlock housing

A controlled handover retires the previous grant. Conceptual illustration.

Use a synthetic example with a shared worktree, a checked-out working copy of a repository. Session A holds epoch 7. Session B asks for ownership. The numbers and identifiers below are invented to show what each decision changes.

InputDecisionResult
B asks for overlapping authority while A’s lease is liveThe repository finds the conflictA keeps epoch 7
A human-approved transfer matches the expected epoch and approval revisionThe transfer commits as one unitA’s lease becomes transferred. B receives epoch 8 on the same scope
A returns with its original lease and epoch 7The old lease fails validationA has no valid authority at this boundary
B presents matching identity, lease, scope, effect and resourceThe repository validates the requestB has valid authority at the repository boundary

The final row says where the check took place. A tool or other component that actually performs a change still needs to honour that decision. A database row cannot stop a process from writing to a file by itself.

What an approved transfer changes

Session AActive lease · epoch 7Transfer requestApproval and revision matchLease transactionEpoch advances to 8Session BA’s old lease is invalid
Session AActive lease · epoch 7Transfer requestApproval and revision matchLease transactionEpoch advances to 8Session BA’s old lease is invalid
Illustrative epochs. Dotted paths show the order of decisions. The lease transaction updates the owner and retires the old lease together.

The first service rollout put privilege in the wrong place

The kernel shipped as a package. It had transactions and tests. There was no service listening for agents, no installed host client and no hook enforcing its decisions. The next package added a private API and a local daemon on the Mac and desktop. A daemon is a background process that handles requests from local tools. Its owner-only Unix-domain socket gave those tools a local entry point while the daemon handled the remote service credential.

The first GitOps rollout made a deployment mistake. GitOps uses committed configuration to reconcile the running system to a desired state. The report records that administrative database material was copied into the application namespace during bootstrap. An application process needs to read and write its rows. The ability to initialise or administer the database belongs to a different operational boundary. Both capabilities landed in the same place.

The recorded repair suspended reconciliation, removed the bootstrap objects from the application namespace and moved bootstrap authority to the data plane. In the corrected arrangement, the database owner could not log in directly, the migrator was separate, and the runtime role could read and change data without schema creation authority. The PostgreSQL role documentation explains how roles separate identities and privileges. The report says the database survived the containment and that reconciliation reached Ready after the correction.

The same report records a successful register, claim, heartbeat, validate and release sequence on each of two hosts. The runtime pod had zero restarts in that observation, and Prometheus reported a successful scrape. Those checks support the service and host-client path that was exercised. They do not measure what would happen if ordinary coding tools were blocked, because this package still left provider hook integration open.

Observe the adapters before letting them decide for tools

The next implementation task was separating what a provider reports from what the platform can safely infer. A hook is a callback invoked by a coding harness when something happens. OpenAI’s Codex hooks and Anthropic’s Claude Code hooks document separate event interfaces. A provider adapter had to interpret the payload it actually received, connect the event to the right parent or child session and map it to a bounded effect.

The first independent review found gaps in nested outcomes, mutation-effect coverage and provider wiring. A later review found that a child identifier in tool or failure events could lose its attribution. Another found that attaching a runtime updated state without appending an audit event. The implementation report also records an order-dependent test limited to 100 events, a denial path that needed an audit record and an unsafe downgrade with populated data. The branch stayed unmerged through those failed reviews. The report records a passing fifth review after targeted corrections, alongside 112 historical test passes on the exact branch.

I kept the operating mode in shadow. Shadow mode computes and records a decision while leaving the tool’s original behaviour in place. It let me compare the effect and identity the adapter inferred against the provider action that actually ran. The Mac Codex canary produced four sanitized events and one attachment notice around a read and a small mutation, with zero blocks. The corrected Claude canary recorded activity across 36 hook exits, also with zero blocks. The replacement stream carried bounded categories and pseudonymous identifiers. The report records retiring legacy forwarding that carried raw command or error content. The provider flags were off at closeout.

An engineer watches flood gates from a grassy bluff through binoculars

Observation can take place outside the operating boundary. Conceptual illustration.

Give the operator a view of the evidence

The Control Centre originally presented synthetic data. The read-only replacement used the control-plane projection, a deliberately reduced view of durable state. It arranged work parent-first. I could start with the objective, follow the delegated session and then find the evidence or outcome. A named snapshot_changed server-sent event prompted a refresh. The WHATWG server-sent events standard defines how a server sends named updates over HTTP and a browser listens for them. I inspected the historical API source and found that event name emitted with a refresh signal. The retained review report describes the browser consuming it.

The projection limited each scoped receipt read to the latest 100 records. It offered a bounded operator view and kept the raw runner inspector behind its own privilege gate. The report describes isolated browser checks at narrow width, high zoom and reduced motion, and a passing read-only source merge. Its feature remained default-off. That is separate evidence from the WP2 service deployment and from WP3 shadow observations.

Evidence from JulyWhat it establishedQuestion it left open
64 concurrent claims in the reported kernel testOne grant and 63 denials in that caseBehaviour across identities, hosts or other contention patterns
Two-host lifecycle checks after the rollout correctionBoth tested host clients exercised the private serviceWhich provider tools would consult it before acting
Bounded provider canaries and sanitized evidenceAdapter activity could be attributed and inspectedWhether a real mutation would be prevented
Read-only console merge and isolated browser reviewThe console could render the projected state and refresh on the named eventWhere and when the feature would be enabled

What I would keep

  • Give temporary authority an explicit owner, resource, effect and lifetime. Keep the objective and reasons for the work alongside it.
  • Treat losing authority as a state transition. Validators should be able to recognise a stale generation even when a session resumes with old context.
  • Separate bootstrap privilege from ordinary runtime access. Check that separation in the deployed configuration as well as in the role design.
  • Use shadow mode to test attribution and data boundaries. A report that says “would deny” is evidence about a decision, and actual enforcement needs its own proof.
  • Let the operator inspect the decision from the parent task down. Keep that view small enough to audit and document the limits of what it shows.

The next work followed the gap left open here. If the control plane says an action is allowed, there is still a question about where that authority should be checked and spent. The retained follow-up began testing the boundary where a real tool would make the change.

Glossary and primary references

Lease

Time-limited authority held by one principal and session for a scoped resource and effect.

Primary reference

Principal

An identity the service can authenticate and use to bind authority.

Primary reference

Resource selector

A canonical name for the part of the system a request would affect.

Primary reference

Fencing epoch

A generation number used to distinguish current authority from an older grant.

Primary reference

Compare-and-swap

Apply a change only if the current value still matches the version you expected.

Primary reference

Shadow mode

Record the decision a policy would have made while allowing the original action to proceed normally.

Primary reference

Server-sent events

An HTTP stream that sends events from a server to a browser.

Primary reference