DR-122: Room keywords are chosen against their priority-3 cost, and projections import the router
DR-122 — Room keywords are chosen against their priority-3 cost
Section titled “DR-122 — Room keywords are chosen against their priority-3 cost”Context
Section titled “Context”detect_room routes a file through four tiers. P0/P1 match directory parts,
P2 matches the filename against a room name only, and P3 scores
content.count() of every room’s keywords + [name] over the first 2,000
characters. P3 fires before the general fallback, cannot be disabled, and
breaks ties by declaration order (miner.py:616-629).
DR-113 hashes the room into the drawer id. So a file routed at P3 changes room whenever its opening 2,000 characters drift — and the next incremental mine leaves its old drawers orphaned while filing a duplicate set at the new id. Every P3-routed file is a latent orphan-plus-duplicate.
This is not hypothetical. The S527 config, with the nine S521 review changes
applied and nothing more, routed 413 of 2,934 files (14.1%) at P3. A margin
analysis put 52% of those at noise or coin-flip level: app/page.tsx filed
under procurement on a 2-vs-2 tie broken by declaration order;
tsconfig.ci.json under workflow at 1-vs-1.
Decision
Section titled “Decision”A room’s keywords are selected against their P3 cost, not only their P0
reach. Where a bare keyword is also ordinary prose, replace it with a compound
that still reaches the same directory at P0 while scoring ~0 at P3 —
supabase-migrations for supabase + migrations, governance-review for
review + governance, provenance-register for provenance.
The technique is bounded by M3, which must be modelled or it silently
misfires: _name_matches is a == b or b in _tokens(a) or a in _tokens(b), so
a compound reaches only directory parts equal to one of its tokens.
Compound-vs-compound never matches unless byte-identical, even when the token
sets are equal — cocoindex-pipeline does not match the directory
cocoindex_pipeline. A compound keyword can therefore only be substituted for a
bare one when the target directory is single-token.
And the projection that proves any of this must IMPORT the real detect_room
and scan_project, not re-implement them. This amends DR-116, which requires
re-implementation from source. Re-implementation was the right correction to the
S521 draft — which modelled the router as exact path equality and shipped 18/18
passing assertions against a fiction — but it is strictly weaker than importing,
and it leaves the same class of error available. Any tier attribution written for
explanation must be asserted equal to the imported router’s verdict on every
file, so the explanation is as trustworthy as the routing.
Alternatives considered
Section titled “Alternatives considered”- Accept P3 routing as semantically useful. A file mentioning “procurement” twenty times plausibly is procurement. Rejected: correctness is not the problem, stability is. The drawer id moves with the content.
- Drive P3 to zero. Not reachable. The residue is driven by room names that
are also ordinary prose, and those names are ratified vocabulary
(
procurement,intelligence) or structurally forced — by M3, only the bare tokentestsreaches the__tests__/directory, so that room must carry its magnet. The floor was measured at 5.7%. - Keep re-implementation (DR-116 as written). Rejected on evidence from this
session: the author’s own first draft used
cocoindex-flow, which cannot reachcocoindex_pipeline, and silently lost 95 files. The imported-router projection caught it before execution; a re-implementation encoding the same misunderstanding would not have.
Consequences
Section titled “Consequences”- Measured effect on the canonical code corpus: P3 fell from 14.1% to 5.7% of
files, and
db-schemafrom 121 substring-routed files to zero. All 11 room counts then matched the projection exactly — 2,934 projected, 2,934 filed. - Every future rooms config, including the docs-site one, is authored against a
keyword’s P3 cost.
~/.mempalace/tools/dir-vocab.pyanswers “what would this candidate actually capture?” against the real tree before a keyword is added;~/.mempalace/tools/project-rooms.pyis the imported-router projector. - A config change whose P3 share rises is a regression even when its P0 routing is correct.
- Full record and the measured before/after:
reports/s527-rooms-execution.md.