Repository navigation
FIX-1551: the CLI runs as the app's own principal - #2170
Conversation
fsdev run and fsdev chat stop answering "who is this caller" themselves.
They ask the loaded app through the same resolution every inbound host
uses (per-flow resolver before the host's, the user fallback, the
organization rules), so a terminal run lands in the organization the
app's HTTP routes would give it.
engine (S1):
- createPrincipalResolution: the host's resolution, extracted so the
in-process entry and every inbound host call the same code.
- resolveInProcessPrincipal + FlowState.resolveInProcessPrincipal: the
terminal's question (source "cli", no request, caller-named user),
returning { userId, orgId, from }.
- source "cli" is reserved: a module-private WeakSet marks the contexts
the in-process entry builds; the resolution refuses "cli" on any other
context, whatever source the adapter declared.
fsdev (S2-S5):
- one identity step shared by run and chat; --org on run/chat, --user on
run; refusal stops before any write, exits 2, names the flow and --org.
- run: an existing --session/--seed-session is checked for flow, org and
user before the seed is written; the seed and the run use one identity.
- --capture records command.principal; one stderr line names the org.
- chat asks per turn; a refused turn fails and the loop continues;
/status shows the organization.
- the hard-coded placeholder organizations and cli-user literals are gone.
S6: goals/cli-principal/runs-in-the-apps-organization (VG, needs
FIX-1500 PR-B). S7: changeset (minor engine + fsdev), package READMEs,
inbound-transports architecture note, and the apps/docs operations in
DOCS.md, published from its draft (docs-writer/docs-editor not yet run).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_08e221df-abbd-4f75-a0e7-72dec9f7f1e6) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b75c1ed4cb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ipal (FIX-1551)
Review round 1:
- A seat pinned to an owner refuses a terminal identity outside its pin
in the shared identity step (run and chat), by the engine's own
pinRejectsCaller over registry.pinOf, before any session, request or
seed is written. Exit 2, like the other identity refusals.
- checkSessionOwner takes the record the caller already read, and gives
a pre-organization (unattributed) session the engine's
UnattributedOrgError message instead of "organization (none)" (BP-030).
- The stderr line names --user as the user's source; `from` is
documented as the organization's source (values unchanged).
- The in-process context is frozen (context, envelope, metadata, body)
before it is marked.
- The no-caller fence covers engine/src/transports (minus host/ and the
barrel) and the mcp, scheduled, node, next, vercel, bullmq and
voice-openai sources.
- Engine exports pinRejectsCaller, InstancePinCaller, isOrgAttributed
and UnattributedOrgError so the CLI reuses the rules.
Codex round 1:
- P1: metadata.body now carries { userId, input }, the shape of an HTTP
action body, so a resolver reading body.input answers the terminal as
it answers HTTP. V3 gains a body-reading flow.
- P2: the changeset is one sentence naming FIX-1551, with the -s exit
code change.
- P2: inbound-transports.md says `cli` is a principal-resolution source
only and is not recorded on requests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
Brings in FIX-1500 PR-B (#2159) so VG can run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
…DME: mara hires from the CLI VG passed on c21ca3b with intent/chat -> vercel/anthropic/claude-sonnet-5. The control (the CLI's ask replaced with the old placeholder answer) failed as expected on the principal and the roster row. PR-B landed first, so the mara paragraph is reconciled here per DOCS.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
…ding (FIX-1551) --org: run in this organization and skip the app's resolver. --user: the organization comes from the app's resolver unless --org is also given; the default user is the resolver's, or cli-user with no resolver or with --org. Drops the "local only" and "still decides the organization" phrasing the docs editorial pass removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
…chen-sink tokens (FIX-1563) #2184 (FIX-1552) merged catalog cases written against the pre-#2159 acme/bravo constants, which #2159 removed, so main fails kitchen-sink typecheck. The operator's leg now lists with the kitchen-sink admin token; the other-org leg uses the token whose entry was refused at boot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
…-sink org (FIX-1563) The test landed with `acme:tok-acme` as its admin credential. The app now refuses any token that does not name `kitchen-sink`, so the admin flow ran without its resolver and both admin-seat cases failed on main. The test now boots the app's real `fsdev.config.ts`, as named-org.test.ts does: the real host resolver, registrar and admin flow, with the token bound to `kitchen-sink`. The in-app hire goes through mara's own `hire` tool rather than a hand-built registration. Both config-booting files get a 30s test timeout. A cold import of the app takes about 4.8s alone, and two of them in parallel workers outran vitest's 5s default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
|
Typecheck & Test was red on
Those constants were removed by #2159. #2184 (FIX-1552) then merged catalog cases that still use them, so The fix from #2191 is ported onto this branch, head
Both cherry-picks become no-ops once #2191 merges. The same push aligns Validated at
Generated by Claude Code |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_61371b95-9149-4d66-98cb-02811acc295d) |
jhoffner
left a comment
There was a problem hiding this comment.
Architect call — #2170 (FIX-1551 impl)
Verdict: wait (code direction looks right; docs pass still owed per PR.)
CLI identity through the app’s resolver (HTTP parity), reserved in-process source: "cli" (WeakSet mark; adapters refused), pin/session checks before any write, exit 2 on refusal — matches approved #2158. Engine exports reused rather than copied.
Hold merge until the apps/docs editorial pass lands (or is explicitly waived by the owner). After that: merge-ready from Architect’s seat.
Not owner approval / not the merge gate.
— FSD Architect
|
The apps/docs editorial pass has landed. Generated by Claude Code |
The problem
fsdev runandfsdev chatnever asked the app who a caller is. They always ran ascli-userin the framework's placeholder organization, whatever the app's own resolver said. So a terminal run wrote records the app's users could never read. Nothing organization-shaped, such as mara hiring a seat intokitchen-sink, could be verified from the terminal.What this does
The CLI now asks the loaded app the same question its HTTP routes ask, through the same code:
devuserinkitchen-sink, and mara's hire from the terminal now lands there (VG, run for real below).cli-userin the placeholder organization. That behaviour is unchanged.--org(onrunandchat) and--user(onrun) let a developer name the identity locally.serveanddevdon't get these flags.source: "cli"is reserved. Only the engine's in-process entry point can produce it, and a transport adapter that stamps it is refused.What's asked of you
Nothing new. D1, the reserved-
clilock-in, and the F1 and F2 answers were approved on #2158.Still owed before merge: a docs-writer and docs-editor pass on the four apps/docs pages. They are DOCS.md's approved draft, published close to verbatim, and this PR leaves
apps/docs/**alone from here on.Parts worth reviewing closely
packages/engine/src/transports/host/createInboundTransportHost.ts).WeakSet(inProcessAsks) holds the marked contexts. OnlyresolveInProcessPrincipaladds to it, after freezing the context, its envelope, its metadata and its body.createPrincipalResolutionrefusessource: "cli"on any unmarked context, before any resolver runs.metadata.bodyhas the HTTP action body's shape,{ userId, input }, so a resolver that reads the body sees the same thing both ways (Codex P1).packages/cli/src/principal.tsandpackages/cli/src/commands/run.ts). The identity step, whichrunandchatshare, applies the engine's ownpinRejectsCallertoregistry.pinOf(flow). Then the session check runs on the record already read. It usesisOrgAttributed/UnattributedOrgError, then flow, org and user. Only after both does the seed get written.pinRejectsCaller,InstancePinCaller,isOrgAttributedandUnattributedOrgErrorso the CLI reuses the rules rather than copying them. These are new exports; nothing was moved.-snow exits 2, where beforerunActionrefused it with exit 1.packages/cli/src/chat/loop.ts): flow guard → identity (resolver, flags, pin) → owner check (rotates the session on a mismatch) → turn.Checks (red / green)
cli-principal.integration.test.tsV1:command.principal=dev/acme-dev/resolver, the stored seeded session isacme-dev, the app router'sGET sessions/v1returns 200, there is one[fsdev] running asstderr line, stdout is all JSON. BR-2: discovery givescli-user/__fsd_default_org__/development-default. Real kitchen-sink after PR-B, model-free:KITCHEN_SINK_TEST_MODE=1 STORE_TYPE=filesystem pnpm fsdev run chat-agent run -i '{"message":"hi","mode":"ask"}' -s fix1551-v1 --capture …exits 0 with[fsdev] running as devuser in organization kitchen-sink (from the app's resolver), and.fsdev/data/sessions/fix1551-v1.jsonhasdevuser/kitchen-sinkorigin/main'srun.ts:expected 'ok cli-user@__fsd_default_org__' to be 'ok dev@acme-dev'run-commandandchattest passes. Only change:chat-turn.integration.test.tspasses the new requiredorgIdtoexecuteTurn(7 call fixtures, no assertions changed)POST /<flow>/actions/respondfor a credential-less caller.bodyorgnames its org frombody.input.message, givingok body-user@org-hiboth waysadmin: expected 'ok cli-user@__fsd_default_org__' to be 'refused: Action request requires non-…'. Planted body withoutinput(the Codex P1 case):expected 'refused: Action request requires non-…' to be 'ok body-user@org-hi'adminrun with-sand--seed-sessionleaves no session and no request records, exits 2, and names the flow and--orgexpected { id: 'v4', flowKind: 'admin', … } to be undefined--org(a credential flow runs asalice@acme),--orgalone givesfrom: flag, blank / whitespace / placeholder--orgare refused with nothing written,--useralone givesbob@acme-dev,--useralone onadminis refused, and a flag-org session is invisible to the app router while the app's own org is readableexpected 200 not to be 200-son a placeholder-org session,--seed-sessionon a same-org/different-user session, and--seed-sessionon another org's session: each refused, owner named, record byte-for-byte unchanged"tampered":truefsdev chat: theadminturn fails naming--org, theechoturn succeeds asdev@acme-dev,/statusshowsOrg: acme-dev, piped exit is 1.--orgnames every turn's org. An invalid--orgis refused at startupserve/devreject--organd--userascommander.unknownOption, andrun/chataccept them under the same parse. Widened fence: no file underengine/src/routes,engine/src/transports(minushost/and the re-exporting barrel), or the mcp, scheduled, node, next, vercel, bullmq and voice-openai sources referencesresolveInProcessPrincipal. Every root is asserted to have been scanned. FIX-1442 body-org tests and the node bind-guard tests pass untouched--orgonserve:expected { ok: true, options: { org: 'x' } } to deeply equal { ok: false, … }. A reference planted inpackages/mcp/src, then inengine/src/transports/http:expected [ Array(1) ] to deeply equal []both timescustom-wsthat resolves asource: "cli"context through the shared host is refused, and so is a spread copy of a real in-process context. The same app's in-process ask still getslocal-dev@acmeexpected 'ok {"userId":"local-dev","orgId":"acm…' to match /^refused: source "cli" is reserved…/acme-dev.desk, pinned todev@acme-dev.fsdev runwith--user alice, and again with--org acme --user dev: refused with exit 2, and the store holds no session, no request, no seed. The owner runs.fsdev chat --user alice: the turn fails and writes nothingexpected { id: 'pin-run', …(11) } to be undefined(session and seed written), and chat printedChatting with acme-dev.desk …with no refusalorgId, with-sand--seed-session: refused with the engine'sUnattributedOrgErrortext ("stored before an organization was required … persistence guide"), and the record is byte-for-byte unchangedexpected 'Session "legacy" belongs to user dev …' to contain 'stored before an organization was req…'--usersource (review 1)run echo --user bob: stderr says[fsdev] running as bob (named by --user) in organization acme-dev (from the app's resolver), and the capture'sfromisresolver(the organization's source, as documented onCliPrincipalSource)--usernot named":expected [ Array(1) ] to deeply equal [ Array(1) ]envelope.flowKindthrowsTypeErrorexpected [ false, true, true, true ] to deeply equal [ true, true, true, true ]pnpm tsx goals/cli-principal/runs-in-the-apps-organization/run.mtson a fresh.fsdev/data. See belowVG, run for real (after merging #2159)
Model: kitchen-sink's
intent/chat→vercel/anthropic/claude-sonnet-5, throughAI_GATEWAY_API_KEY, withFSDEV_DEFAULT_MODELandFSDEV_INTENT_*unset.Control, with the CLI's ask replaced by the old placeholder answer (same command):
The first VG attempt refused to start. That was the
.fsdev/datamy earlier pre-PR-B V1 run had written, and PR-B refuses such a store by design ("Delete the store and restart"). I deleted it and re-ran. Both verdicts are in the goal's verdict log.Suites run (merged tree
c21ca3ba2; headc7088ab71only adds the goal verdict log and the kitchen-sink README)packages/engine,pnpm test: 212 files, 2703 passed, 4 skippedpackages/cli,pnpm test: 22 files, 273 passed@flow-state-dev/kitchen-sink,pnpm test: 21 files, 152 passed.pnpm install, timed out one test at vitest's 5s default:named-org.test.ts› "binds the assistant's flow, a seat and a channel to kitchen-sink".@flow-state-dev/node,pnpm test: 5 files, 46 passed (bind guard)pnpm typecheck: 70/70 tasks, plus the boundary, updater-purity, side-chain and control-shape guardspnpm lint: 24/24pnpm knip:ci: exit 0origin/mainhas moved since the merge at5f48575c0and hasn't been re-merged. The new commits are:Of these, FIX-1543's approved spec ("one owner-pin gate for hired seats") may later want to move the CLI's pin check onto the gate it defines. Today the CLI calls the engine's existing
pinRejectsCaller.Not verified here
#who-a-run-is. That work follows this PR's push.main, becausecreateFlowStateand the router still default todefaultBodyUserIdPrincipalResolver, so nothing needed reconciling. Whichever lands second must keep BR-2: a flow on the framework default answers the CLI withdevelopment-default.lib/workforce-admin-auth.ts,lib/workforce-registrar.ts, a test, the README) and docs, and no engine code. The CLI calls the host's own resolution, so its answer still matches HTTP.Contract
specs/issues/FIX-1551/PLAN.md. S1's shape:FlowState.resolveInProcessPrincipal(question)andresolveInProcessPrincipal({ registry, resolvePrincipal? }, question)→{ userId, orgId, from: "resolver" | "development-default" }.--org/--user,source: "cli",command.principal { userId, orgId, from }withfrom∈resolver | flag | development-default(the organization's source).minorfor@flow-state-dev/engineand@flow-state-dev/fsdev, one sentence naming FIX-1551.Links: FIX-1551 · epic FIX-1455 · spec #2158 · VG dependency #2159 (merged)
🤖 Generated with Claude Code
https://claude.ai/code/session_01ANuyMVi3YS653fcghb9gtB
Note
Medium Risk
Changes authentication and org boundaries for all CLI runs and touches shared inbound principal resolution; mistakes could write data under the wrong org or weaken the reserved
clisource guard.Overview
fsdev runandfsdev chatnow resolve identity through the app, not a fixedcli-userin the development org. The engine addsFlowState.resolveInProcessPrincipal/resolveInProcessPrincipal, sharing the inbound host’s principal-resolution path withsource: "cli"reserved (only in-process entry; transports that fake it are refused before resolvers run).The CLI wires
run,chat, and sharedprincipalhelpers: ask the app per invocation or per chat turn, honor--org/--user, enforce seat pins and session ownership before any write, exit 2 on identity refusal (including mismatched--session), log[fsdev] running as …, and recordcommand.principalin--capture. Chat/statusshows org; wrong-owner sessions rotate instead of running.Exports used by the CLI:
pinRejectsCaller,isOrgAttributed,UnattributedOrgError. Docs, kitchen-sink tests/README, a VG goal, and broad integration tests document and lock the HTTP-parity behavior.Reviewed by Cursor Bugbot for commit c556bc9. Configure here.