Repository navigation
feat(bin): add OpenRouter backend to typed dispatch resolution - #7524
Closed
siddhanthpranavrao wants to merge 3 commits into
Closed
siddhanthpranavrao wants to merge 3 commits into
siddhanthpranavrao wants to merge 3 commits into
Conversation
fm-dispatch-resolve.sh now accepts OPENROUTER_API_KEY as a second opt-in key. When TYPESAFE_API_KEY is absent from both the environment and .env, the resolver sends the same request body to OpenRouter's decisions endpoint with model typesafe/jev-1.13. TYPESAFE_API_KEY keeps winning when both keys are present. Secret handling is unchanged: only the selected key is kept, both source variables are unset before any child process, and the key reaches curl only as a header on a file descriptor. The model line now names the backend that answered. Bootstrap treats either key as activating typed resolver validation.
Contributor
Author
|
Closing: OpenRouter support for typed dispatch resolution landed in #7149 (FM_DISPATCH_PROVIDER=openrouter + FM_DISPATCH_MODEL), which covers this change. Verified live on our homes with typesafe/jev-1.13 through the decisions endpoint. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Let's create a very simple open router adapter and let's create a pull request in the actual GitHub repository. Let's make it very clean. Let's get it reviewed also. Let's test it out also to see if it's working. When opening a pull request, please open a pull request from my personal GitHub account, not from the company account.
Context: the typed dispatch resolver (bin/fm-dispatch-resolve.sh) only talks to TypeSafe's own API behind TYPESAFE_API_KEY. The captain has an OpenRouter account and no TypeSafe account. OpenRouter serves the same Jev model through a dedicated decisions endpoint, POST https://openrouter.ai/api/alpha/decisions, which was probed live from this Mac with the resolver's exact request body (model "typesafe/jev-1.13", state + one Choice question with instructions and criteria): it answered HTTP 200 in about 600 ms with the exact response shape the resolver already validates (answers.rule.choice, answers.rule.probabilities summing to 1, answers.rule.confidence, usage.input_tokens/output_tokens, plus extra fields id, provider, cost that must be tolerated). The chat/completions endpoint rejects the model ("decisions model ... use /api/alpha/decisions"). Cost per call is about two thousandths of a cent.
The pull request needs to be very cleanly open with proper descriptions and testing in place, so that the PR, when it's audited by Kun Chen, he has all the information and it is very, very properly built into his repository, not some patchy fix, a long term fix which anyone can use out there. Let's get reviewed, test it out thoroughly. The credentials are sitting in my aero-lens repository in the .env file. Use that, test it out, confirm the roles with me, so that the roles are set up properly, about how the routing is going to be done based on the model effort and the amount of quota left. And after that we will open the PR using my personal GitHub account and ping me the link.
What Changed
bin/fm-dispatch-resolve.shreadsOPENROUTER_API_KEYfrom the environment or$FM_HOME/.envthroughfmx_env_getwhen noTYPESAFE_API_KEYis present, and POSTs modeltypesafe/jev-1.13tohttps://openrouter.ai/api/alpha/decisionswith the unchanged request body and response validation. A TypeSafe key from either source always wins. Only the selected key is kept, it still reaches curl as a header on a file descriptor, and both key variables plus any caller-exportedAPI_KEY_PRIVATEare unset before child processes run. The output'smodel:line now carries abackend=<name>word.bin/fm-bootstrap.shtreats an OpenRouter key like a TypeSafe key: it activates resolver-field validation ofconfig/crew-dispatch.jsonand scrubs the key from child environments.tests/fm-dispatch-resolve.test.shadds a fake-curl case for endpoint selection, key precedence, secret handling, and an OpenRouter-shaped response with extra fields;tests/fm-bootstrap.test.shadds the.envand environment OpenRouter cases;docs/configuration.md,docs/verification/dispatch-resolve.md, the home-layout skill,bin/fm-env-lib.sh, andbin/fm-test-run.shcomments document the backend table, precedence, and live-run verification.Risk Assessment
✅ Low: Both prior fixes are verified in source (API_KEY_PRIVATE is unset at the top so a caller export cannot survive reassignment, and the backend is rendered as one model-line word via a jq --arg with the RESULT JSON field removed); the OpenRouter path reuses the identical request body, response validation, fd-3 bearer header, and precedence rules, with behavior-driven tests through the public argv/env interface and no live network, and docs match the code.
Testing
Ran the two targeted suites (tests/fm-dispatch-resolve.test.sh with the new OpenRouter selection, precedence and child-env cases, and tests/fm-bootstrap.test.sh for the OpenRouter-gated resolver-field validation); both pass. Then drove the real resolver in a disposable fm-lab FM_HOME against the live OpenRouter decisions endpoint with the aero-lens key and the shipped example rules: three briefs (typo, fresh-news, big refactor) each resolved to the expected rule with real quota-axi evidence, the .env key path worked, a bogus TYPESAFE_API_KEY in the environment correctly took precedence over the real OpenRouter .env key (typesafe 401 error outcome, OpenRouter never called), no keys produced the unchanged off line, and a bad OpenRouter key produced a 401 error outcome with exit 0. A curl shim on PATH proved the real network call carried no TYPESAFE/OPENROUTER/API_KEY_PRIVATE variables in its environment. The bootstrap gating scenario was not driven live; it rests on the test suite only. Evidence is one redacted transcript; the lab home was removed and the worktree is clean.
Evidence: Live OpenRouter resolver transcript (7 runs, curl shim logs, key redacted)
Evidence: OpenRouter-only clear resolution (trivial edit brief)
Evidence: Precedence: bogus TYPESAFE_API_KEY beats real OpenRouter .env key (curl shim argv)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 4 issues found → auto-fixed ✅
bin/fm-dispatch-resolve.sh:150- The opt-in gate now also reads OPENROUTER_API_KEY, but the off line still says only "TYPESAFE_API_KEY absent from the environment and $FM_HOME/.env". An OpenRouter-only operator whose .env line is misspelled or blank gets a message naming a key they were never told to set, which misleads the diagnosis. Remedy: name both keys in the message (e.g. "TYPESAFE_API_KEY and OPENROUTER_API_KEY absent ...") and update the matching sentence in the script header and docs/configuration.md if they quote it.bin/fm-dispatch-resolve.sh:141- The pre-existing code defends the secret copy withexport -n TYPESAFE_API_KEY_PRIVATEso an exported same-named variable in the caller's environment cannot carry the key into child processes. The new selected-key variable API_KEY_PRIVATE (assigned at lines 141/146 and sent to curl at line 350) has no such guard: if the calling environment happens to export API_KEY_PRIVATE (a generic name), bash keeps the export attribute on reassignment and the selected key is inherited by curl, jq, quota-axi and the never-send check children, contradicting the "absent from child environments" contract the docs now claim for the selected key. Remedy: add API_KEY_PRIVATE (and for hygiene BACKEND/MODEL/URL) to theexport -nline at line 85, orunset API_KEY_PRIVATEbefore the selection block.bin/fm-dispatch-resolve.sh:526- Simplification: the change adds a newbackend:field to the resolver's output line and the RESULT JSON (lines 488 and 526) plus matching test assertions. The stated intent asks for a very simple OpenRouter adapter; backend identification is already observable from the response'smodelvalue (jev-1.13.0vstypesafe/jev-1.13-...), so no intent requirement needs a second label. If the maintainer prefers a minimal diff, remove the field and its assertions; if the explicit label is wanted for operators, keep it as is. This is a product/output decision for the author.docs/configuration.md:1346- The section heading "## Typed dispatch resolution (.env TYPESAFE_API_KEY)" and the surrounding anchor text still name only the TypeSafe key while the body now documents two keys. Cosmetic, but Kun Chen reading the ToC will not see OpenRouter is supported. Suggest "(.env TYPESAFE_API_KEY or OPENROUTER_API_KEY)"; check that no other doc links depend on the exact heading anchor before renaming.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-dispatch-resolve.test.sh(all 24 cases pass, including the new OpenRouter selection/precedence/child-env case)bash tests/fm-bootstrap.test.sh(passes; OpenRouter .env and environment key gate resolver-field validation, no child inherits the key)Live:FM_HOME=<lab> OPENROUTER_API_KEY=<aero-lens key> bin/fm-dispatch-resolve.sh <brief> --project aero-lensfor a typo brief, a fresh-news brief and a multi-file refactor brief against docs/examples/crew-dispatch.json and the real quota-axiLive: OPENROUTER_API_KEY only in$FM_HOME/.env, withAPI_KEY_PRIVATE=stale-caller-exportexported in the caller env and a PATH curl shim logging env var presence before exec'ing /usr/bin/curlLive:TYPESAFE_API_KEY=ts-bogus-keyin env plus real OpenRouter key in .env (precedence; shim shows api.typesafe.ai called, OpenRouter not called)Live: no key anywhere (off line, empty stdout, exit 0)Live:OPENROUTER_API_KEY=sk-or-v1-bogus(http 401 error outcome, exit 0)grep -l <key> evidence/*returns zero files✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.