Skip to content

fix(oauth): hold a grant item for 1 major version of its app - #94

Merged
bketelsen merged 2 commits into
mainfrom
irulan/t7-grant-major
Nov 17, 2026
Merged

bketelsen merged 2 commits into
mainfrom
irulan/t7-grant-major

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A grant stored its items with no version of the app. hearth's manifest diff lets an app's next major version change what a capability, a selector or a topic means (hearth ADR-0004, Compatibility). So a grant that an admin approved for the old meaning stayed in force on the new major version. This PR binds each grant item to 1 major version of its app.

  • The app's line. lodge reads the hearth manifest's version (MAJOR.MINOR.PATCH). An app with a missing or malformed version is disabled, with the reason. The line is MAJOR, or 0.MINOR for a 0.y.z version (svu's v0 rule, as hearth manifest diff uses it).
  • Stored with each item. An access request records the app's line when it is made. An approval stores that line with each item it adds, inside the grant's items JSON ("major": "0.1"). An approval of an item that the grant holds already sets its line again.
  • In force for 1 line. Grant gives only the items of the app's current line, to the MCP gateway, to the Connect header Lodge-Grant and to the broker's filters. A new line takes the old items out of force until an admin approves them again on the consent page. An item stored with no line (before this PR) is in force for none.
  • Old requests. A request made on an old line can only be declined: approve answers 409, and the consent page says why and shows the app's version. The grants page shows each item that is not in force.
  • Reload. A reload now refilters every event subscription at once (events.Service.AppsChanged), as a grant change does. Before, a manifest change waited up to 1 minute for the sweep. The gateway already re-listed tools on a reload. Once the registry loads, the reload runs every step (the broker's SyncApps) and then always tells both readers, so a failed step cannot leave the old filters (afterAppsLoad); it reports the steps' errors joined.
  • Migration 0006 adds consent_requests.major (default '', which no approval takes).
  • Docs: ADR-0023 (Proposed) records the rule; specs/oauth.md pins it; the design overview and the site's configure guide say what an owner sees.

The rest of lodge's contract is unchanged: /mcp/<id> with lgm_ tokens, agent.sock and the companion slot (frostnotes, frostmail, Porter and the PocketJournal) do not read these grants.

Upgrade note. A grant approved before this PR has no line, so it stops at the upgrade. Each principal's agent calls request_access once more, and an admin approves it.

Restart. At start, nothing is cached: the gateway reads Grant at each list and call. Event consumers are rebuilt from Grant by the sweep (and, after the next change, before /nats admits clients). Both see the current line only.

Risk tier

Risk tier: 3 — risk:high. Matched paths (.github/risk-paths.json, all L1):

  • internal/oauth/** (auth): Grant returns a subset of what it returned before (the items of the app's current line). addGrant stores the request's line; it never widens an item. The approval adds 1 refusal (409) before its transaction; the request hash, the CSRF checks and the admin check are unchanged. The item hash on the grants page is unchanged (it ignores the line).
  • internal/events/** (auth): new AppsChanged refilters each subscription from its principal's grant, with the same fail-closed path as GrantChanged (a failed refilter revokes the client).
  • internal/apps/apps.go (auth): the hearth manifest loader now requires a valid version; a missing one disables only that app.
  • cmd/lodge/main.go (auth): the reload calls AppsChanged on the gateway and the events service after every successful registry load, also when the broker step fails; the step's error is still returned.
  • internal/store/migrations/** (destructive operations): 0006 only adds a column with a default; no row changes.

Docs housekeeping

  • Cross-links added in both directions (ADR ↔ design ↔ spec)
  • New significant decision recorded in an ADR in this PR (ADR-0023 is Proposed, so it is edited in place)
  • ADR edits are fact-only

Verification

  • make check green (host)
  • make race and make cross green (host)
  • make client-check, ui-check, shell-check: not run locally; the nsl machine does not answer on this host (nsl run -m lodge true exits 1 with no output). This PR changes nothing under client/, ui/ or shell/; CI runs those jobs.
  • make mcp-e2e (nsl): not run, for the same reason. The gateway's MCP protocol is unchanged; the Go tests drive it with the Go MCP SDK client.
  • Revert test: see below.
  • Blocking review point fixed: guard added (tests below) and .memory/corrections/2026-11-16-pr-94-grant-holds-for-one-major.json
  • Blocking cross-review point fixed (a failed SyncApps skipped the refilter): guard cmd/lodge TestAfterAppsLoadTellsTheReaders, and .memory/corrections/2026-11-16-pr-94-reload-tells-readers-after-a-failed-step.json

New tests:

  • internal/gateway TestMCPGatewayNewMajorNeedsConsent: hearth's example app at 0.1.0, a grant, a call; the app goes to 0.2.0; the open session gets tools/list_changed, loses the tool, the call is insufficient_scope and the app sees nothing; the grants page marks the item; an old request's page shows the reason and its approval is 409; request_access, approval, the tool and the call come back.
  • cmd/lodge TestAfterAppsLoadTellsTheReaders: a failed broker step still runs the later steps and both readers, and its error is returned.
  • internal/oauth TestGrantMajor, TestGrantWithoutMajor; internal/apps TestHearthMajor and 3 new cases of TestHearthManifestDisabled; internal/events TestAppsChangedRefilters.

Revert test

In a scratch worktree at 992335f, with inForce's line check replaced by if true (internal/oauth/grants.go) and events.Service.AppsChanged made a no-op, with the tests kept: go test ./internal/gateway/ -run NewMajor fails (the session got no notifications/tools/list_changed), go test ./internal/oauth/ -run 'GrantMajor|WithoutMajor' fails (a grant without a line = [...]; want nothing in force), and go test ./internal/events/ -run AppsChanged fails (the consumer's filters after the reload are [...]). At 0e9317a, with afterAppsLoad's loop changed back to an early return err: go test ./cmd/lodge/ -run AfterAppsLoad fails (ran [sync], want every step, then every reader).

Cross-review

  • Reviewer openai/gpt-6.1-sol; coder anthropic/claude-opus-5-5. Base 789ed5de753a6335c7005efee5b7565e6b71276a.
  • Initial review at 992335ffbdb5921d13168816d3f0dc4c9e058a42, all 20 files: Not ready, 1 blocking finding (high): a failed broker SyncApps in the reload returned before the event subscriptions were refiltered, after the new manifest was in force. Fixed in 0e9317a.
  • Re-review 1 at 0e9317ade9895a4d676ba73f6879a6a63903974a (diff since 992335f): no new findings; the blocker is resolved. Ready, Blocking: none.
  • Limits: the reviewer read the code and did not run tests; the nsl checks and make mcp-e2e did not run locally (see Verification).

A grant stored its items with no version of the app, so the app's next
major version, which hearth's manifest diff allows to change what a
capability, a selector or a topic means, kept every grant that an admin
approved for the old meaning (hearth ADR-0004, Compatibility).

- lodge reads the hearth manifest's version, MAJOR.MINOR.PATCH, and
  disables an app whose version is missing or malformed. The app's line is
  MAJOR, or 0.MINOR for a version 0.y.z.
- An access request records the app's line; an approval stores it with
  each item. Grant gives the gateway and the broker only the items of the
  app's current line, so a new line takes the old items out of force until
  an admin approves them again. An item stored with no line is in force
  for none.
- A request made on an old line can only be declined (409); the consent
  page says so, and shows the app's version. The grants page marks an
  item that is not in force.
- A reload refilters every event subscription at once, as a grant change
  does, instead of waiting for the next sweep.
- Migration 0006 adds consent_requests.major.

ADR-0023 (Proposed) and docs/specs/oauth.md record the rule; the guide
says what an owner sees.
@github-actions github-actions Bot added level:L1 Read every line risk:high Touches a path in .github/risk-paths.json labels Nov 16, 2026
…step fails

The registry is in force once it loads, so a failed SyncApps must not skip
the gateway's tools and the event consumers' refilter: a grant that an app's
new major version takes out of force would keep its events until the next
sweep. The reload now runs each step, then each reader, and joins the steps'
errors. Found by the cross-review.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 16, 2026
@bketelsen
bketelsen merged commit c3fe29e into main Nov 17, 2026
13 checks passed
@bketelsen
bketelsen deleted the irulan/t7-grant-major branch November 17, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L1 Read every line ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants