Skip to content

feat(core): discussion ledger, an append-only resumable state machine (#588 part 1b) - #667

Merged
ajianaz merged 2 commits into
developfrom
feat/discussion-log
Nov 13, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/discussion-log

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1b of #588: tole_core::discussion_log, the append-only ledger of a discussion and the state machine folded from it. Still no model call and no command; the orchestration that drives the models is the next PR.

Why

Design profiles-collaboration-secrets.md A8.3: all discussion state lives in the ledger, so a crash resumes mid-discussion, and the gate must not rest on the orchestrator's own word. The log is also where "the steps cannot be skipped or forged" is enforced, so the code that drives the discussion cannot get it wrong. Part 1a (#665) added the contract, sanitizer, digest validator and gate.

Changes

  • One JSONL line per step in $CODECORA_HOME/tole/discussions/<id>.jsonl (contract, roster, contribution, summary, verdicts, usage, flags, gate, closed). The state, and Next (what must happen now: contribute, summarize, check, decide, finish), are folded from it. A torn last line (a crash mid-write) is ignored; damage elsewhere is a loud error; the file is capped at 16 MiB.
  • The log is the referee. A contribution only from a participant who has not spoken this round; a summary only once everyone has (a verbatim one holds exactly the round and only for a small round, a digest may cite only the round's entries); verdicts only after the summary, one per criterion, with evidence for a met one; the gate's result is computed from the ledger (decide), never supplied; close only after a report or escalate. Nothing after the end. The roster may change between rounds within the contract's participants.
  • The contribution's entry id is the log's own sequence (e<seq>), which every digest line must cite.
  • A torn last line (a crash mid-write, even inside a multi-byte character) is ignored on read and cut off before the next step is appended. Found by Cora review of this PR: appending after the torn bytes glued the new line onto them and made the log unparseable. Three tests cover the append after a tear, a tear inside a character and a log that is only a torn line.
  • Every mutating step holds a sidecar file lock around reading the state and appending, so two writers on one discussion never take the same turn or the same entry id.
  • CHANGELOG.md and docs/epics.md are updated in this PR.

Testing

  • cargo fmt --all; clippy -D warnings on tole-core (also --no-default-features): clean.
  • 9 tests: a full discussion to a checked report with the file's sequence numbers, every refused out-of-order or repeated step, the gate computed for max rounds, budget and a host flag, stall detection (and reset by news), a big round refused as verbatim, a roster change, resume from a new handle with a torn tail ignored and mid-file damage rejected, id and size limits, and a concurrency test (4 threads, 20 rounds of attempts: one turn each, distinct ids). The concurrency test fails 3 of 3 runs with the lock call removed and passes with it. cargo test -p tole-core: all pass.
  • Cora agent review: review_prepare 0 deterministic findings, review_finalize should_block: false with one info note (each step re-reads the whole log, bounded by the cap and by at most 10 rounds of 8 participants).

…#588 part 1b)

Adds tole_core::discussion_log: every step is one JSONL line, the state and
the next step are folded from it, each step is checked against what must
come next and the gate is computed from the ledger. Steps take a lock.
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

serde_json::to_string(&Line { seq, t: now, event }).map_err(|e| e.to_string())?;
line.push('\n');
let mut f = std::fs::OpenOptions::new()
.create(true)
@ajianaz
ajianaz merged commit 1b3e87e into develop Nov 13, 2026
19 checks passed
@ajianaz
ajianaz deleted the feat/discussion-log branch November 20, 2026 08:36
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.

2 participants