Skip to content

perf(workflows): incrementally project child progress - #217

Merged
tt-a1i merged 1 commit into
mainfrom
codex/issue-179-incremental-workflow-progress
Aug 28, 2026
Merged

tt-a1i merged 1 commit into
mainfrom
codex/issue-179-incremental-workflow-progress

Conversation

@tt-a1i

@tt-a1i tt-a1i commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

Workflow child progress currently rebuilds usage, preview, transcript, tool renderer state, and context occupancy from the complete Pi message history on every finalized message and tool lifecycle event. A long tool loop therefore repeatedly traverses an ever-growing history and becomes quadratic. This closes #179.

Value

Long-running Workflow agents keep responsive progress reporting without spending progressively more CPU on derived UI state. The improvement grows with the run: a 10,000-message benchmark visits canonical source messages 10,000 times instead of the 100,005,000 visits required by a conservative one-full-scan-per-progress lower bound.

Approach

  • Add an ephemeral, bounded AgentProgressProjection that folds each finalized Pi message once and produces the existing full progress snapshot shape.
  • Keep Pi messages canonical: rebuild from them at activation startup, after compaction, and at terminal settlement.
  • Sample context occupancy only at those reconciliation boundaries and estimate it incrementally between them.
  • Preserve the first and newest transcript entries, per-entry and aggregate byte limits, tool-call timing identities, native tool rendering, and final canonical reconciliation for missed events.
  • Defer compaction reconciliation by one microtask so Pi can finish its synchronous message mutation first.
  • Keep projection failures inside the child outcome and make abort/dispose unconditional, including persistent and startup hydration failures.

This intentionally does not add a persisted cross-activation checkpoint. Reusing an operator still performs one linear startup hydration per activation.

Validation

  • RED on the base revision: the 100-message tool-loop regression observed 30,704 canonical history reads (limit: 400).
  • node --test --experimental-strip-types tests/extensions/workflows/progress-projection.test.ts tests/extensions/workflows/runner.test.ts — 33/33 passed.
  • node --test --experimental-strip-types tests/extensions/workflows/*.test.ts — 246/246 passed.
  • bun run check — passed. The 12 existing Effect diagnostics remain tracked by file-search: 修复 Effect failure channel 与多次 provide 诊断 #170.
  • bun run test — Node 926/926 and Vitest 30/30 passed.
  • bun benchmarks/workflow-progress.ts:
    • 100 messages: 100 source visits vs 10,050 one-scan lower bound (100.5x reduction).
    • 1,000 messages: 1,000 vs 1,000,500 (1,000.5x reduction).
    • 10,000 messages: 10,000 vs 100,005,000 (10,000.5x reduction).
  • Three independent review agents examined the current diff; all returned no findings after lifecycle, test, benchmark, compaction, and cleanup concerns were addressed.
  • Manual Pi/TUI smoke was not run; the change is covered through deterministic runner/projection tests and the repository-wide suite.

Impact

  • User-visible behavior: progress content and update cadence remain compatible; long Workflow child loops should remain responsive.
  • Model-visible context/tools: no schema, tool, prompt, or capability changes.
  • Runtime/lifecycle: adds per-run ephemeral derived state, bounded to 200 transcript entries, 16 KiB per entry, and 256 KiB aggregate text; canonical state is reconciled at lifecycle boundaries.
  • Persisted config/data: none.
  • Compatibility/risk: compaction and terminal facts still come from Pi's canonical messages. New failure paths fail closed and still clean up the owned child session.

@tt-a1i
tt-a1i merged commit 06f861d into main Aug 28, 2026
2 checks passed
agnitum2009 pushed a commit to agnitum2009/openpi that referenced this pull request Aug 28, 2026
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.

workflows: child 进度更新重复扫描完整历史导致超线性开销

1 participant