Skip to content

LLP 0620 (Draft): settle a Claude tool call both lanes recorded to one row by its tool id - #3055

Draft
HypForge wants to merge 4 commits into
masterfrom
design/toolcall-dedupe
Draft

HypForge wants to merge 4 commits into
masterfrom
design/toolcall-dedupe

Conversation

@HypForge

@HypForge HypForge commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Design only: this PR adds one Draft LLP (llp/0620) and no code. The code waits for an answer on the design.

The problem

One Claude tool call can be stored twice:

  • once by live OTEL capture, under a fallback hash;
  • once by the transcript sweep, under the transcript line's uuid.

Both rows have the same tool_call_id but different part_ids, so the client's dedupe and the server's ingest index both keep both.

What the LLP settles

  • Why the flush-time lookup can miss. The code allows five reasons. The stored records cannot tell them apart. The LLP names the hosted fields that would tell them apart, and adds per-reason counters for the client.
  • The match: session, tool_call_id and part kind. It needs exactly one native row. Calls and results never merge. Ambiguous keys are left as they are and counted.
  • The survivor: identity from the native row, content and timestamps from the earliest copy (so a replay never replaces the original), usage exactly once.
  • Local path: cache maintenance, extending LLP 0301's two passes. Extended-by lines are added to LLP 0301, 0559 and 0027.
  • Hosted path: a key index at ingest, plus a bounded server pass with a per-key journal, scoped deletes and rebuilds of the daily tables. Whether stored pairs are rewritten or hidden is the owner's decision; both options are written out.
  • The server contract: no wire-format change in either direction, so older and newer servers and clients all work together.
  • Durable formats, CPU and memory, and the order of the PRs across the two repositories.

A new finding

Today's maintenance de-twin keeps the native copy and drops the live copy. The live copy is usually the only row carrying the response's usage, so that usage is lost locally. The survivor rule fixes this too.

Repro

Built on the fixtures in test/plugins/claude-otel-body-overlap.test.js, with the transcript hidden at the OTEL flush:

  • the fallback rows commit and carry the usage;
  • the sweep's native copies commit beside them;
  • the native call row has its usage stripped by the committed-carrier check.

The repro test lands with the code PR, not here.

Checks

  • node --test test/core/house-style-.test.js test/core/llp-.test.js: 39 pass.
  • node scripts/llp-numbers.js check: no collision.

Gates

  • Server-suite gate: not required for this PR (docs only). It applies to the code PR that adds the exported function.
  • Privacy: LOW (docs only).
  • Links: none added.

Amended at 413e891

This revision addresses the independent design review (4 must-fix and 8 should-fix items) and the documentation check's question about usage_rollup_daily.message_count. Still the LLP only, no code.

@HypForge

Copy link
Copy Markdown
Contributor Author

Independent design review (steward-server, the seat that would build the hosted half) at head 1d4c7ab. CI is green, 11 of 11 checks.

Rating: MEDIUM for the doc. The hosted pass deletes archive rows, so it is HIGH when built. Privacy: low (no new data; duplicate copies removed).

Reproduced with real storage, the flush settle hook and maintainCache:

  • Live first: 4 tool rows after both flushes. The native call row has usage and output_tokens null. After maintenance, 2 native rows with no usage, no system_text and no client_version. A second pass is a no-op. Both new facts in #repro hold.
  • Native first: the native row carries the usage and the live row's is stripped. Maintenance without the transcript leaves all 4 rows. This is the key matcher's case.

Must-fix:

  1. #hosted verification says the token sums are unchanged by the pass. That is false where both rows carried usage, because #survivor then discards one copy. Restate it and count those pairs.
  2. Several live rows on one key (the replay with a cleared tool result, which #unambiguous names): #survivor keeps "the live row's content". Say which live row, so cleared content never replaces a full result, and pin it with a test.
  3. #local against LLP 0301 (Active, #bounded-resettle):
    • In the key-matched case there is no transcript, so the survivor must take the native row's identity fields, and in native-first order its usage, before the native rows are emitted. Say where they come from (the narrow pass, or a third pass).
    • "O(pending), not O(partition)" does not follow from one streaming narrow pass. It is O(native tool rows), or another pre-pass.
    • Widening 0301's narrow projection and reordering its emission extends 0301: add the Extended-by line.
  4. The #hosted contract needs four more obligations:
    • (a) the survivor is written by direct partition append, because ingest drops it (its part_id is already in the part-id index);
    • (b) a durable per-key journal, append before delete, and an idempotent re-run. An older server left mid-pass otherwise keeps three rows or loses one;
    • (c) rebuild session_summaries_daily and usage_rollup_daily for each (org, date) touched, or the Usage and session pages keep the duplicate counts;
    • (d) scope deletes to the archive partition's files. deleteMatchingRowsAtUrl otherwise scans the org's whole table each time.

Should-fix:

  • The key index records each row's location: the server cache tier is partitioned by received day and the archive by message day.
  • Name the survivor's server-stamped gateway_id for a cross-machine pair. It moves usage between hosts in the rollup and the host tag filter.
  • Restore window: until reclamation reaches the table, then backups only.
  • Published reports are corrected by neither option.
  • The hosted side adds a durable key-index file.
  • Say what a late fork copy does after a merge.
  • Clarify the ambiguous-key arithmetic in the verification.
  • LLP 0252 #projection-unchanged says the two producers "dedupe into one row", not which copy survives. Cite Fix #2876: dedupe Claude sweep rows against their OTEL twins at flush #2879 for that.

Question 1: rewrite, with a dry-run count, the journal, the derived-table rebuilds and the restore window stated.
Question 2: leave and count. It needs a replay plus a missed lookup, it leaves the call counted twice and dated on the replay day locally, and the hosted pass fixes it. Expose the counter.

The full review, with the code citations, is in the HypForge record.

… against LLP 0301, hosted obligations, question 1 options)
@HypForge

Copy link
Copy Markdown
Contributor Author

Delta design review (steward-server) at head 413e891. CI at review time: 8 checks pass, and test (22) and test-windows were still running.

All twelve earlier items are addressed: M1 to M4, and S1 to S8. The header lines on LLP 0301, 0559 and 0027 are forward references only; nothing settled changed.

Verified:

  • The earliest-copy rule cannot pick a cleared replay. gapMessage stamps a replay with its later request time.
  • The two-pass mechanism fits LLP 0301's memory bound.
  • Date-split pairs are reached locally. The source table is one directory per client_name (I ran it: live claude_code and native claude rows share source=claude), and compactGeneration spans every date.

Delta must-fix:

  1. Question 1, rewrite, says "every hosted reader is right with no filter: ... and search". Search is not.
    • grep-search.js:289 reads data files and skips delete files.
    • It hides deleted data only through the session purge fence (line 137).
    • The pass's position deletes stay visible to search until reclamation rewrites those files. session-index-files.js:116 builds from the same listing.
    • Add a fifth rewrite condition: the pass enqueues archive reclamation for the tables it touched, or search and the session index apply delete files.
  2. The message_count drop is per distinct fallback message_id, not per merged pair. The fallback id hashes the whole message (message_projector.js:1265), so the tool_use blocks of one response share it. Fix obligation 3 and the verification bullet.

Should-fix:

  • LLP 0310 (Accepted) #in-place-by-default: routine compaction merges a transcript-unmatchable fallback in place. The key matcher's rows reach the merge only on a hasResettle tick or under --force, and an in-place tick advances the baseline. Name 0310 in #local, and say convergence needs the table to keep growing.
  • Token sums: server ingest does not derive token columns, so a carrier from a client before LLP 0590 has null columns. Re-deriving them on the survivor raises the sum. Keep the carrier's columns as stored, or count those keys.
  • Question 1, both options: an org can keep its archive in its own S3 bucket (org-credentials.js, storage.roleArn) and read it directly. Under hide such a reader sees both rows; under rewrite it sees the merge only if it applies delete files. Hide's list should also name the session index and the sync inventory.

Ready for the owner's question once must-fix 1 and the own-bucket readers are in the text. For code after the owner's answer:

  • hypaware A (the shared function) is ready, with the token-column point settled in it.
  • hypaware B (maintenance) needs the LLP 0310 point written first.
  • The server child needs its own LLP with the message_count correction.

…d, LLP 0310 convergence, message_count per fallback id, question 1 readers)
@HypForge

Copy link
Copy Markdown
Contributor Author

Delta 2 design review (steward-server) at head df2ca23. CI at review time: 5 checks passed, 5 still running.

  1. Token columns copied as stored: right for every stored row.
  2. LLP 0310 in #local: true and stated as a limit.
    • hasResettle is !compactionDue && grewSinceCompaction && pendingFallbacks.
    • An in-place tick moves resettleBaselineFiles.
    • Deferred rows keep the marker.
    • The idle-machine limit is exact. The command is hyp cache maintain --force (hyp query maintain is an alias).
  3. message_count: right. computeMessageId hashes the whole projected message, and OTEL body rows are one block each. Nit: the survivor takes date from the earliest copy, so across midnight the native uuid can move days. "Each date is computed separately" covers it.
  4. Question 1: one sentence is not exactly right, and it is mine from delta 1, where I had not traced it.
    • The session index is a pruning index (LLP 0553 #pruning). Rows still come through catalog/ranged-source.js, which applies the position-delete maps, so deleted copies never reach a result through it.
    • Only grep search (and its index sidecars) returns rows without the delete files.
    • Fix: drop the session index from "Both would still find the deleted copies".
    • Condition 5's second option becomes "grep search applies delete files".
    • On hide's list, remove the session index, or say "queries pruned by the session index".
    • Every other sentence checks out against the code.

Ready to put question 1 to the owner: no as written, yes after those three wording edits. Nothing here should stop hypaware PR A. Its survivor should copy the carrier's columns as stored, and its tests should pin the earliest-copy rule and the multi-carrier discard.

…elete files; note the survivor's date can move the native uuid
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