Skip to content

refactor(host-kit): move settleWithin to a dependency-free leaf module - #4816

Merged
thymikee merged 3 commits into
mainfrom
t3/settlewithin-leaf-module
Nov 20, 2026
Merged

thymikee merged 3 commits into
mainfrom
t3/settlewithin-leaf-module

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

settleWithin sat in retry.ts, so a caller wanting only the deadline race also evaluated the retry policy, the Deadline class, the diagnostics edge and the kernel error vocabulary. That is why #4788 reverted two migrations: the eager-closure budget went up.

settleWithin and SettleWithinOutcome now live in packages/host-kit/src/settle-within.ts, which imports nothing, published as @agent-device/host-kit/settle-within. Every production importer uses that subpath; host-kit/retry no longer exports them.

Newly migrated sites:

  • capture-kit/capture-fact-grace.ts, through a function-scoped await import. A static import fails the eager-closure budget (2 modules against 1 at the merge-base).
  • Both platform-apple/core/perf-xctrace.ts exit waits. They no longer leave the 45 s grace timer armed after xctrace exits; a fake-timer test proves it and fails when the migration is reverted.
  • waitForValidatorCompile in capture-kit/recording/video.ts, same timeout error as before.

provider-limrun has one such race but does not depend on host-kit, so it is untouched. No budget raised, no allowlist, no baseline regenerated. 23 files changed, 241 insertions(+), 201 deletions(-).

Validation

Tested at 79513fc064.

  • R88 Promise.race( total: 34 → 30.
  • pnpm build, check:quick, check:layering, check:fallow, check:package, check:production-exports: pass.
  • eager-closure-budgets.test.ts and the host-kit, capture-kit, platform-apple core, daemon, daemon-client and CLI tests: pass.
  • CI owns the full unit and device lanes.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.46 MB 6.46 MB +173 B
Package (unpacked) 6.46 MB 6.46 MB +173 B
Package (download) 1.97 MB 1.97 MB +119 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 26.3 ms 27.3 ms +1.0 ms
CLI --help 58.3 ms 53.8 ms -4.5 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at 1944ae2. CI is green and the review found no code problems. Live device evidence was not needed, because both migrated waits (xctrace stop and screenshot rotation grace) keep the same settle and rejection behavior and only clear their timer earlier.

Not blocking, take or leave:

  1. The re-export in retry.ts leaves two import paths for settleWithin. Moving the 11 production importers (and process-executable-path.ts) to @agent-device/host-kit/settle-within, deleting the re-export and dropping it from the R88 header would be cleaner.
  2. waitForValidatorCompile in video.ts still hand-rolls a single-deadline race and fits none of the "not migrated on purpose" classes in refactor: settle remaining single-deadline races through settleWithin #4788. It could use settleWithin and bring capture-kit R88 from 5 to 4.
  3. capture-fact-grace.ts uses a function-scoped dynamic import with a long comment. It could import the leaf statically like perf-xctrace.ts does, unless the eager-closure gate refuses it, in which case a one-line note naming the gate would do.

Not verified here: the eager-closure-budgets test and perf-xctrace.test.ts were not run against the old code, and the absolute R88 total of 31 was not reproduced; the per-package -3 change was checked with git grep. Which CI device lane exercises the screenshot rotation-grace dynamic import in the built bundle was not confirmed.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
thymikee and others added 3 commits November 20, 2026 16:05
The primitive sat in retry.ts, so a caller that wanted only the deadline
race also evaluated the retry policy, the deadline class, the
diagnostics edge and the kernel error vocabulary. That is why #4788
reverted the capture-kit grace wait and both perf-xctrace waits: the
eager-closure budget went up.

settleWithin and its outcome type now live in host-kit/settle-within,
which imports nothing. retry.ts re-exports them, so every importer of
host-kit/retry keeps working and its closure is unchanged.

Both migrated sites import the leaf. The capture-kit grace wait reaches
it through the first call, which keeps that facade's closure at one
module. The perf waits previously left the 45 s grace timer armed for
its whole budget after xctrace had exited; the primitive clears it on
every settle path. Behaviour is otherwise the same.
…d race guidance

R11's host-kit export-surface enumeration lists the new subpath, and
R88's guidance names the leaf as the deadline primitive's home.
…lidator compile wait through it

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Follow-up on the three optional notes at 79513fc064 (rebased onto current main):

  1. Applied. All production importers now import settleWithin from @agent-device/host-kit/settle-within; the re-export from host-kit/retry is deleted.
  2. Applied. waitForValidatorCompile in recording/video.ts settles through settleWithin and throws the same video_validator_compile_timeout error on the deadline. R88 total is now 30 (capture-kit 5 → 4).
  3. Not applied: the gate refuses it. A static import in capture-fact-grace.ts fails the eager-closure budget test (2 modules evaluated against 1 at the merge-base), so the function-scoped import stays.

Local: build, typecheck, eager-closure budgets, layering, fallow, production-exports, check:package, and the host-kit, capture-kit, platform-apple core, daemon and CLI tests pass.

@thymikee
thymikee force-pushed the t3/settlewithin-leaf-module branch from 1944ae2 to 79513fc Compare November 20, 2026 15:10
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 79513fc

Since the review of 1944ae2: 1 new · 0 still open · 0 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/host-kit/src/retry.ts:1 🆕 PR claims host-kit/retry keeps re-exporting settleWithin; the diff removes the export instead

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

💬 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: 1 new finding on 79513fc. The verdict and the full list are in the summary comment.

@@ -6,8 +6,6 @@ export {
openScope,

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 · PR claims host-kit/retry keeps re-exporting settleWithin; the diff removes the export instead

import { settleWithin } from '@agent-device/host-kit/retry' no longer resolves: src/retry.ts drops settleWithin and type SettleWithinOutcome from its re-export list, and internal/retry.ts deletes the definitions with no replacement re-export. The PR description claims the façade keeps its old surface, so any importer outside this branch silently breaks. The package-boundaries export list also keeps ./retry without noting the narrowed surface.

Suggested change

Either re-export settleWithin and SettleWithinOutcome from packages/host-kit/src/retry.ts (from ../settle-within.ts) so the façade keeps its old surface, or update the PR description and migration notes to record that @agent-device/host-kit/retry no longer exports them.

Details

persona: maintainability, javascript, 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, the body was stale. At 79513fc064 the re-export is deliberately removed (review note 1): every production importer now uses @agent-device/host-kit/settle-within. The PR body is updated to say so.

@thymikee
thymikee merged commit 5707dc2 into main Nov 20, 2026
26 of 27 checks passed
@thymikee
thymikee deleted the t3/settlewithin-leaf-module branch November 20, 2026 15:26
thymikee added a commit that referenced this pull request Nov 20, 2026
…nts-main

* origin/main:
  docs(commands): generate the keyboard, scroll, and clipboard API blocks (#4809)
  refactor(host-kit): move settleWithin to a dependency-free leaf module (#4816)
  fix(android): share the boot error shape and pin the offline boot-probe retry (#4812)
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