Skip to content

feat(cobol-to-java): AI-agent guardrail — agent changes checked against the verified skeleton (#3652) - #3692

Merged
squid-protocol merged 1 commit into
mainfrom
feat/agent-guardrail-3652
Sep 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feat/agent-guardrail-3652

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3652. Part of #3625.

What

The converter generates the Java skeleton and leaves the business logic for an AI agent. The agent's ticket says "use the verified skeleton, don't invent calls or resources". This checks that it didn't.

At generation: the controller writes guardrail_baseline.json, an inventory of the generated project. It records:

  • every class, with its fields, methods and endpoints;
  • the services, repositories and clients each class calls, plus the program's mock services for unresolved CALLs, which the ticket tells the agent to wire;
  • the SQL tables the project's own SQL names.

After an agent edits the project, or returns a ticket result:

python -m gitgalaxy.tools.cobol_to_java.cobol_to_java_guardrail <java project> [--result TICKET.json RESULT.json ...]
rule catches
unknown-call a changed class calls a service, repository or client its generated code never called (the COBOL program doesn't), or one that doesn't exist
new-component a new service, repository, controller, client, DTO or entity class: a program, file or transaction the skeleton doesn't contain
layout-changed a field added to or dropped from a generated DTO, entity or row class: outside the verified COMMAREA, container or record layout
unknown-table SQL naming a table the project's SQL never uses
new-endpoint a controller entry point the skeleton doesn't define
  • Violations exit 1, so the check can gate CI.
  • Notices don't block: a new helper class (for example in util/), or a deleted file.
  • Outputs: the report goes to agent_guardrail.md / .json and into the audit as section [4]; the section is replaced on each run, not appended. A ticket result gets a guardrail: {status: passed|rejected, violations} verdict written into its JSON.

Evidence

  • No false positives. On all 6 corpora × 3 configs I marked every generated file as changed, so every rule ran against 1,627 files. The result was 0 violations.

  • Planted hallucinations. A CardDemo copy with 6 planted hallucinations reported all 6:

    • a call to an existing service COACTUPC never calls;
    • a call to a nonexistent PaymentGatewayService;
    • SQL against CARDDEMO.CUSTOMER_LOYALTY;
    • a new field in CarddemoCommarea;
    • a new /refund endpoint;
    • a new RefundService.

    A new DateHelper in util/ came through as a notice only. A legitimate edit alongside them passed: it uses the program's own repository, its already-injected service and a library ExecutorService.

How it reads Java

It uses a small scanner, not a parser:

  • comments and string literals (including text blocks) are set aside;
  • braces are counted, and only class-level declarations are read;
  • annotations are stripped, so @Column(name = …) private String x; is still a field;
  • record components count as fields.

Library types are allowed when imported, or fully qualified (java.util.concurrent.ExecutorService).

Safety

  • The generated Java is byte-identical. The only new output is guardrail_baseline.json plus audit section [4] ("not run yet" plus the command). The refraction snapshots were re-blessed for exactly that.
  • tests/cobol_mainframe + tests/tools_recorders gave 889 passed. Preflight --java is all PASS.
  • The two new regexes follow the repo's ReDoS gate: ^[ \t]*, not ^\s* under re.M.
  • java_code is allowlisted in the dead-key audit, because it's written by the external agent, never by gitgalaxy.

Tests (test_agent_guardrail.py)

  • The reader: annotations, records, text blocks, comments and strings don't leak references, and the static logger is not a field.
  • Each rule: a legitimate edit passes (including the mock-service allowance), and each kind of hallucination is caught.
  • Ticket-result mode: passed and rejected verdicts are written into the result.
  • A real scan: generation writes the baseline, the untouched project exits 0, and a planted call to an existing-but-uncalled program exits 1 with the right program attribution. The audit section is replaced, not duplicated.

Scope notes

  • Violations are reported in the guardrail report, not added to migration_worklist. The worklist is what the generators left; the guardrail is what an agent changed.
  • Default runs don't generate agent tickets (features.agent_tickets). The project mode covers agents that edit files directly.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g

…st the verified skeleton (#3652)

Generation now writes guardrail_baseline.json, an inventory of the generated
project: each class with its fields, methods and endpoints, the services /
repositories / clients it calls (plus the program's mock services), and the SQL
tables the project's own SQL names. After an agent edits the project or returns a
ticket's java_code,

  python -m gitgalaxy.tools.cobol_to_java.cobol_to_java_guardrail <project> [--result TICKET RESULT]

checks the changed code and reports unknown-call, new-component, layout-changed,
unknown-table and new-endpoint violations. The report goes to agent_guardrail.md /
.json and into audit section [4]; a ticket result gets a `guardrail` verdict
(passed / rejected). It exits 1 on any violation.

On all 6 corpora x 3 configs, re-checking every generated file finds 0
violations. A CardDemo copy with 6 planted hallucinations reports all 6; the
legitimate edit alongside them passes.

Generated Java byte-identical; refraction snapshots re-blessed (the new baseline
file + audit section [4] only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit f6736eb into main Sep 26, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the feat/agent-guardrail-3652 branch September 26, 2026 00:26
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.

Java conversion: guardrail check of AI-agent output against the verified skeleton

1 participant