Skip to content

fix(limits): report details.limit for KernelModuleProvider refusals - #14306

Merged
N0zoM1z0 merged 7 commits into
morluto:mainfrom
Plastic-time:rrfz/fix-elf-kernel-budget-limits
Nov 28, 2026
Merged

N0zoM1z0 merged 7 commits into
morluto:mainfrom
Plastic-time:rrfz/fix-elf-kernel-budget-limits

Conversation

@Plastic-time

@Plastic-time Plastic-time commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #14234.

Attach structured details.limit metadata to caller-adjustable budget refusals in KernelModuleProvider (inspect_kernel_module: max_file_bytes and max_entries).

This PR originally covered four providers under src/native/elf/. While this PR awaited review, #14631 (1badb6a8a) landed details.limit (and fixed_ceiling for unwind symbol-name text) on main for ElfDependenciesProvider, ElfUnwindRangesProvider, and KernelBuildConfigProvider. After merging main, this PR is narrowed to the remaining KernelModuleProvider fix, its tests, and its rows in docs/reference/limits-and-recovery.md and docs/reference/rea-limit-inventory.md. No separate sub-issue was opened because #14234 already tracks this migration.

Problem and expected behavior

Before this change, when a caller hit max_file_bytes or max_entries in inspect_kernel_module (for example --max-file-bytes 64 or --max-entries 1), KernelModuleProvider returned AnalysisResourceConstraintError with only hand-written remediationAction prose naming raw field names (max_file_bytes / max_entries) and omitted details.limit.

Callers and adapters could not read the controlling parameter name, effective value, unit, schema bounds (minimum, maximum, default_value), applies_at: "next_call", or the CLI adapter's projected cli_flag (--max-file-bytes, --max-entries) without parsing prose.

Expected behavior: max_file_bytes and max_entries refusals in KernelModuleProvider attach limit: elfReadBudgetLimit(KERNEL_MODULE_READ_BUDGETS, ...) backed by the same domain bounds that inspectKernelModuleInputSchema enforces, and drop the hand-written remediationAction so CLI and MCP adapters render adapter-aware recovery text (--max-file-bytes / --max-entries on CLI, max_file_bytes / max_entries on MCP). Existing max_structure_bytes and memory fixed-allowance refusals keep their current behavior unchanged.

Change and scope

  • Single-owner budget definition (src/domain/native/kernelModule.ts): Exported KERNEL_MODULE_READ_BUDGETS: ElfReadBudgets reusing MINIMUM_ELF_READ_FILE_BYTES and DEFAULT_ELF_READ_FILE_BYTES, and wired inspectKernelModuleInputSchema's max_file_bytes and max_entries .min()/.max()/.default() from it.
  • Provider failure projection (src/native/elf/KernelModuleProvider.ts): Attached limit: elfReadBudgetLimit(KERNEL_MODULE_READ_BUDGETS, ...) for file-size (max_file_bytes, forwarding safe-integer failure.observedBytes as required_value) and capacity (max_entries) ArtifactReaderFailure("limit") refusals, and removed the superseded hand-written inputBudgetRemediation helper.
  • Reference docs: Added inspect_kernel_module to docs/reference/limits-and-recovery.md and added its max_file_bytes and max_entries rows to docs/reference/rea-limit-inventory.md.
  • Tests:
    • tests/boundary/filesystem/kernelModule.test.ts: Asserts projected details.limit (including required_value for max_file_bytes: 64) and max_entries: 1 (and verifies max_entries: 16 succeeds).
    • tests/acceptance/kernelModuleCli.test.ts: Asserts public CLI --json refusal payloads for --max-file-bytes 64 (including required_value and at least <bytes>) and --max-entries 1, checking details.limit (including cli_flag), adapter-rendered CLI flag guidance in remediation.action, and successful recovery after raising both flags.
    • tests/boundary/mcp/kernelModuleMcp.test.ts: Asserts public MCP refusal payloads for max_file_bytes: 64 (with required_value) and max_entries: 1, confirming no cli_flag leakage and contract field names in remediation.action, followed by successful recovery on the same connection.
  • Out of scope: ElfDependenciesProvider, ElfUnwindRangesProvider, and KernelBuildConfigProvider (already migrated on main via fix(native)!: report details.limit for remaining native reader budgets and make BEAM table rows adjustable #14631 / 1badb6a8a), and remaining non-kernel-module files in scripts/verify/untyped-budget-refusal-baseline.json tracked under [Bug] Refusals of adjustable per-call budgets name their control only in prose, without details.limit #14234.

Follow the contribution scope.
Not applicable: this is an ordinary error-metadata fix within existing read-only offline kernel-module inspection boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/native/kernelModule.ts owns KERNEL_MODULE_READ_BUDGETS; both inspectKernelModuleInputSchema and KernelModuleProvider read bounds from that single constant. Downstream error projection (projectAnalysisError) and CLI/MCP adapters consume details.limit directly.
  • Contribution scope fit and linked maintainer decision: Not applicable (existing offline kernel-module inspection tool; part of [Bug] Refusals of adjustable per-call budgets name their control only in prose, without details.limit #14234).
  • CLI and MCP/tool-catalog contract: Additive details.limit (and structured details.refusal) on resource_constraint payloads for inspect_kernel_module when max_file_bytes or max_entries is exceeded. Input schemas and numeric bounds are unchanged. CLI output automatically includes details.limit.cli_flag and renders --max-file-bytes / --max-entries in remediation.action.
  • Provider, bridge, target-format, or platform compatibility: Portable offline Node.js provider only; no native bridge or external provider changes.
  • Evidence, artifact, provenance, or reconstruction contract: Existing reported_limits, partial_observation (file-snapshot-hash), and max_structure_bytes / memory fixed-allowance fields remain preserved.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): Read-only bounded artifact reads via withStableArtifactHandle; unchanged lifecycle and cleanup.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: No schema descriptions, bounds, or catalog entries changed; verified via npm run build:cached and npm run docs:check.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/filesystem/kernelModule.test.ts: asserts details.limit for max_file_bytes: 64 (including required_value) and max_entries: 1 (and verifies max_entries: 16 succeeds).
    • tests/acceptance/kernelModuleCli.test.ts: runs rea inspect-kernel-module <path> --max-file-bytes 64 --json and --max-entries 1 --json through the public CLI, asserts details.limit (with cli_flag and required_value) and CLI flag guidance in remediation.action, and verifies recovery after raising both budgets.
    • tests/boundary/mcp/kernelModuleMcp.test.ts: runs inspect_kernel_module through MCP with max_file_bytes: 64 and max_entries: 1, asserts details.limit (with required_value and no cli_flag) and field-name guidance in remediation.action, and verifies recovery on the same connection.
  • Base reproduction (executed on clean origin/main 55c7eaa06 with only the 3 updated test files applied and no production fix):
    • npx vitest run tests/boundary/filesystem/kernelModule.test.ts -t "names max_structure_bytes|retains trailer fields|reads module metadata|returns typed resource and cancellation failures" — 1 failed | 3 passed | 1 skipped (5): returns typed resource and cancellation failures failed because projectAnalysisError(tooSmall.error).details omitted limit (the 1 skipped test is the pre-existing unprivileged Windows symlink EPERM test).
    • npm run test:focused -- tests/acceptance/kernelModuleCli.test.ts tests/boundary/mcp/kernelModuleMcp.test.ts — 2 failed | 6 passed (8):
      • tests/acceptance/kernelModuleCli.test.ts (reports structured details.limit and CLI flags for max-file-bytes and max-entries refusals) failed because details.limit was absent and remediation.action emitted the legacy hand-written string ("Raise max_file_bytes above 64 bytes or select a smaller artifact; the limit is the caller-selected input read budget.") without --max-file-bytes.
      • tests/boundary/mcp/kernelModuleMcp.test.ts (reports structured details.limit without CLI flags for max_file_bytes and max_entries refusals and recovers) failed because fileRefusal.details.limit was undefined.
  • User-visible CLI output observed from rea inspect-kernel-module <path> --max-file-bytes 64 --json (958-byte fixture):
{
  "category": "resource_constraint",
  "code": "resource_constraint",
  "message": "Selected artifact exceeds 64 bytes: <path>",
  "retryable": false,
  "remediation": {
    "action": "inspect_kernel_module reached its max_file_bytes budget of 64 bytes. Pass a larger --max-file-bytes on the next rea inspect-kernel-module run (at least 958 bytes; range 64..536870912 bytes), then retry."
  },
  "details": {
    "operation": "inspect_kernel_module",
    "resource": "file-size",
    "reason": "Selected artifact exceeds 64 bytes: <path>",
    "reported_limits": {
      "max_file_bytes": 64,
      "max_entries": 8192
    },
    "limit": {
      "control_kind": "parameter",
      "parameter": "max_file_bytes",
      "effective_value": 64,
      "unit": "bytes",
      "minimum": 64,
      "maximum": 536870912,
      "default_value": 67108864,
      "applies_at": "next_call",
      "required_value": 958,
      "cli_flag": "--max-file-bytes"
    },
    "refusal": {
      "kind": "adjustable_budget",
      "operation": "inspect_kernel_module",
      "control": "max_file_bytes",
      "effective_value": 64,
      "unit": "bytes",
      "default_value": 67108864,
      "required_value": 958,
      "range": {
        "minimum": 64,
        "maximum": 536870912
      }
    }
  }
}
  • Remaining proof gaps:
    • tests/boundary/filesystem/kernelModule.test.ts contains one pre-existing non-file symlink test (it("reports non-file and missing selections as caller input errors")) that fails with EPERM: operation not permitted, symlink on unprivileged Windows; that test was skipped via -t locally and relies on POSIX CI coverage.

Boundary regressions covered: oversized-input (max_file_bytes) and entry-capacity (max_entries) refusal boundaries on inspect_kernel_module via both filesystem boundary and public CLI acceptance tests, plus guard verification (tests/evaluation/fixedCeilingGuard.test.ts). Lifecycle regressions are unaffected (artifact handle lifetime and cleanup paths were not modified).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Environment: Windows 11 x64, Node.js v24.22.1, head 4dec3c11a, merged with origin/main (55c7eaa06; verified zero conflicts against latest origin/main).

  • npm run test:focused -- src/domain/native/kernelModule.test.ts src/application/binaryDiagnostics/KernelModuleService.test.ts src/native/elf/KernelModuleParser.test.ts tests/acceptance/kernelModuleCli.test.ts tests/boundary/mcp/kernelModuleMcp.test.ts tests/evaluation/fixedCeilingGuard.test.ts — 6 files passed, 48 tests passed
  • npx vitest run tests/boundary/filesystem/kernelModule.test.ts -t "names max_structure_bytes|retains trailer fields|reads module metadata|returns typed resource and cancellation failures" — 1 file passed, 4 passed | 1 skipped (Windows symlink EPERM test skipped)
  • npm run check:fast — passed (typecheck, lint including fixed-ceilings.mjs and rea-numeric-limits.mjs, verify:architecture-guards across 3,167 source files)
  • npm run docs:check (run on 74f04dd6c; docs unchanged in 4dec3c11a) — passed (6/6 tasks + tests/conformance/readmeConsistency.test.ts 8/8 passed)

Compatibility, safety, and release

  • Breaking changes or migration steps: None. details.limit and structured details.refusal are additive; existing code, reported_limits, partial_observation, and schema bounds are preserved.
  • Real Hopper/Ghidra, browser, or OS coverage: Not applicable (offline kernel-module reader with no external provider or browser dependency). Symlink rejection test in tests/boundary/filesystem/kernelModule.test.ts requires privileged symlink creation or POSIX CI.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: No new file writes, network access, or subprocess execution; budget bounds and fixed ceilings remain strictly enforced.

Author readiness

Human owner: @Plastic-time

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

…nel reader refusals

Attach structured `details.limit` metadata to per-call budget refusals across
the remaining `src/native/elf/` providers (`ElfDependenciesProvider`,
`KernelModuleProvider`, `KernelBuildConfigProvider`, and
`ElfUnwindRangesProvider`), following the `morluto#14243` shared-budget pattern:

- Generalize `elfReadBudgetLimit` in `src/domain/native/elfReadBudgets.ts` so
  ELF and kernel readers share one parameter-limit builder.
- Export `ELF_DEPENDENCIES_READ_BUDGETS`, `KERNEL_MODULE_READ_BUDGETS`,
  `KERNEL_BUILD_CONFIG_READ_BUDGETS`, and `ELF_UNWIND_RANGES_READ_BUDGETS` from
  their domain schemas so Zod input bounds and projected `details.limit`
  metadata have a single owner.
- Report `details.limit` for caller-selected file, entry, inflation, and record
  budgets, including `compressed_candidate_bytes` (`max_config_bytes`), while
  moving `KernelBuildConfigProvider` file-size handling onto
  `offlineArtifactFailureDialect.fileSize` and removing its unreachable
  `capacity` branch.
- Report `ElfUnwindRangesProvider`'s fixed 16 MiB `symbol_name_text_bytes`
  allowance through `fixedAllowanceOptions` with narrowing guidance and
  `related: { parameters: ["limit", "offset"] }`, registered in
  `scripts/verify/fixed-ceiling-registry.json` under `morluto#14235`, rather than
  reporting an inverted `details.limit`.
- Remove `ElfDependenciesProvider.ts`, `ElfUnwindRangesProvider.ts`, and
  `KernelBuildConfigProvider.ts` from
  `scripts/verify/untyped-budget-refusal-baseline.json`, clearing all
  `src/native/elf/` entries from the baseline, and update
  `docs/reference/rea-limit-inventory.md` and
  `docs/reference/limits-and-recovery.md`.

Part of morluto#14234
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issue was found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issue was found.

Summary

Adds structured details.limit metadata to KernelModuleProvider refusals for max_file_bytes and max_entries.

  • Kernel-module budget refusals now report structured limits.

The previous-review merge bases differ, so the full PR diff was reviewed.

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@Plastic-time
Plastic-time marked this pull request as ready for review November 24, 2026 08:07
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T08:07:28.979582Z
We couldn’t complete this review. Comment @codex review to try again.
a6cea7f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@Plastic-time thanks for the PR — this branch has merge conflicts with main. Could you merge or rebase onto the latest main and resolve them? Once it's clean and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

…udget-limits

# Conflicts:
#	scripts/verify/untyped-budget-refusal-baseline.json
#	src/domain/native/elfUnwindRanges.ts
@Plastic-time

Copy link
Copy Markdown
Contributor Author

Merged main (72bdcad) and resolved the two conflicts.

  • elfUnwindRanges.ts: main added the limitation codes next to the new ELF_UNWIND_RANGES_READ_BUDGETS. Both are kept.
  • untyped-budget-refusal-baseline.json: main dropped the exports, hardening and PeBinaryFailure entries, and this PR drops the three ELF/kernel entries. All are removed. node scripts/verify/fixed-ceilings.mjs passes.

…udget-limits

# Conflicts:
#	src/native/elf/KernelBuildConfigProvider.ts
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Nov 26, 2026
@Plastic-time Plastic-time changed the title fix(limits): report details.limit for ELF dependency, unwind, and kernel reader refusals fix(limits): report details.limit for KernelModuleProvider refusals Nov 26, 2026
@Plastic-time

Copy link
Copy Markdown
Contributor Author

main moved again after my last merge: your #14631 (1badb6a8a) landed details.limit for ElfDependenciesProvider, ElfUnwindRangesProvider, and KernelBuildConfigProvider. I merged the latest main and narrowed this PR to the remaining KernelModuleProvider refusals (max_file_bytes with required_value, and max_entries). It also drops the hand-written inputBudgetRemediation so CLI and MCP render their own flags, and adds CLI and MCP refusal-and-recovery tests (4dec3c11a). The title and description now match the narrowed scope.

…udget-limits

# Conflicts:
#	docs/reference/limits-and-recovery.md

@gensokyo-dev gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On main e15d64e the three new kernel-module refusal tests fail because inspect_kernel_module budget refusals carry no details.limit. Merged onto current main, the CLI, MCP, boundary and domain kernel-module tests pass (15/15), along with docs:check, the fixed-ceilings guard, tsc, oxlint and oxfmt. The limit uses the same elfReadBudgetLimit owner as the other ELF note readers, and the schema bounds are unchanged.

@N0zoM1z0
N0zoM1z0 merged commit 2c07552 into morluto:main Nov 28, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants