Repository navigation
fix(engine): wire engineToken and normalize apiUrl in headless store context (#544) - #668
Merged
Mihir-Rabari merged 1 commit intoOct 19, 2026
Conversation
…context (Mihir-Rabari#544) In headless action execution (used by MCP ap_run_action), createContextStore dropped engineToken, leading to 401s when accessing store entries. Additionally, normalize apiUrl in buildUrl and engineFileApi so endpoints without a trailing slash do not produce malformed URLs or crash with TypeError: Invalid URL.
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
CodeAnt PR Risk: Low Risk
Assessed commit: |
Mihir-Rabari
approved these changes
Oct 19, 2026
Mihir-Rabari
left a comment
Owner
There was a problem hiding this comment.
Review TL;DR — ✅ APPROVE
Reviewed head: e542b66
First review of this PR — no prior feedback to carry over.
✅ Strengths
- Wires
engineToken: params.engineTokeninto the headlesscreateContextStorecall (piece-helper.ts:237) — exactly the #544 root cause: the store client buildsAuthorization: Bearer ${engineToken}(store.ts:45/79/113) and the headless path never passed one. The oldflowVersionId: 'headless'arg is gone, matching the current{ apiUrl, prefix, flowId, engineToken }signature (store.ts:7) — verified live at this head. - Trailing-slash normalization in
buildUrl(store.ts:151-152) and bothengineFileApiupload/download URLs (engine-file-api.ts:21-22, 76-77) — kills theTypeError: Invalid URLclass from slash-lessinternalApiUrlvalues without disturbing callers that already pass a trailing slash. - Audits the sibling factory like the issue asked: the files path gets the same normalization, so store + files both survive
http://localhost:3100/api-style config.
Tests (mandate check)
- Two real-behavior regression tests (piece-helper.test.ts:77-135): one asserts
store.getcarriesAuthorization: Bearer secret-engine-tokenAND constructshttp://localhost:3100/api/v1/store-entries?key=flow_headless%2Fdemo-keyfrom a slash-lessinternalApiUrl; the other assertsfiles.writebuilds a normalized/api/v1/files/...URL from a slash-less base. Both drive the actual fetch mock throughpieceHelper.executeTool— exactly the "explicit internalApiUrl assertion" regression test #544 requested. Green in Checks (unit); full matrix green at this head.
buildUrlstill throwsTypeErrorifinternalApiUrlarrives genuinelyundefinedfrom the MCP dispatch path (the.endsWithread throws beforenew URL). A small guard with a descriptive error message would make that misconfiguration debuggable — worth a follow-up if the dispatch side ever regresses.
💡 Nits
- The
endsWith('/')ternary now appears 3× across store.ts/engine-file-api.ts — a tinyensureTrailingSlash()util would DRY it.
Prior feedback status: N/A — first review; no prior Mihir/codeant threads.
Acceptance criteria (#544)
- engineToken wired into headless store context → ✅
- No more malformed URLs for slash-less internalApiUrl (store + files) → ✅
- Sibling factories audited (files) → ✅
- Regression test with explicit internalApiUrl assertion → ✅
Clean fix, well-scoped, tested. Merging — thanks! 🎉
— Hermes Agent, reviewing on behalf of @Mihir-Rabari
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.
User description
Resolves #544
Summary of Changes
CodeAnt-AI Description
Fix headless action access to the store and files
What Changed
Impact
✅ Fewer unauthorized store requests✅ Successful file transfers with slash-less API URLs✅ Fewer malformed API requests💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.