Repository navigation
feat(intercept): target-gate schema, opt-in flag and approval requests (S3b 1.2-1.4) - #178
Merged
Merged
Conversation
…s (S3b 1.2-1.4)
Storage, flag and request path of the approval gate for asset targets. The
gate itself is not wired into the tool hook yet (steps 1.5 to 1.7): with this
change nothing is extracted, resolved or blocked, whatever the flag says.
Schema and store (1.2)
- tasks.target_gate, conversations.target_gate (default false).
- intercept_pending.target_key and a partial unique index: one open request
per scope (task or conversation) and host:port.
- target_pins (no foreign keys: a pin outlives its task, its conversation and
its request row) and target_gate_exemption_log. All DDL is idempotent; no
CHECK constraints; the cascade on intercept_pending.conversation_id stays.
- db/target_pins.go: pin lookup with port precedence, list, revoke,
find-or-create of a request, and ResolveTargetRequest, which settles the
row, supersedes the old pin and writes the new version in one transaction.
- Deleting a task or an archive stub revokes its pins and settles its open
target requests in the delete transaction. DeleteConversation and
DeleteConversations revoke the pins of the removed conversations in the
same transaction as the delete.
Opt-in flag (1.3)
- Per task through the create and metadata-patch paths, per conversation
through create and patch; exposed in the task DTO. A retest conversation
takes the flag of the finding's task, never its pins. A spawned task starts
with the gate off.
- The task flag is atomic and read on every call through TargetScope.Enabled.
TargetScope now carries the Interceptor that owns the gate.
Request, wait, decide (1.4)
- pendingManager keeps a list of waiters per request; resolve wakes all.
- RequestTargets: find-or-create per target, one card per request, wait on
channel, poll, context and wait bound. A plain request is never settled by
a call that leaves. A request merged with an ask is bound to its creating
call and a timeout never allows it.
- Decide records the approver (subject of the session token) and the remote
address for every human decision, classic asks included. On a target
request "allowed" pins the displayed addresses; that is the only writer of
pins.
- A request raised while the global egress proxy is set says the approval is
name-only and its pin is stored with name_only_effective.
- Routes: GET/POST .../target-pins and .../target-pins/{pid}/revoke under
/api/tasks/{id} and /api/conversations/{id}; decision_source=target filter.
- ValidateExemptionHost: an exemption written as an IP literal may be private
unicast, never loopback, link-local or metadata, unspecified or multicast.
This was referenced Nov 10, 2026
feat(intercept): target extraction, resolver, exemptions and the gate in the hook (S3b 1.5-1.7)
#179
Merged
Merged
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.
Steps 1.2 to 1.4 of the S3b phase 1 plan (approval gate for asset targets): schema and store, the opt-in flag, and the request / wait / decide path. Follows #177 (step 1.1).
What this does not do
The gate is not wired into the tool hook yet. Extraction, resolution, exemptions and the decision in the hook are steps 1.5 to 1.7. After this PR
target_gatecan be set through the API, but nothing is extracted, resolved, asked or blocked, whatever the flag says. Do not present the flag as a control until 1.7 is merged. There is no UI (phase 4).With the flag off (the default) behaviour is unchanged for every task and conversation: no code added here runs on a tool call.
Schema and store (1.2)
tasks.target_gate,conversations.target_gate, bothBOOLEAN NOT NULL DEFAULT false.intercept_pending.target_key(NULL = classic ask) and the partial unique indexuq_intercept_pending_target: one open request per scope (task or conversation) andhost:port.target_pins, without foreign keys ontask_id,conversation_idandintercept_id: a pin outlives its task, its conversation and its request row.uq_target_pins_activekeeps one active pin per key.target_gate_exemption_log(table only; its writer is step 1.6).IF NOT EXISTS), noDOblock, no CHECK constraint, no existing constraint changed.intercept_pending.conversation_idkeepsON DELETE CASCADE.db/target_pins.go:ActiveTargetPins(the pin on the exact port first, then the pin on port 0; a pin on a specific port never covers a target whose port is not declared),ListTargetPins,RevokeTargetPin,FindOrCreateTargetRequest(INSERT ... ON CONFLICTon the partial expression index),ResolveTargetRequest(settle the row, supersede the old pin, write the new version: one transaction).task_deleted) and its open target requests settled as denied by the system, in the delete transaction. Pins and approval rows stay readable.DeleteConversationandDeleteConversationsare now one transaction each: delete, and revoke the pins of the conversations that were removed (conversation_deleted). The batch form revokes only the ids the delete returned. The request rows of a chat still go with it through the cascade.Opt-in flag (1.3)
target_gateonPOST /api/tasksand onPATCH /api/tasks/{id}; returned in the task DTO. The in-memory flag is atomic and is read on every call throughTargetScope.Enabled, so a switch applies to the next tool call.target_gateonPOST /api/conversationsandPATCH /api/conversations/{id}. A turn runs with the value read when it started.TargetScopenow carries theInterceptorthat owns the gate (needed by the redirect callback of step 1.9).Request, wait, decide (1.4)
pendingManagerkeeps a list of waiters per request;resolvewakes all of them.HandleAskchanges only in theadd/removecall shape.Interceptor.RequestTargets: find-or-create per target, the approval card emitted once by the call that wrote the row, then wait on channel + poll (2 s) + context + wait bound.TARGET_APPROVAL_PENDINGand a later approval still pins.timeout_action = allowis overridden on a merged row, because a timeout cannot pin; the override is recorded in the audit.TARGET_GATE_UNAVAILABLE.Interceptor.Decide(id, allowed, approver, remoteAddr): on a target request, "allowed" pins the addresses the request displayed (old addresses plus displayed ones when the key is already pinned). This is the only writer oftarget_pins. A second decision still returns 409.approver,approver_addr), and on the pin (decided_by,decided_from) for target requests.intercept_pending.decided_bykeeps the actor class (human).global_proxyis set says that the approval is name-only, and its pin is stored withname_only_effective = true. A name-only pin stays name-only when the proxy is removed later; enforcing addresses again takes a revocation and a new approval. (The gate that reads the mark, and skips the address comparison for such a pin, is step 1.6.)GET /api/tasks/{id}/target-pins,POST /api/tasks/{id}/target-pins/{pid}/revoke, and the same pair under/api/conversations/{id}.decision_source=targetis accepted by the approval list filters.POST /api/intercept/pending/{id}/decidekeeps its request and response shape.intercept.ValidateExemptionHost: an exemption written as an IP literal may be private unicast (10.0.0.5), never loopback, link-local (169.254.0.0/16with the cloud metadata address,fe80::/10), unspecified or multicast, nor the two metadata addresses outside link-local (fd00:ec2::254,100.100.100.200). It has no caller yet: the exemption API is step 1.6.Differences from the plan text
name_only_effective, notname_only.ActiveTargetPinisActiveTargetPins(it returns the candidates).RevokeScopePinsandSettleScopeTargetRequestsare unexported helpers that take the delete transaction.CreateConversationandResolveInterceptkeep their signatures;CreateConversationGatedandResolveInterceptBycarry the new arguments.decision_source = target; a merged row is markedaudit.merged_ask.execution_status = unknown: it is host-level and no single call owns its result. A merged row keeps the classic behaviour.Tests
PostgreSQL tests in
db,intercept(newTestMain, own database like the other packages) andserver; unit tests for the waiter list, the exemption guard and the token subject.target_key.TestEveryAgentKindCarriesTargetScope(every session's scope reports the gate off by default),TestTargetGateSeamAllowsWithoutDBWrite,TestTaskTargetGateDefaultsOff.Local run on a freshly created PostgreSQL 16 database:
go build ./...,go vet ./...,go test -count=1 -p 1 ./...(14 packages ok, 820 top-level tests pass, 4 skipped as on main),go test -race -p 1on the CI package list (13 packages ok, no race).Follow-ups
target_pinsbut the pin routes are scoped to an existing task or conversation, so today they are readable in the database only. A read route or an export is required before they are presented as audit evidence.ValidateExemptionHostfrom the exemption API, on the normalised host, and apply the void rule with link-local, unspecified and ULA addresses counted as private, to seeded entries as well.block(). This PR does not touch the guard.decision_source = target, display ofapprover, the task and conversation toggle.