Commit Graph
2 Commits
Author SHA1 Message Date
Nicky LeachandPaperclip 4d8770f6dd test(plugins): assert runtime delivery by event identity (#16871)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Plugins receive committed runtime events without polling.
> - The delivery test checks that an independent writer is visible after
commit.
> - Startup baseline callbacks can still arrive during that transaction.
> - A total callback count mixes startup work with the event under test.
> - This pull request checks the transaction's specific event ID
instead.

## Linked Issues or Issue Description

**What happened?**

The runtime-delivery test failed during #16604 verification. It expected
one callback before an independent transaction committed, but received
two. The test waits for a total callback count derived before startup
baseline delivery is known to be complete. An older baseline event can
arrive during the transaction and fail that assertion.

The failing test and delivery implementation are unchanged from master.
This PR isolates the test-only correction from #16604.

**Expected behavior**

The event created by the independent transaction is absent from
delivered callbacks before commit. That exact event arrives after
commit. Other committed startup callbacks can arrive at any time.

**Steps to reproduce**

1. Start lifecycle delivery with startup events still pending.
2. Begin an independent agent update after the expected callback count
is first reached.
3. Let a baseline callback arrive before that transaction commits.
4. The old global-count assertion fails even though the transaction's
event is not delivered early.

**Additional context**

Scoped maintenance follow-up for #16604. No runtime behavior or feature
files change here. #16605 remains a draft without review requests.

## What Changed

- Read the new journal event ID inside the independent writer's
transaction.
- Assert that this ID is not delivered before commit.
- Wait for that same ID after commit and check its company, resource,
and type.
- Remove the total callback-count assumption.
- Wait for the company startup baseline, its acknowledgments, and
coordinator idleness. Flush earlier listener notifications with a
barrier, then wait for that barrier wake to settle before the
independent write.

## Verification

- The earlier full feature run passed 821/822 tests and failed this
exact count assertion with two callbacks instead of one. That failure
remains recorded in #16604.
- The failing test file is byte-identical on the reviewed feature head
and master. Neither the profile-replacement correction nor this PR
changes the delivery implementation.
- `pnpm exec vitest run
server/src/__tests__/agent-runtime-hooks.test.ts`: all 17 tests pass
with the event-ID assertion.
- `pnpm --filter @paperclipai/server typecheck`: passed.
- Standard Greptile initially returned 4/5: startup delivery could still
hide a missing independent wake. The correction adds observable startup
acknowledgment, listener flushing, and coordinator idleness. All 17
runtime-hook tests and server typechecking pass with it. A negative
control drops runtime notifications while forwarding the barrier and
fails the after-commit delivery assertion; startup work cannot mask that
loss.
- `git diff --check` and the full PR diff scan for secrets and personal
data passed.
- Full local build and repository-wide tests were not run for this
test-only correction. At `714a74bf0991617c9ad85ce17bae22c533d1ed22`,
hosted CI run 39295664656 passed: all 55 checks succeeded, with two
optional Storybook checks skipped. Standard Greptile returned 5/5, the
security scan passed, all review threads are resolved, and the branch is
mergeable against master. The tests use real PostgreSQL and controlled
plugin callbacks; live provider behavior is not qualified.

## Risks

Test-only change. The commit boundary assertion remains: the new event
ID must be absent inside the transaction and present after commit.
Existing startup callbacks no longer count as early delivery of a
different event. Runtime notification and retry behavior are unchanged.

## Model Used

OpenAI Codex, GPT-6, with reasoning, repository inspection, code
execution, and testing. The exact deployment model ID and context window
are not exposed in this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-19 10:55:37 -07:00
Nicky LeachandPaperclip 9f4a956b90 Add durable agent runtime synchronization hooks (#16499)
## Thinking Path

> - Paperclip manages agents and their runtime configuration.
> - Plugins can maintain external agent computers.
> - Configuration and file saves currently miss durable plugin delivery.
> - A transient activity notification cannot recover after interruption.
> - This pull request adds an opt-in agent runtime resource stream.
> - The existing dispatcher delivers and acknowledges its committed
work.
> - Plugins can prepare computers when configuration changes.

## Linked Issues or Issue Description

Related: #15631 and #16203 establish agent lifecycle and native durable
delivery.

**Problem**

Plugins cannot reliably react to agent configuration and instruction
changes without polling or waiting for execution.

**Proposed solution**

Add an opt-in `agent_runtime` stream to the existing resource journal.
Record changes at the database mutation and managed file audit
boundaries. Wake the dispatcher with content-free commit notifications.
Provide scoped runtime inputs to the selected lifecycle plugin.

**Alternatives considered**

Route-only activity events miss service and background writers.
Scheduled scans delay changes and repeatedly query unchanged state.

**Roadmap alignment**

This extends the existing plugin and agent configuration work.

## What Changed

- Add durable update/delete events for agent runtime state, including an
existing-agent baseline.
- Capture configuration changes, instruction edits, deletion, restore,
and managed run writeback.
- Add commit notifications and a reconnect scan. Register one listener
for configured, enabled runtime subscribers. Release it when none
remain.
- Keep HTTP startup independent of queued plugin callbacks.
- Add `ctx.agents.getRuntime`. Require lifecycle capability, invocation
company, enabled plugin, and owning lifecycle selection.
- Keep legacy agent/project subscriptions isolated. Manual inbox reads
retain both legacy streams.
- Resolve recovered instruction paths without reading or hashing bundle
contents. Use the company reporting graph for runtime health.
- Repair missed file events on identical save/deletion retries after a
journal failure; preserve content tokens and conditional-write checks.
- Correlate file audits with runtime revisions to deduplicate recorded
retries without a new table. Bound the lookup with the existing
company/timestamp index.
- Document the contract, migration, access boundaries, and
session-connection requirement.

## Verification

- Rebased the full stack onto origin/master after #16507.
- Final replayed stack: `pnpm -r typecheck` and `pnpm build` passed.
- All 132 affected runtime, skill, connector, publication, instruction,
managed-agent, and delivery tests passed after the latest-master rebase.
Workspace typecheck and build passed.
- Journal failure injection verifies recovery on identical file writes,
deletions, and instruction retries from an acknowledged inbox.
- Deduplication follow-up: 80 runtime/instruction/delivery tests and
server typecheck passed. Repeated retries create no audit/events; old
hashes returning after an intervening commit still repair delivery.
Built-in/native instruction writer regressions passed all 56 tests.
- PR 1 follow-up tests cover valid/cyclic reporting chains, listener
registration failure, multiple subscribers, global/company disable,
re-enable, unload, and startup with blocked callbacks.
- Database coverage includes rollback, journal failure, no-op
suppression, file saves/deletion, ordering/replay, owner/company denial,
independent-client commits, and real listener loss/reconnect.
- SDK/shared suites passed 1,059 tests during implementation.
CLI/delivery regressions also passed.
- Migration safety, map checks, diff whitespace, and local secrets/PII
scan passed.
- Hosted CI and security checks are fully green at `b296405e2`. Standard
Greptile and Apex both returned 5/5 with no unresolved findings.
- The broad local suite encountered an unchanged diagnostic test that
rejects the word "private" from an error stack. This worktree lives
under /private/tmp. The same unchanged diagnostic suite passed all 108
tests in the original checkout. Hosted full-suite checks provide
exact-head verification.

## Risks

- Apply migration 0347 before enabling a runtime subscriber. Runtime
notifications require session-level PostgreSQL LISTEN. Transaction-mode
poolers are unsupported for this opt-in feature.
- Database triggers share the mutation transaction. Journal failure
prevents configuration commits. Trigger work adds a journal insert to
relevant changes.
- Filesystem publication and SQL commit are separate boundaries. Direct
filesystem edits do not emit hooks. External clients must fence stale
revisions and retain conditional-write checks.
- The reader returns only that plugin's own instance secrets. Keep them
out of UI data, logs, plugin state, and agent files.
- No private transport integration or live remote computer qualification
is included.

## Model Used

OpenAI Codex, GPT-6, with reasoning, repository inspection, code
execution, and testing. The exact deployment model ID and context window
are not exposed in this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` /
`Closes: #` / `Refs: #` OR (b) described the issue in-PR following the
relevant issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub references)
- [x] My branch name describes the change and contains no internal
Paperclip ticket id
- [x] I have run tests locally and they pass (focused suites; broad
local limitation documented above)
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-16 07:53:04 -07:00