Skip to content

One Permit for One Change

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

Who Gets to Make the Next Change? left me with a control plane that could identify the current lease holder. A lease gives one session temporary authority over a scoped piece of work. The next question was what happened when that session tried to change something. The control plane could validate a claim, but a file write, Git operation or deployment happens somewhere else. I wanted the component making the change to take responsibility for that last check.

I set the goal for the next slice around a single attempted change. The action should have a concrete target, use current authority, and leave enough evidence to tell a successful authorization from a completed action. Coding agents helped implement and test the boundary. I kept the operational decision separate. The late-July source could advance while the production controls stayed off.

An engineer meters water directly over a seed tray in a glasshouse

The handle and the controlled effect meet at one station. Conceptual illustration.

The hook was a tempting place to spend the permit

A pre-tool hook gives a harness a point to check a request before running a tool. It seemed like a reasonable place to ask the control plane whether a change was allowed. The first implementation went further and used that point to consume the authorization. A permit is one-use authority for a particular operation. Consuming it is the durable decision that marks that authority as spent.

The independent review rejected that arrangement. The hook and the actual tool ran at different boundaries. By spending the permit in the hook, the system could record that authority was consumed before the component doing the work reached the action. That left an unresolved interval between the check and the effect, and a consumed permit alone supplied no evidence that a tool ran. This is a time-of-check versus time-of-use problem. The clocks matter, but so does which component owns the operation.

The review also found a possible 1.022-second combined path against a one-second host deadline. The 22 milliseconds were a reported timing case, not a production latency percentile. The model had an 0.8-second authorization allowance inside the overall one-second deadline. An inner budget does not make the remaining stages instantaneous. There is still validation, a final consume step and the tool invocation. The Python project documents how asyncio deadlines and cancellation work. A cancellation or timeout tells a caller its wait ended. It cannot reverse a change an external system already accepted.

I kept the hook path deny-only for protected operations without a qualified execution wrapper. That made the gap explicit. A hook could describe an attempted operation and identify which provider sent it. The component that executed the operation had to own the final authorization step. A synthetic executor provided a way to exercise that boundary using test callbacks before routing real provider tools into it. A later source change gave the daemon’s test-only route an explicitly synthetic name, so that a protocol test could no longer be mistaken for live enforcement.

Match the permit to one operation and one resource

The lease still answered who had standing authority. The permit carried a narrower question. Can this session perform this effect on this resource, under this generation of the lease, for this operation ID? The operation ID identifies the attempt. The resource selector is the normalized name of its target. The fencing epoch is the lease’s generation number. A changed generation makes a previous grant stale.

The database operation locks the permit row before checking its state. PostgreSQL’s row-lock documentation explains how a competing transaction waits on that row instead of making an independent decision from the same value. Rootweaver checks the permit’s active state and expiry, then verifies the linked lease and session, operation fingerprint, resource and epoch. Successful consumption updates the permit to consumed in that transaction. Two calls sharing a permit cannot both take the active-to-consumed transition. The implementation also scoped the database operation by workspace. The recovery report records a matching PostgreSQL row security policy for the permit table.

The exact order below is from the later provider-adapter merge. The function already has a permit inside the host deadline by the time this excerpt begins.

Exact excerpt from the private implementation. protected_mutations.py at f9b044d0, lines 173–182

                # Consumption is deliberately adjacent to the side effect. The permit
                # is bound to this operation ID, selector, live lease and epoch.
                await self._invoke(
                    self._authority.consume_operation_permit,
                    permit.id,
                    request.permit_request.operation_id,
                    request.permit_request.resource,
                )
                await self._sink(sink)
            return MutationResult(executed=True)
Explain this code line by line
  1. The first comment explains the placement of the consume operation. It appears immediately before the callback that changes state.
  2. The second comment lists what the permit ties together. The authority service checks the request against the permit and current lease.
  3. Start the awaited authority call. The next statement outside the call waits until this one finishes.
  4. Select the operation that checks and consumes the permit.
  5. Supply the identifier of the issued permit.
  6. Supply the current request’s operation identifier so it can be compared with the bound operation.
  7. Supply the resource named by the current request.
  8. Close the call. If the authority rejects it, control leaves this path before the callback.
  9. Invoke the supplied sink, the component that actually performs the change.
  10. Return the successful execution result once the callback returns. The later exception handler takes a separate denial path.

The source places consumption next to execution in the same wrapper. The database transaction and a filesystem or remote operation are still separate. A crash after consumption can leave a spent permit with no confirmed downstream effect. A crash after an external side effect can leave a changed system without a local success receipt. This was a narrower claim than exactly-once execution. The permit prevents a second spend. A durable outcome record or reconciliation has to answer whether the effect happened.

Gloved hands hold a notched tab beside a wet metering fixture

Spending one tab records a use. The tray still has an outcome of its own. Conceptual illustration.

Here is a synthetic example using a scratch repository and invented identifiers. It illustrates the decision boundaries, not a recorded July run.

AttemptWhat authority seesWhat the operator can conclude
Write the scratch report under operation write-42, using the current lease generationThe permit is active and matches the operation and target. The wrapper consumes it and calls the writer.A successful tool result supports that the writer returned successfully.
Repeat write-42 with the already-spent permitThe stored status is consumed.The same permit cannot authorize a second callback.
Try the same permit after a change of lease generation, before it has been spentThe live lease no longer validates the permit.The wrapper has no valid permission to run the callback.
Stop after consume, before the caller sees a tool outcomeThe row can show consumed while the tool outcome is unknown.Read back the target or consult the effect’s receipt before deciding what to do next.

Where the permit is spent

Typed requestOne effect and targetPermit checkCurrent lease and scopeConsume permitRecord one useTool callbackObserve the outcome
Typed requestOne effect and targetPermit checkCurrent lease and scopeConsume permitRecord one useTool callbackObserve the outcome
Dotted arrows show the successful path. The wrapper stops before the tool callback when authority rejects the consume. A consumed row does not confirm the outcome.

Give the wrapper a typed job

Moving the check next to a callback still leaves a question about what the callback is allowed to do. A typed request describes a specific kind of operation with defined fields. The provider adapters checked that the normalized event came from the expected provider, represented the right stage and named the same effect as the protected request. The adapters handed the request to concrete sinks for a file write, a patch or a bounded Git operation. Other effects took distinct callbacks. The operation’s shape belonged to the wrapper instead of being inferred from a general string of commands.

This is the file adapter’s branch that stops when the controlled execution boundary is disabled. Its caller already resolved a target inside the sink’s owned root and checked the effect and resource domain.

Exact excerpt from the private implementation. mutation_sinks.py at f9b044d0, lines 88–92

        if not self._boundary.enabled:
            return ProtectedMutationBoundary._denial(request)
        return await self._boundary.execute(
            request, lambda: _atomic_write(target, content)
        )
Explain this code line by line
  1. Read the execution boundary’s feature flag. This is the actual governed file sink’s gate.
  2. Return a denial if the boundary is disabled. No file-writing callback is invoked.
  3. Otherwise call the protected execution wrapper and await the result.
  4. Pass the typed request and a callable for the already-resolved target and content. Constructing the callable does not write the file.
  5. Close the call. The returned result belongs to the wrapper that performs the final authorization check and invokes the callback.

A separate lifecycle change made a human pause revoke active leases and active permits in one transaction. It used a scope revision, a number that changes on each update, to reject a request prepared against old state. Resuming reopened admission and required new authority. I wanted that distinction because a pause is an operational decision. Reopening an intake route should leave the next grant visible as its own decision.

An engineer walks outside a glasshouse past idle watering stations

The operator can inspect the system before admitting a real operation. Conceptual illustration.

What passed and what remained switched off

The recovery report records a stale branch being rebuilt on current main. One correction aligned service readiness with the migration that created the operation-permit table. Earlier CI had exercised an integration suite and found a remaining assertion that expected the previous migration head. The change made the readiness decision depend on the schema the new path actually required. CI evidence and an admitted runtime remained separate.

Evidence in the July recordsWhat it supportedWhat remained outside the result
Earlier verifier rejection, including the 1.022-second caseExposed the host budget overrun and moved permit consumption next to the callbackProduction latency and failure recovery
Recovery merge and required integration gatesThe source and migration contract passed its reported candidate checksActive enforcement on either provider host
12 focused provider-adapter tests and 82 combined selected tests reported passingTyped routing and denial behavior in the tested source sliceTwo database-backed permit cases could not run on the workstation
Provider-adapter source merge f9b044d0The wrappers were present in source mainInstallation on Codex and Claude hosts, live permits and full recovery behavior
Pause/resume source and targeted checksRevocation and read-model intent, with some local boundary coverageA live migration or rollout of the new pause flow

The reports were careful about the runtime. A source merge passed, flags stayed disabled, and the provider execution wrappers had yet to be installed on either host. One handover reports a healthy replacement service from a separate operational repair. That observation concerned the service the hosts could reach. It did not demonstrate that the new source was running or that a real agent write had passed through it.

What I would keep

  • Put the final authority check in the component that owns the concrete effect. Keep earlier hooks useful for description and admission without treating their decision as execution.
  • Bind short-lived authority to a specific scope, operation, resource and generation. Record the consumed state and the outcome separately.
  • Name synthetic capabilities so a protocol test cannot be read as a deployment receipt.
  • Make pause revoke old authorization. Treat resume as fresh admission.
  • Test crash and retry behavior at the boundary where results can be ambiguous. A green adapter suite supports the cases it exercised.

The retained follow-up moved the typed request toward the host daemon. That introduced another boundary to review. The local client needed a way to ask for a specific effect while the daemon retained the lease authority and recognized the correct working environment. The subsequent work began to make that handoff explicit.

Glossary and primary references

Lease

Time-limited authority for a scoped piece of work.

Primary reference

Permit

One-use authority for one named operation.

Primary reference

Fencing epoch

Lease generation used to distinguish current authority from a prior grant.

Primary reference

Consume

Record the authorization as spent before invoking the tool.

Primary reference

Sink

The concrete component that performs the state change.

Primary reference

Row lock

A database lock that serializes conflicting operations on a row.

Primary reference

Row security

Database policy that limits which rows a role can access.

Primary reference