Repository navigation
refactor(core): resolve database and websearch config through Effect Config - #34846
Closed
kitlangton wants to merge 3 commits into
Closed
kitlangton wants to merge 3 commits into
kitlangton wants to merge 3 commits into
Conversation
Contributor
Author
|
Superseded by #34935 — this work belongs on the v2 branch, so both PRs were consolidated there. |
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.
First slice of moving core runtime config off import-time
process.envsnapshots and onto EffectConfig, with config ownership distributed to the services that consume it.ConfigProviderbecomes the single test seam.What changed
WebSearch (
packages/core/src/tool/websearch.ts)defaultConfigLayerdecodes oneConfig.all({...})when the layer is built, instead of readingprocess.envdirectly at module scope.truthyConfighelper (truthy's 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 the old behavior.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.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, so they now yieldconfiguredPathdirectly:opencode db/opencode db path(packages/opencode/src/cli/cmd/db.ts) and theresetDatabasetest fixture (packages/opencode/test/fixture/db.ts). This removes the last 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. Now every consumer resolves through the same Config read.Tests
packages/core/test/database-path.test.tsexercisesconfiguredPaththroughConfigProvider.fromUnknown(explicit:memory:, absolute, relative, channel-default cases) and proves the layer seam: the preload setsOPENCODE_DB=":memory:"in the environment, and the test shows a provider override wins at layer build.tool-websearch.test.tsgains decoding tests driven entirely byConfigProvider.fromUnknown— including regression cases for the lenient grammar (TRUEenables,bananadisables, invalid provider ignored).sdk-next/test/embedded.test.tspreviously mutatedFlag.OPENCODE_DBper test and relied on dynamic import ordering. That was already broken ondevlocally: the path baked at first import, test 1 deleted its directory infinally, and the remaining 3 tests failed withSQLITE_CANTOPEN. Since the defaultConfigProvider.fromEnv()snapshots the process environment on first use, placement is process-wide; the file now points all embedded hosts at one shared temp database up front and cleans it inafterAll. All 4 tests pass now (previously 1/4 locally).httpapi-exercise/environment.tsdrops the now-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 for these call sites and skipped: it shines when reusing an existing domain schema with strict failure semantics, but both call sites here need the lenient legacy grammar (and the provider field needs warn-and-ignore, whichConfig.optioncan't express since it only swallows missing data). Good candidates for it are future migrations likeOPENCODE_MODELS_URLasConfig.url.ConfigProvider(see follow-up PR) can differ.ConfigServicehelper (packages/opencode/src/effect/config-service.ts) but skipped it here: both call sites already have a natural home, and the helper's generated test layer wouldn't be used by the existing tests. Worth revisiting once more config-backed services exist in core (it could also unifyServerAuth.Configand V1RuntimeFlags).Verification
bun typecheckacross the workspace (29/29 packages)packages/coresuite: 1071 pass / 0 failpackages/sdk-nextsuite: 5 pass / 0 fail (embedded tests were 1/4 on clean dev locally)packages/opencodescript/httpapi-exercise.ts --mode coverage: 208 pass / 0 fail, plus focused V1 tests using theresetDatabasefixture