Skip to content

refactor: de-duplicate exported type names within each package - #4757

Merged
thymikee merged 2 commits into
mainfrom
t3/q6-no-duplicate-exported-type-names
Nov 19, 2026
Merged

thymikee merged 2 commits into
mainfrom
t3/q6-no-duplicate-exported-type-names

Conversation

@thymikee

@thymikee thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Behavior: 11 same-name exported type collisions existed within single packages; each internal declaration is renamed, never the public one. BEFORE: packages/contracts exported PointTarget/RefTarget/SelectorTarget/ElementTarget/InteractionTarget from both client-target.ts (public) and interaction.ts (internal, fan-in 50), plus one collision each in command-runtime, daemon, platform-apple, and three in maestro. AFTER: the internal sets get distinct names (contracts: Interaction*-prefixed target types; the other six similarly suffixed); all importers updated. client-target.ts and the public subpath surface are untouched (R83 snapshot unchanged).

Reason: one name must mean one type inside a package, so an importer can no longer silently pick the wrong same-named type.

38 files touched (35 rename + 3 gate); gross diff 726 lines (<1,000), rename-only modulo import re-wrapping.

Impact. SIZE: rename-only in packages; net +476 lines is the R87 rule + test in the gates commit. PERF: none (type-only). COLLOCATION: one name = one concept per package, now enforced by R87.

Validation

Tested SHA: 14da66c8d6 (head). pnpm check:affected --run --head 14da66c8d6 passed format, lint, typecheck, layering, fallow, build, package, integration-node, vitest-related and other gates (exit=0), then hit this sandbox's 300s command cap during the full unit suite, so CI's serialized gate validates the pushed head per docs/agents/testing.md. No local exactCommit receipt; unresolved risk.

Local evidence at head: check:layering OK incl. R87 (10/10 rule tests); R87 reports the 11 collisions at merge-base e766e8890f, zero at head. Unit shards pass: contracts+command-runtime 1457 tests, daemon 4549, maestro+platform-apple 2256 (+2 load flakes passing in isolation). depgraph:test, lint, typecheck, check:production-exports, check:package green; format applied. Blast radius: depgraph affected packages/contracts/src/interaction.ts = fan-in 50, all type-only. CI runs the full gate; device/native lanes out of scope per task.

11 same-name exported type collisions existed within single packages.
The big one: packages/contracts exported PointTarget/RefTarget/
SelectorTarget/ElementTarget/InteractionTarget from both client-target.ts
(public, never-exclusive client props) and interaction.ts (internal,
kind-discriminated), with 45 importers split between them. Rename the
internal sets, never the public ones:

- contracts/interaction.ts: InteractionSelectorTarget,
  InteractionRefTarget, InteractionElementTarget, InteractionPointTarget,
  InteractionRequestTarget (client-target.ts untouched)
- command-runtime: selector-wait.ts SelectorWaitSnapshotOptions
- daemon: session-open-execution.ts OpenRuntimeHintClearOperation
- maestro: MaestroRuntimePlatform, MaestroSnapshotTargetQuery,
  MaestroInputTargetResolution
- platform-apple: adapter.ts SimulatorBridgeSnapshotSource

Rename-only; importers updated. One name now means one type inside a
package, so an importer can no longer silently pick the wrong same-named
type.
New zero-baseline rule: no two modules of one package may export the
same name in the type namespace. Re-exports resolve transitively, so a
barrel re-exporting one declaration is the same symbol, and aliases
across package boundaries stay legal at layer seams. Registered in
LAYERING_RULE_IDS/LAYERING_RULES (the object-key trick makes a missing
rule a type error) with a unit test beside the rule module. Verified to
report exactly the 11 collisions fixed in the previous commit at
origin/main and zero at this head.
@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.41 MB 6.41 MB -2.9 kB
Package (unpacked) 6.41 MB 6.41 MB -2.9 kB
Package (download) 1.95 MB 1.95 MB -983 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.6 ms 45.1 ms +17.5 ms
CLI --help 62.0 ms 76.0 ms +14.0 ms

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 14da66c

Warning

The isolation lease for this review ended before the review finished (an artifact of the staging environment). There is a chance that some of its findings are unverified, or that something was missed. Comment @apex-sentinel-staging review to run it again.

2 finding(s): 2 minor.

🟡 Minor (2)

Where Finding
scripts/layering/unique-exported-type-names.ts:176 R87 star-export path keeps origin-keyed composite keys as export names for downstream consumers
scripts/layering/unique-exported-type-names.ts:219 R87 treats every non-packages/ path as one "src (root package)"

Reviewed with this repository's own Sentinel configuration (7b6500cd2da2).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 14da66c. The verdict and the full list are in the summary comment.

Comment on lines +176 to +186
for (const [name, nameOrigins] of origins) {
const site = sites.get(name)!;
if (nameOrigins.size === 1) {
out.set(name, site);
} else {
// A star-star conflict keeps several origins on one name; report each origin once.
// Identifiers cannot contain '@', so the composite key is unambiguous.
for (const origin of nameOrigins) out.set(`${name}@${origin}`, { ...site, origin });
}
}
return out;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · R87 star-export path keeps origin-keyed composite keys as export names for downstream consumers

one.ts declares Opts, two.ts declares Opts, star.ts does export * from './one.ts'; export * from './two.ts', and barrel.ts does export type { Opts } from './star.ts' — star.ts exports Opts@one.ts and Opts@two.ts as names, the barrel's typeExportOf lookup of plain Opts misses and records origin=star.ts as its single origin, yielding zero violations for a genuine intra-package collision. The composite-key encoding at line 183 is decoded only in the final grouping loop (line 198), not by consumers of the returned map.

Suggested change

Return a structured per-name origin list from exportsOf instead of encoding multiple origins into the map key, or have typeExportOf/export-star consumers recognize the name@origin form and carry all origins forward. Add a test with a conflicted star module re-exported by a barrel in the same package.

Details

persona: senior-developer

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Comment on lines +219 to +223
});
}
}
}
return violations;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · R87 treats every non-packages/ path as one "src (root package)"

Two same-named exported types in different non-packages/ directories (e.g. one in scripts/, one in test/) are reported as a collision inside src (root package). packageOf maps every path not matching ^packages/([^/]+)/ to that single bucket, so all tooling-tree types share one namespace.

Suggested change

Decide and encode which directories form the root package for R87 (e.g. only src/, or each top-level folder separately) and cover the scripts//test/ case in the test file.

Details

persona: javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 14da66c is ready, CI is green (18 checks, none failing), and there are no conflicts. Nothing blocks merge.

Not blocking, and you can take or leave these: the JSDoc at unique-exported-type-names.ts:40 describes the inner exportsOf resolver, so it belongs on exportsOf, and the exported function needs its own one-line description. Also, check.ts:649 calls workspaceSpecifierTargets(repoRoot) again after main() and selector-pipeline-ownership already did, so computing it once in main() and reading it from LayeringContext would avoid re-reading the manifests.

Two open inline threads do not apply, so please resolve them. The first (#4757 (comment), barrel hides collision) does not hold: the loop at unique-exported-type-names.ts:193-203 runs exportsOf on every production source, so both collisions are grouped and reported at :208, and an ambiguous star re-export is already TS2308. The second (#4757 (comment), scripts/test bucket) does not hold: R87 only sees tracked production sources under src/** and packages/*/src/**, so the root-package bucket holds only src/.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee
thymikee merged commit c5528b3 into main Nov 19, 2026
18 checks passed
@thymikee
thymikee deleted the t3/q6-no-duplicate-exported-type-names branch November 19, 2026 15:10
thymikee added a commit that referenced this pull request Nov 19, 2026
…odes

Main defines R87 as unique-exported-type-names (#4757), so the
promise-race ratchet takes R88 in the rule, its test, the check.ts
comments and the success line. The count now parses each source with the
shared layering parser and counts Promise.race CallExpression nodes, so
comments, strings and spacing cannot move the count; the header's LOC
figures are corrected. Conflict with main in check.ts resolved keeping
both rules.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
thymikee added a commit that referenced this pull request Nov 20, 2026
…odes

Main defines R87 as unique-exported-type-names (#4757), so the
promise-race ratchet takes R88 in the rule, its test, the check.ts
comments and the success line. The count now parses each source with the
shared layering parser and counts Promise.race CallExpression nodes, so
comments, strings and spacing cannot move the count; the header's LOC
figures are corrected. Conflict with main in check.ts resolved keeping
both rules.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
thymikee added a commit that referenced this pull request Nov 20, 2026
…ace ratchet (#4766)

* feat(host-kit): add settleWithin deadline settle to the retry module

Adds settleWithin(work, timeoutMs) beside Deadline/sleep/pollUntilSettled and
exports it through the existing ./retry subpath. The typed outcome is
{ kind: 'settled', value } | { kind: 'deadline' }; the deadline timer is
cleared on every settle path, and the doc comment states it does not cancel
the work (a late rejection stays observed, a rejection that beats the
deadline propagates).

* refactor(daemon): settle deadline races through host-kit settleWithin

Removes the daemon-local settleWithinBudget and migrates every hand-rolled
deadline race in the daemon to settleWithin: closeDaemonServers and session
teardown in server-shutdown, the request drain and platform-owner/plugin
closes in daemon-runtime, the lease-release drain in provider-lease-expiry,
and the idle-expiry settle budget in daemon-session-idle-expiry (dropping its
bespoke budgetElapsedAfter timer). Races that are not deadlines (the abort
race in artifact-tracking, TTL/retry timers) are untouched.

* chore(gates): ratchet Promise.race counts per package (R87)

New layering rule promise-race-ratchet (R87): Promise.race( occurrences per
package over production sources must not grow past the merge-base with
origin/main, measured by the shared merge-base ratchet machinery. Deadline
races belong to settleWithin in @agent-device/host-kit/retry, which clears
its own timer on every settle path; non-deadline races are out of scope for
the count. Registered in LAYERING_RULES with a unit test.

* fix(host-kit): settleWithin keepAlive:false unrefs the deadline timer

A deadline awaited by a background sweep must not hold the event loop:
the removed budgetElapsedAfter() unref'd its timer on purpose. settleWithin
now takes { keepAlive: false } to unref the deadline timer, and
expireIdleSession passes it (a hung idle expiry could otherwise keep a
daemon with closed servers alive for up to the 46s teardown budget). The
default stays ref'd for shutdown callers, where an unref'd timer could let
the process exit mid-report. Host-kit test covers the unref'd case and the
ref'd default.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

* refactor(daemon): drop dead abort controller and shutdown locals

retryPending() takes no signal, so the AbortController in the lease drain
only cancelled the old sleep; pass retryPending directly. Awaiting
emitDaemonDiagnostic inside the owner-shutdown catch drops the
ownerFailed/ownerFailure locals.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

* chore(gates): renumber race ratchet to R88 and count CallExpression nodes

Main defines R87 as unique-exported-type-names (#4757), so the
promise-race ratchet takes R88 in the rule, its test, the check.ts
comments and the success line. The count now parses each source with the
shared layering parser and counts Promise.race CallExpression nodes, so
comments, strings and spacing cannot move the count; the header's LOC
figures are corrected. Conflict with main in check.ts resolved keeping
both rules.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

* fix(daemon): drain reports its result when a release fails inside the budget

settleWithin rejects a work rejection that arrives while the deadline
has not yet been reported, so a pending release failing inside the
drain window threw out of drain instead of returning its report. The
drain bounds shutdown; a failed release is a pending release, so the
report stands.

settleWithin's doc now states the spent-budget ordering explicitly: a
rejection after the deadline is swallowed, and a caller that must see
the work's own failure awaits the work.

---------

Co-authored-by: Mistral Vibe <vibe@mistral.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant