7Per-worktree uv environments — moved to :mod:`oc_orchestrator.worktree_env`.
11Plan 270 P4. This module's code now lives in the standalone
12``oc_orchestrator`` package; this file keeps ``oc_chat.core.worktree_env``
13working for every importer that has always spelled it that way, and it
14carries the one piece of wiring oc_chat owns here: the ``oct`` timing
17It is a REBINDING, not a wrapper: the last statement replaces this
18module's entry in :data:`sys.modules` with the moved module itself, so
19``oc_chat.core.worktree_env`` and ``oc_orchestrator.worktree_env`` are
20one object. That is what keeps every private name reachable, every
21``monkeypatch`` effective across the seam, and every ``isinstance``
22true — a wrapper that merely re-exported public names would break all
25The oct timing hook (plan 270 P4)
26---------------------------------
27The moved module treats ``oct`` as absent by default, which is what
28takes the toolchain out of the dispatcher package's import graph. oc_chat
29HAS ``oct``, so importing this path registers the live hook and the
30engine timing ledger fills exactly as it did before the split. The
31import is a STATEMENT rather than an ``importlib.import_module`` call:
32the plan-245 timing witness hides ``oct`` by patching
33``builtins.__import__``, which ``import_module`` bypasses.
37- Register :func:`_oct_hook` as the moved module's default hook.
38- Bind the moved module to this path.
45 L3 - semantic details (an unknown hook target)
46 L4 - deep tracing (the rebinding)
50- Registering the hook is IDEMPOTENT and global to the process: the
51 moved module holds one default and the last registration wins. Only
52 this module and a test ever register one.
53- The hook never catches: each call site keeps its own failure policy,
54 and the timing edge's own ``except ImportError`` is what degrades a
55 missing ``oct`` to a null context.
56- Retirement rule (plan 270 P8): this path stays until an explicit
57 retirement plan retargets its importers. New code names
58 ``oc_orchestrator.worktree_env`` directly — and registers its own
59 hook if it wants timings.
63- oc_diagnostics (structured debug logging via _dbg)
64- oc_orchestrator.worktree_env (the moved module this path binds)
65- oct.timing.ledger (lazy; timed_stage, optional - resolved through the hook this module installs)
68from __future__
import annotations
73from oc_diagnostics
import _dbg
75from oc_orchestrator
import worktree_env
as _moved
79 """Resolve one member of ``oct`` for the moved module.
81 Byte-for-byte the pre-270 ``_default_oct_hook``, minus the
82 ``"package"`` target that plan 270 P1 retired when the venv repair
83 file moved into ``oc_diagnostics``. Nothing is caught here.
86 if target ==
"timed_stage":
87 from oct.timing.ledger
import timed_stage
90 _dbg(
"OC_CHAT.MAIN", func, f
"VALIDATION_ERROR: unknown target {target!r}", 3)
91 raise _moved.WorktreeEnvError(f
"unknown oct hook target {target!r}")
94_moved.use_oct_hook(_oct_hook)
96_dbg(
"OC_CHAT.MAIN",
"module",
"worktree_env shim -> oc_orchestrator.worktree_env", 4)
98sys.modules[__name__] = _moved
Any _oct_hook(str target)