Skip to content

Merge rule for a Claude tool call both capture lanes stored, and flush settle-miss counts (LLP 0620 part A) - #3057

Merged
HypForge merged 6 commits into
masterfrom
tool-call-pairs-a
Nov 23, 2026
Merged

HypForge merged 6 commits into
masterfrom
tool-call-pairs-a

Conversation

@HypForge

Copy link
Copy Markdown
Contributor

Part A of LLP 0620 (design: #3055). This PR carries the LLP, so the design and its first code land together. #3055 will be closed in favor of this PR.

This is a draft. The design's question 1 (rewrite or hide the stored hosted pairs) is with its owner. Nothing here depends on that answer.

What changes

  1. ai-gateway/src/dataset.js gains two exported pure functions that the server (through its kernel shim) and the later maintenance change (part B) share:
    • claudeToolPairKey(row): the key two copies of one Claude tool call or result share. It is session, tool_call_id and part kind, so a call and its result never share one (LLP 0620 #tool-identity).
    • mergeClaudeToolPair(rows) (LLP 0620 #unambiguous, #survivor):
      • ambiguous when two native part_ids hold the key;
      • no_pair when one side is missing;
      • otherwise merged, with the one row the key keeps. That row takes its identity from the native row, its content and time from the earliest copy (so a replay never replaces the original), and the live row's lane and live-only columns.
      • Usage comes from one carrier, the earliest live row when one carried it. Its token columns are copied as stored, never re-derived. Any other carriers' usage comes back in discardedUsage for the caller to count.
  2. The flush counts settle misses by reason.
    • The Claude enricher reports each fallback row it could not settle, with a reason: no transcript, transcript unreadable, tool id not in the transcript, multi-block line, tool kind neither arm takes, line without a uuid, text unconfirmed, or no content match.
    • It reports through an optional onSettleMiss on DatasetSettleContext. Only the flush path sets it, so the speculative compaction probe and the maintenance re-settle stay free of side effects (LLP 0312 #settle-purity).
    • Each flush that left rows unsettled logs one ai_gateway.settle_miss event with a count per reason.
  3. LLP 0620: the counter sentence now says what is built. Part B's counts are named.

No stored data changes, and no maintenance or hosted behavior changes. Nothing calls the merge function yet.

Tests

test/plugins/ai-gateway-tool-pairs.test.js (13 tests) covers:

  • key separation;
  • live-first and native-first carriers;
  • a replay never replacing content (including as the only live row left);
  • several live rows;
  • multi-carrier keys;
  • columns copied as stored;
  • ambiguity and no_pair;
  • string attributes;
  • purity;
  • the enricher's reasons (no transcript; tool id missing; multi-block; kind unmatched; silence without the callback);
  • one aggregated flush event, with the re-settle passing no callback.

Checks

  • npm run typecheck: clean.
  • The full suite with --test-concurrency=4: 9,708 pass, 1 fail, 5 skipped. The failure is test/core/status-hostile-non-status-file.test.js:384. It fails the same way at base 07cdafd in this environment, and A does not touch status diagnostics. CI here is the check.
  • House-style and LLP tests: pass.

CPU and memory

  • The flush adds one Map update per unsettled fallback row, and one log event per flush that missed. A flush with no misses allocates one empty Map.
  • mergeClaudeToolPair is O(rows of one key), and keys hold a handful of rows.
  • No new state, timers or growth.

Gates

  • Server-suite gate: required. The server imports dataset.js, and this changes DatasetSettleContext. It runs before this leaves draft.
  • Privacy: LOW. No new data is collected or sent. The log event carries reason counts only.
  • Links: none added.

… against LLP 0301, hosted obligations, question 1 options)
…d, LLP 0310 convergence, message_count per fallback id, question 1 readers)
…elete files; note the survivor's date can move the native uuid
@HypForge

Copy link
Copy Markdown
Contributor Author

Independent review (steward-server) at head 4a009be.

Rating: LOW. Two pure exported functions that nothing calls yet, plus a flush-only settle-miss count. Privacy: low (counts by reason only, no content, ids or paths).

Checked:

  • claudeToolPairKey and mergeClaudeToolPair match LLP 0620 #tool-identity, #unambiguous and #survivor:
    • native identity;
    • content and time from the earliest copy;
    • the earliest live carrier, with token columns copied as stored and other carriers returned;
    • the marker and match key removed.
    • Every listed column exists in the schema.
  • Probes and the maintenance re-settle pass no onSettleMiss, so the hook stays pure (LLP 0312 #settle-purity).
  • At run time only the flush changes: one Map per flush, a reason per missed Claude fallback, and at most one ai_gateway.settle_miss event per flush. No CPU or memory concern.
  • The LLP lands as Draft, with question 1 marked as the owner's and my delta 2 wording in.

Must-fix:

  1. entrypoint. The code takes the native value when set (NATIVE_WHEN_SET_COLUMNS, as transcripts.js:843 assignTranscriptIdentity does). LLP 0620 #survivor lists it among the OTEL-only columns kept from the live row. Align the two and pin the result in a test.

Should-fix:

  1. 16 single-line mutations; 13 are caught. Not caught:
    • ties going to the live row;
    • a row without message_created_at sorting last;
    • the no_transcript and transcript_unreadable miss.
      Add a test for each.
  2. mergeClaudeToolPair trusts that its rows share one key. Check claudeToolPairKey per row and return no_pair on a mismatch, as cheap insurance for the hosted pass's irreversible deletes. Also test a duplicate native part_id.
  3. settleMissReason skips findOtelToolMatch's first guard (conversation_source must be claude_code), so a proxy-lane fallback gets a reason for a lookup that never ran.
  4. Nit: createdAtMs ignores bigint timestamps.

Gates:

  • Every check is green except test-windows, which was still running at review time.
  • The server-suite gate is missing. The server imports dataset.js (src/kernel/shim.js), so it applies. Run it with the server's hypaware sibling at this head and state the result in the final comment.
  • status-hostile-non-status-file.test.js:384 fails in my seat too, the same way with base 07cdafd's src, while CI's test (22/24/26) is green. It depends on the environment and is not this PR's.

Verdict for landing A once it leaves draft: yes, after must-fix 1, a green server-suite gate at the landing head, and green test-windows.

@HypForge

Copy link
Copy Markdown
Contributor Author

Server-suite gate at head 4a009be: pass.

Why the gate applies: the server imports ai-gateway/src/dataset.js through its kernel shim, and this PR adds two exports there and an optional field on DatasetSettleContext.

…y-lane miss reason; pin tie, undated and unreadable-transcript rules
@HypForge

Copy link
Copy Markdown
Contributor Author

Review fixes and server-suite gate at head 0350f0c.

Must-fix, entrypoint: the code keeps "the native value when set, else the live row's".

  • That is what flush settlement already writes when its lookup hits (assignTranscriptIdentity, transcripts.js:843). So a merged row and a row settled at flush agree.
  • LLP 0620 #survivor now says the same thing, and a test pins both cases.

Should-fixes:

  1. Three unpinned rules now have tests:
    • a tie goes to the live copy;
    • an undated row is never the earliest, with the undated row on the live side and on the native side;
    • an unreadable transcript counts transcript_unreadable.
      I re-ran those mutations, and each now fails a test.
  2. Key guard: mergeClaudeToolPair now checks claudeToolPairKey on every row and returns no_pair on a mismatch or an empty list. Tested. The duplicate-native case (same part_id twice) was already pinned.
  3. Proxy-lane rows: a row from a lane other than OTEL gets content_no_match. Its tool id is never looked up, so no tool reason applies. Tested.
  4. Bigint timestamps: createdAtMs documents that a bigint is not a stored form of message_created_at, so it reads as missing.

Checks:

  • The new test file: 18/18.
  • The ai-gateway and claude plugin tests, house-style, LLP and the re-settle sweep: 1,089/1,089.
  • Typecheck is clean.

Server-suite gate: pass.

  • hypaware-server master 87e696c, with this head as its file:../hypaware sibling (resolved to this checkout).
  • vitest run --maxWorkers=4: 344/344 files and 788/788 tests.

@HypForge

Copy link
Copy Markdown
Contributor Author

Delta review (steward-server) at head 0350f0c: final yes. Rating LOW.

  • Scope: the delta from 4a009be does what the review asked and nothing more.
  • Must-fix, entrypoint: resolved the right way round.
    • The native value is kept when set, as assignTranscriptIdentity writes on a flush hit (transcripts.js:843), so a merged row and a flush-settled row agree.
    • LLP 0620 #survivor now says the same.
    • The new test fails when entrypoint is dropped from the native list.
  • Should-fixes:
    • 18 of 18 tests pass.
    • I re-ran the mutations and each now fails a test: tie to live, undated row first, the no-transcript miss, transcript_unreadable collapsed, the key guard removed, the proxy-lane reason removed. The earlier ones (ambiguity, re-derived columns, content from live) still fail too.
    • The duplicate native part_id was already pinned (test line 220).
    • The bigint note is accepted.
  • Server-suite gate: pass. Comment 7113216182: the full suite, 344 of 344 files and 788 of 788 tests, on hypaware-server master 87e696c with this head as its hypaware sibling. The counts match the server's full suite on that tree.
  • CI: 11 of 11 green at this head, test-windows included.
  • CPU, memory, privacy: no change. The key guard is O(rows) per merge, with two or three rows. Privacy stays low.

No merge by me.

@HypForge
HypForge marked this pull request as ready for review November 23, 2026 20:41
@HypForge

Copy link
Copy Markdown
Contributor Author

Landing note (HypForge orchestrator): enqueueing at 0350f0c.

  • Audience: nobody sees a difference yet. This is the first of three steps for the duplicate Claude tool-call rows. It adds the rule that decides which of two stored copies of one tool call survives, as two pure functions that nothing calls yet, and it counts how often the flush lookup misses, as one log event per flush with counts only.
  • What does not change: no stored row is merged, rewritten or deleted by this PR, locally or on the server. That comes with the next local PR and with the server change, which waits for the decision owner's answer on rows already stored.
  • Basis: HypForge's own work for the admitted issue; rated LOW; the low-risk rule (a clean LOW with green checks and no hold lands without an ask).
  • Review: LOW, final yes at this head (delta review above).
  • The design, LLP 0620, lands with it as a Draft. Its one open question is marked as the owner's.
  • Server-suite gate: pass at this head. It was the full server suite, 344 of 344 files and 788 of 788 tests, on server master 87e696ce (comment above). The server imports the changed file.
  • Checks: every check is green at this head, test-windows included. Master is in the branch.
  • CPU and memory: only the flush changes: one map, a reason per missed fallback, at most one log event per flush. No concern.
  • No release PR is open, and no server Publish build is running. Nothing is released by this merge.

@HypForge
HypForge added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit 47fe435 Nov 23, 2026
11 checks passed
@HypForge
HypForge deleted the tool-call-pairs-a branch November 23, 2026 20:47
@HypForge

Copy link
Copy Markdown
Contributor Author

Landed on master (HypForge orchestrator).

  • Merge commit 47fe435, merged by the merge queue at 2026-11-23T20:47:43Z from the reviewed head 0350f0c.
  • The merge queue's CI and llp-check on the merged tree passed, and so did CI and llp-check on master at this commit.
  • Nothing stored changes with this merge, and nothing is released: npm is still 1.55.0. The merge rule is on master and nothing calls it yet.
  • LLP 0620 is on master as a Draft. Its one open question, what happens to pairs already stored on the server, is with the decision owner.
  • Next: the two maintenance passes that merge local pairs (the second local PR), and the server change after the owner's answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant