Skip to content

CORE (signing sitting): v3 V3-04: reasoning trace chained per step (R3) - #69

Merged
githubscum merged 3 commits into
mainfrom
lotor-lane/v3-04-reasoning-per-step
Oct 22, 2026
Merged

githubscum merged 3 commits into
mainfrom
lotor-lane/v3-04-reasoning-per-step

Conversation

@githubscum

Copy link
Copy Markdown
Owner

What it does

V3-04, rung R3. Before this change, reasoning reached the chain only at session end, as a transcript hash and a thoughts/1 sidecar. Nothing bound an action to the reasoning that came before it. This PR adds that binding.

  • src/reasoning/index.js (new). At each tool call it reads the transcript forward from a per-session byte cursor. It collects the assistant's thinking and text blocks since the previous tool_use and appends one reasoning-step/1 receipt for that action. The receipt holds full SHA-256 digests, block counts, lengths, a segmentDigest and the kind of reasoning exposed.
  • src/ingest/index.js. The session-end pass recomputes every step from the whole transcript and reconciles it against the per-step receipts on the chain: matched, late (filled in here) or mismatched (surfaced, never smoothed). The result is a reasoning field (reasoning-trace/1) on the session receipt, bound by digest to a sidecar at <home>/reasoning/<session>-s<n>.jsonl. This follows the thoughts/1 pattern.
  • Hook wiring is NOT applied. It is in proposals/v3-04-hook-post-tool-use.patch: one import plus one never-throwing call in bin/hook-post-tool-use.js, placed before the egress fast path. bin/ is core, and the live self-mod gate blocks edits to bin/*.js in any checkout, this clone included. The builder did not edit it and did not route around that.

Lotor captures; it does not judge intent. R3 is recorded as evidence to read, never as declared intent.

Reasoning-kind taxonomy and detection

The kind comes from the blocks that actually landed, never from a requested think flag or a model id (V3-01: the think flag is a request, not a switch).

kind detection observed locally
thinking-unsigned thinking block, non-empty text, no signature yes (Ollama-routed glm, minimax)
thinking-signed thinking block, non-empty text, non-empty signature yes (Claude)
thinking-redacted redacted_thinking block, OR thinking with empty text and a non-empty signature (digest is taken over the opaque payload) yes, the empty-text-plus-signature form (Claude); no redacted_thinking blocks seen
text-inline-reasoning text block containing <think> or </think>: R3 leaked into R0 yes, rare
text-only visible text, no reasoning block yes
none nothing between the previous action and this one yes
unrecorded the step could not be read (see below). Never reported as none n/a

kind is the deepest kind present, in the table's order. kinds lists every kind present, so a mixed step loses nothing.

"Full" vs "summarized" thinking cannot be told apart from a Claude Code transcript. No marker distinguishes them; every thinking block carries the same fields (type, thinking, signature). So Lotor never asserts "full". thinking-signed means "readable, vendor-signed, fidelity undetermined", and thinking-unsigned is the nearest the record can show to full, without proving it. This matches V3-01 finding 6 and the spec's "reach overclaimed" risk.

Finding. The existing parser skips empty thinking blocks, so today signature-only thinking reads as "no thinking". That is R3 misfiled as absent. Locally this was the largest single class of thinking blocks for the current Claude models. The per-step path records it as thinking-redacted. The parser itself is unchanged here (it is out of scope, and changing it would move parserVersionHash).

Segments

  • A step's segment is every reasoning block after the previous tool_use and before this one.
  • Parallel calls (several tool_use blocks under one message id) share the segment and carry batchIndex 0, 1 and so on.
  • A real human prompt closes the open segment. Turn-end text is counted as unattributedBlocks at session end and is not credited to the next turn's first action.
  • isSidechain lines are skipped.
  • The hook payload's tool_use_id is the match key. Without it, the fallback is tool name plus canonical input digest, recorded as matchedBy.

Absence and the race

  • The hook fires before the tool_use line is flushed. The receipt gets status: unrecorded, kind: unrecorded, reason: tool-use-not-in-transcript, and transcript.partialLineBytes when a partial line was seen. A partial trailing line is never consumed. The session-end pass marks the step late with its real kind.
  • Other unrecorded reasons: no-session-id, no-transcript-path, transcript-missing, transcript-unreadable: <code>.
  • Denied calls get no PostToolUse, so their steps arrive as late at session end.
  • Malformed lines are skipped and counted (malformedLines). CRLF is stripped.
  • Truncated or rewritten transcripts, and a changed transcript path (resume), reset the cursor and are recorded in transcript.cursorReset. Rewrites are caught by a head digest over the first 4 KB. Already-claimed ids are never recorded twice.
  • Concurrency. Cursor read, advance and write run inside the chain lock (appendReceiptGuarded), so parallel hooks cannot interleave.

Privacy

  • No reasoning text is written to the chain, the cursor files or the sidecar. They hold only digests, lengths and counts. A test plants a canary in every reasoning string and scans every file under the temp home for it.
  • The transcript stays the only home of the text. A holder of the transcript can recompute every digest and check it against the chain.
  • Residual risk. A plain SHA-256 of a very short visible text block can be guessed by dictionary. This is the same posture as paramsDigest. A keyed digest would block outside verification. That trade-off is the owner's call.

Measured overhead (E5)

Synthetic data, this machine, in-process, 40 steps each, transcript about 0.9 MB:

chain entries chain size step median step p95 transcript capture median bytes per step receipt
0 0 KB 5.7 ms 6.9 ms 2.2 ms ~1.1 KB
1,000 457 KB 7.3 ms 11.0 ms 1.6 ms ~1.1 KB
10,000 4.6 MB 32.9 ms 39.5 ms 2.3 ms ~1.1 KB
30,000 13.8 MB 93.3 ms 143.5 ms 2.0 ms ~1.1 KB

The transcript side is flat because the cursor reads only the new bytes. Cost grows with chain size for one reason: createStore plus appendReceiptGuarded each re-read the whole chain on every append. That cost already exists today, but only on matched-rule calls. This PR makes it per tool call. The fix is a tail-only append in src/store, which is core and is not in this PR. It should be decided before the patch is applied on a large live chain. Node process start-up for the hook is not included: the hook process already exists.

npm test

ℹ tests 1075
ℹ pass 1074
ℹ fail 0
ℹ todo 1

Baseline on main @ 5198a07 was 1056 pass, 0 fail. The new tests are test/reasoning-per-step.test.js (17) and test/reasoning-hook-wiring.test.js (1, todo). They were confirmed failing first: with the module moved aside, the suites fail at import. Coverage:

  • the kinds, from synthetic fixtures
  • per-step binding: the reasoning between action 1 and action 2 lands on action 2 only
  • the offset read
  • parallel batches
  • the turn boundary
  • the name+input fallback
  • the unflushed race and its session-end late reconcile
  • missing transcript and missing path
  • CRLF and malformed lines
  • truncate or rewrite cursor reset
  • chain verification, where tampering with a step's kind breaks verify()
  • no text leak

No pin or freshness stamp was re-stamped, and none failed.

Left open, and why

  • test/reasoning-hook-wiring.test.js is todo. It asserts the wired hook lands one reasoning-step, and it fails until the patch is applied.
  • test/core-classification.test.js now lists src/reasoning as GRANTABLE, with the same reason as ingest. This is a proposal: keep it, or move it to CORE_DIRS plus selfModFragmentsForBase().

Overlap with parallel work

V3-03 (tool I/O digest) also edits bin/hook-post-tool-use.js. This PR's hook change is two hunks: one import, and one call just after parsePayload, before matchEgress. Apply them in either order. Expect a trivial context conflict in that region. V3-02 (reach certificate) can read R3 presence from reasoning-step.kind on the chain, which is computed from what was recorded, not from what was configured.

Signing-sitting steps

  1. Review src/reasoning/index.js, the ingest hunk and the patch.
  2. Decide the classification of src/reasoning (GRANTABLE as proposed, or core).
  3. Decide on the store tail-append (E5) before wiring on a large chain.
  4. Under signature, apply the patch: git apply proposals/v3-04-hook-post-tool-use.patch. If CRLF checkout trips it, add --ignore-whitespace.
  5. Remove the todo option in test/reasoning-hook-wiring.test.js, then run npm test.
  6. Optionally delete the patch file once it is applied.

🤖 Generated with Claude Code

githubscum added a commit that referenced this pull request Oct 22, 2026
The KNOWN-LIMITS numbering test requires contiguous entries, so numbers
follow the merge order #65, #66, #64, #63, #60, #62, #61, #67, #68, #69,
#70, #71: #62 takes 75, #61 takes 76, this PR takes 77. Every citation on
this branch moves with it (KNOWN-LIMITS.md heading and the limit 53 note,
src/views/matcher-history.js header, test/matcher-history.test.js comment).

On this branch alone the numbering test reports 75 and 76 missing; that
clears once #62 and #61 are on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
githubscum added a commit that referenced this pull request Oct 22, 2026
The KNOWN-LIMITS numbering test requires contiguous entries, so numbers
follow the merge order #65, #66, #64, #63, #60, #62, #61, #67, #68, #69,
#70, #71: #62 takes 75, #61 takes 76, #67 takes 77, this PR takes 78.
Every citation on this branch moves with it: KNOWN-LIMITS.md heading,
CHANGELOG.md, docs/receipt-coverage.md, and the V3-03 proposal note. The
staged .patch carries no limit number and is unchanged.

On this branch alone the numbering test reports 75, 76 and 77 missing;
that clears once #62, #61 and #67 are on main.

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

Copy link
Copy Markdown
Owner Author

Merge-order notes, no change pushed to this branch

Order: #65, #66, #64, #63, #60, #62, #61, #67, #68, #69, #70, #71. This PR adds no KNOWN-LIMITS entry, so it needs no renumbering. npm test on this branch as-is: 1075 tests, 1074 pass, 0 fail, 1 todo.

Expected conflicts (not rebased, per instruction):

  1. test/core-classification.test.js, GRANTABLE block: v3 V3-05: observe reach rungs from the response, never the request #60 lands first with reach in the spot where this PR adds reasoning. Keep both, reach first, and add a comma to the end of the reach line. This conflict was not in the original brief; I found it in a local simulation of the full order.
  2. src/ingest/index.js: CORE (signing sitting): v3 V3-02: reach certificate, measured not declared, on session receipts #70 (merges after this) conflicts here. It resolves on CORE (signing sitting): v3 V3-02: reach certificate, measured not declared, on session receipts #70's side: keep this PR's import and reasoning block first, then CORE (signing sitting): v3 V3-02: reach certificate, measured not declared, on session receipts #70's. Details are on CORE (signing sitting): v3 V3-02: reach certificate, measured not declared, on session receipts #70.
  3. Staged hook patches: this PR's proposals/v3-04-hook-post-tool-use.patch and CORE (signing sitting): v3 V3-03: tool I/O digest on post-tool-use receipts (R2) #71's proposals/v3-03-tool-io-digest-2026-10-22.patch both edit the post-tool-use hook, in separate hunks. On the fully merged tree they apply cleanly in either order, the second at a line offset only. Details are on CORE (signing sitting): v3 V3-03: tool I/O digest on post-tool-use receipts (R2) #71.

Full 12-PR simulation with these resolutions: 1225 tests, 1218 pass, 0 fail, 7 todo.

@githubscum

Copy link
Copy Markdown
Owner Author

Second-family review (minimax-m3): fixes and rejections

Every finding was checked against the code before any change. Commits: 043c34a (fixes and tests), a8404bc (.gitattributes). npm test: 1082 tests, 1081 pass, 0 fail, 1 todo (the todo is the hook-wiring test, removed at the sitting as planned). git apply --check proposals/v3-04-hook-post-tool-use.patch passes.

Rejected

B1 (hunk 1 malformed): false positive. Hunk 1 is unchanged. The hunk @@ -44,6 +44,7 @@ covers lines 44 to 49, and that includes the blank line 47. The patch carries it as a blank context line. Six old lines and seven new, so the header is correct. The reviewer misread that blank context line. The committed blob passes git apply --check.

There is a related problem the review did not name. With core.autocrlf=true (the Windows default, and the setting on this machine), the patch is checked out as CRLF. Its blank context lines then become \r, and git rejects the file as corrupt patch at ...:8 before it reads a hunk. The PR body's fallback, --ignore-whitespace, does not help, because this is a parse error and not a whitespace mismatch. I reproduced both. Fix: .gitattributes now has proposals/*.patch text eol=lf. The patch content is unchanged. After a fresh checkout the file is LF and git apply --check passes.

S3 (partialLineBytes off by one with no newline): does not hold. When lastNl === -1, chunk.length - (lastNl + 1) is chunk.length - 0, which is the whole chunk. The code was not changed. I added a test that pins this case (a chunk with no newline reports partialLineBytes === bytesRead === file size and toOffset === 0). That test passes on the original code too. The race test now asserts the exact byte count (40), not just > 0.

Fixed

B2: harness noise read as the operator. Confirmed. A <system-reminder> user line closed the segment and moved the pending reasoning to unattributed, so the next action was recorded as kind: 'none'. isHumanPrompt now decides on the text that is left after the chapters view's noise strippers run. It reuses claudeUserText, which is now exported from src/views/chapters.js. Adding the export is the only change there, so the chapters behaviour is unchanged and there is still one copy of the rule. Two rules are kept on top of it:

  • a line that carries a tool_result is never a prompt (as before);
  • a line with only an attachment (image or document) is a prompt, because only the operator attaches files. The chapters view does not open a chapter for an attachment-only line, so the two views differ on that one case.

The fail-first fixture has thinking, then a <system-reminder> user line, then a string-content <local-command-caveat> line, then a <local-command-stdout>/<local-command-stderr> line, then the tool_use. The step now keeps the thinking digest and has 0 unattributed blocks. A second test checks the other direction: operator text that sits next to a wrapper still closes the segment.

S1: KIND_ORDER vs the documented precedence. Confirmed. The code now matches the docs and the PR body: thinking-redacted ranks above text-inline-reasoning. A new test pins every adjacent pair in KIND_ORDER, with the shallower block placed first so input order cannot decide the result. The mixed-step test now covers the disputed pair.

S2: an unsigned empty thinking block was recorded as none. Confirmed, including the disagreement with the parser on whitespace-only blocks. Such a block is now thinking-empty, a new kind, with over: 'empty' and a digest over the blank text. It is the shallowest kind, after text-only. The channel was open but carried nothing, so this kind does not claim reasoning, and it is never none. A step now agrees with session.thinkingBlocks that a block existed. The taxonomy comment, KIND_ORDER and blocks.thinkingEmpty were all updated. The old test that locked in none now asserts thinking-empty.

Weak tests strengthened

  • The mixed step now includes text-inline-reasoning (S1 pair), and an adjacent-pair test was added.
  • The turn-boundary test now has realistic harness fixtures (B2). The bare-prompt case also asserts unattributedBlocks === 1.
  • Tamper test: it builds its own step, guards the findIndex with assert.ok(i >= 0), and holds under --test-name-pattern isolation.
  • text-inline-reasoning now also covers a bare <think> opening tag.
  • Cursor resets: transcript-rewritten and transcript-truncated each get a pinned test, and transcript-path-changed (resume) is now tested, including that a step claimed before the reset is not recorded twice. no-session-id is tested too.
  • Fail-first, run against the original src/ with the new tests: 4 failed (B2 fixture, S1 pair test, mixed step, S2). All pass after the fix.
  • The todo wiring test was left as it is, by design: the sitting removes it after the patch is applied.

Not changed (nits, verified by reading, out of scope for this pass)

N1 (the 4096-claim bound) and N2 (captureStep is exported and takes no lock) hold as described. N7 (the fast-path comment becomes false once the patch lands) is in hunk 2 and is left for the sitting. N3 to N6 are disclosure-level only.

Store cost: merge order

recordReasoningStep now calls appendReceiptGuarded(build, { withChain: false }). captureStep never reads the chain argument. The current store ignores the extra argument, and the suite is green on it. #69 must merge after #72 for the per-step cost to drop. Until then, every tool call still reads the whole chain, about 275 ms at 40k entries.

githubscum added a commit that referenced this pull request Oct 22, 2026
The KNOWN-LIMITS numbering test requires contiguous entries, so numbers
follow the merge order #65, #66, #64, #63, #60, #62, #61, #67, #68, #69,
this branch moves with it (KNOWN-LIMITS.md heading and the limit 53 note,
src/views/matcher-history.js header, test/matcher-history.test.js comment).

On this branch alone the numbering test reports 75 and 76 missing; that
clears once #62 and #61 are on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
githubscum and others added 3 commits October 22, 2026 15:30
New src/reasoning module: at each tool call, read the transcript forward
from a per-session byte cursor, collect the thinking and text blocks since
the previous action, and append one reasoning-step receipt (digests,
counts, lengths, kind). No reasoning text on the chain. Session-end ingest
reconciles every step (matched / late / mismatched) into a digest-bound
sidecar. The PostToolUse wiring is a patch under proposals/ for the
signing sitting; bin/ is core and was not edited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- B2: isHumanPrompt now decides "operator speaking" on the text that
  survives the chapters view's noise strippers (claudeUserText, exported,
  behaviour unchanged). A <system-reminder> or <local-command-*> user line
  no longer closes the segment and files the next action as none.
- S1: KIND_ORDER matches the documented precedence (thinking-redacted
  above text-inline-reasoning); a test pins every adjacent pair.
- S2: an unsigned empty or whitespace-only thinking block is now
  thinking-empty (shallowest kind), never none, so the step agrees with
  the parser's session.thinkingBlocks that a block existed.
- Store cost: appendReceiptGuarded(build, { withChain: false }). Ignored
  by the current store; with the tail-only store (PR #72) the per-step
  append stops reading the whole chain.
- Tests: fail-first system-reminder fixture, bare <think> tag, exact
  partialLineBytes, each cursor-reset reason pinned (incl. path-changed),
  no-session-id, tamper test self-contained with a guarded index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With core.autocrlf=true the staged .patch is checked out CRLF, its blank
context lines become "\r", and git apply rejects it as corrupt before
reading a hunk. --ignore-whitespace does not help. Patch content unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@githubscum
githubscum force-pushed the lotor-lane/v3-04-reasoning-per-step branch from a8404bc to e0f8609 Compare October 22, 2026 20:31
@githubscum
githubscum merged commit 5f41d2a into main Oct 22, 2026
githubscum added a commit that referenced this pull request Oct 22, 2026
Applied in the live install, each step signed by the owner:
- store: tail-only append (proposals/store-tail-append, #72); PENDING_LANDING flipped
  in the same change. Precondition: live chain 37,173 entries, seq continuous.
- hooks: V3-02 session-open reach certificate (#70), V3-04 per-step reasoning (#69),
  V3-03 tool I/O digest (#71), applied from git's stored patches.
- chain: canonicaliser keeps an own __proto__ key in the hash (found while fixing #70);
  existing hashes unchanged (live chain had zero such keys).
- tests: hook-wiring todo markers removed.

npm test: 1292 tests, 1292 pass, 0 fail, 0 todo.
Deferred to the post-merge evaluation: the #68 matcher line-ending fix, the
KNOWN-LIMITS pin re-stamp (needs re-verification of every limit), verifyChain seq
continuity, keyed digests, R2 on every tool call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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