Skip to content

Account composition input per document and charge completion (1.9.0-dev) - #81

Merged
ThorFuchs merged 1 commit into
mainfrom
fix/composition-per-document-accounting
Nov 9, 2026
Merged

ThorFuchs merged 1 commit into
mainfrom
fix/composition-per-document-accounting

Conversation

@ThorFuchs

Copy link
Copy Markdown
Owner

Summary

Fixes two accounting gaps in JSONCompositionScope (public since 1.6.0), salvaged from #63 without its performance toolkit, as decided in the 2026-11-09 PR review. Targets 1.9.0-dev.

  • Per-document input capacity. parseDocument checkpoints and retires the preceding input count before admitting the next document, so inputBytes applies to each document. The reported input total stays cumulative. Work, logical retention, accepted-capacity history and first-failure identity never restart. Today, multi-document compositions hit the input limit early because input is counted across all documents.
  • Completion is charged. Building the final report now charges its own cost on the original ledger: 424 logical bytes (32 header bytes plus 49 counter slots) and 50 work units (49 counter copies plus one final work update). Overflow, quota exhaustion or cancellation at completion prevents a successful report, even when the adapter catches the error.
  • Additive API. A new reserveExternalLogicalBytes(_:count:overhead:) overload checks the multiplication and then the addition before growth. The existing two-argument form keeps its signature.

The runtime change is about 50 lines in JSONCompositionScope.swift and JSONWorkMeter.swift. The five carried files are byte-identical to #63's versions, and none of them had changed on main since #63's base.

Behavior note for adapters: reported retainedBytes and workUnits for a completed composition grow by 424 and 50. A composition sitting exactly at its retention or work limit before this change now refuses at completion. That is the intended correction: the report's own cost was previously unaccounted.

Tests

  • CompositionContractTests expectations now include the completion buffer and work (+424, +50).
  • Two root functions carried from Reconcile native composition with NAV8 for source-bound qualification #63's proof work: jcompOwnedCancellationOccursInsideNativeWork (cancellation observed inside each of 7 native stages) and jcompOriginalHealthAndIdentitySurvivePackageSubstitution.
  • Inventories: JSONIntegrationTests goes from 34 to 36 in the native, portable and WASI lists, with the harness assertion updated.

Local results at da33936 (macOS 27, SDK 27.2, Apple Swift 6.4.2, language mode 6):

Lane Exit Result
python3 Scripts/ci.py --lane composition 0 passed (9 commands)
python3 Scripts/ci.py --lane native 0 passed (58 commands)
python3 Scripts/ci.py --lane docs 0 passed

Not run locally: safety, linux and wasm lanes, and performance. #63's quiet-runner performance gate isn't carried over; that check failed in #63 because the runner was busy (64.10% against a 90% idle rule), not because of a measured slowdown.

Left behind on #63's branch (kept for provenance)

The 41-file Tools/CompositionQualification additions stay on codex/composition-nav8-r3: compiler-bug reproducers, proof negatives, benchmark and probe, and the composition-performance.yml workflow on the xcode-27 runner. The guide keeps the explicit-borrow guidance and points to that branch for the reduced Swift compiler crash reproducers.

Overlap

#74 (1.9 workflows) also changes TestDiscovery.json (JSONIntegrationTests 34 → 43) and CHANGELOG. Whichever lands second should add the counts together (43 + 2) and merge the bullets under Unreleased — 1.9.0-dev.

🤖 Generated with Claude Code

Salvage the native composition accounting correction from the historical
composition branch (PR #63) onto current main without its performance
toolkit. parseDocument retires the preceding input count before the next
document, so inputBytes applies per document while the reported total
stays cumulative. Completion now charges its own 424-byte counter report
and 50 work units on the original ledger. Add the checked
reserveExternalLogicalBytes(_:count:overhead:) overload; the two-argument
form keeps its signature.

Carry the contract test expectations and the two owned cancellation and
substitution proofs. Update the composition guide, resource and
qualification contracts, discovery counts (JSONIntegrationTests 34 -> 36),
CHANGELOG (1.9.0-dev) and the CLI source identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThorFuchs
ThorFuchs merged commit 5353da4 into main Nov 9, 2026
9 checks passed
@ThorFuchs
ThorFuchs deleted the fix/composition-per-document-accounting branch November 9, 2026 21:29
ThorFuchs added a commit that referenced this pull request Nov 9, 2026
Merge main at 5362626 (#81 composition per-document input and charged
completion, #82 README for 1.8.0). Combine the Unreleased 1.9.0-dev
CHANGELOG entries, set JSONIntegrationTests to 45 (43 here plus #81's two
owned proofs) in the native, portable and WASI inventories and the
harness assertion, and regenerate the CLI source identity.

This candidate builds JSONIntegrationTests with -strict-memory-safety
-warnings-as-errors. Mark #81's test-only withUnsafeCurrentTask
cancellation hook with unsafe, using the same justification as the
existing composition contract test. Behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ThorFuchs added a commit that referenced this pull request Nov 10, 2026
Squash of the 1.9 candidate: ordered Inspection batches, the public immutable configured store with exact-ID lookup and bounded BFS follow (public API admitted by the maintainer 2026-11-10), exact Transform source definitions with compile reports, finite indexed selection scopes, cross-product acceptance, composition CI execution lanes, and the reconciliations with published 1.8.0 and #81. The full commit history, including the qualified source-bound commits, remains on branch codex/1.8-selection-main-qa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant