Skip to content

Add @Confined correctness contract for call- and frame-confined types - #12997

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
dougqh/confined-correctness-contract
Nov 17, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
masterfrom
dougqh/confined-correctness-contract

Conversation

@dougqh

@dougqh dougqh commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds a second contract family next to the perf contracts:

  • @CorrectnessContract: a meta-annotation for rules code must follow, in the RFC 2119 sense. A violation is a bug, not a tradeoff. Unlike @PerfContract there is no suppression: code that needs to break the rule shows the contract is wrong for that type, so the annotation changes instead of the use being exempted. (@SuppressPerfContract naming one is already invalid, since its value must be perf contracts.)

  • @Confined(Extent), the first correctness contract: where an instance stays valid.

    • CALL: only during the call it was passed into.
    • FRAME: only in the frame that obtained it, and completed on every path before that frame exits. For an AutoCloseable type, that means a try-with-resources (the same shape Error Prone's @MustBeClosed checks), unless the obtaining method returns it and hands the obligation to its caller.

    Both imply the instance never crosses threads. The rule follows the declared type: a subtype that doesn't carry the annotation is unconfined when declared as that subtype.

First user: TagMap.EntryReader → @Confined(FRAME). A store may answer with a flyweight it reuses for the next read or write, so a reader kept in a field or collection can later report another tag's value. Entry implements EntryReader and is the keepable form, which is why the rule goes by declared type.

AGENTS.md gets one review rule: when a change uses a type carrying a correctness contract, check it against that contract's Checker contract. Like the perf contracts, this is documentation plus a machine-readable checker contract for AI review; no static checker enforces it yet. The checker contract applies to production source sets: tests and benchmarks that misuse a type on purpose, to verify its behavior, are outside the rule.

Motivation

EntryReader's Javadoc says a reader MUST NOT be kept past the call that produced it, but nothing checks it. A review of #13004 (the dense id store, whose readers are reused flyweights) asked for a guard before dense tags go on by default. @NoEscape is close, but it is a SHOULD: retaining a @NoEscape value costs performance and can be exempted with a reason. Keeping a reader corrupts data.

Additional Notes

🤖 Generated with Claude Code

@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Oct 22, 2026
@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 90.91%
• Overall Coverage: 60.31% (-0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3040f2d | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.81 s 14.80 s [-0.7%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 13.65 s 13.69 s [-1.1%; +0.5%] (no difference)
startup:petclinic:appsec:Agent 17.13 s 16.90 s [+0.4%; +2.4%] (maybe worse)
startup:petclinic:iast:Agent 16.97 s 17.05 s [-1.2%; +0.3%] (no difference)
startup:petclinic:profiling:Agent 16.13 s 16.78 s [-7.9%; +0.2%] (no difference)
startup:petclinic:sca:Agent 17.08 s 16.99 s [-0.5%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 16.21 s 16.22 s [-1.2%; +1.1%] (no difference)

Commit: 3040f2d0 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh
dougqh force-pushed the dougqh/confined-correctness-contract branch from b017ada to 4c42be5 Compare November 13, 2026 14:54
@dougqh
dougqh changed the base branch from dougqh/apmlp-1642-queue-api to dougqh/unify-contract-package November 13, 2026 14:54
@dougqh

dougqh commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T15:58:24.564543Z 4c42be5 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 chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c42be57f2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@dougqh
dougqh marked this pull request as ready for review November 13, 2026 15:55
@dougqh
dougqh requested review from a team as code owners November 13, 2026 15:55
@dougqh
dougqh requested review from bric3 and removed request for a team November 13, 2026 15:55

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

The EntryReader documentation preserves the stricter rule that the next map read or write may invalidate a reader. @Confined(FRAME) adds a review contract without runtime enforcement.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4c42be5

@bric3 bric3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a couple comments over the codex findings,

@bric3 bric3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a few polish comments

Base automatically changed from dougqh/unify-contract-package to master November 16, 2026 14:26

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

The stream refactor preserves stable-entry materialization while exposing Stream, consistent with declared-type confinement. The contract explicitly permits producer-owned cursors, addressing the earlier iterator concern.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 31ab8d0

dougqh and others added 2 commits November 16, 2026 18:08
@CorrectnessContract marks annotations that state a MUST: breaking one is
a bug, so unlike a perf contract there is no suppression. @Confined, the
first, says where an instance of a type stays valid: CALL (the call it
was passed into) or FRAME (the frame that obtained it).

EntryReader is the first user. A store may answer with a flyweight it
reuses, so a kept reader can later report another tag; @Confined(FRAME)
lets review catch one stored in a field or collection. Entry implements
EntryReader and is the keepable form, so the rule follows the declared
type. AGENTS.md points reviewers at the checker contracts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TagMap's iterator keeps its look-ahead reader in a field, which the
every-extent rule forbade: the rule binds consumers, and the code that
produces and recycles an instance may hold the one it is handing out.
stream() yields stable Entry objects, so it is now typed Stream<Entry>;
under the declared-type rule, Stream<EntryReader> made collecting it a
violation. Also define CALL as a borrowed argument and FRAME as local
use, and link RFC 2119.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/confined-correctness-contract branch from 31ab8d0 to 74dbb1a Compare November 16, 2026 23:09

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Bits Code Review: PASS

More details

The stream refactor preserves stable Entry materialization, so collecting a stream does not retain reusable readers. The confinement contract also explicitly permits producers to hold the instances they recycle.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 74dbb1a

@pr-commenter

pr-commenter Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

LLM Validation

LLM Validation Gate — java-agent-instructions

✅ PASS

  • No blocking-case regressions; the quality change is within noise (baseline/candidate confidence intervals overlap).

6 case(s) · quality 81.4 → 81.2 (-0.1) · win-rate 50% [50%–50%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

No safety or blocking-case regressions across 6 case(s). Overall pairwise win-rate 50% [50%–50%], quality -0.1 — see the verdict above for whether that clears the noise band.

Results

  • Pairwise win-rate: 50% [50%–50%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 81.4 → 81.2 (/100, -0.1)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 23/27 (85%) — expected_criteria the candidate met; does not affect the gate
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 warn -0.6 50% [50%–50%] ok
java-unit-test-conventions-001 warn -0.6 50% [50%–50%] ok
java-premain-safety-001 warn -2.5 50% [50%–50%] ok
java-ci-download-guidance-001 warn +0.8 50% [50%–50%] ok
java-documentation-only-validation-001 warn +3.3 50% [50%–50%] ok
java-existing-spock-maintenance-001 warn -1.4 50% [50%–50%] ok

Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs.

The Javadoc promises extents run from narrowest to widest, so a new one
must go in its place, not at the end. Nothing executed the enum before,
which failed internal-api's coverage check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh

dougqh commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-17 21:04:33 UTC ℹ️ Start processing command /merge


2026-11-17 21:04:40 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-11-17 21:42:14 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-17 22:43:59 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b971a46 into master Nov 17, 2026
685 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/confined-correctness-contract branch November 17, 2026 22:43
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants