availability of experimental mixed mode in `new Miniflare()` or `unstable_startWorker`

With --x-mixed-mode available in wrangler dev, is there an experimental option in the constructor of config object for miniflare/startWorker? So that we get mixed mode when running workers programatically?
33 Replies
Hard@Work
Hard@Workโ€ข6mo ago
AFAICT you can pass it a mixedModeConnectionString, but you would have to generate it yourself
Victor
VictorOPโ€ข6mo ago
I was playing around with the generator for it which spat out a URL by passing in the .config from startWorker(), but trying to fetch() on it just returned HTTP 400 you must pass in a binding
Hard@Work
Hard@Workโ€ข6mo ago
What if you generate the URL, then pass it into Miniflare?
Walshy
Walshyโ€ข6mo ago
cc:@Dario who is working on this
Dario
Darioโ€ข6mo ago
Hey ๐Ÿ™‚ yeah you can absoluately start miniflare with the mixedModeConnectionString, you just need to run startMixedModeSession and then take the mixedModeConnectionString and plumb it to the Miniflare constructor it should be pretty straightforward, however I think we'll also need to have an API in startWorker to allow this ๐Ÿค” it might just be startWorker doing everything for you, or maybe startWorker accepting a mixedModeConnectionString both should be pretty easy to implement ๐Ÿค” ignore the above, I checked with the team and forgot one aspect of mixed mode ๐Ÿ˜… yeah it should already be possible ๐Ÿ™‚ yeah we'd only need a way to allow you to enable the experimental mixed mode there ๐Ÿค” I can get something ready for you today ๐Ÿ™‚
korinne
korinneโ€ข6mo ago
@Victor Can I ask your use-case for this? Super curious
Dario
Darioโ€ข6mo ago
@Victor @DemosJarco | Sushidata if you want you can give the prerelease in this PR a try ๐Ÿ™‚ https://github.com/cloudflare/workers-sdk/pull/9480
GitHub
add experimentalMixedMode dev option to unstable_startWorker by...
Fixes https://jira.cfdata.org/browse/DEVX-1958 This PR adds an experimentalMixedMode dev option to unstable_startWorker so that developers can programmatically start a mixed mode session using star...
Victor
VictorOPโ€ข6mo ago
Well there's 3 answers to that - immediate answer - get access cache & deployed do/d1 access in raw node.js (long running docker instance that can't be deployed to cf) - planned long term answer - Unify the gap between our non cf-infra and cf infra without needing to make a ton of proxy workers - future long term answer answer - had some calls with prospective customers that want on prem solutions and exploring potential options for seeing how much can be ran locally but with certain access to live services That's amazing. I'll try it out in a bit (after my meetings)
Dario
Darioโ€ข6mo ago
great! thanks! ๐Ÿ˜„ I've tested it and it should work nicely, please let me know if it doesn't so that I can address any issue you might encounter ๐Ÿ™‚
Victor
VictorOPโ€ข6mo ago
what token perms are needed for the one passed into dev.auth? nvm I'm dumb and forgot to recompile ts (and was wondering why it wasn't working
Victor
VictorOPโ€ข6mo ago
Can confirm it works too
No description
Dario
Darioโ€ข6mo ago
yay! ๐Ÿฅณ thanks for confirming that it works ๐Ÿ˜„ I need to add tests in my PR and then it should hopefully be ready to merge soon ๐Ÿ™‚ meaning that the change will be soon (hopefully tomorrow?) be in the next wrangler beta release ๐Ÿ™‚
Victor
VictorOPโ€ข6mo ago
One thing I did notice is doing patchConfig() with a new remote resource doesn't attach it Another bug I found: binding to a remote workflow which is defined in another worker binding "USER_WORKFLOW" refers to a service "core:user:worker-name", but no such service is defined
korinne
korinneโ€ข6mo ago
Woah that is a really interesting idea -- would you be down to chat about this sometime? I would love to document this. if you're up for it, you can find time on my calendar and we can chat: https://calendar.app.google/6p7MB5PyCLgHbXus5
Victor
VictorOPโ€ข6mo ago
Sure! I just put some time on your calendar for tomorrow
korinne
korinneโ€ข6mo ago
Perfect! Chat then ๐Ÿ™‚ Thanks so much!
Dario
Darioโ€ข6mo ago
thanks! acknowledged ๐Ÿ‘ workflows are currently not supported, we're working on it ๐Ÿ™‚
Victor
VictorOPโ€ข6mo ago
I thought it was supported...
currently the bindings included in this are: services, kv_namespaces, r2_buckets, d1_databases, queues and workflows
wrangler@4.16.0
GitHub
Release wrangler@4.16.0 ยท cloudflare/workers-sdk
Minor Changes #9288 3b8f7f1 Thanks @petebacondarwin! - allow --name and --env args on wrangler deploy Previously it was not possible to provide a Worker name as a command line argument at the sam...
korinne
korinneโ€ข6mo ago
@Victor would you actually be okay meeting next week, such as next tuesday? So sorry, something came up super last minute
Victor
VictorOPโ€ข6mo ago
Sure
Dario
Darioโ€ข6mo ago
oh... no sorry that's my bad, that changelog meant to convey that we've added the remote: true flag for the bindings (which I belive is in place) but not that they work in mixed mode, sorry for the confusion ๐Ÿ™‡
Dario
Darioโ€ข6mo ago
@Victor @DemosJarco | Sushidata I just tried using startWorker with patchConfig and that actually looks to work as intended for me I've run a js script that calls startWorker and patchConfig with a worker that simply logs responses from the bindings and everything does seem to work as it should (see the attached screenshots) Could you clarify what isn't working for you?
No description
No description
No description
flof.fly
flof.flyโ€ข3mo ago
Same
Victor
VictorOPโ€ข3mo ago
Workflows is not currently supported at this time with remote bindings (despite experimental_remote being present for it as part of the wrangler.json schema) -# Versions of wrangler since my last post stopped it from crashing on startWorker() but will still crash on invoking and binding function
flof.fly
flof.flyโ€ข3mo ago
DurableObjects in general are not, but is there a way to communicate with them via Worker binding? https://developers.cloudflare.com/workers/development-testing/#using-remote-resources-with-durable-objects-and-workflows if so, how?
// Talk to the deployed Worker that fronts the DO
"services": [
{
"binding": "TENANT_SERVICE",
"service": "my-worker-in-prod", // or "<worker-name>-<env>"
"experimental_remote": true // required for remote binding in local dev
}
],`
// Talk to the deployed Worker that fronts the DO
"services": [
{
"binding": "TENANT_SERVICE",
"service": "my-worker-in-prod", // or "<worker-name>-<env>"
"experimental_remote": true // required for remote binding in local dev
}
],`
const tenantService = c.env.TENANT_SERVICE;
// now how do I get to talk with the DO that worker has access to?
// I'd love:
const id = tenantService.env.MY_DO.idFromString(orgId);
const myDo = tenantService.env.MY_DO.get(id);
const tenantService = c.env.TENANT_SERVICE;
// now how do I get to talk with the DO that worker has access to?
// I'd love:
const id = tenantService.env.MY_DO.idFromString(orgId);
const myDo = tenantService.env.MY_DO.get(id);
I'm just trying to export data out of my SQLite DO
Victor
VictorOPโ€ข3mo ago
Directly/built-in cloudflare, there isn't. The only option would be to stand up a live deployed worker (put it behind ZT access or whatever other type of auth meets your needs) that is connected to it, and have it export the values
flof.fly
flof.flyโ€ข3mo ago
I see, and protect it with some admin APIKey oh wait what's ZT access
Victor
VictorOPโ€ข3mo ago
For DO SQL, I created my own variant of their D1 rest endpoint, (hono on a worker that has the DO binding) so I can run queries outside of DO binding anywhere
flof.fly
flof.flyโ€ข3mo ago
Wow! I'd love to see it!
Victor
VictorOPโ€ข3mo ago
Cloudflare Zero Trust https://developers.cloudflare.com/cloudflare-one/applications/configure-apps/self-hosted-public-app/ You can make a "self-hosted public application" and put the domain of the created worker and the endpoint of the application
flof.fly
flof.flyโ€ข3mo ago
Sounds super cool, i'm very new to it! But i'll try it out Thank you very much, would be amazing to see a sample repo with all of this to "chat with your DO SQLite"
Victor
VictorOPโ€ข3mo ago
Sorry, that code isn't open source and way too tightly intertwined to publish. But it's based on https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/query/, but: api endpoint: - instead of DATABASE_ID in the url, it's the doid 64 character hex worker: - internally it connects to the do via the hex id in the url and runs sqlExec() rpc function in the DO itself do: - sqlExec() that takes { sql, params } from the worker api json body and runs it (calling this.ctx.storage.sql.exec(sql, ...params) inside this.ctx.storage.transaction()) and then runs .toArray() on the result, which it just passes up the chain until it dumps it as json output. - Gets some metadata from the ouput like .rowsRead, .rowsWritten, etc) - Wrap in performance.now() to get timing metadata, but the value it gives sometimes isn't correct because of side channel timing mitigations (even though technically it should work because database works should count as I/O) ZT is good if you want to keep it to internal access (scripted apps, other parts of your infra). But if you want to expose it to external users, you might want to stick to api key, jwt, etc instead
flof.fly
flof.flyโ€ข3mo ago
I see thank you

Did you find this page helpful?