Skip to content

integrations: readable egress denials, Dependabot alert powers, routed-model usage - #1822

Merged
nikhilunni merged 14 commits into
mainfrom
fix/integration-grant-gaps
Nov 19, 2026
Merged

nikhilunni merged 14 commits into
mainfrom
fix/integration-grant-gaps

Conversation

@nikhilunni

Copy link
Copy Markdown
Contributor

Summary

A long-running agent session that owned dependency upgrades hit five problems with integrations. Each one made the agent guess instead of act:

  1. Dependabot alerts had no power. No GitHub operation mapped to the App permission vulnerability_alerts. The request passed the proxy only through the metadata:read catch-all, and GitHub refused it.
    • New powers: vulnerability_alerts:read and vulnerability_alerts:write.
  2. metadata:read matched every GET under a repository (GET /repos/*, where * crosses /).
    • It now covers the repository root and the named metadata endpoints, each scoped to one segment.
    • Paths that GitHub puts under another permission moved to that power (contents:read, issues:read, actions:read).
    • Breaking: a GET that only the old rule let through is now refused. See the upgrade note in CHANGELOG.md.
  3. A policy denial was unreadable. HTTP/1 closed the connection. HTTP/2 sent an empty 403, or reset the stream with CANCEL, which curl reports as (92) Stream error in the HTTP/2 framing layer. slack history printed nothing.
    • Now both protocols answer with a 403 and a JSON body: {"ok":false,"error":"egress_policy_denied","message":"<method> <path> …"}.
    • The proxy sends the denial at once and then discards the request body: 1 MiB at most, within 2 s. Nothing is buffered.
    • A body that does not finish gets RST_STREAM(NO_ERROR) (RFC 9113 §8.1).
    • A denial is never a 2xx. HTTP/1 still closes after it.
  4. The bundled CLIs split a value with a newline. A multiline value became extra curl arguments, so slack api chat.update text=… saved only the first line.
    • 18 wrappers now build their arguments in a loop that keeps each value whole.
  5. Routed-model sessions recorded 0 tokens and an Anthropic-priced cost.
    • Usage now comes from the stream: message_start, merged with each message_delta, emitted at message_stop. A turn that ends early emits what its streams reported.
    • A routed session's RunCost uses the router's catalog prices. The orchestrator passes them as ENGRAM_MODEL_ROUTER_PRICING.

While reading the minter, I also found that the variables:read and variables:write powers minted the key variables. GitHub's key is actions_variables, so those grants never worked.

Behaviour changes to note

  • Output tokens for Anthropic models rise. Before, the harness read output_tokens from the assistant lines, which repeat the message_start value (about 1). It now reads the final count from message_delta. Token dashboards will show the jump. The new numbers are correct.
  • A routed model with no catalog prices emits no RunCost. No cost is better than a wrong one.

Review

An independent review of the first five commits found:

  • the HTTP/2 drain had no deadline and buffered the body;
  • the metadata globs still crossed /;
  • some endpoints were under the wrong permission;
  • an interrupted message lost its usage;
  • the denial text suggested a grant for denials that no grant can fix.

The later commits fix each of these.

Test plan

  • cargo nextest for engram-egress-proxy (203) and engram-git-github (14). This includes a new HTTP/2 test (denied request with a body: readable 403 + JSON) and the rewritten HTTP/1 reject test (403, never a 2xx, body discarded).
  • bun test connectors + task-create (246), bun run typecheck.
  • Web: vitest (githubSetup), oxfmt --check, oxlint.
  • python3 -m unittest for integrations-cli. The new test_cli_args.py fails on the old slack script.
  • cargo clippy -D warnings on macOS for the proxy and the minter.
  • engram-harness-claude is Linux-only, and its tests and clippy did not run locally. CI's Linux lanes run them.

🤖 Generated with Claude Code

nikhilunni and others added 14 commits November 19, 2026 09:35
…pository only

The `metadata:read` operation matched `GET /repos/*`, and `*` crosses `/`,
so it let every GET under a repository through the proxy. A path with no
power of its own, such as Dependabot alerts, then reached GitHub with a
minted token that lacked the permission and failed as a GitHub 403.

- `metadata:read` now matches the repository root (`segment-path:/repos/*/*`)
  and the metadata endpoints by name (events, forks, stats, rules, ...).
- `compare`, `tarball`, `zipball` and the dependency graph move to
  `contents:read`, where GitHub puts them.
- New powers `vulnerability_alerts:read` (list Dependabot alerts) and
  `vulnerability_alerts:write` (dismiss one). The minter maps the power name
  to the GitHub App permission of the same name.

A GET that only the old catch-all let through is now refused at the proxy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The minter turned `variables:read` into the App permission key
`variables`, which GitHub does not have, so the clamp always dropped it
and `gh variable list` failed. Map `variables` to `actions_variables`, in
the minter and in the setup page's copy of the same mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A request the session's grants do not permit got no readable answer:
HTTP/1 closed the connection, and HTTP/2 sent an empty 403 and dropped the
unread request body, so h2 reset the stream. `curl -sS` printed nothing or
"Stream error in the HTTP/2 framing layer", and an agent could not tell a
missing grant from a network fault.

Both protocols now answer a policy denial with a 403 (400 for an
unparseable GraphQL request) and a JSON body:
{"ok": false, "error": "egress_policy_denied", "message": "<method> <path> ..."}.
Slack clients read `ok`/`error`, GitHub clients read `message`. HTTP/2
reads the request body (up to 1 MiB) before it answers, so the stream
ends cleanly. HTTP/1 still closes the connection after the answer, and a
malformed or smuggling-shaped request still closes without one. A denial
is never a 2xx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wrappers built their curl arguments as a newline-separated string and
split it with IFS. A value with a newline (a multiline Slack message, a
Jira description) became two arguments: the field kept only its first
line, and the rest went to curl as a URL. `slack api chat.update` saved a
truncated message this way.

Each wrapper now appends `--data-urlencode <field=value>` to its own
argument list in a loop, which keeps every value whole. vanta still splits
a `...MatchesAny` list on commas, vercel still rewrites `team=` to
`teamId=`, and cortex still adds its paging defaults. A unittest runs the
wrappers against a fake curl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the previous commit found:
- The new metadata globs (`/repos/*/events*` and the rest) used the plain
  form, where `*` crosses `/`, so `/repos/o/r/contents/src/events/x.ts`
  matched `metadata:read`. They are now `segment-path:/repos/*/*/<name>`.
- Some endpoints sit under a different GitHub permission: `activity`,
  `codeowners/errors`, `community/profile` and commit `comments` need
  Contents read, `assignees` needs Issues read, `environments` needs
  Actions read, and `teams` needs Administration (dropped).
- GETs the old catch-all covered and nothing else did: the root
  `contents` listing, and `topics`/`languages` with a query string.

`compare`, `tarball` and `zipball` keep the plain form, because a ref can
contain `/`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the previous commit found that HTTP/2 read the request body
before it answered, with no deadline and into a buffer: a client that
never ended its body never got the denial, and 64 such streams could hold
64 MiB.

- HTTP/2 sends the complete denial first, then discards the body without
  keeping it (1 MiB, 2 s). A body that does not end gets
  `RST_STREAM(NO_ERROR)`, which RFC 9113 §8.1 allows after a complete
  response; the implicit reset h2 sends for an unread body is `CANCEL`,
  which curl reports as a framing error. The 413 path does the same.
- HTTP/1 discards the unread part of a declared body (same limits) after
  the answer, so the close does not send a TCP RST ahead of it.
- Only a request the grants do not cover tells the guest to ask for a
  grant. A Google credential request or a malformed GraphQL body says that
  no grant permits it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he catalog

A session on a routed model (OpenRouter) recorded zero tokens for every
model call, and its run cost came from Claude Code's `total_cost_usd`,
which prices every model with Anthropic's list.

The harness read usage from the CLI's `assistant` lines. Those repeat the
`message_start` usage, and a router sends zeros there; the real counts
arrive in `message_delta`. For Anthropic models the same lines carried an
`output_tokens` of about 1, so output tokens were under-counted too and
now rise to the real numbers.

- `GenerationLedger` keeps the usage of each streaming message, keyed by
  `parent_tool_use_id`: `message_start`, merged with each `message_delta`
  (larger value wins; Anthropic's counts are cumulative), emitted at
  `message_stop`. A turn that ends first (result, interrupt, crash) emits
  what its streams reported. An `assistant` line counts only for a message
  the CLI did not stream.
- The orchestrator passes the routed model's catalog `pricing` as
  `ENGRAM_MODEL_ROUTER_PRICING`; a profile env var cannot set it. A routed
  session's `RunCost` is its turn's tokens at those prices, and no cost
  when the model has no prices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The catalog derived a power's read/write access from its operation's HTTP
method, and a method-less operation counted as write. Slack's Web API is
POST-only and declares no methods, so every Slack power showed as "write"
(`channels:read`, `users:read`, ...), and so did Datadog's
`profiling:read`/`test_optimization:read` and Notion's `search:read`. The
profile editor groups and presets powers by this label.

`powerAccess`: `<resource>:read` reads, any other level writes, and only a
power with no level takes its operation's access. The web's parser and the
custom-connector editor use the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `users:read` matched `/api/users.*` and `usergroups:read` matched
  `/api/usergroups.*`, which include writes (`users.setPresence`,
  `users.profile.set`, `usergroups.create`, `usergroups.update`). They now
  list their read methods.
- Slack retired `files.upload` on 2025-11-12, so `slack upload` failed.
  It now calls `files.getUploadURLExternal`, sends the bytes to the
  returned `files.slack.com` URL, and shares the file with
  `files.completeUploadExternal`. The connector opens `files.slack.com`
  for that upload (`files:write`) and for downloading a file's
  `url_private` (`files:read`), and drops the `files.upload` operation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four Linux-only tests still passed the old dedupe set, so the harness
tests did not compile on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikhilunni
nikhilunni merged commit 248bb22 into main Nov 19, 2026
51 of 53 checks passed
@nikhilunni
nikhilunni deleted the fix/integration-grant-gaps branch November 19, 2026 18:33
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