Repository navigation
fix(memory): budget the rendered view and publish merges at once - #23
PermutationResearch wants to merge 3 commits into
Conversation
- size() counts the <chat> wrapper and every id+n|text line, not the node's own text. - A batch starts only when every view line is built and the view is over budget; it merges the most due pairs down to half. - A merged parent publishes immediately; compacting stays until the view fits the target with a sibling pair left. - mostDuePair is exported and used by coarsen, so the ports share one ranking. - Add the shared OptChat v1 conformance fixture as a test: 95 scenario steps plus 5 ranking cases.
- PI_OPENAI_STATEFUL=0: no server-side carryover, OptChat rebuilds the view each turn - memory tools on; only the rules judge gate left enabled - extension path resolves through symlinks, OMP_BIN/PATH fallback for the host binary
- A built parent now publishes its view inside the build, so the three summary crash stages kill with two acked records in the main log, not three. - Follows the batch rule from the conformance fixture.
|
CI is green at head The upstream run on this PR sits at Local replay of I don't have write access to this repository (both accounts on my side are read-only), so I can't merge. Ready when you are. |
What this fixes
Memory.size()budgeted summary node bytes, butrender()sends the<chat>wrapper plus${start}+${2**level}|${text}per line. The view the model actually receives was therefore largerthan the configured
viewBytes, and the batch gate never fired at the right moment.The shared conformance fixture (
docs/company-os/optchat.v1.conformance.json, generated from thereference
memory-core.mjsbyscripts/optchat-conformance-fixture.mjs) pins the correct semantics.Before this change optchat matched 49/95 scenario steps;
pi-durablematched 95/95.Behaviour changes
size()=CHAT_WRAPPER_BYTES+ the rendered bytes ofevery line (including its trailing newline).
lineBytes()is now the single place that answers"how many bytes does this part cost in the prompt".
once, instead of being held until the whole batch reaches
compactionViewBytes. The batch stayscompactingwhile it is over target and a due sibling pair exists, which is what the referenceimplementation does.
for longer, so the provider cache hit more often. The contract requires immediate publish, so this
trades some cache reuse for a view that is correct at every step. Worth knowing before merging.
mostDuePair()is exported and used bycoarsen(). The same ranking rule is duplicated incompanyos-durable/memory-core.mjsandcompanyos-pi-durable/src/optchat/memory.ts; exporting ithere keeps the three ports comparable and lets the conformance test pin the rule directly.
Tests
New
tests/conformance.test.tsreplays the shared fixture (95 append/build steps, byte-exact viewtiling, rendered bytes and target per step) and the 5 due-pair ranking cases. Existing memory,
memory-endpoint and store tests were updated to the rendered-byte contract — those assertions encoded
the old node-byte budgeting, so they were wrong rather than newly broken.
Not covered here
The full
bun testrun still shows ~196 failures in this environment, all in suites that spawn afixture HTTP server on port 0 and fail with
EADDRINUSE(tests/host/integration.test.tsand thegates/evidence suites that share
startCompressorServer) plusgit initreturning 128 in theevidence isolation helpers. Those are environment failures, not regressions from this change, but
they mean the host-integration path is unverified on this machine.
Also included (separate commit, easy to drop)
scripts/oc: the wrapper I run OMP with —PI_OPENAI_STATEFUL=0(no server-side carryover, OptChatrebuilds the view each turn), memory tools on, only the
rulesjudge gate on. It resolves symlinks soit works installed as
~/.local/bin/oc, and findsompvia$OMP_BIN,PATH, then the Tern installpath. Say the word and I will split it into its own PR.
Verification beyond unit tests
Live runs with the fixture in place:
oc --no-session -p "…"on a clean directory producesoptchat-dirs/<id>/{main,tree,view.json,metrics.jsonl}, and the rules gate writes{"type":"rules","pRule":1,"added":true}plus aledger.jsonlentry that a later fresh process canquote back verbatim.