Skip to content

Bound the bounded workers' input to the model's context window - #1137

Merged
brettheap merged 10 commits into
mainfrom
fix/semantic-sweep-input-budget
Sep 22, 2026
Merged

brettheap merged 10 commits into
mainfrom
fix/semantic-sweep-input-budget

Conversation

@brettheap

@brettheap brettheap commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-1

Parent-side half of the input-size guard, for opensoft/xFactory#479. Authored on Brett Heap's word "brief a writer to add the input-size guard" (2026-09-22). Draft: no merge is sought. The child-side half is opensoft/xFactory#481, and the two land together.

The cause, verified before anything was built

scripts/doc_health/semantic.py's build_analysis_input assembled the whole selected corpus plus the whole promoted-spec grounding into one prompt with no size bound anywhere — not in the module, not in runner.py, not in either workflow. Once that prompt outgrew the model's context window the analysis child began failing, and it failed invisibly: claude -p --output-format json writes its error to stdout, the child redirects stdout into worker-result.json, and the cleanup step deletes the workspace.

Measured from the nightly's own semantic-sweep-bundle artifacts, against each child's conclusion and its Run bounded no-tools analysis step duration:

night analysis-input.txt scope child step
2026-08-30 8,430,004 changed docs failure 3 s
2026-08-31 3,640,354 changed docs failure 2 s
2026-09-01 3,829,890 changed docs (54 of 661) failure 2 s
2026-09-02 2,524,427 changed docs (10 of 661) success 200 s
2026-09-02 1,869,042 changed docs (0 of 661) success 56 s
2026-09-03 2,913,875 changed docs (17 of 666) failure 3 s
2026-09-04 2,932,442 changed docs (19 of 669) failure 2 s
2026-09-11 6,402,585 changed docs (142 of 713) failure 3 s
2026-09-12 6,586,271 changed docs (145 of 716) failure 3 s
2026-09-14 7,418,276 changed docs (178 of 726) failure 4 s
2026-09-15 7,418,276 changed docs (178 of 726) failure 2 s
2026-09-16 7,418,276 changed docs (178 of 726) failure 3 s
2026-09-17 7,663,396 changed docs failure 3 s
2026-09-18 7,706,463 changed docs failure 2 s
2026-09-19 7,940,307 changed docs failure 2 s
2026-09-20 12,331,149 full corpus (weekly) failure 2 s
2026-09-21 7,940,307 changed docs (188 of 733) failure 2 s

Accepted at or under 2,524,427 bytes; refused at or over 2,913,875; every refusal two to four seconds.

Three controls rule out authentication. (1) On 2026-09-11/12/14/15 the sibling cataloger child — same runner, same vault token, same flag set, same model — ran 226/324/188/305 s on 82,712 bytes while the analysis child died in 2–4 s. (2) The readiness lane records the model's own errors per cluster: 0 of 12 errored on 2026-09-09…09-15, 12 of 12 errored with HTTP 403 on 09-16…09-21 — so auth was provably healthy across the whole first window, and the analysis child failed anyway. (3) After the Cloud PC account's seat was assigned (2026-09-22 ~01:10Z), the re-run put both children on the same runner in the same minute: cataloger 35555555963 attempt 2 succeeded (01:20:45Z–01:25:44Z, 3,137-byte recommendation) on 82,712 bytes; analysis 35555553515 attempt 2 failed in 3 seconds (01:20:39Z → 01:20:42Z) on the same 7,940,307 bytes, token fetch green, nothing printed.

The cataloger is a second lane with a different cause, and this PR does not claim otherwise. It classifies one shard per run — shards.json[0], byte-identical on 2026-09-14 (success), 09-15 (success), 09-16 (failure) and 09-21 (failure) — so size explains nothing there. Its 09-21 failure flipped to success on rerun after the seat was assigned, and the cause is not proven from the logs because the CLI's error was swallowed the same way. The circumstantial evidence is the readiness artifact from that night: job conclusion success, findings.json 12 entries of which 12 errored, all "api_error_status": 403. The budget here is owed for the analysis lane, and stands as defense for the cataloger's larger shards (largest in the 2026-09-21 bundle: 732,810 bytes).

Reproduced, with the error the log could not show — real 2026-09-21 bundle, child's exact flag set: exit 1, zero bytes on stderr, and on stdout {"is_error": true, "terminal_reason": "blocking_limit", "result": "Prompt is too long", "duration_ms": 358}.

The budget arithmetic

At 2,799,448 bytes of this corpus the CLI states the numbers itself:

the request is ~1086484 tokens (limit 1000000) but this conversation is only ~700164 tokens — the rest is system prompt, tool definitions, and attachment content

context limit                       1,000,000 tokens   (stated by the CLI)
- CLI fixed overhead, MEASURED        386,320 tokens   (1,086,484 - 700,164)
- the model's own answer               64,000 tokens   (max output)
= usable prompt content               549,680 tokens
x bytes per token, MEASURED               3.998 bytes  (2,799,448 / 700,164)
= 2,197,600 bytes
x 0.87 safety margin
= 1,911,912  ->  DEFAULT_INPUT_BUDGET_BYTES = 1,900,000

Forwards: 1,900,000 bytes is ~475,200 content tokens, ~861,520 of the request with the overhead, and a full 64,000-token answer still leaves ~74,000 spare. The measured ceiling (~2.45 MB) sits exactly inside the observed 2,524,427-accepted / 2,913,875-refused bracket.

Why the budget cannot bound only the changed docs

night promoted-spec grounding changed docs total
2026-09-02 102 specs, 1,866,899 B 10 docs, 655,400 B 2,524,427 B
2026-09-21 123 specs, 3,051,663 B 188 docs, 4,886,516 B 7,940,307 B

Every run ships every promoted spec as contradiction grounding regardless of scope, and that population alone is now past the ceiling. So the budget bounds the whole assembled prompt and reserves a share for each population — semantic-normative-prose needs the changed docs, semantic-contradiction needs the specs.

What this changes

  • semantic.py — DEFAULT_INPUT_BUDGET_BYTES, GROUNDING_BUDGET_SHARE, render_analysis_input, document_cost, pack_within_budget (three-phase deterministic first fit: corpus into its reserved share, grounding into its own, then leftovers re-offered to what was deferred, corpus first), corpus_documents, build_analysis_input_with_stats, analysis_input_with_stats, five budget fields plus a named deferred list on SweepMeta, and the same record on the bundle's meta.json so the child enforces the parent's number rather than a duplicated constant. Whole documents only — nothing is ever truncated mid-document, and a single oversized document defers itself rather than starving the documents behind it.
  • runner.py — --semantic-input-budget-bytes.
  • report.py — the input line plus one line per deferred document.
  • catalog_dispatch.py — shard_analysis_input (the cataloger child's own assembly, reproduced so the parent can measure it) and a catalog-bundle meta.json carrying the same budget and each shard's measured assembled size. build_shards bounds a shard by entry count, which is not a byte bound. Shard identity and selection are untouched, so the catalog's carry-forward is untouched.
  • openspec/changes/add-worker-input-budget/ and the README "OpenSpec Records" entry.

Replayed against the real 2026-09-21 corpus the packer produces 1,899,448 bytes, 93 documents sent, 218 deferred and named.

Governing-spec finding — RULING NEEDED

This is normative, not an implementation detail, on two counts, so the OpenSpec change is in this PR as a Status: draft packet:

  1. Hermes-layer sweep scope resolution makes scope "Hermes-owned policy resolved deterministically by orchestration" over incremental | full-weekly | full-nightly, and Sweep sequencing and snapshot consistency says the sweep's corpus "is exactly the deterministic pass's inventory for that run". A byte budget narrows the swept set on a second axis no Hermes layer declares.
  2. The semantic sweep is unavailable protects a prior finding whose sweep "was skipped or unavailable" from reading as resolved. A partial sweep is neither — it ran and returned findings over a silently narrowed corpus. Without a delta, the first night a document is deferred its prior semantic findings vanish and the next run emits "uncited resolution" errors against findings nobody disposed of.

The delta is one ## MODIFIED (Sweep sequencing and snapshot consistency, one added scenario) and one ## ADDED (Bounded worker input budget, five scenarios). It follows the house pattern canon already uses for bounded narrowing: xfactory-semantic-kernel's Bounded semantic context permits a narrowed term subset only against "an explicit itemized truncation naming each omitted closure member".

Three open questions are declared in the proposal and tasks.md § Group 0: the grounding share (half, as built), that this packet caps and records rather than carrying deferrals over (there is no sweep cursor, and health/inventory/<date>.json is emitted unconditionally by finalize, so a deferred document would be in tomorrow's baseline and never re-selected), and the live HTTP 403 org-entitlement block no code here addresses.

Copilot's review, and what it changed

Copilot raised two findings on the first head and both were right; both are fixed in b67155e6, pinned by tests, and their threads are answered and resolved.

  • A deferred document's prior findings could read as resolved. The uncited-resolution comparison excludes a family only when the whole sweep was skipped (semantic_meta.skipped_reason), and a successful partial pack leaves that empty. So the first budgeted night would have manufactured one uncited-resolution ERROR per deferred document carrying a semantic finding — which the nightly files as a regression issue, forbidden for these families, and exactly the hole this packet's own spec delta says must not exist. report.uncited_resolutions gains a third, narrowest exclusion axis, unavailable_keys (exact (family, repo, path) triples), built by runner.main from semantic_meta.deferred across both semantic families. SweepMeta.deferred now carries structured (repo, path) pairs, because a path contains separators.
  • An explicit --semantic-input-budget-bytes 0 was silently replaced by the default. or folded a zero or a negative back, so a bad cap quietly became the good one and pack_within_budget's validation was never reached. The default is now resolved once, only for is None.
  • From the same reading, unprompted: enforce_contract is now given the sent corpus rather than the selected one, so a finding naming a document the model never saw is dropped instead of admitted.

A third round, on the re-review's own observations

Copilot's re-review of 04372198 reported Findings: None and named three things anyway; all three were right, and all three are fixed in 2dd7c6b7:

  • The spec contradicted the build. The ADDED requirement said every bounded worker lane bounds the input it sends, while the cataloger's parent only measured its shards and dispatched them regardless. The requirement now states the two assembly shapes and what each owes — the orchestrator packs where it assembles the prompt; where the worker assembles it, the orchestrator measures each unit, records it, and does not dispatch one it has measured over the budget. The build now does that: an over-budget shard is absent from shards.json, the only list the child reads, while its file still ships so the bundle stays a complete record. Shard identity is untouched, so the catalog's carry-forward is untouched.
  • The configured budget never reached the catalog. _write_shard_bundle took input_budget_bytes with a default that prepare_catalog_bundle never passed, so an operator-set cap bounded the semantic lane only. Threaded now — and the flag is renamed --worker-input-budget-bytes (old spelling kept as an alias), because the ceiling is one fact about the fleet: both children run the same CLI against the same model on the same host.
  • A bad budget could pass unnoticed. pack_within_budget validates, but a run whose corpus is empty returns before any packing and a catalog bundle with no shards writes no prompt at all — so --worker-input-budget-bytes 0 would have been discovered the first night the corpus was non-empty. semantic.require_budget is now called at the top of run_sweep, prepare_bundle and _write_shard_bundle.

Two further rounds, each on an observation the re-review named while reporting Findings: None:

  • A stray # noqa: D401 left above _write_shard_bundle's docstring as a surviving edit anchor — removed, and what it gestured at written into the docstring instead (88fa681c).
  • grounding_share accepted 0.0 and 1.0, each giving one population a reserved share of zero — exactly what the ADDED requirement forbids. The parameter is exposed, so the default satisfying the invariant was not enough; the bound is now strict (e59b4881).
  • The MODIFIED block still contradicted itself. It reproduced Sweep sequencing and snapshot consistency's first scenario verbatim — "the sweep's corpus is exactly the deterministic pass's inventory for that run" — which a budgeted run does not satisfy, so the packet was proposing a narrowing and restating the sentence forbidding it. The scenario now reads "drawn from exactly the deterministic pass's inventory for that run and from no other snapshot" (the requirement's real subject: one snapshot shared by both passes) with a third bullet stating that the set sent may be a subset, named as such. The proposal's argument is amended in the same words (083d01e1).

Two more, each again alongside Findings: None: the catalog telemetry counted shards built rather than dispatchable (they differ once an over-budget shard is held back, so a run that classified nothing would still have reported a shard — dispatchable_shard_count added beside the unchanged shard_count), and two scenario counts went stale when the ADDED requirement gained its sixth scenario (857166d6).

One observation is declined, deliberately. The final re-review asks to align document_cost's separator accounting exactly with the rendered JSON, "to avoid unnecessary deferrals". The packer charges the 2-byte ", " separator for every document including the first, which needs none — so it over-charges by at most 2 bytes per document: 186 bytes on the 93-document 2026-09-21 pack, 0.01% of the budget. That conservatism is the point. A guard must never be optimistic about the size of what it is about to send, and this is what makes input_bytes <= budget true by construction rather than only by the assertion that follows it. The behaviour stays; the comment on _JSON_ITEM_SEPARATOR_BYTES already states it ("conservative by at most 2 bytes per document — never optimistic").

What the first pytest-suite run caught

Run 35677414742 went red on five tests, both causes about the new change directory rather than any code, and both fixed in 04372198:

  • target_release was outside the vocabulary. The declaration opened THE NEXT ADDITIVE MINOR, DELIBERATELY NOT NUMBERED HERE, so the gate read the token THE. That spelling is lawful only for the twenty active packets scripts/target-release-register.yaml names, and writing this packet into the register would be granting itself an exception rather than declaring honestly. It is now implemented, measured rather than asserted: this packet moves no file under contracts/, defines no record kind, adds no schema field, and contracts/manifest.yaml carries no doc-health row a byte budget could change — so there is no cut to allocate a number at, and deferred-allocation would be declaring a bundle this packet does not owe.
  • The per-change sweep ledger was stale. A new change in the corpus owes a row; seeded with the tool's own validate-sequenced-after.py . --seed-ledger --moved-by '#1137', which added exactly one line and moved nothing else.

A later run caught a third, and it is the one worth reading: rewriting canon's "the sweep's corpus is exactly the deterministic pass's inventory for that run" left that bullet uncarried by the MODIFIED block, and the modified-block-currency self-gate reports every such subject and requires it NAMED, in the same commit, with the reason. Named in ccb9c919, with the re-measurement the gate's own runbook asks for (carriage ledger: 13 (info), scenario-title completeness: 0 (error); tests/doc-health/test_modified_block_currency*.py → 301 passed). The row retires when this packet archives and its block is promoted into canon.

Worth recording for the next writer: python3 scripts/validate-sequenced-after.py . passes with the ledger stale. It is tests/sequenced_after/test_sweep.py that reads the ledger, and only the pytest gate runs it — so running the plain validator is not a substitute for running the suite.

Verification

  • python3 -m pytest tests/doc-health/test_semantic_input_budget.py -q → 30 passed
  • python3 -m pytest tests/doc-health tests/code_surface tests/target_release tests/sequenced_after tests/citation_remainder -q → 7 failed, 2616 passed, 1 skipped in 315s. All seven failures are pre-existing on origin/main — reproduced in a clean worktree at 6b298a1e with the same seven names; they are carved_reach.CarveReachUnavailable (the openDox/openXdox gitlinks are not materialized in a plain clone) and its dependants. CI checks out submodules, so they pass there.
  • python3 scripts/validate-sequenced-after.py . → sequenced_after validation passed (44 active changes, 16 declaring the field), archive-date and archive-date-vs-commit agreement passed.
  • OPENSPEC_TELEMETRY=0 openspec validate add-worker-input-budget --strict → Change 'add-worker-input-budget' is valid
  • python3 scripts/validate-target-release.py . → 44 active proposals, 44 declaring — 22 implemented, … 0 outside the vocabulary, target_release validation passed
  • python3 -m pytest tests/code_surface tests/target_release tests/sequenced_after -q → 538 passed
  • OPENSPEC_TELEMETRY=0 openspec validate --all --strict → Totals: 107 passed, 1 failed (108 items); the one failure is the pre-existing dispositioned add-chain-attestation.
  • python3 scripts/validate-openspec-cli-pin.py --all --strict → exit 0, 1 finding(s) are ACCEPTED EXCEPTIONS (the same dispositioned add-chain-attestation entry).

Pin-sync

The nightly's prepare job runs python3 openxFactory/scripts/doc-health.py from the aggregation's gitlink, so this PR changes nothing in the nightly until the aggregation's openxFactory gitlink is moved to its merge commit. The reusable workflow itself is consumed @main, so no workflow change is needed for it. That pin-sync is the orchestrator's separate act and is deliberately not in this PR.

Lane: openxfactory-1

🤖 Generated with Claude Code

The doc-health nightly's analysis child has failed every night since
2026-08-30 except the two 2026-09-02 runs, silently. semantic.py's
build_analysis_input assembled the whole selected corpus plus the whole
promoted-spec grounding into one prompt with no size bound anywhere in
the module, the runner, or the workflow. Once that prompt outgrew the
model's context window, claude -p wrote {"result": "Prompt is too long"}
to stdout, the child redirected stdout into worker-result.json, and the
cleanup step deleted it -- leaving exit code 1 and an empty stderr.

Size separates the nights with no exception: accepted at 2,524,427 bytes
and below, refused at 2,913,875 and above, every refusal in two to four
seconds. The control is the sibling cataloger child, which on
2026-09-11/12/14/15 ran 188-324s on 82,753 bytes of input with the same
runner, token, flag set and model. Re-run on 2026-09-22T01:20Z after the
Cloud PC account's seat was assigned, the analysis child failed again in
three seconds on the same 7,940,307-byte input while the cataloger child
ran for minutes in the same minute.

semantic.py now packs within a byte budget: whole documents only, never a
fragment; deterministic (repo, path) order; a reserved share for each of
the two populations, because the promoted-spec grounding alone is now
3,051,663 bytes and a bound that reached only the changed docs would
leave the lane dead; and every deferred document named in the bundle's
meta.json and in the report. The budget travels with the bundle so the
child enforces the number the parent packed against.

catalog_dispatch.py gains the same budget in its own bundle meta plus the
measured assembled size of each shard: build_shards bounds a shard by
entry count, which is not a byte bound. Shard identity and selection are
untouched.

The default is 1,900,000 bytes, derived from figures the CLI states
itself at 2,799,448 bytes of this corpus -- a 1,000,000-token limit, a
measured 386,320-token fixed overhead, 64,000 tokens reserved for the
answer, and a measured 3.998 bytes per token.

The child-side refusal and the stderr capture are the aggregation's
surface and land separately.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 22, 2026 01:27
@sourcery-ai

sourcery-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

This draft bounds semantic and cataloger worker inputs by measuring the complete assembled prompts, packing whole documents deterministically under a bundle-carried byte budget, and recording all deferrals for reporting and semantic continuity; it also adds the corresponding OpenSpec governance and tests, while child-side workflow enforcement lands in a companion repository.

Sequence diagram for bundle-carried worker input enforcement

sequenceDiagram
    participant Orchestrator
    participant Packer
    participant Bundle
    participant Worker
    participant Model
    Orchestrator->>Packer: build_analysis_input_with_stats()
    Packer->>Packer: pack_within_budget()
    Packer-->>Orchestrator: bounded prompt and budget stats
    Orchestrator->>Bundle: write analysis-input.txt and meta.json
    Bundle-->>Worker: input_budget_bytes and assembled input
    Worker->>Worker: Check input size
    alt input within budget
        Worker->>Model: Invoke bounded analysis
        Model-->>Worker: Findings output
    else input over budget
        Worker-->>Orchestrator: Refuse before model invocation
    end
Loading

Entity relationship diagram for budget and deferral records

erDiagram
    SEMANTIC_BUNDLE_META {
        int input_budget_bytes
        int input_bytes
        int docs_included
        int docs_deferred
        boolean truncated
    }
    DEFERRED_DOCUMENT {
        string repo
        string path
        int bytes
        string population
    }
    SEMANTIC_BUNDLE_META ||--o{ DEFERRED_DOCUMENT : records
Loading

Flow diagram for deterministic worker input budgeting

flowchart TD
    A["Selected corpus and promoted-spec grounding"] --> B["render_analysis_input"]
    B --> C["Measure prompt scaffold and document_cost"]
    C --> D["pack_within_budget"]
    D --> E["Reserve budget shares"]
    E --> F["First-fit whole-document packing"]
    F --> G["Re-offer unused capacity: corpus first"]
    G --> H["Assemble bounded analysis-input.txt"]
    F --> I["Record deferred documents"]
    H --> J["Write bundle meta.json"]
    I --> J
    J --> K["Report sent bytes and named deferrals"]
Loading

File-Level Changes

Change Details Files
Add deterministic, whole-document packing for semantic analysis prompts under a shared byte budget.
  • Introduce a 1,900,000-byte default and configurable grounding share.
  • Measure the complete rendered prompt, reserve capacity for corpus and grounding, then re-offer unused capacity to deferred documents.
  • Defer oversized documents without truncation and record their identities and population.
scripts/doc_health/semantic.py
tests/doc-health/test_semantic_input_budget.py
Propagate input-budget accounting through execution bundles, CLI invocation, and reports.
  • Add the semantic input-budget CLI option and pass it through bundle preparation and sweep execution.
  • Persist budget, actual bytes, included/deferred counts, truncation status, and deferred entries in metadata.
  • Report the actual input and name every deferred document.
scripts/doc_health/runner.py
scripts/doc_health/report.py
scripts/doc_health/semantic.py
Measure and record cataloger shard prompt sizes against the same worker budget.
  • Reproduce the cataloger child's prompt assembly in the parent for byte-accurate measurement.
  • Add shared budget and per-shard size metadata, including over-budget shard identifiers.
  • Leave shard construction identity and entry-count selection unchanged.
scripts/doc_health/catalog_dispatch.py
tests/doc-health/test_semantic_input_budget.py
Document the normative contract for bounded worker inputs and partial sweeps.
  • Add a draft OpenSpec proposal with measured failure evidence, budget arithmetic, implementation scope, and unresolved policy questions.
  • Modify sweep sequencing to permit a sent subset only when all deferred documents are explicitly reported.
  • Add requirements for deterministic packing, worker-side pre-invocation refusal, and protection of prior findings for deferred documents.
  • Register the draft change in the OpenSpec records README.
openspec/changes/add-worker-input-budget/proposal.md
openspec/changes/add-worker-input-budget/specs/doc-health/spec.md
openspec/changes/add-worker-input-budget/tasks.md
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Unresolved issues affect budget propagation, invalid CLI values, and preservation of deferred findings.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds deterministic byte-budgeting for semantic and catalog worker inputs, records deferred documents, and documents the proposed policy.

Changes:

  • Bounds whole-document prompt packing with corpus/grounding budget shares.
  • Propagates budget metadata through bundles, reports, and CLI options.
  • Adds focused tests and OpenSpec documentation.
File Summary
tests/​doc-health/​test_semantic_input_budget.py Tests budget enforcement and metadata.
scripts/​doc_health/​semantic.py Implements budgeted packing and deferral tracking.
scripts/​doc_health/​runner.py Adds CLI budget handling and propagation.
scripts/​doc_health/​report.py Reports input and deferred documents.
scripts/​doc_health/​catalog_dispatch.py Measures catalog shard input sizes.
README.md Documents the active OpenSpec change.
openspec/​changes/​add-worker-input-budget/​tasks.md Lists implementation and ratification tasks.
openspec/​changes/​add-worker-input-budget/​specs/​doc-health/​spec.md Defines governing requirements.
openspec/​changes/​add-worker-input-budget/​proposal.md Describes the proposed policy and rationale.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/doc_health/runner.py Resolved
Comment thread scripts/doc_health/semantic.py Resolved
Copilot AI review requested due to automatic review settings September 22, 2026 01:36
…ytes

The 82,753 figure in the previous commit, the README entry and the
proposal was an ESTIMATE (prompt.md plus the re-dumped payload plus a
200-byte allowance for the framing), not a measurement. The framing is
41 bytes smaller than that allowance.

Measured instead: the shard-assembly heredoc was lifted out of the
SHIPPED aggregation workflow (opensoft/xFactory
.github/workflows/doc-health-cataloger-worker.yml, "Run bounded no-tools
classification") and executed against the real 2026-09-21 bundle's
shard CATSHARD-0000-9b082395f2, and its output compared byte for byte
with catalog_dispatch.shard_analysis_input over the same shard:

  workflow-assembled bytes : 82712
  catalog_dispatch  bytes  : 82712
  IDENTICAL                : True

which both fixes the figure and proves the parity the new function's
docstring claims -- the parent now measures exactly what the child
assembles.

The previous commit's message keeps the estimate; the org ruleset
refuses a force-push, so this commit is the correction of record.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Fix zero-budget fallback handling, preserve deferred findings during resolution, and prevent grounding starvation.

Review effort: Lite
Findings: 2 Medium severity

Open (2)

Copilot AI review requested due to automatic review settings September 22, 2026 01:53
Two defects Copilot found in the budget's first cut, both real.

A DEFERRED DOCUMENT'S PRIOR FINDINGS COULD READ AS RESOLVED. The
uncited-resolution comparison excludes a family only when the whole
sweep was SKIPPED (`semantic_meta.skipped_reason`), and a successful
partial pack leaves that field empty while some documents never reached
the model at all. So the first budgeted night would have manufactured
one uncited-resolution ERROR per deferred document that carried a
semantic finding -- and the nightly files those as a regression issue,
which the doc-health contract forbids for the semantic families. It is
also the exact hole this packet's own spec delta says must not exist.

`report.uncited_resolutions` gains a third and narrowest exclusion axis
beside `unavailable_families` and `unavailable_repos`: `unavailable_keys`,
exact (family, repo, path) triples this run could not re-confirm.
`runner.main` builds it from `semantic_meta.deferred` across both
semantic families. `SweepMeta.deferred` now holds structured (repo, path)
pairs rather than a rendered "<repo>/<path>" string, because a path
contains separators and the rendering belongs to the report.

AN EXPLICIT --semantic-input-budget-bytes 0 WAS SILENTLY REPLACED by the
default: `args.semantic_input_budget_bytes or DEFAULT` folds a zero or a
negative straight back, so a bad cap quietly became the good one and
`pack_within_budget`'s validation was never reached. The default is now
resolved exactly once, and only for `is None`.

Also, from the same review round: the finding contract is given the SENT
corpus rather than the SELECTED one, so a finding naming a document the
model never saw is dropped rather than admitted.

Six new tests, including the control that both prior findings WOULD be
reported without the exclusion.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Address deferred-document carry-over, endpoint validation, and refill starvation concerns.

Review effort: Lite
Findings: None

Resolved since last review (2)

Two required gates the local validator run did not reach, both red on
pytest-suite run 35677414742 and both about the new change directory
rather than about any code.

TARGET_RELEASE WAS OUTSIDE THE VOCABULARY. The declaration opened with
"THE NEXT ADDITIVE MINOR, DELIBERATELY NOT NUMBERED HERE", so the gate
read the token `THE`. That spelling is lawful only for the twenty active
packets the target-release register names, and writing this packet into
the register would be granting itself an exception rather than declaring
honestly. It is now `implemented`, which is the right value and is
measured rather than asserted: this packet moves no file under
`contracts/`, defines no record kind, adds no schema field, and
`contracts/manifest.yaml` carries no doc-health row a byte budget could
change -- so there is no cut to allocate a number at, and
`deferred-allocation` would be declaring a bundle this packet does not
owe.

THE PER-CHANGE SWEEP LEDGER WAS STALE. A new change in the corpus owes a
row. Seeded with the tool's own command --
`validate-sequenced-after.py . --seed-ledger --moved-by '#1137'` -- which
added exactly one line and moved nothing else.

Note for the reader: `scripts/validate-sequenced-after.py .` PASSES with
the ledger stale; it is `tests/sequenced_after/test_sweep.py` that reads
the ledger, and only the pytest gate runs it. Running the plain validator
is not a substitute for running the suite.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 02:15

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Resolve the specification contradiction, ensure catalog shards are actually bounded and receive the configured budget, and validate non-positive budgets before empty-corpus returns.

Review effort: Lite
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Exclude oversized shards from dispatch instead of only recording them

scripts/​doc_health/​catalog_dispatch.py:517

This only records oversized shards; it does not prevent them from being dispatched. build_shards is still entry-count based, so a shard whose measured prompt exceeds input_budget_bytes remains in shards.json and the child-side refusal will drop that shard's classification entirely. The parent must split/defer/requeue oversized shards (or otherwise make the dispatch selection exclude them) so the catalog lane is actually bounded rather than merely failing safely.

Three gaps Copilot's re-review of 0437219 named, all real.

THE SPEC CONTRADICTED THE BUILD. The ADDED requirement said every
bounded worker lane bounds the input it sends, while the cataloger's
parent only MEASURED its shards and dispatched them regardless. The
requirement now states the two assembly shapes and what each owes: where
the ORCHESTRATOR assembles the prompt it packs within the budget; where
the WORKER assembles it from a unit the orchestrator prepared, the
orchestrator measures each unit, records it, and does not dispatch one it
has measured over the budget. Dispatching it and letting the child refuse
is conformant and useless -- the same shard is selected again next run.
The build now does that: an over-budget shard is absent from
`shards.json`, which is the only list the child reads, while its file
still ships so the bundle stays a complete record. Shard IDENTITY is
untouched, so the catalog's carry-forward is untouched.

THE CONFIGURED BUDGET NEVER REACHED THE CATALOG. `_write_shard_bundle`
took `input_budget_bytes` with a default and `prepare_catalog_bundle`
never passed one, so an operator-set cap bounded the semantic lane only.
It is threaded now -- and the flag is renamed `--worker-input-budget-bytes`
(with the old `--semantic-input-budget-bytes` kept as an alias) because
the ceiling is ONE fact about the fleet: both children run the same CLI
against the same model on the same host.

A BAD BUDGET COULD PASS UNNOTICED. `pack_within_budget` validates, but a
run whose corpus is empty returns before any packing and a catalog bundle
with no shards writes no prompt at all, so `--worker-input-budget-bytes 0`
would have been discovered the first night the corpus was non-empty.
`semantic.require_budget` is now called at the top of `run_sweep`,
`prepare_bundle` and `_write_shard_bundle`.

Three new tests, including the two-shard bundle where exactly one shard
is over the cap.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 02:28

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The broad orchestration and normative specification changes warrant final human review, with a documentation nit remaining.

Review effort: Lite
Findings: None

The previous commit left a `# noqa: D401` line above
`_write_shard_bundle`'s docstring -- an edit anchor that survived, marking
nothing and suppressing nothing. Removed, and what it gestured at is
written where it belongs: the docstring now states that the parent cannot
pack the child-assembled prompt, only measure it, and that an over-budget
shard is left out of `shards.json` while its own file still ships.

Raised by Copilot's re-review of 2dd7c6b ("a documentation nit
remaining"), which reported no findings.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 02:33

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Fix the reserved-share validation and update stale CLI flag references in the proposal and task list.

Review effort: Lite
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Reject grounding_share endpoints to preserve reserved capacity

scripts/​doc_health/​semantic.py:600

The packer accepts grounding_share=0 or 1, which gives one population no reserved capacity and contradicts the stated requirement that each population has a reserved share. Because grounding_share is an exposed parameter, callers can bypass the invariant even though the default is valid; reject the endpoints (or otherwise enforce a strictly positive share for both populations).

`grounding_share` accepted 0.0 and 1.0, each of which gives ONE of the
two populations a reserved share of zero -- exactly what the ADDED
requirement forbids ("each population SHALL have a reserved share of the
budget, so that no population can be starved to nothing by another"). The
default satisfies the invariant, but the parameter is exposed, so a
caller could bypass it. The bound is now strict.

Raised by Copilot's re-review of 88fa681, which reported no findings.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 02:38

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

A normative specification scenario still conflicts with the budget-limited implementation and requires clarification.

Review effort: Lite
Findings: None

The MODIFIED block reproduced *Sweep sequencing and snapshot
consistency*'s first scenario verbatim, and that scenario says the
sweep's corpus "is exactly the deterministic pass's inventory for that
run". A budgeted run does not satisfy it: the set sent is a subset. The
packet was therefore proposing a narrowing and simultaneously restating
the sentence that forbids it.

Resolved rather than left beside itself. The scenario now reads "drawn
from exactly the deterministic pass's inventory for that run and from no
other snapshot" -- which is the requirement's real subject, ONE snapshot
shared by both passes, and what the immutable-checkout check beside it
exists to protect -- and a third bullet states that where the budget
holds documents back the set SENT is a subset of that corpus, named as
such, with the shared snapshot unaffected.

The proposal's "Why this is normative" section is amended to say the
same in the same words, so the packet's argument and its delta agree.

Raised by Copilot's re-review of e59b488, which reported no findings.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 02:43

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The cross-cutting worker-budget changes require final human review.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 22, 2026 03:11
Rewriting canon's "the sweep's corpus is exactly the deterministic pass's
inventory for that run" left that bullet uncarried by this packet's
MODIFIED block, and the modified-block-currency self-gate reports every
such subject and requires it NAMED in the same commit, with the reason --
which it is: the bullet is the packet's whole subject, and a packet that
bounds the worker's input cannot restate it without falsifying its own
delta.

Nothing canon obliged is released. The successor says more rather than
less -- "drawn from exactly the deterministic pass's inventory for that
run and from no other snapshot", which is the requirement's real subject,
ONE snapshot shared by both passes, the thing the immutable-checkout
bullet beside it protects -- and the block adds a third bullet stating
that the set SENT may be a subset, named as such, the shared snapshot
unaffected. The narrowing that does happen is the packet's declared
normative claim, argued in proposal.md and carried by the block's own
added scenario. The row retires when the packet archives and its block is
promoted into canon.

Re-measured in this commit, as the gate's runbook requires:

  python3 scripts/doc-health.py --single-repo . --family modified-block-currency
    carriage ledger: 13 (info -- editorial)
    scenario-title completeness: 0 (error -- the gate-bearing arm)

  python3 -m pytest tests/doc-health/test_modified_block_currency*.py -q
    301 passed

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Fix the catalog shard-count telemetry and update the two scenario-count references.

Review effort: Lite
Findings: None

CATALOG TELEMETRY COUNTED THE WRONG THING. `shard_count` is the number
of shards BUILT, and since an over-budget shard is now held back the two
can differ -- so a run that classified nothing would still have reported
a shard. `_write_shard_bundle` returns the DISPATCHABLE ids,
`prepare_catalog_bundle`'s meta gains `dispatchable_shard_count` beside
the unchanged `shard_count`, and the CLI line prints both.

TWO SCENARIO COUNTS WENT STALE when the ADDED requirement gained its
sixth scenario (*A dispatchable unit measures over the budget*): the
packet's tasks.md and the README OpenSpec Records entry both still said
five. Both corrected, and the README entry now also states the two
assembly shapes the requirement separates.

Raised by Copilot's re-review of ccb9c91, which reported no findings.

For opensoft/xFactory#479.

Lane: openxfactory-1
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 22, 2026 03:17

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Align document_cost separator accounting with the rendered JSON size to avoid unnecessary deferrals.

Review effort: Lite
Findings: None

@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap marked this pull request as ready for review September 22, 2026 03:44

@sourcery-ai sourcery-ai 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.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 7 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap

Copy link
Copy Markdown
Contributor Author

FREEZE — lane openxfactory-1, 2026-09-22T03:45:01Z: landing head 857166d6 by merge commit on Brett Heap's word "land the input-size guard when green" (recorded as a RULED line in the register; governing issue opensoft/xFactory#479). Gates at this head: required checks success, Copilot 0 threads, closingIssuesReferences empty, no closing keyword in any commit, merge preview on main cd246a0 passes plain validate-sequenced-after (44 active / 16 declaring) and openspec --all --strict (107 pass, the known add-chain-attestation), README OpenSpec Records bullet present. Rule 6 window follows.

Lane: openxfactory-1

@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-1 (openXfactory-1)

LANDING — lane openxfactory-1, session 393ade52-a921-4dd9-9dc5-224ebc056651@Eagle, 2026-09-22T03:45:15Z, PR #1137 into opensoft/openxFactory main

Guard at 2026-09-22T03:45:19Z on head 857166d636783047e40cd3831ea22852c6eba076: six required checks SUCCESS (lane-line, openspec-cli-pin, pytest-suite, release-tag-gate, signed-execution-chain-gate, wallet-validation); closingIssuesReferences = []; 0 unresolved threads; main's newest decided pytest-suite = success; no other-lane open LANDING into opensoft/openxFactory main (who --landing). mergeStateStatus BLOCKED = the code-owner-review ruleset that never clears on the author's own account; admin merge on Brett Heap's recorded word (input-size guard (parent side) + add-worker-input-budget draft packet; Brett Heap 2026-09-22 land the input-size guard when green). Merge = merge commit.

@brettheap
brettheap merged commit 9da52e3 into main Sep 22, 2026
16 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-1 (openXfactory-1)

LANDED — lane openxfactory-1, session 393ade52-a921-4dd9-9dc5-224ebc056651@Eagle, 2026-09-22T03:45:26Z, PR #1137 into opensoft/openxFactory main → 9da52e3

@brettheap
brettheap deleted the fix/semantic-sweep-input-budget branch September 22, 2026 03:47
brettheap added a commit that referenced this pull request Oct 6, 2026
…as they stand' (#1250)

Lane: openxfactory-1

## The two words

Brett Heap gave both words on 2026-10-06, in session to lane `openxfactory-1`. Both are RULED lines on the estate's lane register, with object `opensoft/openxFactory:openspec/changes/add-worker-input-budget`.

1. **The ratification.**

   > 0.4: (a) ratify as they stand

   It answers `tasks.md` 0.4, *"Ratify or amend the two spec deltas"*. The question was put to him as *"task 0.4: (a) ratify the two doc-health deltas as they stand, or (b) amend first"*, and he chose (a). RULED at **2026-10-06T13:55:03Z** (`opensoft/brett-wip` commit `06709554`, `lanes/log/openxfactory-1.md`).

2. **The origin file.**

   > #1250: (i) add the origin file

   It answers the RULING NEEDED this PR raised on Copilot's finding `r4196698454`. Option (i) was put to him as adding `.openspec.yaml` in the ratifying commit, with values following the 2026-08-25 origin sweep `b7513733`. RULED at **2026-10-06T17:24:57Z** (`opensoft/brett-wip` commit `f739ab74`).

This lane has held the change's claim since 2026-09-24T16:33:03Z.

## What is ratified

`add-worker-input-budget`'s two `doc-health` spec deltas, as they stand and with no amendment:

- **MODIFIED: *Sweep sequencing and snapshot consistency*** (three scenarios);
- **ADDED: *Bounded worker input budget*** (six scenarios).

The ratified text is `specs/doc-health/spec.md` blob `9a817d65`. That blob is the same at #1137's merge commit `9da52e31` and on `main`. **No requirement or scenario text moves in this PR.**

## The origin declaration, on the second word

**Why it is needed.** `document-lifecycle` § *Proposal origin declaration* says:

> A proposal whose own `Status:` declares `ratified`, or any standing beyond it, SHALL carry approval provenance in its origin.

This packet had no `.openspec.yaml`, and it was the only active change without one.

**What it declares.** The new `openspec/changes/add-worker-input-budget/.openspec.yaml` is hand-written in the form of sweep `b7513733`. Every value is derived from the packet's own record and is folded or plain, so the file parses:

- `schema: spec-driven`;
- `created: 2026-09-22`, from the packet's true first commit, `ee2185d6` (2026-09-22T01:26:47Z);
- `origin.kind: ad_hoc`. No `Staging ID:` header and no staging topic's exit names this change, checked in both directions;
- `origin.id: openxFactory:adhoc:2026-09-22-add-worker-input-budget`;
- a folded `reason` that quotes the second word;
- the drafting pair: lane `openxfactory-1`, on *"brief a writer to add the input-size guard"*, `proposed_on: 2026-09-22`;
- the approval pair: Brett Heap, *"0.4: (a) ratify as they stand"*, `approved_on: 2026-10-06`.

**What it changes.**
- `proposal-support.py verify add-worker-input-budget` now **passes**, where `main` refuses it with *"no origin declaration"*.
- `proposal-origin`'s WARNING for the missing origin is gone.
- No other finding moves.

## What this PR does not do

- **Group 4's 4.1 sequencing question stays open.** The *"Sequencing tension, named rather than hidden"* note in `tasks.md` asks Brett Heap a question. Was *"land the input-size guard when green"* the approved exception, or should 0.4 have gated 4.1? Neither word answers that question, and the note does not move.
- **No archive.** The archive is a separate act.
- **No other substance moves.** That covers proposal substance, `code_surface:`, `target_release:`, realization and the sequenced-after ledger row.
- **It lands by SQUASH.** The lane's coordinator lands it in a Rule 6 window. The archive PR is a separate landing, as a merge commit.

## Every changed line, file by file

**`openspec/changes/add-worker-input-budget/proposal.md`** (the front-matter header):
- `Status: draft` becomes `Status: ratified`.
- One line is added after it: `Ratified: 2026-10-06 by Brett Heap (openxFactory repository owner) — …`. The line carries:
  - the 0.4 word, verbatim, and the question as it was put;
  - the register RULED line;
  - both requirement names;
  - the #1137 `9da52e31` baseline;
  - "archives nothing" and "does not answer the Group 4 sequencing question on 4.1";
  - the record path.

**`openspec/changes/add-worker-input-budget/tasks.md`:**
- `- [ ] 0.4 Ratify or amend the two spec deltas.` becomes `- [x] 0.4 …`.
- Ten record lines follow it: the word, the question, the RULED line, both requirement names, the 4.1 question staying open, no archive, and the record.

**New: `openspec/changes/add-worker-input-budget/.openspec.yaml`** (52 lines): the declaration described above.

**`README.md`** (*OpenSpec Records* > *Active changes*, the `add-worker-input-budget` entry only):
- `` `Status: draft` `` becomes **`` `Status: ratified` ``**. A parenthetical gives:
  - the date, Brett Heap, the 0.4 word, "no amendment" and the RULED time;
  - the link to the record;
  - *"the origin declaration `.openspec.yaml` added on his second word, verbatim "#1250: (i) add the origin file", RULED 2026-10-06T17:24:57Z"*.
- The closing sentence changes. It read: "`Status: draft` is unchanged: …". It now reads: "Resolving the questions ratified neither spec delta; the 2026-10-06 word did (task 0.4). **RATIFICATION ONLY** — the archive is a separate later act on Brett Heap's word, and the Group 4 sequencing question on 4.1 stays open."

**New: `openspec/changes/add-worker-input-budget/review/ratification-2026-10-06.md`:**
- The header: `Status: ratified`, `Kind: report`, `Decision date:`, `Ratifier:`, one `Ratified:` citation and the ratified baseline.
- The sections:
  - Decision;
  - 1, the word;
  - 2, what the word does not decide;
  - 3, what this pull request changes, including the origin file and the second word, verbatim;
  - 4, a disclosure;
  - 5, the measurements, and the statement that this PR lands by squash.

**`ideation/staging/doc-health-sweep-carry-over/doc-health-sweep-carry-over.md`** (Copilot `r4198710846`, the first Conflicts bullet only):
- The status clause *"`add-worker-input-budget` is `Status: draft`, its two deltas unratified (its task 0.4)"* now says the packet is `Status: ratified` (task 0.4, Brett Heap's word of 2026-10-06) but still ACTIVE, not archived.
- A parenthesis records what the clause read before. The sequencing constraint, proposing this topic's change after that packet archives, is unchanged.

**Not moved:**
- `specs/doc-health/spec.md`;
- the Group 4 4.1 note;
- `tests/sequenced_after/corpus-ledger.yaml`.

## Precedent followed

- **#974** (`c521504c`):
  - `Status: draft` becomes `Status: ratified`, with one citation line in the lifecycle header;
  - the ruled box is ticked with its record;
  - the README row is moved in place, with a bold `Status: ratified` and the word and the record link;
  - a **RATIFICATION ONLY** tail;
  - a `review/ratification-<date>.md` record carries `Status: ratified` and ONE citation.
- **#1151** (`cd494e4c`): the closest case, an in-place ratification of a draft already on `main`. Copied: the one-line `Ratified:` form inside the front-matter, and the record's sections.
- **#1028**: the record header. `Decision date:` and `Ratifier:` accompany the citation.
- **#267**: the record-citing `Ratified:` spelling for an in-session ruling. Both citations clear the three-way floor, and each document carries exactly one citation in its 15-line window.
- **Sweep `b7513733`**: the `.openspec.yaml` form, on the second word:
  - `created` from the true first commit;
  - an `ad_hoc` id carrying the created date;
  - a folded `reason` derived from the record and checked in both directions;
  - the approval quoted from the packet's own citation.
- **Not copied:** `Status:` and `Ratified by:` on `tasks.md` and `design.md`. The packet has no `design.md`. Its `tasks.md` carries no `Status:` header to move, and `document-lifecycle` does not rule `tasks.md`.

## Landing: squash

**This PR lands by SQUASH, and only a squash landing conforms to the second word.** Option (i) was put as adding the origin file *in the ratifying commit*. On this branch the ratification is `a93865f0` and the origin file is the later commit `b3b7db42`, so only a squash puts the two into one commit on `main`. The record's § 5 says the same.

The archive gate's origin-retention walk takes the FIRST commit whose `proposal.md` declares `Status: ratified` as the ratifying commit. A probe on throwaway copies measured two landings:

- **Squash, the conforming landing:** the squash commit is the ratifying commit and carries the origin. The walk reads *"ORIGIN RETAINED … declaration unchanged since the ratifying commit"*. #974 and #1151 also landed by squash.
- **Merge, not conforming:** the walk takes `a93865f0`, which has no origin, as the ratifying commit, and reads *"ORIGIN RETENTION NOT COMPARABLE"*. The gate does not refuse that, but it leaves no retention baseline.
- **Rebase, not conforming and not run:** it would also land `a93865f0` as a commit of its own, ahead of the origin file.

## Observation (no change made)

`proposal.md` § Impact says *"two requirements MODIFIED, one ADDED"*. The delta has carried one MODIFIED and one ADDED requirement since its first commit, `ee2185d6`. The record's § 4 discloses this. It is not corrected here, because it is proposal text.

## How it was verified

All runs used full clones named `openxFactory`. The full set ran at the same time in two same-kind clones: `main` `51456835`, and this branch merged with it (`9e67f838`). The gates and doc-health then ran again on `main` `e6380965` and on `cc0fc853`. After that, the full set ran a third time on `main` `e6380965` and on `60c38a56`. All three runs gave the same results. The record's § 5 names each measured tree by sha (Copilot `r4198710942`).

Copilot's review `5433270341` at `60c38a56` raised no inline finding. Its "previously missed" note on record § 5 is answered in `7229fde4`, which rewrites only the record's landing paragraph to say this PR lands by squash. The gates and doc-health ran again on that tree against `main` `e6380965`, with identical results. The branch then merged `main` `c44c1610`, which archived `add-factory-mcp-conformance` (#1252) and touched no byte of this packet. The gates and doc-health ran once more, on `main` `c44c1610` and on that merge, `8dbb011e`. The results were again identical: `verify` exits 1 on `main` and 0 on the branch, and doc-health reports 284 against 282 finding lines, the difference being only the `proposal-origin` WARNING. Copilot's review `5433389325` at `8dbb011e` (thread `r4199425241`) asked that record § 5 list every tree measured. `6f4e98d1` rewrites that list as six runs, each named by sha. The gates and doc-health ran on it against `main` `c44c1610`, with identical results. Last, the branch merged `main` `a2dc658d` (#1254, no byte of this packet) as `35b17c30`, and the gates and doc-health on that merge against `main` `a2dc658d` were again identical. Its other note asks to put the Group 4 sentence *"is still open even as this line is written"* in the past tense. That note is left as it stands, because both briefs keep the Group 4 note untouched and the sentence is anchored to when it was written.

Because the carry-over topic changed, `tests/ideation_routing` and `tests/document_catalog` also ran on `main` `e6380965` and on `60c38a56`: 86 passed on each. `tests/ideation-dashboard` cannot be collected in a clone without the openDox and openXdox legs; CI runs it.

| gate | `main` | this PR |
| --- | --- | --- |
| `validate-openspec-cli-pin.py --all --strict` | exit 0; 1 failed item, `add-chain-attestation`'s accepted exception; 0 UNDISPOSITIONED | the same |
| `validate-openspec-cli-pin.py --change add-worker-input-budget` | exit 0; 1 passed | the same |
| `validate-code-surface.py`, `validate-target-release.py`, `validate-scope-globs.py` | exit 0 | the same output |
| `validate-sequenced-after.py .`, and with `--ledger-diff` | exit 0 | the same output; the ledger row does not move |
| `proposal-support.py . verify add-worker-input-budget` | **exit 1**, "no origin declaration" | **exit 0**, "proposal support verification ok" |
| `doc-health.py --single-repo . --as-of 2026-10-06` | 284 finding lines | 282: the same set without the `proposal-origin` WARNING's two lines. **No new finding.** The `modified-block-currency` INFO, which records the delta's deliberate rewording of canon's "is exactly" bullet, stays |
| `pytest` over `tests/doc-health`, `sequenced_after`, `review_lane_pin`, `proposal-support`, `code_surface`, `target_release`, `packet_reference`, `citation_remainder`, `scope_globs`, `former_id_arrival` and `openspec_cli_pin` | 3581 passed, 7 failed and 3 skipped | the same, with the same 7 tests failing. All 7 come from the clone, whose `openDox` and `openXdox` legs were not initialized. CI runs the full suite |

**The citation checks were proven to read both files, on a throwaway copy:**
- damaging either `Ratified:` line raised a CRITICAL `ratified-provenance` finding naming the damaged file;
- removing the proposal's citation raised one;
- giving the record `Status: record` raised one.

The intact files raise none.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 6, 2026
…l request in the README

--moved-by needs a real pull-request number, and this branch had none
until #1258 was opened, so the row is seeded here rather than in the
archive act. This follows the order 5216c70 and 14920ec used.

Seeded by the machine, not by hand:

  python3 scripts/validate-sequenced-after.py . --seed-ledger --moved-by '#1258'
  -> wrote tests/sequenced_after/corpus-ledger.yaml (232 rows, 1 moved by #1258).
  python3 scripts/validate-sequenced-after.py . --ledger-diff
  -> per-change sweep ledger consistent with the corpus (232 rows).

The diff is one line: add-worker-input-budget's row goes from state active
to archived, moved_by "#1137" -> "#1258", and
moved_on 2026-09-22 -> 2026-10-06. A flipping row takes its archive
directory's date. No other row moved.

README: the archived bullet's ARCHIVE-PR-NUMBER-PENDING marker (two
occurrences, one line) now names PR #1258.

Refs #1250

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 8, 2026
…t Heap's word 'ratify 1262 when ready' (#1264)

Lane: openxfactory-1

Drafts and RATIFIES the OpenSpec change `amend-worker-input-budget-dispatch-wording`, the amendment #1262 asks for. Refs #1262.

**Ratified in place, as drafted, on Brett Heap's word *"ratify 1262 when ready"*.** No requirement or scenario text moved at ratification: the spec delta is blob `eead8960` at every commit of this PR. The archive is a separate act on its own word.

## The words

Brett Heap, verbatim, in session on 2026-10-07. Each is a RULED line on the lane register (`opensoft/brett-wip`, `lanes/log/openxfactory-1.md`) except the second, which the issue itself records.

1. *"(a) land as ratified, amend later"*. His ruling on Copilot's comment [`4202036546`](#1258 (comment)) at #1258. RULED at 2026-10-07T09:42:21Z (commit `98b8b3d4`).
2. *"log the issue to change this"*. The lane filed #1262.
3. *"draft the amendment change for 1262"*. This PR.
4. *"ratify 1262 when ready"*. RULED at 2026-10-07T09:58:32Z (commit `f6964352`). Its condition held at `5b3edf14`: every required check green, `pytest-suite` included, and Copilot's review `5441182701` recommending approval with one low-severity citation fix, taken in `5d236d7d`. The ratification is commit `3a7ba60c`.
5. *"yes, land it when green"*. RULED at 2026-10-07T10:04:03Z (commit `43e9a5c2`). This PR lands by SQUASH, by the lane's coordinator, inside a Rule 6 window. The squash commit is then the ratifying commit on `main`, and it carries the origin's approval pair. Closing #1262 still needs its own word, and the archive is a separate later pull request.

## What changes

One `## MODIFIED` requirement in `doc-health`, *Bounded worker input budget*. Only the last sentence of its second paragraph is replaced.

As promoted (canon on `main` `16779816`, lines 4083-4087):

> Where the WORKER assembles the prompt from a dispatchable unit the orchestrator prepared, the orchestrator SHALL measure each unit's assembled size, record it, and SHALL NOT dispatch a unit it has measured over the budget — dispatching one and letting the worker refuse is conformant but useless, because the same unit is selected again next run.

As amended (#1262's text, verbatim):

> Where the WORKER assembles the prompt from a dispatchable unit the orchestrator prepared, the orchestrator SHALL measure each unit's assembled size, record it, and SHALL NOT dispatch a unit it has measured over the budget. The worker's refusal of an over-budget input (scenario "A worker receives an input over the budget") is a backstop that keeps such an input from reaching the model. It does not make an over-budget dispatch conformant, and relying on it wastes the run, because the same unit is selected again next run.

`diff` of canon's block (`openspec/specs/doc-health/spec.md`:4070 to the end, 52 lines) against the delta's block gives one hunk:

```diff
17,18c17,21
< measured over the budget — dispatching one and letting the worker refuse is
< conformant but useless, because the same unit is selected again next run.
---
> measured over the budget. The worker's refusal of an over-budget input
> (scenario "A worker receives an input over the budget") is a backstop that
> keeps such an input from reaching the model. It does not make an
> over-budget dispatch conformant, and relying on it wastes the run, because
> the same unit is selected again next run.
```

The title, the first and third paragraphs and all six scenarios (16 bullets) are byte-identical to canon. The archived delta under `openspec/changes/archive/2026-10-06-add-worker-input-budget/` is history and is not edited.

## Task 1.1: the realization never dispatches over budget (CONFIRMED)

#1262's acceptance 1, checked read-only:

- `scripts/doc_health/catalog_dispatch.py` at #1137's merge `9da52e31`:
  - :513-515 measures each shard's assembled input in bytes;
  - :516-517 adds the shard to the dispatch list only when it is `<= input_budget_bytes`;
  - :527-528 writes `shards.json` from that list alone;
  - :535-543 records the rest as `shards_over_budget`.
- On `main` `16779816`, the gate is at :521-522 and the write at :532-533.
- The worker reads only that list. `opensoft/xFactory` `.github/workflows/doc-health-cataloger-worker.yml`:171-175 takes `ids[0]` of `shards.json` and exits 0 when the list is empty. The file is identical at `b2479b6e` (xFactory#481) and at `main`.
- `tests/doc-health/test_semantic_input_budget.py`:503, `test_a_shard_measured_over_the_budget_is_never_dispatched`, asserts that the over-budget shard is not dispatched.

So the amended sentence describes behaviour that already holds, and `code_surface: none` is measured, not assumed.

## The ratification (commit `3a7ba60c`)

Following #1250's pattern (`3cec62fd`), in one commit, so the ratifying commit also carries the approval pair:

- `proposal.md`: `Status: draft` becomes `Status: ratified`, with one `Ratified:` line citing the word, the RULED line and the record;
- `tasks.md`: `Status: ratified` with a `Ratified by:` line; boxes 0.1 and 0.2 ticked with the word;
- `.openspec.yaml`: `approved_by` (Brett Heap, the word verbatim) and `approved_on: 2026-10-07` ADDED after the drafting pair. Every existing field is unchanged, checked by parsing both versions;
- `review/ratification-2026-10-07.md`: the record (`Status: ratified`, `Kind: report`, `Decision date:`, `Ratifier:`, one `Ratified:` citation and the ratified baseline);
- `README.md`: the *Active changes* entry in its ratified form, ending **RATIFICATION ONLY**.

Not moved: `specs/doc-health/spec.md`, the ledger row and the self-gate row.

## Files

- `openspec/changes/amend-worker-input-budget-dispatch-wording/`:
  - `.openspec.yaml`: an `ad_hoc` origin written by `proposal-support.py declare-adhoc` with the drafting pair, the approval pair added at ratification, and a `related:` list;
  - `proposal.md`, `tasks.md`, `review/ratification-2026-10-07.md`;
  - `specs/doc-health/spec.md`, the one delta.
- `README.md`: the *Active changes* entry.
- `tests/doc-health/test_modified_block_currency_self_gate.py`: one `_LEDGER_SUBJECTS` row, with its docstring count and chronology. The carriage arm reports this block once, at INFO (1 of 25 units uncarried, which is the amended sentence). A `**Removed from canon by**` marker was not used, because the marker would be promoted into canon and carry the old sentence with it, which #1262's acceptance 3 forbids.
- `tests/sequenced_after/corpus-ledger.yaml`: the seeded row (`--moved-by '#1264'`).

Registered and not taken (`tasks.md` § 5): a code comment at `scripts/doc_health/catalog_dispatch.py`:527-528 and a test docstring at `tests/doc-health/test_semantic_input_budget.py`:506-508 still echo the old clause. Editing them would give a wording packet a code surface.

## Review

Copilot reviewed each head this PR asked it to:

- `5441182701` at `5b3edf14`: approval recommended, with one low-severity citation fix (`r4205972528`), taken in `5d236d7d`.
- `5441515765` at `3a7ba60c`, the ratifying commit: three non-normative record fixes (`r4206239376`, `r4206239452`, `r4206239504`), taken in `e9c63a18`. None touched requirement or scenario text; the spec delta is still blob `eead8960` and `.openspec.yaml` is unchanged.
- `5441560962` at `e9c63a18`: approval recommended, no findings.
- `5441620162` at `a2761b1f`, this head (after the merge of `main` below): approval recommended, no findings.

Every review thread is answered and resolved: 4 threads, 0 unresolved.

`main` then moved to `a38585e9` (#1266, `correct-naming-families-count`), and this branch took it by merge commit `a2761b1f`, never a rebase. The only conflict was the head of the README *Active changes* list, where both entries are kept, this packet's first, with no byte of either entry changed.

## Gates

Same-kind full clones named `openxFactory`.

**At this head, `a2761b1f`, against `main` `a38585e9`:**

| gate | `main` `a38585e9` | this head |
| --- | --- | --- |
| `validate-openspec-cli-pin.py --all --strict` | exit 0; 113 passed, 1 failed (the accepted `add-chain-attestation` exception), 0 undispositioned | exit 0; 114 passed, the same 1 accepted exception |
| `validate-openspec-cli-pin.py --change amend-worker-input-budget-dispatch-wording` | n/a (exit 2, no such change) | exit 0; 1 passed |
| `proposal-support.py . verify amend-worker-input-budget-dispatch-wording` | exit 0 | exit 0 |
| `validate-code-surface.py`, `validate-target-release.py`, `validate-scope-globs.py` | exit 0 | exit 0 |
| `validate-sequenced-after.py .` | exit 0 (47 active, 19 declaring) | exit 0 (48 active, 20 declaring) |
| `validate-sequenced-after.py . --ledger-diff` | exit 0 (233 rows) | exit 0 (234 rows) |
| `validate-former-id-arrival.py`, `validate-release-tag-gate.py` | exit 0 | exit 0 |
| `doc-health.py --single-repo .` | 31 critical, 22 error, 69 warning, 19 info | 31 critical, 22 error, 69 warning, **20 info**. The one added finding is this block's carriage-ledger INFO, named by the self-gate row. No other line moves: no `ratified-provenance` or `proposal-origin` finding names the ratified packet |
| pytest: `tests/sequenced_after`, `tests/proposal-support`, the self-gate module and `test_semantic_input_budget.py` | | 537 passed |

**Earlier, against `main` `16779816`,** the same validator and doc-health rows held at `24b7862b` (draft), `5b3edf14` (ledger seeded), `3a7ba60c` (ratified) and `e9c63a18`. At `24b7862b` the pytest subset (`tests/doc-health`, `sequenced_after` and nine more gate modules) and the whole suite (`--continue-on-collection-errors`) failed exactly the same ids as `main` (7 and 237, from the clone's uninitialized `openDox` and `openXdox` legs) plus the 4 `sequenced_after` ledger tests that fail until the row is seeded; at `5b3edf14`, with the row seeded, those modules passed (337 tests). CI's `pytest-suite` runs the whole suite with the legs. It was green at `5b3edf14`, and `gh pr checks` reports it at this head.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants