Skip to content

Memory, per-turn usage accounting, full AGY cognition, and durable-write fixes - #3

Merged
apresmoi merged 24 commits into
mainfrom
feat/operational-ecosystem
Aug 30, 2026
Merged

Memory, per-turn usage accounting, full AGY cognition, and durable-write fixes#3
apresmoi merged 24 commits into
mainfrom
feat/operational-ecosystem

Conversation

@apresmoi

Copy link
Copy Markdown
Collaborator

What

Memory is switched on. Mneme now flows end to end: recall into the prompt, recordTurn write-back after. Wired in-process rather than over MCP, because recall is prompt-side — MCP can only offer tools the model may call once the prompt exists, so it cannot prepend a recall packet, and write-back would depend on the model choosing to call a tool. The legacy generated-Pi runtime already did exactly this; the daimon organization runtime had lost the wiring.

Proven by a test that drives two real wakes and asserts turn 1's content reappears in turn 2's prompt.

Per-turn usage accounting. An advisory append-only ledger, one line per completed turn, 64 MiB rotation, written in the broker success branch after the completed record is sealed — not in the completed frame, which would permanently break crash-recovery replay. Grok and AGY are metered; codex is deliberately absent so it can never claim zero.

Validated against a live Grok frame: input 11828 · output 34 · cacheRead 5248 · total 17110 · $0.0045 for a two-word reply.

Counts are labelled a lower bound everywhere they surface. An all-zero usage block reads as unknown, not free — the vendor's own documented rule.

AGY becomes a first-class engine. Previously toolAccess: "none" and maxToolTurns: 1, so AGY agents could not use Moltnet and could not participate in an organization. That was Daimon policy, not an AGY limitation: AGY supports MCP and calls tools headlessly under --print, verified live against a probe server. Now registered through agy mcp add --type http against the same per-wake endpoint Codex and Grok get, scoped by the per-agent HOME so agents cannot collide.

maxToolTurns is 16, not unbounded: AGY's terminal usage frame is the sum over model steps and each tool step resends the whole context — measured, one call against an empty-schema tool takes a wake from 13,796 to 45,381 tokens.

AGY's non-spec server/discover handshake request is answered; every other unknown method still gets MethodNotFound.

Durability fixes.

  • The native broker build was broken on main: a style commit deleted two trailing blank lines from the .inc sources without regenerating the provenance sidecars, so source_sha256 mismatched. Restoring them fixes it with no digest re-pinning; rebuilding would have moved five pins.
  • Causal sequence allocation was a plain writeFile — 64 concurrent allocations all returned seq 1. Now temp-write → fsync → rename → dirsync, with an advisory lock across the read-increment-write.
  • acquireLease published the final filename before writing valid JSON. Now publishes via link(2), not rename(2) — rename overwrites unconditionally and would have turned a torn read into a double-lease bug.

Verification

408 tests, 404 pass, 0 fail, 4 skipped. tsc --noEmit clean. npm run build passes for the first time in this branch.

Every fix carries a failing-before test and a mutation check. Two worth noting: the causal-sequence in-process queue is a contention optimization only — correctness is owned entirely by the lock file; and the lease exclusion guarantee is pinned by a deterministic contract test (publish onto an existing name must fail EEXIST and leave content intact) rather than an unwinnable race test.

Not included

Session continuity via --continue/--conversation was assessed and rejected: it carries every prior wake's transcript into every future one with no compaction hook Daimon owns, converting a bounded per-wake cost into an unbounded one, and it breaks the at-least-once wake-replay semantics the contract manifest pins. --continue, --conversation, and -c are now rejected in commandArgs so it cannot be half-enabled.

@apresmoi
apresmoi merged commit ef75a90 into main Aug 30, 2026
1 check passed
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