Skip to content

#3863: port tickets get a token budget (tiktoken when it loads, else bytes/4) - #3919

Merged
squid-protocol merged 6 commits into
mainfrom
feat/3863-ticket-budget
Sep 27, 2026
Merged

squid-protocol merged 6 commits into
mainfrom
feat/3863-ticket-budget

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #3863. The COACTVWC porting ticket was about 268 KB of prompt, and the Gemini porting agent returned nothing. 49 KB of the ticket JSON was facts.screen_bindings, full BMS field inventories that the generated *Screen classes already carry.

Change

  • count_tokens(text) -> (bytes, tokens, how) uses tiktoken's o200k_base when it loads.
    • tiktoken is an optional dependency, and its first use downloads the encoding. So any failure falls back to bytes/4, and the report says which method was used.
    • The encoding is loaded once per process.
  • trim_ticket(ticket, budget) and --ticket-budget (default 64,000 tokens; 0 turns it off):
    • A ticket within budget is left byte-identical.
    • An over-budget ticket has each screen_bindings fact's field inventory replaced by a reference to the generated screen class, with its field count. The class name follows the screen forge's naming, unless a name clash renamed it.
    • The ticket records trimmed (bytes and tokens before and after) and its section sizes.
    • A ticket still over budget after trimming says so in over_budget. The porting rules are never trimmed.
  • port_runner:
    • It prints the prompt's token count before sending.
    • An HTTP error or backend failure is logged with the error text; it is no longer scored as an empty port attempt. The HTTP body is decoded losslessly with decode_bytes.

This addresses item 1 of the proposal. Item 2, referencing facts the generated code already carries across more sections, is follow-up work.

Tests

tests/cobol_mainframe/test_port_ticket_budget.py:

  • counting with tiktoken, and the offline fallback when get_encoding raises;
  • under budget → byte-identical;
  • over budget → trimmed and recorded;
  • still over budget → recorded, with the rules untouched.

pr_gates.py: 7/7 pass.

🤖 Generated with Claude Code

squid-protocol and others added 3 commits September 27, 2026 14:59
…bytes/4)

An over-budget ticket trims facts.screen_bindings' field inventories to references to the generated
screen classes that carry them, records what was trimmed and its sizes before/after, and says
when it is still over budget; a ticket within budget is byte-identical. port_runner prints the
prompt's tokens and logs a backend error instead of scoring it as a port attempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

squid-protocol and others added 3 commits September 27, 2026 16:08
…ickets open sources via on_disk (#3815)

The ground-truth CI job has no tiktoken, so patching tiktoken.get_encoding failed at import. The
tests now put a fake (offline) or no tiktoken in sys.modules. Port tickets open program and
copybook sources through unicode_paths.on_disk, so an NFD-named file on Linux is found.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
import sys
import types
import math
from unittest.mock import patch
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