Repository navigation
refactor(core): resolve database and websearch config through Effect Config - #34935
Closed
kitlangton wants to merge 1 commit into
Closed
kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
This was referenced Jul 2, 2026
Contributor
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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.
Consolidates #34846 and #34920 onto
v2(they were mistakenly opened againstdev). Moves core runtime config off import-timeprocess.envsnapshots and onto EffectConfig, with config ownership distributed to the services that consume it, plus aConfigProviderseam for embedded hosts.ConfigProviderbecomes the single test seam.What changed
Database (
packages/core/src/database/database.ts)layerFromPath(path())evaluated on import, reading theFlagenv snapshot). There is now exactly one public placement value:Database.configuredPath, an Effect that resolvesOPENCODE_DB/OPENCODE_DISABLE_CHANNEL_DBthrough EffectConfig. The node layer isLayer.unwrap(Effect.map(configuredPath, layerFromPath)), built per runtime instead of per import.Database.path()is deleted rather than kept as a V1 compat shim. Its V1 consumers were already Effect-shaped and now yieldconfiguredPathdirectly:opencode db/opencode db pathand theresetDatabasetest fixture. This removes a real skew surface — previouslypath()read the live environment while the layer read the frozen first-use snapshot, so late env mutation could makeopencode db pathdisagree with the running app.Flag (
packages/core/src/flag/flag.ts)truthy(name)reads the environment at call time,truthyConfig(name)reads the same grammar through EffectConfigso layer builds can be steered by aConfigProvider.OPENCODE_DBis removed from theFlagsnapshot; database config now lives in the database module.WebSearch (
packages/core/src/tool/websearch.ts)defaultConfigLayerdecodes oneConfig.all({...})when the layer is built, instead of readingprocess.envat module scope.truthyConfig(case-insensitivetrue/1, missing or malformed →false). This layer builds at Location boot, where a strict-decode defect would surface as opaque session failures;OPENCODE_EXPERIMENTAL=TRUEkeeps meaning enabled. An invalidOPENCODE_WEBSEARCH_PROVIDERlogs a warning and is ignored, matching old behavior.Embedded host seam (
packages/sdk-next/src/opencode.ts)ConfigProvider.fromEnv()snapshots the process environment on first use, so runtime env mutation cannot steer later layer builds.OpenCode.create(options?)now accepts aconfigProvider, provided to both the application-node build and the embedded routes layer, so per-host config (like database placement) resolves against it.OpenCode.layerWith(options)mirrors it for the layer form.ConfigProvider.orElse(ConfigProvider.fromEnv())for env fallback.Tests
packages/core/test/database-path.test.ts: exercisesconfiguredPaththroughConfigProvider.fromUnknown(:memory:, absolute, relative, channel-default) and proves the layer seam — the preload pinsOPENCODE_DB=":memory:"in the environment, and a provider override wins at layer build.tool-websearch.test.ts: decoding tests driven entirely byConfigProvider.fromUnknown, including lenient-grammar regressions (TRUEenables,bananadisables, invalid provider ignored).sdk-next/test/embedded.test.ts:Flag.OPENCODE_DB = ":memory:"becomesprocess.env.OPENCODE_DB = ":memory:"(the Flag entry no longer exists; the env read happens at layer build, after module scope). New test proves a hostconfigProviderplaces the database at a per-host path while the process env says:memory:.httpapi-exercise/environment.ts: drops the redundantFlag.OPENCODE_DBmutation and documents the must-run-before-first-Config-read ordering contract.Design notes
RuntimeConfig/Flagservice: config values are inputs owned by their consuming services, read once at layer build.Flagshrinks by attrition as remaining keys migrate (OPENCODE_MODELS_*, OTLP, etc. are follow-ups).Config.booleanwould have turned 7 previously-tolerated env values (including uppercaseTRUE) into startup/Location-boot defects. Strictness may be worth revisiting per-variable, but as an explicit decision — not a side effect of the migration.Config.schema(...)was evaluated and skipped for these call sites: it fits when reusing a domain schema with strict failure semantics, but both call sites need the lenient legacy grammar, and the provider field needs warn-and-ignore, whichConfig.optioncan't express (it only swallows missing data). Future migrations likeOPENCODE_MODELS_URLare better candidates.ConfigProvidercan differ, which is the feature.ConfigServicehelper (packages/opencode/src/effect/config-service.ts) into core; skipped since both call sites have a natural home. Worth revisiting once more config-backed services exist in core (could also unifyServerAuth.Configand V1RuntimeFlags).Verification (against
v2)bun typecheckinpackages/core,packages/sdk-next,packages/opencodepackages/coresuite: 1101 pass; the 6 failures (watcher timeouts under full-suite load) reproduce identically on cleanorigin/v2locally and pass in isolationpackages/sdk-nextembedded suite: 5 pass / 0 fail (includes the new per-host placement test)packages/opencodescript/httpapi-exercise.ts --mode coverage: 209 pass / 0 fail (missing=15routes without scenarios is pre-existing onv2)