Repository navigation
[AI-4468] Move request identity to internal/api/reqctx - #2805
Conversation
The keys of the customer, organization, caller kind, server side mark and request id were private to internal/api, so a controller in another package could not read them. They now live in reqctx with their setters and readers, and internal/api keeps one-line delegates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Text review: 3 unclear of 28
[Nit] T1.3 PR opening: it names two package paths (internal/api, internal/api/reqctx), and the pr-description sample keeps paths out of the three opening sentences. Rewrite: "The customer, organization, caller kind, server-side mark and request id of a request were stored under keys that only the API package could see, so a controller in another package had to go through Server to read them. This PR moves those keys, with their setters and readers, into a package of their own that any controller can import. Nothing changes at run time and the API spec does not change."
Note: the key comments in reqctx.go for organizationKey, kindKey and CallerFrom (lines 14-15, 21-22, 80-84) end on a reversing "which ..." clause. They are moved word for word from server.go on the base, so they are not findings here.
| @@ -0,0 +1,14 @@ | |||
| # internal/api/reqctx | |||
|
|
|||
| Who a request is from, as the auth middleware put it on the context: the customer (app), the organization, the request id, the sort of caller (`auth.Kind`), whether it is the customer's own backend, and the end user's `routing.Caller`. A controller reads it with `IdentityFrom`, or with one `...From` function when it needs one value. | |||
There was a problem hiding this comment.
[Should fix] T1.1 The first sentence has no verb and the list packs six values into it. Rewrite:
| Who a request is from, as the auth middleware put it on the context: the customer (app), the organization, the request id, the sort of caller (`auth.Kind`), whether it is the customer's own backend, and the end user's `routing.Caller`. A controller reads it with `IdentityFrom`, or with one `...From` function when it needs one value. | |
| This package holds who a request is from. The auth middleware puts the customer (app), the organization, the request id, the kind of caller (`auth.Kind`), the server-side flag and the end user (`routing.Caller`) on the context. A controller reads them with `IdentityFrom`, or with one `...From` function when it needs a single value. |
There was a problem hiding this comment.
Fixed in ac5da32: AGENTS.md now opens with a sentence with a verb, and names who sets each value (checked in server.go:1471-1477, requestid.go:42, scheduled_delivery.go:1365-1368). Test: the commands in the file, probed in probe.log
| - **Inside the repo this package imports only `internal/auth` and `internal/routing`.** `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents` prints those two and nothing else. That keeps `reqctx` free to import from any package that `internal/api` imports. | ||
| - **`internal/api` is not among its dependencies.** `go list -deps ./internal/api/reqctx | grep -x '.*/internal/api'` prints nothing. | ||
| - **The context keys stay unexported.** The `With...` and `...From` functions are the only way to put a value in or read it back, so a setter and its reader cannot drift apart. `grep -nE '^type [A-Z][A-Za-z]*Key ' reqctx.go` prints nothing, and `go doc -short .` lists only functions and `Identity`. | ||
| - **`IdentityFrom` returns nil when the request has no customer or an empty one.** A controller must not act for the app named "". `TestIdentityFromIsNilWhenCustomerIsMissingOrEmpty` locks it. |
There was a problem hiding this comment.
[Should fix] T1.2 Each rule mixes the rule, its check and its reason, and "locks it" is jargon. Rewrite (same facts, check and reason in separate sentences):
| - **Inside the repo this package imports only `internal/auth` and `internal/routing`.** `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents` prints those two and nothing else. That keeps `reqctx` free to import from any package that `internal/api` imports. | |
| - **`internal/api` is not among its dependencies.** `go list -deps ./internal/api/reqctx | grep -x '.*/internal/api'` prints nothing. | |
| - **The context keys stay unexported.** The `With...` and `...From` functions are the only way to put a value in or read it back, so a setter and its reader cannot drift apart. `grep -nE '^type [A-Z][A-Za-z]*Key ' reqctx.go` prints nothing, and `go doc -short .` lists only functions and `Identity`. | |
| - **`IdentityFrom` returns nil when the request has no customer or an empty one.** A controller must not act for the app named "". `TestIdentityFromIsNilWhenCustomerIsMissingOrEmpty` locks it. | |
| - **Inside the repo, this package imports only `internal/auth` and `internal/routing`.** Check it with `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents`, which must print those two and nothing else. Any package that `internal/api` imports can then import `reqctx` without an import cycle. | |
| - **`internal/api` must not be a dependency.** `go list -deps ./internal/api/reqctx | grep -x '.*/internal/api'` must print nothing. | |
| - **The context keys stay unexported.** Code puts a value in or reads it back only through the `With...` and `...From` functions, so a setter and its reader cannot drift apart. `grep -nE '^type [A-Z][A-Za-z]*Key ' reqctx.go` must print nothing, and `go doc -short .` must list only functions and `Identity`. | |
| - **`IdentityFrom` returns nil when the request has no customer, or the customer is empty.** A controller must not act for an app named "". `TestIdentityFromIsNilWhenCustomerIsMissingOrEmpty` covers this. |
There was a problem hiding this comment.
Fixed in ac5da32: Rules now state rule, check and reason in separate sentences. Test: each check was run and broken in a scratch copy (probe.log)
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Security review, round 1, head 01803ab, base 1e6ffb2. I found no Blocker and no Should fix, and one Nit.
| Checked | Result |
|---|---|
| Who can call the exported setters | Outside tests only internal/api imports reqctx, and Go's internal/ rule keeps other modules' trees out. The setters are called in the same eight places as on the base, with the same values. |
| A value stored under one key and read under another | No old key is left. Each setter and its reader share one struct type, and the five types are distinct. |
| Scheduled delivery | It still runs as the task's app and user, with the task's caller kind, and is server side. ScheduledTasksSuite passes. |
| A device that poses as a backend or as another user | PostureSuite, SessionOwnershipSuite, ProxyKindSuite and AccountSuite pass. |
| Mutations | 15 checked, 0 survived. |
The whole integration run is not done here.
|
|
||
| - **Inside the repo this package imports only `internal/auth` and `internal/routing`.** `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents` prints those two and nothing else. That keeps `reqctx` free to import from any package that `internal/api` imports. | ||
| - **`internal/api` is not among its dependencies.** `go list -deps ./internal/api/reqctx | grep -x '.*/internal/api'` prints nothing. | ||
| - **The context keys stay unexported.** The `With...` and `...From` functions are the only way to put a value in or read it back, so a setter and its reader cannot drift apart. `grep -nE '^type [A-Z][A-Za-z]*Key ' reqctx.go` prints nothing, and `go doc -short .` lists only functions and `Identity`. |
There was a problem hiding this comment.
[Nit] S1.1 This package now lets any package under acceleration/ mark a context as server side or name its customer. On the base only internal/api could do that, because the keys were private to it. Nothing misuses it today. The rules keep the keys private but do not say who may write them, and later PRs of this series add packages that read identity from here.
Fix: add a rule that only server.go, requestid.go and scheduled_delivery.go of internal/api call the With... functions outside tests, and that other code only reads. The command is grep -rlE 'reqctx\.With' --include='*.go' . | grep -v _test.go, run in acceleration/, which prints those three files.
There was a problem hiding this comment.
Fixed in ac5da32: Added the rule on who may call With...; the grep prints server.go, requestid.go and scheduled_delivery.go and also printed a fourth file when I added a caller (probe.log)
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Round 1 at 01803ab on 1e6ffb2. The base has not moved, so the head is the merged tree. The code change is sound. The two Should fix findings are both in the new AGENTS.md.
| Checked | Result |
|---|---|
| The eight writes of the keys | I rewrote the base files mechanically (context.WithValue on a key to its setter) and compared them with the head. Only the import, the removed keys and the delegates differ. |
| The six readers | The bodies are identical to the base apart from the key names. No old key is left in the repo. |
Build, go vet with and without integration, openapi.yaml |
Pass, no diff |
Unit tests with -race; reqctx 50 times with -cpu 1 |
Pass |
The 11 integration suites of the description, plus TestAccountSuite |
Pass |
| Mutations | 42 checked, 0 survived |
The new TestADeliveryRunsAsItsTasksOwnerServerSide |
It fails when the server side mark in scheduledOwnerContext is false or dropped. Without it, the rest of ScheduledTasksSuite passes with the mark false, as the description says. |
The description does not mention the added AGENTS.md and CLAUDE.md. CI has run only the labeler and GitGuardian, because the PR is a draft. The other generated SDK files were not regenerated here, since openapi.yaml has no diff.
|
|
||
| - **Inside the repo this package imports only `internal/auth` and `internal/routing`.** `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents` prints those two and nothing else. That keeps `reqctx` free to import from any package that `internal/api` imports. | ||
| - **`internal/api` is not among its dependencies.** `go list -deps ./internal/api/reqctx | grep -x '.*/internal/api'` prints nothing. | ||
| - **The context keys stay unexported.** The `With...` and `...From` functions are the only way to put a value in or read it back, so a setter and its reader cannot drift apart. `grep -nE '^type [A-Z][A-Za-z]*Key ' reqctx.go` prints nothing, and `go doc -short .` lists only functions and `Identity`. |
There was a problem hiding this comment.
[Should fix] R1.1 The check for unexported keys passes when the rule is broken. I added each of these to reqctx.go and ran the grep; it printed nothing every time:
| Added | grep |
|---|---|
type ( CustomerKey struct{} ), one key per line as in a normal block |
nothing |
type CustomerKey[T any] struct{}, type CustomerKey2 struct{}, type Customer struct{} |
nothing |
var CustomerKey = customerKey{} |
nothing |
type CustomerKey struct{} in another file of the package |
nothing |
Rule 3 also runs from another directory than rules 1 and 2. From acceleration/, grep prints only an error that reqctx.go does not exist, and go doc -short . fails. The go doc check does show a broken rule, but a reader has to compare its list by eye.
Rule 2 has the same problem (line 8). With an import of internal/api added, go list -deps stops at the import cycle and the grep still prints nothing. Only stderr shows the error.
Fix: use commands that run from acceleration/ and print a line when the rule breaks. For rule 3, this one printed nothing on the head and printed the added key in every row above:
go doc -short ./internal/api/reqctx | grep -vE '^func (With[A-Za-z]+|[A-Za-z]+From)\(|^type Identity |^ +func IdentityFrom\('
For rule 2, go build ./internal/api/reqctx fails with import cycle not allowed. Say once, above the rules, that every command runs from acceleration/.
The rewrite in T1.2 keeps the old commands, so please do not apply it as it is.
There was a problem hiding this comment.
Fixed in ac5da32: Every command runs from acceleration/. Key rule uses your go doc | grep -v command: empty on head, prints the key for a type block, exported var and key in another file. Import rule uses go build, which fails with import cycle not allowed on an internal/api import (probe.log)
|
|
||
| ## Rules | ||
|
|
||
| - **Inside the repo this package imports only `internal/auth` and `internal/routing`.** `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents` prints those two and nothing else. That keeps `reqctx` free to import from any package that `internal/api` imports. |
There was a problem hiding this comment.
[Should fix] R1.2 The reason given here is not true. reqctx imports internal/routing, and through it internal/store, internal/llm, internal/usage and others. A package that reqctx depends on cannot import it. I added an import of reqctx to internal/store, and the build failed with import cycle not allowed.
19 of the packages that internal/api imports directly are in that list (go list -deps ./internal/api/reqctx).
Fix: say what holds, for example "A package that reqctx does not depend on can import it. go list -deps ./internal/api/reqctx lists the ones that cannot." The rewrite in T1.2 repeats the claim, so it needs the same change.
There was a problem hiding this comment.
Fixed in ac5da32: Reason replaced with: a package that reqctx depends on cannot import it, and go list -deps ./internal/api/reqctx lists them (internal/store and internal/llm are in the output)
| @@ -0,0 +1,14 @@ | |||
| # internal/api/reqctx | |||
|
|
|||
| Who a request is from, as the auth middleware put it on the context: the customer (app), the organization, the request id, the sort of caller (`auth.Kind`), whether it is the customer's own backend, and the end user's `routing.Caller`. A controller reads it with `IdentityFrom`, or with one `...From` function when it needs one value. | |||
There was a problem hiding this comment.
[Nit] R1.3 The auth middleware does not put the request id on the context; withRequestID does. A scheduled delivery sets the customer, the server side mark and the caller kind in scheduledOwnerContext, with no middleware. The package comment in reqctx.go:1 says the same thing, and so does the rewrite in T1.1.
Fix: name the three writers, or say "as internal/api put it on the context".
There was a problem hiding this comment.
Fixed in ac5da32: AGENTS.md names the three writers (middleware, withRequestID, scheduled delivery); reqctx.go:1 now says as internal/api put it on the context
…e the writers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Round 2 on ac5da32 (previous 01803ab). The AGENTS.md rewrite fixed the earlier findings, and I found two small errors in the new text. Both are in lines this round changed.
Earlier findings
- R0.1 fixed: AGENTS.md and CLAUDE.md exist.
- T1.1, R1.3 fixed: the intro names the writers and each one is true (
withCustomerat server.go:1471-1476,withRequestIDat requestid.go:42,scheduledOwnerContextat scheduled_delivery.go:1365-1368). - T1.2 fixed: rule, check and reason are separate sentences.
- T1.3 fixed: the PR opening has no package paths, and the body names AGENTS.md and CLAUDE.md. I checked the body against the diff: the diagram, the table, the "18 test files" count, the test names and the "no production caller" claim hold.
- R1.1 fixed: rules 1, 2 and 4 each work from
acceleration/. The rule 4 command is empty on head and prints the key in my probes (exported var in a var block, exported func). - R1.2 fixed in its fact (
internal/storeandinternal/llmare ingo list -deps), but the sentence after it is wrong, see R2.1. - S1.1 fixed for a plain caller, but see R2.2.
New findings
- [Should fix] R2.1 AGENTS.md:11 — "Any other package can import
reqctx" is false. Go's internal rule bars every package outsideacceleration/(tui,sdks/go, the examples). Probe: a file intui/zzthat imports it fails with "use of internal package ... not allowed", while one inacceleration/internal/zzbuilds. Fix: "Any other package inacceleration/can importreqctx." While there, "lists them, ... among them" reads oddly: "go list -deps ./internal/api/reqctxlists them;internal/storeandinternal/llmare two of them." - [Should fix] R2.2 AGENTS.md:13 — the check for "only three files call
With..." stays silent when a caller renames the import (rc "…/reqctx") or dot-imports it: I ran both probes and the output was still the three files. Fix: grep for the setters' names,grep -rlE 'With(Customer|Organization|ServerSide|Kind|RequestID)\b' --include='*.go' . | grep -v _test.go | grep -v internal/api/reqctx/; it prints the three files on head and a fourth in both probes. - [Nit] AGENTS.md:3 — the second sentence is about 70 words with a list inside a list. Split it after "on the context": one sentence for who sets what.
- [Nit] PR body, "What differs" — "The keys of the request's public key, the actor, the logged app and the request failure stay in
internal/api" reads badly. Say: "The keys for the request's public key, the actor, the logged app and the request failure stay ininternal/api."
Checks on head: go build ./..., go vet ./internal/api/..., go test ./internal/api/reqctx, go test ./internal/api -count=1 and the openapi regeneration are clean. The delta has no Go code beyond the one-line package comment, so there is nothing else to mutate. CI: draft, go and integration skipped.
Details: reviewer-2.md in the ledger.
|
|
||
| - **Inside the repo, this package imports only `internal/auth` and `internal/routing`.** Check it with `go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agents`, which must print those two and nothing else. | ||
| - **`internal/api` must not be a dependency.** Check it with `go build ./internal/api/reqctx`, which fails with `import cycle not allowed` when it is. | ||
| - **A package that `reqctx` depends on cannot import it.** `go list -deps ./internal/api/reqctx` lists them, `internal/store` and `internal/llm` among them. Any other package can import `reqctx`. |
There was a problem hiding this comment.
[Should fix] R2.1 "Any other package can import reqctx" is false. A file in tui/zz that imports it fails with use of internal package ... not allowed; one in acceleration/internal/zz builds. Write "Any other package in acceleration/".
There was a problem hiding this comment.
Fixed in 024d159: the rule is deleted (the import cycle is the compiler's job). The false sentence is gone from AGENTS.md.
| - **`internal/api` must not be a dependency.** Check it with `go build ./internal/api/reqctx`, which fails with `import cycle not allowed` when it is. | ||
| - **A package that `reqctx` depends on cannot import it.** `go list -deps ./internal/api/reqctx` lists them, `internal/store` and `internal/llm` among them. Any other package can import `reqctx`. | ||
| - **The context keys stay unexported.** Code puts a value in or reads it back only through the `With...` and `...From` functions, so a setter and its reader cannot drift apart. `go doc -short ./internal/api/reqctx | grep -vE '^func (With[A-Za-z]+|[A-Za-z]+From)\(|^type Identity |^ +func IdentityFrom\('` must print nothing. | ||
| - **Outside tests, only `server.go`, `requestid.go` and `scheduled_delivery.go` of `internal/api` call the `With...` functions.** Other code only reads. `grep -rlE 'reqctx\.With' --include='*.go' . | grep -v _test.go` must print those three files. |
There was a problem hiding this comment.
[Should fix] R2.2 This grep stays silent for rc "…/reqctx" with rc.WithCustomer, and for a dot import: I ran both and got the same three files. Grep the setter names instead: grep -rlE 'With(Customer|Organization|ServerSide|Kind|RequestID)\b' --include='*.go' . | grep -v _test.go | grep -v internal/api/reqctx/ prints the three files on head and a fourth in both probes.
There was a problem hiding this comment.
Fixed in 024d159: the check now matches the setter names (With(Customer|Organization|ServerSide|Kind|RequestID)), not reqctx\.With. On head it prints the three files. With an alias, a dot import and a plain fourth caller in scratch packages it prints a fourth file each time.
…calls, split the intro Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Delta round 3 on PR 2805, head 024d159 (previous reviewed head ac5da32), base 1e6ffb2 (unchanged, the PR's baseRefOid). The delta is one file, acceleration/internal/api/reqctx/AGENTS.md, and one PR body line. The four fixes hold. One new Should fix: the setter command in rule 4 misses a sixth With... setter, and the rule still says "only" three files call them.
REVIEWED: 024d159 merged onto 1e6ffb2 (the head contains ac5da32 as an ancestor, and the diff is AGENTS.md only: git diff --stat ac5da32aa 024d15912 = 1 file, 2 insertions, 3 deletions)
PRIOR:
- R2.1 — fixed — the bullet "A package that reqctx depends on cannot import it" is deleted (AGENTS.md hunk at line 11). The remaining import claim, "Inside the repo, this package imports only internal/auth and internal/routing", holds:
go list -f '{{join .Imports "\n"}}' ./internal/api/reqctx | grep Vision-Agentsprints those two on head. - R2.2 — fixed — the setter command now finds callers that use an alias or a dot import. Mutation: alias probe (
rc "…/reqctx",rc.WithCustomer, internal/zzalias/a.go) and dot probe (. "…/reqctx", internal/zzdot/a.go). Old commandgrep -rlE 'reqctx\.With': silent on both. New command: prints both. 2 checked, 0 survived. - R2.3 — fixed — intro split after "on the context" (AGENTS.md line 3). Each sentence is now shorter and states its own subject.
- R2.4 — fixed — PR body line 35 now reads "The keys for the request's public key, ...". Read back with
gh pr view 2805 -R GetStream/Agents --json body: byte-identical to the fixer's body-after copy apart from gh's trailing newline (diff 2805/body-after.md delta3-body-now.mdis empty).
NEW FINDINGS:
[Should fix] acceleration/internal/api/reqctx/AGENTS.md:13 — the command greps for five fixed names (With(Customer|Organization|ServerSide|Kind|RequestID)). A sixth setter passes silently. Probe: I added func WithProbe to reqctx and called it from internal/api/zzsix_probe.go; the command printed only server.go, scheduled_delivery.go and requestid.go. The rule still says "only" those files call "the With... functions", so the claim is false and the check stays silent. Fix: take the names from go doc, as one command: names=$(go doc -short ./internal/api/reqctx | sed -n 's/^func \(With[A-Za-z]*\)(.*/\1/p' | paste -sd'|' -); grep -rlE "($names)\b" --include='*.go' . | grep -v _test.go | grep -v internal/api/reqctx/. Probe of the fix: with WithProbe added, it prints internal/api/zzsix_probe.go plus the three files; on head it prints the three files only. Also change "It matches the setter names" to say the names come from go doc, so a new setter needs no edit.
MUTATIONS: 7 checked, 1 survived (the sixth setter, the NEW FINDING above; the fix catches it).
- alias caller (rc.WithCustomer): old silent, new prints. Caught.
- dot-import caller (WithCustomer): old silent, new prints. Caught.
- plain caller (reqctx.WithKind) outside internal/api: both print. Caught.
- non-test internal/api file calling WithKind (internal/api/zzprobe_nontest.go): new prints a fourth file. Caught.
- _test.go caller (internal/zzalias/x_test.go): not printed (the
_test.gofilter works). Caught. - sixth setter WithProbe: current command silent. Survived; the derived-name command prints it. Fix recorded above.
- Rule 1 import list and rule 2 cycle check: unchanged text, rerun on head (two packages printed; build passes). Not a mutation of this delta.
Every probe file was removed;git status --shortin the worktree is empty.
CHECKS ON HEAD (acceleration/):
go build ./...rc 0 (18 s).go test ./internal/api/reqctx -count=1: ok.- Intro claims, grep on head: withRequestID sets the id at requestid.go:42; scheduledOwnerContext sets customer, server side, kind and caller at scheduled_delivery.go:1365-1368; the auth path sets customer, organization, server side and kind at server.go:1471-1474, then the caller at server.go:1477 (routing.WithCaller). All match the intro.
- CI (
gh pr checks 2805): labeler pass, GitGuardian pass, go and integration SKIPPED (draft, per the #2130 rule; not a failure).
UNVERIFIED:
- The command is run on macOS (BSD grep). GNU grep (Linux) prints a
./prefix; thegrep -v internal/api/reqctx/filter still works on that prefix. Not run on Linux. No CI job runs these AGENTS.md commands (unverified: no workflow grep). - The go doc and paste steps of the proposed fix ran on macOS only.
DETAILS: /Users/kanat/.claude/ship-task/Agents/AI-4467/AI-4468/reviewer-3.md (this file)
The setter check listed five names by hand, so a sixth With... setter passed unseen. It now reads the names from go doc, so a new setter needs no edit. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
|
Fixed in 161fb41 (R3.1). The setter check in Probes: with a |
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Delta 024d159..161fb41 is one line of acceleration/internal/api/reqctx/AGENTS.md.
R3.1 is fixed. The setter check now takes the names from go doc. On head, run from acceleration/, it prints internal/api/server.go, internal/api/scheduled_delivery.go and internal/api/requestid.go, the three files the rule names. I added a func WithProbe to reqctx and a caller that dot-imports the package: go doc listed WithProbe and the command printed the caller as a fourth file. The old fixed-name command stayed silent on that probe.
No new findings. Earlier findings stay fixed. The check was run on macOS only here; the fixer ran it on Linux. No Go changed, so no suite was rerun.
👋 Hi Kanat, want a second pair of eyes on this?I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.
Or comment |
The customer, organization, caller kind, server side mark and request id of a request were stored under keys that only the API package could see, so a controller in another package had to go through
Serverto read them. This PR moves those keys, with their setters and readers, into a package of their own that any controller can import. Nothing changes at run time and the API spec does not change.How it works
The new package has an
AGENTS.md(its rules, each with a command that shows when it is broken) and aCLAUDE.mdthat only links it.reqctximports onlyauthandrouting.IdentityFromhas no production caller yet: the session controllers read it in a later PR of this series.What differs from the base
internal/apicustomerContextKey,organizationContextKey,serverSideContextKey,kindContextKey,requestIDContextKeycustomerKey,organizationKey,serverSideKey,kindKey,requestIDKeyinreqctxCustomerFrom,OrganizationFrom,ServerSideFrom,KindFrom,RequestIDFromreqctx, delegates inapiCallerFromreqctx.CallerFrom, delegate inapicontext.WithValue(ctx, <key>{}, v)inserver.go,requestid.go,scheduled_delivery.goreqctx.With*(ctx, v)context.WithValueandhuma.WithValueon these keys in 18 test filesreqctx.With*The keys for the request's public key, the actor, the logged app and the request failure stay in
internal/api, since this PR does not need them elsewhere.Tests
TestIdentityFromIsNilWhenCustomerIsMissingOrEmptyTestIdentityFromReadsAllRequestIdentityFieldsIdentityis not filledTestServerSideFromReadsBackFalseTestRequestIDFromRoundTripsTestOrganizationFromRoundTripsIndependentlyScheduledTasksSuite/TestADeliveryRunsAsItsTasksOwnerServerSide(integration)Mutations and commands
Each mutant was applied, tested and restored in turn, and a test failed for every one:
CustomerFromaccepts an empty customer.IdentityFromis off, or always on. Each field ofIdentityis dropped, andServerSideis read from the caller.internal/apicalls another reader, or returns the zero value.withRequestIDandscheduledOwnerContextis swapped or emptied.Two mutants needed more than the first run: an empty organization in the middleware is caught by
TestAccountSuite, and a false server side mark inscheduledOwnerContextis caught only by the new test.gofmt -lnamesdispatch_channel_test.goandsession_create_unit_test.go, as it does on the base.The whole integration run is not done here.
🤖 Generated with Claude Code