Skip to content

perf(workflows): append replay journal incrementally - #318

Merged
tt-a1i merged 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-184-journal-accumulator
Aug 31, 2026
Merged

tt-a1i merged 1 commit into
openpi-dev:mainfrom
testikun:codex/issue-184-journal-accumulator

Conversation

@testikun

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Problem

Closes #184.

Workflow replay journals currently re-serialize the complete pretty-printed journal while trimming old entries. Near the 2 MiB cap, repeated slice(1) and full JSON size recalculation make append/eviction cost grow close to quadratically for large runs.

Value

Large read-only Workflows can retain hundreds of replayable agent results. Incremental accounting keeps journal admission and oldest-entry eviction proportional to the number of new entries, while preserving the exact replay artifact and its atomic write path.

Approach

  • Add a WorkflowJournalAccumulator with cached per-entry JSON fragments, UTF-8 byte accounting, and a head-cursor queue.
  • Append encodes only the new entry; eviction subtracts known bytes and releases dropped payload references immediately.
  • Keep boundedJournal() as a compatibility adapter for array callers.
  • Let persistence write the accumulator's complete canonical JSON through the existing atomic file writer.
  • Preserve the v2 artifact format, oldest-first retention, duplicate-key replay order, and malformed/legacy fail-closed loading.
  • Add a reproducible benchmark:workflow-journal script for 128/512/1024 entries.

Validation

  • bun run check — passed (config contract, discipline, format, lint, typecheck).
  • bun run test under Node 24 — 1,076 passed, 1 skipped; Vitest 30/30 passed.
  • Focused journal/artifact tests — 26/26 passed.
  • node --experimental-strip-types --expose-gc benchmarks/workflow-journal.ts:
    • 128 entries: append 7.909 ms, 2,034,146 bytes retained.
    • 512 entries: append 22.447 ms, 2,034,149 bytes retained.
    • 1,024 entries: append 43.575 ms, 2,034,179 bytes retained.
    • Final serialized bytes exactly matched incremental accounting in every run.
  • Before this change, the equivalent 4 KiB fixture took approximately 1,123 ms at 1,024 entries; the incremental append path took approximately 4 ms.

Impact

  • User-visible behavior: none.
  • Model-visible context/tools: none.
  • Runtime/lifecycle: journal append and eviction are incremental; replay semantics are unchanged.
  • Persisted data: same v2 journal.json schema and canonical pretty JSON; writes remain atomic.
  • Compatibility/risk: array-based callers remain supported; oversized/malformed/legacy behavior remains fail closed.

@github-actions github-actions Bot added the area:workflows Workflow engine, capability, skills, or tests label Aug 31, 2026

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 1e481d0. No blocking findings. The incremental accumulator avoids re-encoding retained entries while preserving canonical v2 JSON, oldest-first retention, replay ordering, and atomic persistence. Independent validation: focused 26/26, bun run check, full Node 1076 passed with one platform skip, Vitest 30/30; 6000 differential append checks matched the reference algorithm, and a 1024-append probe confirmed each payload was encoded once. Current Node 22.19.0, Node 24, and Windows CI passed. Non-blocking follow-ups: retain the encode-count probe as a regression test and clarify that benchmark flushMs measures JSON assembly rather than disk persistence.

@tt-a1i
tt-a1i merged commit ba550bc into openpi-dev:main Aug 31, 2026
5 checks passed
agnitum2009 pushed a commit to agnitum2009/openpi that referenced this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:workflows Workflow engine, capability, skills, or tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(workflows): replay journal 反复完整序列化导致近二次开销

2 participants