-
Notifications
You must be signed in to change notification settings - Fork 0
fix(#407): commensurable term-fidelity byte meta + retain per-attempt artifacts #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| node_modules/ | ||
| node_modules | ||
| out/ | ||
| dist/ | ||
| bin/relayfile-mount | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { BYTE_ACCOUNTING_NOTE, deriveByteAccounting } from './byte-accounting' | ||
|
|
||
| // Pins the client-vs-broker byte derivation used in divergence-bundle meta. | ||
| // The whole point of the module is that the exact-2.0 codex artifact can no | ||
| // longer reach meta as an unlabeled, misreadable pair — so these tests assert | ||
| // the labels, the shared-baseline ratio, and the guard rails. | ||
| describe('deriveByteAccounting', () => { | ||
| it('reports a ~1.0 ratio for one-to-one delivery on a shared baseline', () => { | ||
| const acc = deriveByteAccounting({ | ||
| clientBytesReceived: 4096, | ||
| clientChunks: 12, | ||
| snapshotOffset: 4096 | ||
| }) | ||
| expect(acc.clientToBrokerByteRatio).toBe(1) | ||
| expect(acc.commensurable).toBe(true) | ||
| expect(acc.snapshotOffset).toBe(4096) | ||
| }) | ||
|
|
||
| it('rounds the ratio to 4 dp', () => { | ||
| const acc = deriveByteAccounting({ | ||
| clientBytesReceived: 1000, | ||
| clientChunks: 3, | ||
| snapshotOffset: 3000 | ||
| }) | ||
| expect(acc.clientToBrokerByteRatio).toBe(0.3333) | ||
| }) | ||
|
|
||
| it('surfaces (does not hide) the historic exact-2.0 reading, with the do-not-misread note', () => { | ||
| const acc = deriveByteAccounting({ | ||
| clientBytesReceived: 8192, | ||
| clientChunks: 20, | ||
| snapshotOffset: 4096 | ||
| }) | ||
| // The number is preserved for forensics — but it is explicitly labeled and | ||
| // carries the note so it can never again be read as "double delivery". | ||
| expect(acc.clientToBrokerByteRatio).toBe(2) | ||
| expect(acc.note).toBe(BYTE_ACCOUNTING_NOTE) | ||
| expect(acc.note).toMatch(/NOT proof of double PTY delivery/) | ||
| expect(acc.clientUnit).not.toBe(acc.brokerUnit) | ||
| expect(acc.clientBaseline).toMatch(/probe-install/) | ||
| expect(acc.brokerBaseline).toMatch(/worker-start/) | ||
| }) | ||
|
|
||
| it('yields a null ratio and non-commensurable flag when the broker predates offsets', () => { | ||
| const acc = deriveByteAccounting({ | ||
| clientBytesReceived: 500, | ||
| clientChunks: 4, | ||
| snapshotOffset: undefined | ||
| }) | ||
| expect(acc.snapshotOffset).toBeNull() | ||
| expect(acc.clientToBrokerByteRatio).toBeNull() | ||
| expect(acc.commensurable).toBe(false) | ||
| }) | ||
|
|
||
| it('yields a null ratio when the offset is zero (avoids divide-by-zero)', () => { | ||
| const acc = deriveByteAccounting({ | ||
| clientBytesReceived: 0, | ||
| clientChunks: 0, | ||
| snapshotOffset: 0 | ||
| }) | ||
| expect(acc.clientToBrokerByteRatio).toBeNull() | ||
| // The offset was present (0) so the baselines are still comparable. | ||
| expect(acc.commensurable).toBe(true) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Pure derivation of the client-vs-broker byte accounting recorded in each | ||
| // divergence-bundle `meta.json`. Kept dependency-free (no Playwright, no xterm) | ||
| // so it is unit-testable in isolation — and so the two byte figures can never | ||
| // again be dropped into meta as a bare, unlabeled pair that reads as an | ||
| // "exact-2.0 double-delivery" signal. | ||
| // | ||
| // Background (term-fidelity program, 2026-07-17): `quiet.activity.bytes` and | ||
| // `brokerOffset` read exactly 2.0 apart in 5/5 codex bundles. That was PROVEN | ||
| // NOT to be double delivery — a headless probe measured client-bytes / | ||
| // snapshot-offset = 1.0000, and BrokerManager does exactly one IPC send per | ||
| // worker_stream event. The 2.0 was a derivation artifact of pairing two figures | ||
| // that measure different things on (historically) unstated baselines. This | ||
| // module makes what each figure measures explicit and computes the ratio on a | ||
| // SHARED baseline so the number is meaningful. | ||
|
|
||
| export interface ByteAccountingInput { | ||
| // Client side: cumulative UTF-8 byte length of every `broker:pty-chunk` STRING | ||
| // this renderer received for the agent since the activity probe was installed. | ||
| // The probe is installed at harness launch, BEFORE the agent is spawned, so | ||
| // this series starts at the agent's very first byte (baseline = agent start). | ||
| clientBytesReceived: number | ||
| clientChunks: number | ||
| // Broker side: the attach snapshot's cumulative per-worker byte `offset` — raw | ||
| // PTY bytes the broker grid had consumed at capture, counted from worker start | ||
| // (offset 0). `undefined` on brokers that predate stream-offset support. | ||
| snapshotOffset: number | undefined | ||
| } | ||
|
|
||
| export interface ByteAccounting { | ||
| clientBytesReceived: number | ||
| clientChunks: number | ||
| snapshotOffset: number | null | ||
| // clientBytesReceived / snapshotOffset, rounded to 4 dp. `null` when the | ||
| // offset is absent or zero (no meaningful ratio). ~1.0 on a faithful | ||
| // one-IPC-send-per-chunk pipeline. | ||
| clientToBrokerByteRatio: number | null | ||
| // True when both figures share the agent-start baseline and are therefore | ||
| // directly comparable. (Always true when snapshotOffset is present, because | ||
| // the probe is installed before spawn; recorded explicitly so a future change | ||
| // that installs the probe mid-stream can flip it to false rather than silently | ||
| // producing an incomparable ratio.) | ||
| commensurable: boolean | ||
| clientBaseline: string | ||
| brokerBaseline: string | ||
| clientUnit: string | ||
| brokerUnit: string | ||
| note: string | ||
| } | ||
|
|
||
| export const BYTE_ACCOUNTING_NOTE = | ||
| 'clientToBrokerByteRatio compares client-received IPC bytes to the broker raw-PTY ' + | ||
| 'offset on a shared agent-start baseline. ~1.0 means one-to-one delivery. A ratio ' + | ||
| 'near an integer such as 2.0 is NOT proof of double PTY delivery — historically it ' + | ||
| 'was a derivation artifact (UTF-8 re-encoding of the decoded IPC string vs raw PTY ' + | ||
| 'bytes, and differing baselines). Never infer a delivery mechanism from this number; ' + | ||
| 'confirm duplicate delivery by counting BrokerManager IPC sends per worker_stream event.' | ||
|
|
||
| function round4(value: number): number { | ||
| return Math.round(value * 10_000) / 10_000 | ||
| } | ||
|
|
||
| export function deriveByteAccounting(input: ByteAccountingInput): ByteAccounting { | ||
| const hasOffset = | ||
| typeof input.snapshotOffset === 'number' && | ||
| Number.isFinite(input.snapshotOffset) | ||
| const snapshotOffset = hasOffset ? (input.snapshotOffset as number) : null | ||
| const ratio = | ||
| snapshotOffset !== null && snapshotOffset > 0 | ||
| ? round4(input.clientBytesReceived / snapshotOffset) | ||
| : null | ||
| return { | ||
| clientBytesReceived: input.clientBytesReceived, | ||
| clientChunks: input.clientChunks, | ||
| snapshotOffset, | ||
| clientToBrokerByteRatio: ratio, | ||
| commensurable: snapshotOffset !== null, | ||
| clientBaseline: 'activity-probe-install (installed pre-spawn ⇒ agent first byte)', | ||
| brokerBaseline: 'worker-start (snapshot offset 0)', | ||
| clientUnit: 'utf8-bytes-of-decoded-broker:pty-chunk-string', | ||
| brokerUnit: 'raw-pty-bytes-consumed-by-broker-grid', | ||
| note: BYTE_ACCOUNTING_NOTE | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the exact-2.0 scenario motivating this change, this still divides the unchanged
quiet.activity.bytesby the unchanged fullbroker.offset; the parent harness already installed the activity probe beforespawnRealAgent, so wrapping those values introduces no new shared-baseline adjustment. Moreover, re-encoded decoded-string bytes are not necessarily equal to raw PTY bytes. Consequently an existing 2.0 result remains 2.0 while the metadata marks itcommensurableand describes it as an artifact, potentially obscuring an actual duplicate or missing-delivery signal. Record comparable offset/delta metadata from the received events or explicitly mark this ratio non-commensurable.Useful? React with 👍 / 👎.