Repository navigation
feat(grants): the trail records whose credential ran (TASK-172 §8/§10.5) - #2028
Merged
Merged
Conversation
Every ToolCall now carries `credentialOwnerId`, the Connection's `createdBy` at
call time, for every connection type including `github-app`. With per-person
Connections that is the first question a trail reader asks — whose Linear was
this? — and it is COPIED onto the record rather than joined to the row, because
removal ends by deleting the row and the trail outlives it (§8).
The broker resolves the connection for every call it makes, and both branches
already read `createdBy` for the approval room, so every record site takes the
value from the resolved connection: the ok record, the refusal/failure record,
the parked `pending_approval` record, the two records `executeApprovedToolCall`
writes, and the decision record `approvalActionService` writes when a person
rules on a parked call. The parked envelope carries it for exactly that last
one: the Connection can be gone before the decision lands.
Two places deliberately record no owner: a call refused before a connection
resolved (there is no credential to name, and the row has not been read yet),
and a row with no `createdBy`. Both are `undefined` rather than a guess.
The table self-bootstraps, so an instance whose `tool_calls` predates the column
never gains it from `CREATE TABLE IF NOT EXISTS`; the DDL now also carries the
`ALTER TABLE … ADD COLUMN IF NOT EXISTS` retrofit, and the trail route projects
the field so the page can name the owner.
Tests: 20 arms across seven suites, incl. `the trail names the credential owner`
on a database with no connection store to join, and the retrofit's statement.
Ledger: 17 mutants over four files, 16 killed, 1 recorded equivalent (dropping
the column from `CREATE TABLE` changes nothing because the ALTER adds it to
every table, fresh or existing), 0 NAMED-ARM MISSES, all files restored.
Two arms the ledger forced into existence, both real gaps: the `{ ok: false }`
proposal branch had no test at all, and the executed-approval record had none.
vera flagged the trap before the gate: `tool_calls` is declared in `config/schema.sql` (what `init-pg-db.ts` executes to build a fresh database) AND in the model's DDL, with the INSERT naming the columns a third time. The first commit added `credential_owner_id` to the model DDL and made the INSERT use it, so an existing database was fine and a fresh one built from schema.sql would have disagreed with the code. schema.sql now declares the column, and `ToolCall.credentialOwnerSchema.test.js` asserts the two CREATEs declare the SAME column set and that the INSERT names nothing outside the shipped set — not that today's column appears in both, which is the check that lets the next column repeat the mistake. That arm also deletes the last recorded equivalent: dropping the column from the model's CREATE used to change nothing because the ALTER added it back (M14), and now the two CREATEs disagree. The ledger is 20 mutants, 20 killed. It also corrects the model's comment, which claimed the table self-bootstraps "rather than being part of schema.sql" — false on main, and exactly the belief that produces this bug. Durability, stated rather than implied (vera): `credentialOwnerId` holds against the CONNECTION going away, not the PERSON. The id is an owner reference, so deleting a User row leaves it dangling; an audit that must still name the person after account removal needs a denormalised label beside it.
This was referenced Sep 29, 2026
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.
What this is
§10 step 5, the trail column. Every
ToolCallRecordgainscredentialOwnerId— the Connection'screatedByat call time, for every connection type includinggithub-app— so the trail answers whose Linear was this? without joining the row it came from. It is copied, not joined, because removal ends by deleting the Connection and the trail outlives it (§8).Both
resolveConnectionbranches already readcreatedBy(the approval room needs it), so the broker takes the value from the connection it resolved and every record site passes it: the ok record, the refusal/failure record, the parkedpending_approvalrecord, both recordsexecuteApprovedToolCallwrites, and the decision recordapprovalActionServicewrites when a person rules. The parked envelope carries it because the Connection can be gone before a decision lands.Two sites deliberately record nothing: a call refused before a connection resolved (there is no credential to name yet), and a row with no
createdBy. Both readundefined, not a guess.Which durability claim this makes
It holds against the Connection going away, not the person. The id is an owner reference, so deleting a User row leaves it pointing at nothing; an audit that must still name the person after account removal needs a denormalised label beside it. Stated in the model's field doc so the two claims cannot be read as one.
The column lives in three places, and all three agree
tool_callsis declared inconfig/schema.sql— whatinit-pg-db.tsexecutes to build a fresh database — and in the model's DDL, with the INSERT naming the columns a third time. (The model's old comment claimed the table "self-bootstraps rather than being part of schema.sql"; that was false, and it is the belief that produces this bug.)ToolCall.credentialOwnerSchema.test.jsasserts the two CREATEs declare the same column set and the INSERT names nothing outside the shipped set — a column added to some copies now reddens a test instead of passing on every existing database and being wrong only on a fresh one.ALTER TABLE … ADD COLUMN IF NOT EXISTSremains the retrofit for an instance that built the table before the column existed.Evidence at
73647bb3toolBroker|approval|ToolCall|grants|seatGrant|roomGrant) 24 suites / 209 passed.agentsRuntime.rateLimitTiers) and passes in isolation on re-run — timing-sensitive rate limiters this diff does not touch. It is not deterministic: the earlier full run failed two different rate-limit suites, and the one that failed then passed now.eslinton the five source files: 0 errors. On the modified test files the finding set is +0 / −1 against main (measured by diffing the message multisets, not line numbers — the.jstest corpus is the ungated burn-down and a line-number diff would have lied)./tmp/kai-172trail-ledger.py, multi-file, anchors assert occurrence and print the match count, pristine copies restored): 20 mutants / 20 killed / 0 survivors / 0 NAMED-ARM MISSES, baseline 81/81 asserted before every run.{ ok: false }proposal branch had no test at all, and the executed-approval ok record had none.Gate: Vera (code).
Merge-order note (vera, 75539)
#2029 changes this file's
hostedRow()fixture owner from'owner-1'to the ObjectId-shaped6a8f6de2a1dccf2e02f31459(OWNER), because TASK-181's owner check refuses an id that cannot name an account — a'owner-1'fixture would now refuseconnection_owner_missingbefore the call is made. Two assertions here still expect'owner-1'and must readOWNERonce both land: the parked-call arm'scredentialOwnerIdand the approval-proposal arm'scredentialOwnerId.'owner-1'stays correct everywhere else — the github suite and the model suites never walk the owner check.Both PRs are mine, so "whoever lands second" is me: press #2028 first, and I will rebase #2029 onto the new main, update those two assertions, re-run the ledger and evidence, and re-ask Vera at the new head (her clearance is head-bound).