Skip to content

refactor(reasons): declare the R4 reasons in ReasonTable rows - #4934

Merged
thymikee merged 10 commits into
mainfrom
refactor/r4-cli-daemon-client-reasons
Nov 22, 2026
Merged

thymikee merged 10 commits into
mainfrom
refactor/r4-cli-daemon-client-reasons

Conversation

@thymikee

@thymikee thymikee commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Every R4-batch details.reason in the CLI src/ tree and packages/daemon-client now reads a ReasonTable row beside its classifier. Seven values these trees share with other batches wait for batch R7 (#4937): remote_instance_mismatch, daemon_retirement_unconfirmed, owner-unavailable, runtime-contract-invalid, app-device-scope, invalid_plugin, daemon-owner-unrecognized.

Tables land in the module that classifies the failure: the daemon-client lifecycle and config tables, a daemon transport table in contracts/daemon-http.ts (the wire vocabulary client, proxy and daemon all read), and per-owner tables for fill, logs, open, record, daemon lifecycle, remote connections, the host runtime, the platform runtime, and Limrun. REMOTE_DAEMON_UNAVAILABLE_REASON and DAEMON_CONTENDED_REASON stop being exports: the row is the one spelling.

Value

  • ReasonTable declarations in production sources: 40 -> 49
  • Rows on the generated Error reasons page: 116 -> 160
  • Page owners (sections): 22 -> 29
  • R89 reason literals for the 44 R4 values: all replaced by table reads; wire spellings unchanged

Before / after

// before
new AppError('COMMAND_FAILED', 'Invalid daemon response', { reason: 'daemon_response_invalid' });
// after
new AppError('COMMAND_FAILED', 'Invalid daemon response', {
  reason: DAEMON_TRANSPORT_REASONS.replyInvalid.reason,
});

Validation

Head 82249b2. Locally green: check:quick, generate:reasons, check:command-docs, test/wire-compat and check:daemon-wire-compat, check:layering (R89 shrinks), check:package, check:production-exports, check:doc-prose, the full src unit project. No independent reviewer ran: the brief disallowed subagents, so the diff was cold-read in one pass.

🤖 Generated with Claude Code

Every details.reason the CLI src tree and the daemon client publish now reads a
ReasonTable row beside the code that classifies the failure: the daemon-client
lifecycle, config, and transport tables, the fill, logs, open, record, daemon,
connection, host-runtime, platform-runtime, and Limrun tables, plus the limrun
runner and download tables.

No value's wire spelling moves, so the error reasons page gains rows and no
behavior changes. REMOTE_DAEMON_UNAVAILABLE_REASON and DAEMON_CONTENDED_REASON
are dropped as exports: the table is the one place each value is spelled.
The two client wire-compat consumers whose bodies now read a table row carry
their new digest and rationale in the ledger, as ADR 0006 asks of an additive
client-side change.
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.50 MB 6.50 MB +1.9 kB
Package (unpacked) 6.50 MB 6.50 MB +1.9 kB
Package (download) 1.98 MB 1.98 MB +540 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 17.8 ms 17.9 ms +0.1 ms
CLI --help 36.6 ms 37.8 ms +1.1 ms

@apex-sentinel-staging

This comment has been minimized.

Nothing imports it; the reasons collector also reads tables that are not exported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The code at e803b0b does not yet meet the R4 invariant, and all 21 checks pass. The earlier Repo Guards failure was the unused LIMRUN_RUNNER_REASONS export, and this commit removes it.

The finding from the earlier review is unchanged, because this commit only drops that one export. Several details.reason values in AppError still come from bare literals with no ReasonTable row: remote_instance_mismatch (daemon-client-transport.ts:866, also matched as a bare string at :542), daemon_retirement_unconfirmed (daemon-client-lifecycle.ts:383 and daemon-lifecycle-errors.ts:140), app-device-scope (platform-runtime-open-target.ts:35), invalid_plugin (provider-plugin-policy.ts:35), and owner-unavailable and runtime-contract-invalid (platform-runtime-gateway.ts:387, :394), in the file whose table at :44 covers only shutDown. daemon-lifecycle-errors.ts:233 also publishes the bare daemon-contracts constant DAEMON_RECORD_OWNER_UNRECOGNIZED_REASON.

This matters because these routes still publish reasons that are missing from the generated Error reasons page, while the PR body says the batch is complete. The affected routes are a remote daemon instance change, a daemon replacement that cannot be confirmed, a macOS app-device open with a non-app surface, an invalid WebDriver plugin, a missing runtime owner, a runtime contract violation, and an unreadable daemon-record owner.

The rule is: every reason property inside an AppError construction in src/ and packages/daemon-client resolves to a TABLE.row.reason read. Please use R89 filtered to those two trees as the list of sites, not the list above. Add the rows to the owning tables: DAEMON_TRANSPORT_REASONS or DAEMON_UNAVAILABLE_REASONS for the instance mismatch and the retirement, the existing gateway table for the two runtime reasons, and new open and plugins tables, plus a row for the daemon-contracts constant. Some of these values are also spelled in packages outside those trees (daemon, proxy, plugins, platform-apple, capture-kit). If those are meant for a later batch, please say so in the PR body and the issue, and name that batch.

Not verified here: generate:reasons, R89 and the Fallow audit were not run, the 40 to 49 ReasonTable declaration count and the list of 44 R4 values were not recomputed, and the wire-compat ledger digests were not recomputed. The leftover-literal search was a grep for reason: '...', so a reason passed through a variable or a cross-file identifier could hide more sites.

Before merge, the remaining AppError reasons need rows, or the PR body and the issue need to name the batch that will cover them.

@thymikee

Copy link
Copy Markdown
Member Author

R89 filtered to src/ and packages/daemon-client at e803b0b finds exactly seven untyped sites, all values the reason inventory assigns to batch R7 because other batches' packages also raise them: remote_instance_mismatch (daemon-client-transport.ts:866, plus the bare match at :542), daemon_retirement_unconfirmed (daemon-client-lifecycle.ts:383, daemon-lifecycle-errors.ts:140), owner-unavailable and runtime-contract-invalid (platform-runtime-gateway.ts:387, :394), app-device-scope (platform-runtime-open-target.ts:35), invalid_plugin (provider-plugin-policy.ts:35), plus DAEMON_RECORD_OWNER_UNRECOGNIZED_REASON (daemon-lifecycle-errors.ts:233). Declaring them here would put each value's row in this PR while its other producers stay in other packages, which is what R7 groups. The PR body now says so, and #4937 tracks R7 with these sites listed.

@thymikee

Copy link
Copy Markdown
Member Author

The deferral settles the remaining item at e803b0b: the PR body now names the seven shared values and assigns them to batch R7, and #4937 lists those sites, which is the alternative the review offered. The R4 code changes look complete for this batch, and all 21 checks pass.

…n-client-reasons

* origin/main:
  docs(commands): generate blocks for every public command and halve hand-written prose (#4919)
  fix(depgraph): budget the blast-radius query, not the whole-tree scan (#4920)
  refactor: remove dead exports and stale fallow exemptions (#4931)
  refactor(reasons): declare the R6a reasons in ReasonTable rows (#4938)

# Conflicts:
#	website/docs/docs/error-reasons.md
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier review at e803b0b found no problems. Review of 41d20b8 now finds two issues that need fixing before merge.

Five Limrun runner reasons are declared in the R4 rows, but production does not publish them from those rows. For example, when a USE_IP lookup returns an invalid IPv4 value, prepareLimrunRunnerProducts passes the literal limrun_runner_products_invalid. limrunRunnerError publishes that argument unchanged. Missing bind addresses, upload failures, occupied XCTest slots and failed launches take the same path with their own literals. The wire spellings stay the same, but the generated docs read the table while production uses spellings owned by the callers. Every reason published through limrunRunnerError should come from its LIMRUN_RUNNER_REASONS row. Please make limrunRunnerError take a key of that table, read LIMRUN_RUNNER_REASONS[key].reason when it builds the error, and replace the callers' literals with row keys. Use the same keys for DEFAULT_HINTS.

The claim "Each in-scope R4 reason is emitted through its owning ReasonTable row while retaining its published spelling" does not hold at 41d20b8 for those five reasons. The existing R89 scan skips function parameters, so it cannot see this. The changed remote-health test at daemon-client-lifecycle-remote-health.test.ts:84 expects the same remote_daemon_unavailable spelling as the base version, so it cannot tell the migration from the old code. After the fix above, please either add a case that fails when a runner reason bypasses its row, or narrow the claim.

Could limrun-ios-runner-errors.ts own both the wire spelling and the default hint for each runner failure, by having limrunRunnerError accept a row key and resolve both inside the module?

CI is green: 21 checks, 0 not passing. Not verified here: the generator was not re-run locally, so the consistency of error-reasons.md rests on the diff comparison and the passing generated-block check in CI. No other change is needed before merge.

… by key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

At 555c63e: limrunRunnerError now takes a LIMRUN_RUNNER_REASONS row key. It reads that row's reason and its default hint inside limrun-ios-runner-errors.ts, so that module owns both. DEFAULT_HINTS is keyed by row. The 16 caller literals in limrun-ios-runner-products.ts and limrun-ios-runner.ts are row keys now. New test in limrun-ios-runner-errors.test.ts: passing a published spelling instead of a key fails the typecheck (@ts-expect-error) and throws at runtime, so a reason cannot bypass its row. Local runs: root tsc --noEmit passes and the test file passes 6/6.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

One docs problem remains at 555c63e, and the code change itself is otherwise fine. The earlier findings from 41d20b8 are fixed.

The new error reference promises that daemon_response_invalid carries the received data in details.line (error-reasons.md:276). A daemon HTTP reply with a JSON body of {} reaches the invalid-result branch in daemon-client-rpc.ts:44-49, and that branch emits the reason with no line. Running the handler from the base and head blobs showed both return only requestId and reason in details for this input. The base page made no such promise, so the regression is in the new documentation. A caller who follows the page cannot read the received body for a malformed RPC envelope that parses as JSON. The row summary in daemon-http.ts:148 should state that details.line is optional. Please regenerate the error reasons page after that change.

Not verified here: tsc and the test file were not run locally; the author's report and CI were relied on. CI is green, with 21 checks and none failing. The PR has merge conflicts with main, so it needs a rebase before merge. No other merge blocker is open.

thymikee and others added 2 commits November 22, 2026 10:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-client-reasons

* origin/main:
  refactor(reasons): declare the platform-android reasons in ReasonTable rows (#4928)

# Conflicts:
#	website/docs/docs/error-reasons.md
@thymikee

Copy link
Copy Markdown
Member Author

At 91ccbb8: the daemon_response_invalid summary now says details.line carries what arrived when present, which covers the empty-result HTTP path in daemon-client-rpc.ts that sends no line. Main is merged in. The only conflict was the generated page, which is regenerated on top of main. I merged rather than rebased because the branch already has a merge commit from main. Local runs: pnpm typecheck passes, and the reason-table guard passes 5/5.

@apex-sentinel-staging

This comment has been minimized.

@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 91ccbb8. The verdict and the full list are in the summary comment.

…t is raised

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

…n-client-reasons

* origin/main:
  refactor(reasons): declare the R5 provider reasons in ReasonTable rows (#4932)

# Conflicts:
#	website/docs/docs/error-reasons.md
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The restore reason from the earlier review (#4934 (comment)) is fixed at 47f41cc: it now has its own ReasonTable<'close'> at https://github.com/callstack/agent-device/blob/47f41cc/src/platform-runtime-android-application-tools.ts#L28-L34 and the page lists it under close. One finding remains.

The new CONNECTION_DEVICE_CONFLICT row in https://github.com/callstack/agent-device/blob/47f41cc/website/docs/docs/error-reasons.md#L540 promises details.keys, but that field is absent on reachable conflicts. Opening against a live proxy lease for SIM-REMOTE with a matching device spec and --udid SIM-OTHER reaches leasedIdentityConflict in https://github.com/callstack/agent-device/blob/47f41cc/src/cli/commands/proxy-lease-device.ts#L252. It emits the reason with requestedDevice and deviceKey, without keys. The device selector mismatch at line 321 does the same. Only the spec comparison at line 240 supplies keys. The identity classifier from both revisions was run in memory and the field is absent in both. A caller following the reference can wait for a field that never arrives and misread a device mismatch as a device-spec mismatch. Please describe both spec and device conflicts in the source row at https://github.com/callstack/agent-device/blob/47f41cc/src/cli/commands/proxy-lease-device.ts#L47, state that details.keys is present only for device-spec mismatches, and regenerate the error reference. The existing proxy-lease-device-spec.test.ts:588 already follows the live lease route.

Could daemon-client own DAEMON_TRANSPORT_REASONS in a package-local transport error module? Every production reference to the table or its six spellings outside the declaration is in daemon-client, including its request, timeout and fallback classifiers. The daemon HTTP contracts already own the shared request size and protocol vocabulary, while these markers describe local client failures.

The code has the one finding above. All 21 checks are green. There are no conflicts. Not verified here: pnpm typecheck and the reason-table guard were not run locally, so CI is the evidence for them, and the merge commit's conflict resolution was not diffed line by line beyond its delta contents. Nothing else blocks merge once the finding is fixed.

thymikee and others added 2 commits November 22, 2026 11:06
…nection device conflicts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

At 8eab9f0:

  • The CONNECTION_DEVICE_CONFLICT row now covers both a connection bound to another device and a lease from another device spec. It says details.keys is present only for the device-spec mismatch. The row key is renamed from deviceSpec to device to match, and the page is regenerated.
  • Simplicity question: adopted. DAEMON_TRANSPORT_REASONS moved from contracts/daemon-http.ts into a new daemon-client/src/daemon-client-transport-reasons.ts. Every production reader is in daemon-client, and contracts no longer imports ReasonTable there.
  • Local runs: pnpm typecheck passes; the reason-table guard and the daemon-client transport and dispatch-disclosure tests pass 35/35; check:daemon-wire-compat exits 0 (protocol unchanged); oxlint is clean.
  • An empty x.tmp slipped into the first of these two commits. The second removes it.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 8eab9f0

Since the review of 47f41cc: 0 new · 0 still open · 0 no longer raised

No open findings.

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

💬 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.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 8eab9f0 looks good, and the earlier findings from #4934 (comment) are fixed. The details.keys wording is corrected in proxy-lease-device.ts and the page row, and moving the reasons to daemon-client answers the ownership question. CI is green: 21 checks, 0 not passing. Not verified here: pnpm typecheck and the generator were not run locally, so CI is the evidence. No conflicts are known, and nothing else is needed before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 22, 2026
@thymikee
thymikee merged commit db869f3 into main Nov 22, 2026
21 checks passed
@thymikee
thymikee deleted the refactor/r4-cli-daemon-client-reasons branch November 22, 2026 11:15
thymikee added a commit that referenced this pull request Nov 22, 2026
* origin/main:
  feat(contracts): allow third-party snapshot producers (#4905)
  refactor(reasons): declare the R3 apple-runner reasons in ReasonTable rows (#4922)
  refactor(reasons): declare the R4 reasons in ReasonTable rows (#4934)
  refactor(snapshot): one shared model for occluding system surfaces (#4956)

# Conflicts:
#	website/docs/docs/error-reasons.md
thymikee added a commit that referenced this pull request Nov 22, 2026
* origin/main:
  feat(contracts): allow third-party snapshot producers (#4905)
  refactor(reasons): declare the R3 apple-runner reasons in ReasonTable rows (#4922)
  refactor(reasons): declare the R4 reasons in ReasonTable rows (#4934)
  refactor(snapshot): one shared model for occluding system surfaces (#4956)

# Conflicts:
#	test/repo-guards/runner-refusal-reason-docs.test.ts
#	website/docs/docs/error-reasons.md
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