Skip to content

feat(grants): the trail records whose credential ran (TASK-172 §8/§10.5) - #2028

Merged
lilyshen0722 merged 2 commits into
mainfrom
kai/task172-trail
Sep 29, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
kai/task172-trail

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What this is

§10 step 5, the trail column. Every ToolCallRecord gains credentialOwnerId — the Connection's createdBy at call time, for every connection type including github-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 resolveConnection branches already read createdBy (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 parked pending_approval record, both records executeApprovedToolCall writes, and the decision record approvalActionService writes 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 read undefined, 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_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 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.js asserts 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 EXISTS remains the retrofit for an instance that built the table before the column existed.

Evidence at 73647bb3

  • 8 suites / 81 arms green on the touched surface; neighbourhood (toolBroker|approval|ToolCall|grants|seatGrant|roomGrant) 24 suites / 209 passed.
  • Full backend 501 suites / 4698 passed / 24 skipped. One suite failed in that parallel run (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.
  • eslint on 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 .js test corpus is the ungated burn-down and a line-number diff would have lied).
  • Ledger (/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.
    • The new schema-agreement arm deletes the last recorded equivalent. Dropping the column from the model's CREATE used to change nothing, because the ALTER added it back (M14, previously recorded as equivalent). With the two CREATEs compared it now kills. M13 (drop the ALTER) and M18 (drop it from schema.sql) both kill too.
    • Two arms the ledger forced into existence earlier, both pre-existing gaps: the { 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-shaped 6a8f6de2a1dccf2e02f31459 (OWNER), because TASK-181's owner check refuses an id that cannot name an account — a 'owner-1' fixture would now refuse connection_owner_missing before the call is made. Two assertions here still expect 'owner-1' and must read OWNER once both land: the parked-call arm's credentialOwnerId and the approval-proposal arm's credentialOwnerId. '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).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant