Skip to content

Harden agent-provider recovery and eliminate validation flakes - #1752

Merged
ymichael merged 23 commits into
mainfrom
bb/run-full-validation-test-suite-thr_ibixcjmwv9
Aug 18, 2026
Merged

ymichael merged 23 commits into
mainfrom
bb/run-full-validation-test-suite-thr_ibixcjmwv9

Conversation

@ymichael

@ymichael ymichael commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR captures the fixes found during a full lint, build, test, integration-test, and manual QA run, with extra coverage focused on agent providers and recovery behavior.

  • preserve Pi's stable provider identity when a session is resumed under a different bb routing identity
  • make daemon recovery converge reliably across disconnect and terminal-state races
  • prevent duplicate provider item settlements while respecting explicit item/started lifecycle resets
  • bound Codex bridge settlement tracking so command output is never retained in deduplication state
  • make ignored live web-search probes retry correctly within a sufficient outer test deadline
  • remove timing and shared-state flakes across provider permissions, dynamic ACP, recovery, plugin lifecycle, injected skills, repository discovery, app artifacts, and iPad command typeahead
  • keep the manual recovery runbook resilient to expected disconnect-settlement races

Bugs and fixes

Area Problem Fix / regression coverage
Pi resume Resume used the current bb thread ID as Pi's persisted-session identity, which could reopen or discard the wrong JSONL file Preserve providerThreadId separately from the live bb routing ID; verify reopen, identity reporting, and discard against the original file
Daemon recovery Recovery could race terminal state settlement or submit a continuation with stale turn targeting Re-read state after settlement, use auto-targeted fresh turns, and cover crash/restart permutations
Provider events Retried terminal items or independent server/provider denial settlement could create duplicate canonical completions Suppress repeated Codex settlements with bounded item-ID state and enforce storage-level idempotency
Item lifecycle A broad storage guard could drop valid completions when an item ID was explicitly reopened, including thread-scoped background tasks Reset settlement state on the latest item/started; cover same-turn and background ID reuse
Event persistence performance Per-completion synchronous lifecycle queries could scan large histories and block recovery batches Preload requested lifecycle keys once per SQLite variable batch through a generated partial index; pin the query plan in tests
Live web search Ignored probes were treated as completed instead of retried, while the retry test's 90-second outer limit was shorter than its two possible 60-second waits Retry ignored probes, cover the behavior, and allow 150 seconds for the complete scenario
Validation flakes Loaded runners exposed short budgets, shared fixtures, redundant builds, and focus timing races Bound deadlines, isolate state, widen intentional budgets, avoid redundant SDK rebuilds, and synchronize focus assertions
Manual recovery QA An expected active -> error disconnect transition could fail the runbook before recovery was attempted Treat the intermediate wait as observational, re-read state, and recover unless already idle

Validation

  • full lint pass
  • full build pass
  • full unit/test pass
  • full integration-test pass
  • complete qa/manual-runbook.md pass, including agent-provider, dynamic ACP, permission, and daemon-recovery scenarios
  • follow-up review fixes: 390 DB tests, 164 Codex-provider tests, live web-normalization integration, relevant typechecks, server/host-daemon builds, and repository lint with zero errors

AGENT GENERATED: by GPT-5 Codex

@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

Comment thread packages/db/src/data/events.ts Resolved
Comment thread packages/db/src/data/events.ts Resolved

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

Plain English summary

This PR makes agent sessions recover more reliably after daemon restarts. It keeps a stable Pi session identity across BB thread changes.

It filters duplicate completion events. It also changes slow or unreliable tests.

Findings

  • P1 — The database uses the wrong lifecycle boundary. The runtime grammar lets item/started reopen an item identifier. The database only resets after turn/started. It can drop a valid second completion within one turn. Thread-scoped background items have no reset boundary.

  • P1 — The database lookup can block the server event loop. Each completed item runs a synchronous turn-start query. SQLite can scan many unrelated rows for an old turn. A one-million-row benchmark took 15.8 seconds for 100 oldest-turn lookups.

  • P1 — The Codex bridge retains full completion payloads. The fingerprint set keeps every unique item JSON string until session close. A reproduction retained 125.4 MiB for 2,000 outputs of 64 KiB.

  • P2 — The web-search retry has an insufficient outer limit. Two 60-second waits can run in sequence. Vitest stops the complete test after 90 seconds.

Architecture

The Pi identity split belongs in the provider bridge. The protocol increase to version 132 correctly forces old daemons to update.

The bridge, runtime grammar, and database now apply separate duplicate rules. These rules use different lifecycle models.

Use the runtime item lifecycle as the shared contract. Keep the bridge filter bounded and treat it as an optimization.

Load database lifecycle keys once per batch. This change removes repeated hot-path queries and centralizes the rule.

Security and performance

I found no separate authorization, path traversal, or command-execution flaw. The unbounded Codex set creates a denial-of-service risk.

The repeated SQLite scan can stall the server during a large recovery batch.

Validation

All current GitHub checks pass.

I also ran these exact-head checks:

  • The fake recovery suite passed 8 tests across 7 files.
  • The database event suite passed 79 tests.
  • The Pi bridge suite passed 24 tests.
  • The Codex calibration suite passed 2 tests.
  • The host-daemon contract suite passed 38 tests.
  • The source app and Settings route loaded in Chromium without console errors.
  • git diff --check passed.

The tests do not cover item reuse within one turn. They do not cover large histories or long Codex sessions.

I would fix the four inline findings before merge. I posted this as a comment review only.

@ymichael
ymichael merged commit 511d7db into main Aug 18, 2026
10 checks passed
@ymichael
ymichael deleted the bb/run-full-validation-test-suite-thr_ibixcjmwv9 branch August 18, 2026 06:12
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