Implementation plan: simplify config resolution / interpolation
Superseded status (2026-10-16): the user approved immediate pre-1.0 removal of automatic cache search, marker-based partial-stage resume and chained fanout. The candidate implements removal, not deprecated opt-in compatibility. Historical inventories below explain prior decisions; use current migration notes and workflow guidelines for supported calls.
Goal: replace the “three binding times hidden in one ${...} syntax” design with
explicit, single-purpose mechanisms, so the InterpolationKeyError bug class and
the freeze.py grammar parser largely disappear.
Target semantics after this plan:
Binding time |
Mechanism |
Replaces |
|---|---|---|
submit-time |
eager OmegaConf resolution (everything by default) |
freeze.py simple-ref chain following |
save_dir creation |
|
|
stage-start |
deferred resolvers: |
same resolvers, but ONE resolution point |
per-sweep-item |
merge override BEFORE resolution |
|
Phase 1 — save_dir_policy on the runner (kills ${vinc:}/${now:} in configs)
New API
proj.submit(cfg, save_dir_policy=None | "increment" | "timestamp")
# CLI: flexlock run ... --save-dir-policy increment
Implementation
New module
flexlock/save_dir.py:next_versioned_path(path, fmt="_{i:04d}") -> str— move the body ofvinc_resolver(resolvers.py:61) here as a plain function; the resolver becomes a thin deprecated wrapper around it.apply_save_dir_policy(cfg, policy) -> None— resolvescfg.save_dirto a concrete string exactly once:"increment":next_versioned_path(base), then claim atomically withmkdir(exist_ok=False)+ retry on collision. This fixes the documented vinc race (resolvers.py:73-77) at the right layer."timestamp":base / now.strftime(config.TIMESTAMP_FORMAT).None: resolve as-is (current behaviour).
Call sites:
api.py:577-590— replace the “resolve save_dir exactly once” try/except withapply_save_dir_policy(config, save_dir_policy).runner.py_prepare_node(runner.py:365) and_build_node_cfg(runner.py:298) — thread the CLI flag through; keep the timestamp fallback but route it through the same function.
Sweep interaction: the policy applies once to the sweep root; items keep getting
sweep_root/sweep_{i:04d}via the existingdir_suffixpath (api.py:1144-1150). Assert policy is not applied per-item.Deprecation:
vinc_resolver/now_resolveremit aDeprecationWarningpointing atsave_dir_policywhen fired. Keep them registered and working for one minor version.
Deletions unlocked (end of phase or Phase 5)
The vinc cache-draining hack
api.py:758-773(re-wrap afterto_container(resolve=True)).The
${vinc:}special-casing comment/path insnapshot.py:99.The
load_sweepquoting hack (utils.py:414) that string-protects resolver calls so vinc fires late.
Tests
apply_save_dir_policyunit tests: increment idempotency within one submit, atomic-claim collision retry, timestamp format.Regression: two concurrent submits with
"increment"on the same base get distinct dirs (the race vinc could not fix).Existing vinc tests stay green (deprecated path still works).
Phase 2 — one deferred-resolution point + rebuild freeze.py on OmegaConf
2a. Deferred stub context manager
New helper in resolvers.py:
@contextmanager
def deferred_stubbed():
"""Re-register run_lock/latest so they re-emit their own call string
with args already resolved by OmegaConf."""
# run_lock stub: lambda *args: "${run_lock:" + ",".join(map(str, args)) + "}"
Key fact this exploits: OmegaConf resolves nested interpolations in resolver
args before invoking the resolver. So resolving
${run_lock:${precompute_dir},key} under the stub yields the frozen string
${run_lock:/data/precomputed,key} — with zero string parsing on our side.
(Today’s _resolve_in_root bug would have been structurally impossible.)
Verify this arg-pre-resolution behaviour against the pinned omegaconf version in a dedicated test before building on it.
2b. Reimplement select_and_freeze_root_refs
New implementation (same signature, freeze.py):
Deep-copy the root config; enter
deferred_stubbed().OmegaConf.resolve(root_copy)— OmegaConf itself does all simple-ref, cross-tree, multi-hop, mixed-string, and relative-ref resolution, with correct grammar, while deferred calls collapse to frozen call strings.OmegaConf.select(root_copy, key)and return a detached copy.Error mapping: catch
InterpolationKeyError/InterpolationResolutionErrorand re-raise asUnresolvedInterpolationErrorwith the existing “set it via overrides=…” hint (freeze.py:240-244).
Delete: _freeze_walk, _resolve_in_root, _freeze_embedded_in_root,
_process_interps_in_string, _process_one_interp, _freeze_simple_ref,
and the balanced-brace scanner — the whole hand-rolled grammar.
Known behaviour changes to handle explicitly:
Relative refs
${.foo}: OmegaConf resolves them (correctly, since the tree is still attached). Today they are preserved verbatim. The only consumer of “preserve verbatim” is the sweep${.variable}placeholder — removed in Phase 3, so land 2b together with or after Phase 3. Any other intra-stage relative ref resolves to the same value either way.Type preservation: stub output is a string; real
run_lockreturns native types at stage start, unchanged.Missing keys inside deferred args resolve-fail early now (good — surface at submit, not on the worker).
2c. Single deferred-resolution point
New function resolve_deferred(cfg) -> DictConfig (freeze.py or resolvers.py):
to_container(resolve=True) with real resolvers + re-wrap. Called at exactly
two places:
worker.py:worker_loopright aftermerge_task_into_cfg(worker.py:122).api.py local single-run path, replacing the existing eager
to_container(resolve=True)at api.py:770.
Document: “run_lock/latest fire once, at stage start, on the worker.”
Tests
Port
tests/test_node_selection.py— assertions on frozen output stay identical (they describe the same contract); delete tests that pin internals of the old scanner.Keep all regression tests (cross-tree resolver args, multi-hop mixed strings,
${latest:}preservation, etc.) as black-box contract tests.
Phase 3 — sweeps: merge before resolution, serialize plain dicts
_submit_sweep(api.py:1137-1151): for each override, merge into the base config first, then run the Phase-2 freeze (eager resolve + deferred preserved) on the merged item. Item-injected keys (e.g.variable) exist before any resolution, so${.variable}-style placeholders and theirInterpolationKeyErrors disappear._validate_sweep_save_dirs: operate only on merged, resolved items — never touchbase_config.save_dir(the exact bug intest_submit_sweep_relative_save_dir_ref). The unresolved-base guard becomes dead code; remove it.Task DB payloads: store
to_container(resolve=False)of the merged item — now a plain dict of concrete values plus deferred call strings. Worker side:merge_task_into_cfgkeeps working unchanged;resolve_deferred(Phase 2c) completes the config.print_configsweep preview (api.py:596-602) uses the same merged items, so preview == execution.
Tests
Existing sweep regression tests must pass unchanged (they test observable behaviour).
New: sweep item referencing an injected key via a normal ref (
${variable}) — the pattern that replaces${.variable}; document the migration in the changelog.
Phase 4 — preflight check (side-effect-free full resolution)
Project.check(config=None, sweep=None, ...)+flexlock run --check: run the full Phase-2/3 pipeline underdeferred_stubbed(), including per-sweep-item merges, and report every resolution error with itsfull_key— without touching the filesystem (possible because vinc’smkdirside effect is gone from resolution).Wire
print_config=Truethrough the same code path so preview can never diverge from submit.
Phase 5 — deprecation & cleanup
Remove (after one deprecation minor):
${vinc:}/${now:}resolvers (keepnext_versioned_pathhelper).api.py:577-590 resolve-once block, api.py:758-773 cache-drain block.
snapshot.py vinc special case; utils.py
load_sweepquoting hack.
Docs: rewrite the interpolation section around the binding-times table at the top of this file; add a migration guide (
${vinc:...}→save_dir_policy="increment",${.variable}→${variable}).
Sequencing & effort
Phase |
Depends on |
Risk |
Est. |
|---|---|---|---|
1 |
— |
low |
0.5–1 day |
2a |
— |
low (one omegaconf-behaviour test gates it) |
0.5 day |
2b |
2a, 3 (relative-ref removal) |
medium |
1–2 days |
2c |
2a |
low |
0.5 day |
3 |
— |
medium |
1 day |
4 |
2, 3 |
low |
0.5 day |
5 |
all |
low |
0.5 day |
Recommended landing order: 1 → 2a → 2c → 3 → 2b → 4 → 5. Each step keeps the full suite green; 2b (the freeze.py rewrite) goes last among the functional phases because it needs the sweep-placeholder pattern gone first.
Risks / open questions
OmegaConf arg pre-resolution (2a’s foundation): verified by a pinned test; if a future omegaconf changes this, the test fails loudly.
Fingerprint stability: configs frozen by the new path may differ textually from the old path (e.g. relative refs now resolved), changing
smart_runfingerprints once → one-time cache miss for existing runs. Call this out in the changelog.${latest:}: kept as a deferred read-only resolver alongsiderun_lock. If it turns out unused in practice, fold it into Phase 5 removals instead.Backward compat window: old configs with
${vinc:}keep working until Phase 5; CI should run the example projects under both styles during the window.