Skip to content

Target charges v2 loop-body intrinsics per iteration - #338

Merged
flyingrobots merged 1 commit into
mainfrom
fix/target-v2-intrinsic-cost
Nov 19, 2026
Merged

flyingrobots merged 1 commit into
mainfrom
fix/target-v2-intrinsic-cost

Conversation

@flyingrobots

Copy link
Copy Markdown
Owner

Plain-English Walkthrough

TL;DR

Under the shared-read schedule, native Target refused modules that call a target pure intrinsic from a bounded for body, even though the source checker accepted them [claim:root-cause, confidence:1.00]. Target's intrinsic-cost check now charges a literal-bound loop body once per iteration under v2, so such modules lower at their source minimum. Jedit's flat ReplaceRange now passes Target lowering at its source minimum [claim:flat, confidence:0.95].

Walkthrough

Root cause. Target runs two cost judges. The shared-read meter (fold_work) charges a for body times its bound. The separate pure-intrinsic check (target_ir/pure_intrinsics.rs) refused any intrinsic reached from a loop body, because under the copying schedule loop work was charged elsewhere. Under v2 that refusal disagreed with the source checker. ReplaceRange's effect loop calls proposal.childWrite, which reaches contentEdgeId.

Fix. Under v2, a literal-bound loop body is charged iter + body × bound in the intrinsic check. That check still counts only intrinsic templates, a subset of the shared-read meter's total, so the source minimum stays at or above the native one. The copying schedule is unchanged.

Verification.

  • RED: native_target_lowers_loop_intrinsics_at_the_shared_read_source_minimum failed with "target pure-intrinsic cost is unestablished or exceeds the step budget".
  • GREEN: that test passes, Target still refuses one step below the minimum, and the reference evaluator, now extended with loops, stays within budget: 2,944 metered steps against 3,025 static.
  • cargo xtask verify exits 0.

Flat ReplaceRange (jedit#410 at 06846ca): the source minimum is 261,523,656 steps and 175,260,814 bytes. At exactly that budget the build passes compilation and Target lowering, then stops at the provider (ProviderLowererRefused, InvalidSemanticArtifact), which is Echo's concern. One step less is refused at the source.

The docs are agent-written and not yet human-reviewed.

Appendix: Citations
Claim Evidence Confidence Notes
claim:root-cause crates/amblicit-syntax/src/target_ir/pure_intrinsics.rs For arm @8f880a14; RED test above 1.00
claim:flat CLI build in scratch with this branch's binary 0.95 Depends on jedit#410 sources; not a committed test.

Closes #337

Native Target's separate pure-intrinsic cost check refused any intrinsic
reached from a `for` body ("charged elsewhere; refused rather than
undercharged"). Under the shared-read schedule the source checker
admits such modules with the shared-read meter, which charges a
literal-bound loop body once per iteration, so Target refused modules
the source accepted (#337). Under v2, Target's intrinsic check now
charges a literal-bound loop body times its bound. The copying
schedule keeps the refusal.

The reference evaluator gains bounded loops; a module with intrinsics
in a loop, a helper and a fold step stays within its minimum.

RED: native_target_lowers_loop_intrinsics_at_the_shared_read_source_minimum
failed with "target pure-intrinsic cost is unestablished or exceeds the
step budget". GREEN: 5/5; cargo xtask verify exit 0.
Flat ReplaceRange (jedit#410 @ 06846ca): passes Target lowering at its
source minimum 261,523,656 steps / 175,260,814 bytes; one step less is
refused at source.

Agent-Session: AFC0A5E0-B032-49DC-8B18-CB932831DCC2
Agent-Tool: Claude Code
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • New Features
    • Native Target modules using the shared-read schedule can now use pure intrinsics in literal-bound loops. Their cost is counted once per iteration.
    • The copying schedule continues to reject intrinsics in loop bodies.
    • Jedit ReplaceRange’s minimum budget is documented as 261,523,656 steps and 175,260,814 bytes.
  • Documentation
    • Updated cost-schedule guidance and test-plan coverage for intrinsic calls in loops.

Walkthrough

Native Target now charges intrinsic calls in literal-bound loop bodies per iteration under the shared-read schedule. The changes add loop-cost tests, extend the reference evaluator to run For loops, and document the schedule behavior and test requirements.

Changes

Native Target shared-read loop costs

Layer / File(s) Summary
Shared-read intrinsic cost metering
crates/amblicit-syntax/src/target_ir/pure_intrinsics.rs, docs/topics/core-cost-schedules/README.md, CHANGELOG.md
The meter detects the shared-read schedule and charges literal-bound loop-body intrinsic costs per iteration. Other loop cases retain the existing rejection behavior. The docs and changelog describe the schedule distinction.
Loop lowering and budget validation
crates/amblicit-syntax/tests/shared_read_foreign_calls.rs, crates/amblicit-syntax/tests/core_cost_schedules/reference.rs, docs/topics/core-cost-schedules/test-plan.md
Tests cover direct and helper calls in loops, a fold-step call, lowering at minimum budgets, rejection one step below, and reference-evaluator metering. The reference evaluator now handles For loops.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • flyingrobots/amblicit#335 concerns static minimum loop-cost charging for ReplaceRange. This PR changes Target’s per-iteration charging for intrinsic calls in literal-bound loops and reports a ReplaceRange source minimum.
Merge Risk: Minimal · up to 8f880

Under the shared-read schedule, Target now charges intrinsic calls in literal-bound loops once per iteration, so such modules lower at their source minimum. The copying schedule still refuses them. Tests cover the minimum and one-step-below budgets. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: under the v2 shared-read schedule, Target's intrinsic cost check charges literal-bound loop-body intrinsics once per iteration. The changeset (pure_intrinsics.rs, refe…
Description check Passed The description is directly related to the changeset. It explains the root cause in pure_intrinsics.rs, the per-iteration charging fix under v2, the copying schedule staying unchanged, the RED/GREEN t…
Linked Issues check Passed [#337] is closed. Under the task rules, it supplies background only, so no active directly linked coding requirements apply. The PR objectives and the current PR description treat #337 the same way. T…
Out of Scope Changes check Passed Every changed area maps to the stated fix. The pure_intrinsics.rs hunk changes only the v2 literal-bound For branch and the shared flag. The copying schedule keeps its existing refusal branch fo…
Full details: Title check

Explanation

The title names the main change: under the v2 shared-read schedule, Target's intrinsic cost check charges literal-bound loop-body intrinsics once per iteration. The changeset (pure_intrinsics.rs, reference evaluator, tests, docs) matches this. The title is specific, concise, and free of file lists or vague terms.

Full details: Description check

Explanation

The description is directly related to the changeset. It explains the root cause in pure_intrinsics.rs, the per-iteration charging fix under v2, the copying schedule staying unchanged, the RED/GREEN test results, and the flat ReplaceRange measurements. It also references the closed issue #337.

Full details: Linked Issues check

Explanation

[#337] is closed. Under the task rules, it supplies background only, so no active directly linked coding requirements apply. The PR objectives and the current PR description treat #337 the same way. The reviewed diff (merge base 9829810 to head 8f880a1) also covers the goal named in the PR. In crates/amblicit-syntax/src/target_ir/pure_intrinsics.rs, Meter gains a shared flag. It is set when required_core_capabilities contains fold_work::SHARED_READS_CAPABILITY. Under that flag, a For with CoreBound::Literal(bound) is charged iter + body × bound. Other loops keep the refusal path. Test coverage is claimed in tests/shared_read_foreign_calls.rs and tests/core_cost_schedules/reference.rs. I did not run the tests. The claims in the PR body (RED/GREEN, 2,944 vs 3,025 steps, cargo xtask verify) are unverified by me. The jedit#410 result rests on a scratch CLI run and is not a committed test. Those points affect confidence, not this assessment, because no active requirement applies.

Full details: Out of Scope Changes check

Explanation

Every changed area maps to the stated fix. The pure_intrinsics.rs hunk changes only the v2 literal-bound For branch and the shared flag. The copying schedule keeps its existing refusal branch for intrinsics in loop bodies, including through helpers, so the PR body's claim that the copying schedule is unchanged matches the diff. The reference evaluator (tests/core_cost_schedules/reference.rs) adds For evaluation for the budget test. The test fixture and compile_source helper in tests/shared_read_foreign_calls.rs support the new tests. The CHANGELOG, docs/topics/core-cost-schedules/README.md, and test-plan.md updates are documentation of the same behavior. No unrelated change was found in the reviewed summary or in the diff hunk I read.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A literal loop counts each turn
Shared-read costs now scale and learn
Helpers join the measured flow
Fold steps find their budget, too
The reference walks the list in stride
Minimum costs are checked beside

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: bc6cea54-c6f6-4b8e-9338-a73cf81aa19a
Commits

Reviewing files that changed from the base of the PR and between 9829810 and 8f880a1.

Files selected for processing: 6

  • CHANGELOG.md
  • crates/amblicit-syntax/src/target_ir/pure_intrinsics.rs
  • crates/amblicit-syntax/tests/core_cost_schedules/reference.rs
  • crates/amblicit-syntax/tests/shared_read_foreign_calls.rs
  • docs/topics/core-cost-schedules/README.md
  • docs/topics/core-cost-schedules/test-plan.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 3

AGENTS.md — configured
docs/topics/tests/README.md — auto-discovered
docs/topics/documentation/README.md — auto-discovered
Path-based instructions: 3

Source excerpt: Topic `README.md` files must not describe intended behavior before it lands.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/topics/core-cost-schedules/README.md
Applicability reference: AGENTS.md: # AGENTS Edict uses RED/GREEN test-driven development for nontrivial changes.

CodeRabbit inference engine (docs/topics/tests/README.md)

Files:

  • docs/topics/core-cost-schedules/test-plan.md
Applicability reference: AGENTS.md: # AGENTS Follow the canonical [durable decision policy](docs/topics/documentation/README.md#durable-decision-discipline).

CodeRabbit inference engine (docs/topics/documentation/README.md)

Files:

  • docs/topics/core-cost-schedules/README.md
  • docs/topics/core-cost-schedules/test-plan.md
Additional comments: 1

crates/amblicit-syntax/src/target_ir/pure_intrinsics.rs: 1

177-177: Functional Correctness

The loop binder is in scope when the shared-read body is metered, so the reported refusal does not occur for for xs in input.xss bounded 16 { let n = echo.total(xs); }.

@flyingrobots
flyingrobots marked this pull request as ready for review November 19, 2026 06:44
@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-19T06:44:47.082855Z
We couldn’t complete this review. Comment @codex review to try again.
8f880a1 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

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@flyingrobots
flyingrobots merged commit 57b35d2 into main Nov 19, 2026
6 checks passed
@flyingrobots
flyingrobots deleted the fix/target-v2-intrinsic-cost branch November 19, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Target refuses v2 intrinsic costs that the source checker accepts (flat ReplaceRange)

1 participant