@vellumai/assistant 0.11.9 → 0.11.10-dev.202609091114.7b6342c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +2 -2
- package/Dockerfile +6 -12
- package/docs/architecture/memory.md +17 -9
- package/docs/guardian-request-flow.md +7 -4
- package/docs/runbook-trusted-contacts.md +13 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +72 -0
- package/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/openapi.yaml +729 -63
- package/package.json +1 -1
- package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +19 -21
- package/src/__tests__/assistant-event-hub-machine-name.test.ts +40 -0
- package/src/__tests__/assistant-event-hub.test.ts +45 -0
- package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +0 -1
- package/src/__tests__/compactor-assistant-tail-preview.test.ts +111 -0
- package/src/__tests__/compactor-tail-resolution.test.ts +116 -0
- package/src/__tests__/computer-use-native-history.test.ts +30 -0
- package/src/__tests__/computer-use-window-schema.test.ts +24 -0
- package/src/__tests__/config-get-vision-flag.test.ts +36 -0
- package/src/__tests__/config-loader-validation-reset-notice.test.ts +47 -15
- package/src/__tests__/context-search-conversations-source.test.ts +27 -5
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +189 -195
- package/src/__tests__/conversation-agent-loop.test.ts +690 -50
- package/src/__tests__/conversation-fork-crud.test.ts +132 -45
- package/src/__tests__/conversation-fork-retrospective.test.ts +9 -7
- package/src/__tests__/conversation-lifecycle.test.ts +684 -10
- package/src/__tests__/conversation-pairing.test.ts +10 -9
- package/src/__tests__/conversation-runtime-assembly.test.ts +288 -1
- package/src/__tests__/conversation-surfaces-history-restored-completion.test.ts +21 -4
- package/src/__tests__/conversation-surfaces-point-at-budget.test.ts +150 -0
- package/src/__tests__/conversation-surfaces-point-at-capability.test.ts +161 -0
- package/src/__tests__/copy-composer-tc-templates.test.ts +2 -2
- package/src/__tests__/credential-security-invariants.test.ts +1 -0
- package/src/__tests__/delivered-post-record.test.ts +107 -0
- package/src/__tests__/guardian-action-service-scope.test.ts +53 -0
- package/src/__tests__/guardian-question-mode.test.ts +88 -138
- package/src/__tests__/headless-browser-mode.test.ts +63 -13
- package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
- package/src/__tests__/heartbeat-service.test.ts +118 -27
- package/src/__tests__/host-cu-proxy.test.ts +159 -1
- package/src/__tests__/host-proxy-interface.test.ts +15 -0
- package/src/__tests__/host-proxy-preactivation.test.ts +61 -0
- package/src/__tests__/injector-chain.test.ts +3 -3
- package/src/__tests__/injector-registry-order-guard.test.ts +1 -1
- package/src/__tests__/injector-v3-suppression.test.ts +587 -45
- package/src/__tests__/llm-schema.test.ts +70 -2
- package/src/__tests__/logger.test.ts +33 -32
- package/src/__tests__/mcp-config-secret-boundary.test.ts +2 -0
- package/src/__tests__/memory-config-file-parity.test.ts +18 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +53 -3
- package/src/__tests__/messages-read-boundary-guard.test.ts +0 -1
- package/src/__tests__/messaging-send-tool.test.ts +251 -128
- package/src/__tests__/messaging-shared.test.ts +19 -0
- package/src/__tests__/notification-decision-fallback.test.ts +98 -76
- package/src/__tests__/notification-decision-strategy.test.ts +10 -38
- package/src/__tests__/notification-events-source-context-probe.test.ts +211 -0
- package/src/__tests__/openai-responses-prompt-cache.test.ts +7 -2
- package/src/__tests__/openai-responses-provider.test.ts +42 -0
- package/src/__tests__/outlook-messaging-provider.test.ts +9 -0
- package/src/__tests__/platform-callback-registration.test.ts +162 -3
- package/src/__tests__/plugin-api-webhook-url.test.ts +66 -4
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/__tests__/pricing.test.ts +29 -0
- package/src/__tests__/prompt-cache-cross-turn-stability.test.ts +63 -3
- package/src/__tests__/scheduler-result-notification.test.ts +209 -0
- package/src/__tests__/strip-memory-injections.test.ts +75 -27
- package/src/__tests__/tool-approval-seed-content-blocks.test.ts +4 -13
- package/src/acp/auto-install.test.ts +35 -1
- package/src/acp/resolve-agent.test.ts +3 -3
- package/src/agent/loop.ts +116 -45
- package/src/api/constants/personality-sliders.test.ts +21 -0
- package/src/api/constants/personality-sliders.ts +64 -0
- package/src/api/events/contact-record-request.ts +16 -4
- package/src/api/events/contact-request.ts +10 -1
- package/src/api/index.ts +12 -0
- package/src/api/responses/memory-v3-selection-log.ts +64 -13
- package/src/api/surfaces.ts +6 -5
- package/src/background-wake/next-wake.test.ts +13 -0
- package/src/background-wake/next-wake.ts +4 -2
- package/src/calls/__tests__/voice-session-bridge.test.ts +166 -0
- package/src/calls/__tests__/voice-turn-sight-hold.test.ts +301 -0
- package/src/calls/voice-session-bridge.ts +162 -1
- package/src/calls/voice-triage-escalate.ts +1 -1
- package/src/channels/types.ts +14 -0
- package/src/cli/__tests__/catalog-search-help.test.ts +1 -0
- package/src/cli/__tests__/contacts-address-prompt-cli.test.ts +701 -0
- package/src/cli/__tests__/contacts-record-prompt-cli.test.ts +276 -15
- package/src/cli/__tests__/roadmap-cli.test.ts +313 -0
- package/src/cli/__tests__/run-assistant-command.ts +59 -20
- package/src/cli/commands/__tests__/conversations-slack.test.ts +12 -0
- package/src/cli/commands/__tests__/plugins-search.test.ts +81 -0
- package/src/cli/commands/config.help.ts +3 -1
- package/src/cli/commands/contacts.help.ts +179 -12
- package/src/cli/commands/contacts.ts +442 -47
- package/src/cli/commands/memory/worker.ts +1 -1
- package/src/cli/commands/platform/__tests__/credits-format.test.ts +152 -0
- package/src/cli/commands/platform/__tests__/credits.test.ts +20 -0
- package/src/cli/commands/platform/credits-format.ts +108 -0
- package/src/cli/commands/platform/index.help.ts +33 -11
- package/src/cli/commands/platform/index.ts +7 -18
- package/src/cli/commands/plugins.help.ts +4 -1
- package/src/cli/commands/plugins.ts +2 -1
- package/src/cli/commands/roadmap.help.ts +171 -0
- package/src/cli/commands/roadmap.ts +358 -0
- package/src/cli/index.help.ts +2 -0
- package/src/cli/lib/__tests__/cli-output.test.ts +5 -0
- package/src/cli/lib/cli-output.ts +6 -6
- package/src/cli/program.ts +2 -0
- package/src/config/__tests__/webhook-routing.test.ts +42 -0
- package/src/config/acp-defaults.test.ts +3 -3
- package/src/config/acp-defaults.ts +5 -5
- package/src/config/bundled-skills/acp/SKILL.md +8 -11
- package/src/config/bundled-skills/computer-use/SKILL.md +21 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +6 -0
- package/src/config/bundled-skills/contacts/SKILL.md +61 -11
- package/src/config/bundled-skills/messaging/SKILL.md +2 -0
- package/src/config/bundled-skills/messaging/TOOLS.json +4 -4
- package/src/config/bundled-skills/messaging/tools/messaging-send.ts +160 -36
- package/src/config/bundled-skills/messaging/tools/shared.ts +6 -0
- package/src/config/bundled-skills/schedule/SKILL.md +10 -2
- package/src/config/bundled-skills/screen-annotation/SKILL.md +80 -0
- package/src/config/bundled-skills/screen-annotation/TOOLS.json +73 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-annotation.test.ts +74 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-clear-marks.ts +33 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-point-at.ts +25 -0
- package/src/config/env-registry.ts +2 -0
- package/src/config/feature-flag-registry.json +39 -7
- package/src/config/input-modalities.test.ts +71 -0
- package/src/config/input-modalities.ts +95 -0
- package/src/config/loader.ts +2 -0
- package/src/config/schemas/__tests__/memory-v3.test.ts +58 -15
- package/src/config/schemas/heartbeat.ts +3 -3
- package/src/config/schemas/llm.ts +47 -10
- package/src/config/schemas/memory-storage.test.ts +39 -0
- package/src/config/schemas/memory-storage.ts +21 -0
- package/src/config/schemas/memory-v3.ts +73 -46
- package/src/config/schemas/services.ts +18 -0
- package/src/config/webhook-routing.ts +12 -2
- package/src/context/compactor.ts +12 -13
- package/src/context/strip-injections.ts +29 -25
- package/src/context/token-estimator.ts +2 -2
- package/src/daemon/__tests__/embedding-reconcile.test.ts +77 -0
- package/src/daemon/__tests__/lifecycle-embedding-reconcile.test.ts +3 -0
- package/src/daemon/__tests__/turn-actor.test.ts +68 -0
- package/src/daemon/conversation-agent-loop-handlers.ts +152 -22
- package/src/daemon/conversation-agent-loop.ts +19 -3
- package/src/daemon/conversation-messaging.ts +3 -2
- package/src/daemon/conversation-runtime-assembly.ts +191 -69
- package/src/daemon/conversation-surfaces.ts +32 -62
- package/src/daemon/conversation.ts +153 -46
- package/src/daemon/embedding-reconcile.ts +64 -1
- package/src/daemon/handlers/config-embeddings.ts +31 -0
- package/src/daemon/host-cu-proxy.ts +66 -50
- package/src/daemon/host-cu-target.ts +139 -0
- package/src/daemon/host-proxy-preactivation.ts +29 -1
- package/src/daemon/mcp-reload-service.ts +6 -0
- package/src/daemon/providers-setup.ts +5 -26
- package/src/daemon/trust-context.ts +1 -1
- package/src/daemon/turn-actor.ts +46 -0
- package/src/heartbeat/heartbeat-service.ts +72 -13
- package/src/inbound/platform-callback-registration.ts +77 -11
- package/src/inbound/pod-webhook-claim.ts +35 -0
- package/src/inbound/velay-webhooks-gate.ts +20 -0
- package/src/ipc/gateway-client.ts +91 -0
- package/src/live-voice/__tests__/live-voice-photo.test.ts +174 -0
- package/src/live-voice/__tests__/live-voice-session-guardian.test.ts +127 -0
- package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +42 -2
- package/src/live-voice/__tests__/live-voice-sight-frame.test.ts +81 -0
- package/src/live-voice/__tests__/protocol.test.ts +67 -0
- package/src/live-voice/live-voice-connection.ts +14 -1
- package/src/live-voice/live-voice-photo.ts +109 -4
- package/src/live-voice/live-voice-session-manager.ts +10 -1
- package/src/live-voice/live-voice-session.ts +196 -31
- package/src/live-voice/protocol.ts +134 -1
- package/src/mcp/__tests__/reload-signal-emission.test.ts +54 -0
- package/src/mcp/__tests__/reload-signal.test.ts +57 -0
- package/src/mcp/__tests__/startup.test.ts +150 -0
- package/src/mcp/reload-signal.ts +50 -0
- package/src/mcp/startup.ts +101 -0
- package/src/messaging/providers/outlook/adapter.ts +2 -13
- package/src/messaging/providers/outlook/client.ts +13 -1
- package/src/messaging/providers/outlook/types.ts +3 -0
- package/src/messaging/providers/telegram-bot/adapter.ts +9 -2
- package/src/messaging/providers/telegram-bot/client.ts +8 -2
- package/src/messaging/providers/whatsapp/adapter.ts +9 -2
- package/src/messaging/providers/whatsapp/client.ts +8 -2
- package/src/notifications/AGENTS.md +5 -0
- package/src/notifications/README.md +21 -7
- package/src/notifications/__tests__/assistant-reply-producer.test.ts +3 -10
- package/src/notifications/__tests__/background-failure-signal.test.ts +96 -0
- package/src/notifications/__tests__/broadcaster.test.ts +171 -7
- package/src/notifications/__tests__/decision-engine.test.ts +79 -6
- package/src/notifications/__tests__/edit-notification.test.ts +59 -0
- package/src/notifications/__tests__/resolve-visible-in-source.test.ts +96 -0
- package/src/notifications/__tests__/schedule-result-producer.test.ts +397 -0
- package/src/notifications/access-request-copy.ts +5 -5
- package/src/notifications/approval-card-data.ts +29 -13
- package/src/notifications/assistant-reply-producer.ts +0 -4
- package/src/notifications/background-failure-signal.ts +13 -1
- package/src/notifications/broadcaster.ts +65 -2
- package/src/notifications/conversation-pairing.ts +263 -155
- package/src/notifications/copy-composer.ts +38 -22
- package/src/notifications/decision-engine.ts +89 -61
- package/src/notifications/delivered-post-record.ts +81 -0
- package/src/notifications/deliveries-store.ts +8 -1
- package/src/notifications/edit-notification.ts +16 -0
- package/src/notifications/events-store.ts +68 -2
- package/src/notifications/guardian-question-mode.ts +24 -232
- package/src/notifications/home-feed-side-effect.ts +1 -0
- package/src/notifications/notification-utils.ts +13 -5
- package/src/notifications/resolve-visible-in-source.ts +56 -0
- package/src/notifications/schedule-result-producer.ts +275 -0
- package/src/notifications/signal.ts +5 -0
- package/src/oauth/__tests__/seed-providers-managed.test.ts +82 -0
- package/src/oauth/seed-providers.ts +201 -3
- package/src/onboarding/onboarding-events-store.ts +14 -8
- package/src/persistence/conversation-crud.ts +68 -19
- package/src/persistence/embeddings/embedding-backend.test.ts +162 -0
- package/src/persistence/embeddings/embedding-backend.ts +148 -11
- package/src/persistence/embeddings/embedding-gemini.test.ts +328 -9
- package/src/persistence/embeddings/embedding-gemini.ts +211 -27
- package/src/persistence/embeddings/embedding-openai.test.ts +113 -0
- package/src/persistence/embeddings/embedding-openai.ts +55 -4
- package/src/persistence/embeddings/embedding-types.test.ts +24 -0
- package/src/persistence/embeddings/embedding-types.ts +25 -1
- package/src/persistence/job-utils.ts +6 -2
- package/src/persistence/message-metadata.ts +20 -0
- package/src/persistence/migrations/283-memory-v3-selections-message-id-and-sections.ts +2 -1
- package/src/persistence/migrations/376-notification-deliveries-canonical-message-id.ts +37 -0
- package/src/persistence/schema/memory-injection.ts +31 -9
- package/src/persistence/schema/notifications.ts +8 -0
- package/src/persistence/steps.ts +2 -0
- package/src/plugin-api/index.ts +2 -1
- package/src/plugin-api/vision-support.test.ts +81 -0
- package/src/plugin-api/vision-support.ts +57 -10
- package/src/plugin-api/webhook-url.ts +18 -4
- package/src/plugins/AGENTS.md +1 -1
- package/src/plugins/defaults/channel/injectors.ts +3 -1
- package/src/plugins/defaults/injector-order.ts +2 -2
- package/src/plugins/defaults/memory/AGENTS.md +263 -30
- package/src/plugins/defaults/memory/__tests__/conversation-memory-orphan-sweep.test.ts +4 -0
- package/src/plugins/defaults/memory/__tests__/conversation-memory-purge.test.ts +6 -0
- package/src/plugins/defaults/memory/__tests__/db-memory-attach.test.ts +9 -3
- package/src/plugins/defaults/memory/__tests__/memory-log-stores-degraded.test.ts +3 -7
- package/src/plugins/defaults/memory/__tests__/relocated-memory-test-rows.ts +18 -0
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +16 -2
- package/src/plugins/defaults/memory/conversation-memory-purge.ts +2 -0
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +13 -13
- package/src/plugins/defaults/memory/graph/__tests__/conversation-graph-memory-v2-routing.test.ts +19 -12
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +17 -15
- package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +1 -1
- package/src/plugins/defaults/memory/hooks/__tests__/post-compact.test.ts +121 -0
- package/src/plugins/defaults/memory/hooks/init.ts +10 -0
- package/src/plugins/defaults/memory/hooks/injection-metadata.ts +100 -0
- package/src/plugins/defaults/memory/hooks/post-compact.ts +19 -7
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +11 -83
- package/src/plugins/defaults/memory/injectors.ts +4 -4
- package/src/plugins/defaults/memory/job-handlers.ts +4 -1
- package/src/plugins/defaults/memory/jobs/__tests__/embed-concept-page.test.ts +1 -0
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +11 -3
- package/src/plugins/defaults/memory/memory-db.ts +4 -0
- package/src/plugins/defaults/memory/memory-marker.ts +28 -17
- package/src/plugins/defaults/memory/src/__tests__/memory-v2-simulate-route.test.ts +0 -1
- package/src/plugins/defaults/memory/src/__tests__/memory-worker-routes.test.ts +20 -0
- package/src/plugins/defaults/memory/src/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/src/memory-worker-routes.ts +3 -1
- package/src/plugins/defaults/memory/substrate/__tests__/cli-command-store.test.ts +1 -1
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +66 -0
- package/src/plugins/defaults/memory/substrate/__tests__/injected-block-slugs.test.ts +345 -0
- package/src/plugins/defaults/memory/substrate/__tests__/page-index.test.ts +0 -1
- package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +170 -1
- package/src/plugins/defaults/memory/substrate/__tests__/reembed-job.test.ts +1 -0
- package/src/plugins/defaults/memory/substrate/capability-slugs.ts +53 -0
- package/src/plugins/defaults/memory/substrate/cli-command-store.ts +4 -18
- package/src/plugins/defaults/memory/substrate/consolidation-job.ts +40 -1
- package/src/plugins/defaults/memory/substrate/ingest.ts +11 -9
- package/src/plugins/defaults/memory/substrate/injected-block-slugs.ts +426 -42
- package/src/plugins/defaults/memory/substrate/page-index.ts +5 -4
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +127 -14
- package/src/plugins/defaults/memory/substrate/skill-store.ts +1 -18
- package/src/plugins/defaults/memory/v2/__tests__/backfill-jobs.test.ts +1 -0
- package/src/plugins/defaults/memory/v2/__tests__/injection.test.ts +2 -8
- package/src/plugins/defaults/memory/v2/__tests__/router.test.ts +0 -1
- package/src/plugins/defaults/memory/v2/injection.ts +4 -4
- package/src/plugins/defaults/memory/v3/__tests__/capabilities.test.ts +16 -0
- package/src/plugins/defaults/memory/v3/__tests__/carry-integration.test.ts +1004 -319
- package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +227 -4
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +836 -263
- package/src/plugins/defaults/memory/v3/__tests__/live-integration.test.ts +65 -38
- package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +354 -3
- package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +688 -104
- package/src/plugins/defaults/memory/v3/__tests__/overlong-sections.test.ts +109 -0
- package/src/plugins/defaults/memory/v3/__tests__/page-content.test.ts +144 -0
- package/src/plugins/defaults/memory/v3/__tests__/plugin-schema.test.ts +534 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-log-store.test.ts +449 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +265 -27
- package/src/plugins/defaults/memory/v3/__tests__/render-injection.test.ts +34 -117
- package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +491 -4
- package/src/plugins/defaults/memory/v3/__tests__/section-needle.test.ts +124 -1
- package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +264 -4
- package/src/plugins/defaults/memory/v3/__tests__/selection-log-store.test.ts +560 -22
- package/src/plugins/defaults/memory/v3/__tests__/shadow-integration.test.ts +40 -33
- package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +718 -63
- package/src/plugins/defaults/memory/v3/__tests__/types.test.ts +83 -2
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/capabilities.ts +90 -14
- package/src/plugins/defaults/memory/v3/card.test.ts +15 -16
- package/src/plugins/defaults/memory/v3/card.ts +16 -15
- package/src/plugins/defaults/memory/v3/dense.ts +10 -0
- package/src/plugins/defaults/memory/v3/ever-injected-store.test.ts +643 -140
- package/src/plugins/defaults/memory/v3/ever-injected-store.ts +462 -212
- package/src/plugins/defaults/memory/v3/hot-set.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/injector.ts +366 -278
- package/src/plugins/defaults/memory/v3/learned-edges.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/maintain-job.ts +299 -73
- package/src/plugins/defaults/memory/v3/orchestrate.ts +327 -214
- package/src/plugins/defaults/memory/v3/overlong-sections.ts +83 -0
- package/src/plugins/defaults/memory/v3/page-content.ts +72 -92
- package/src/plugins/defaults/memory/v3/plugin-schema.ts +346 -0
- package/src/plugins/defaults/memory/v3/pool-log-store.ts +291 -0
- package/src/plugins/defaults/memory/v3/pool-select.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/pool-select.ts +160 -60
- package/src/plugins/defaults/memory/v3/prune.test.ts +1042 -329
- package/src/plugins/defaults/memory/v3/prune.ts +433 -270
- package/src/plugins/defaults/memory/v3/rare-term-lane.test.ts +269 -0
- package/src/plugins/defaults/memory/v3/rare-term-lane.ts +141 -0
- package/src/plugins/defaults/memory/v3/render-injection.ts +43 -82
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +316 -28
- package/src/plugins/defaults/memory/v3/section-needle.ts +145 -11
- package/src/plugins/defaults/memory/v3/sections.ts +103 -16
- package/src/plugins/defaults/memory/v3/selection-log-store.ts +243 -78
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +189 -68
- package/src/plugins/defaults/memory/v3/tuning-profile.ts +6 -0
- package/src/plugins/defaults/memory/v3/types.ts +169 -23
- package/src/plugins/defaults/memory/v3-eval/__tests__/eval-packets.test.ts +21 -4
- package/src/plugins/defaults/memory/v3-eval/eval-packets.ts +77 -26
- package/src/plugins/types.ts +14 -0
- package/src/providers/__tests__/connection-model-compat.test.ts +1 -0
- package/src/providers/__tests__/provider-secret-catalog.test.ts +4 -0
- package/src/providers/__tests__/xml-tool-call-salvage.test.ts +172 -0
- package/src/providers/inline-audio-support.test.ts +34 -0
- package/src/providers/inline-audio-support.ts +27 -0
- package/src/providers/model-catalog.ts +102 -0
- package/src/providers/openai/__tests__/chat-completions-extra-body.test.ts +51 -0
- package/src/providers/openai/__tests__/chat-completions-provider-xml-salvage.test.ts +291 -0
- package/src/providers/openai/chat-completions-provider.ts +114 -14
- package/src/providers/openai/codex-models.ts +1 -0
- package/src/providers/openai/responses-provider.ts +65 -15
- package/src/providers/opencode/client.test.ts +24 -0
- package/src/providers/opencode/client.ts +6 -1
- package/src/providers/provider-secret-catalog.ts +11 -1
- package/src/providers/retry.ts +6 -0
- package/src/providers/vellum/client.ts +14 -1
- package/src/providers/vellum/personality-directions.test.ts +163 -0
- package/src/providers/vellum/personality-directions.ts +120 -0
- package/src/providers/xml-tool-call-salvage.ts +212 -0
- package/src/runtime/AGENTS.md +7 -2
- package/src/runtime/__tests__/background-job-runner.test.ts +115 -0
- package/src/runtime/__tests__/guardian-form-registry.test.ts +0 -32
- package/src/runtime/__tests__/host-observe.test.ts +44 -0
- package/src/runtime/assistant-event-hub.ts +14 -9
- package/src/runtime/auth/__tests__/guard-tests.test.ts +1 -4
- package/src/runtime/auth/__tests__/route-policy.test.ts +65 -0
- package/src/runtime/auth/same-actor.ts +4 -3
- package/src/runtime/background-job-runner.ts +10 -0
- package/src/runtime/channel-reply-delivery.ts +1 -162
- package/src/runtime/guardian-action-service.ts +20 -1
- package/src/runtime/host-observe.ts +56 -6
- package/src/runtime/http-server.ts +35 -0
- package/src/runtime/outbound-post-reconciliation.ts +183 -0
- package/src/runtime/routes/__tests__/contact-address-prompt-route.test.ts +231 -0
- package/src/runtime/routes/__tests__/contact-record-prompt-route.test.ts +59 -3
- package/src/runtime/routes/__tests__/guardian-form-routes.test.ts +85 -0
- package/src/runtime/routes/__tests__/heartbeat-routes.test.ts +24 -0
- package/src/runtime/routes/__tests__/platform-credits-routes.test.ts +239 -0
- package/src/runtime/routes/__tests__/roadmap-routes.test.ts +469 -0
- package/src/runtime/routes/__tests__/watch-routes.test.ts +70 -1
- package/src/runtime/routes/__tests__/webhook-routes.test.ts +83 -0
- package/src/runtime/routes/contact-prompt-routes.ts +177 -28
- package/src/runtime/routes/conversation-query-routes.ts +53 -11
- package/src/runtime/routes/events-routes.ts +13 -3
- package/src/runtime/routes/guardian-action-routes.ts +7 -0
- package/src/runtime/routes/guardian-form-routes.ts +6 -4
- package/src/runtime/routes/heartbeat-routes.ts +41 -53
- package/src/runtime/routes/index.ts +2 -2
- package/src/runtime/routes/integrations/a2a.ts +12 -3
- package/src/runtime/routes/integrations/vercel.ts +13 -3
- package/src/runtime/routes/platform-routes.ts +175 -23
- package/src/runtime/routes/roadmap-routes.ts +744 -0
- package/src/runtime/routes/watch-routes.ts +50 -0
- package/src/runtime/routes/webhook-routes.ts +24 -2
- package/src/runtime/web-presence.ts +13 -9
- package/src/schedule/__tests__/schedule-timezone.test.ts +21 -3
- package/src/schedule/__tests__/worker-mcp-tools.test.ts +88 -0
- package/src/schedule/schedule-timezone.ts +25 -0
- package/src/schedule/scheduler.ts +19 -0
- package/src/schedule/worker.ts +119 -2
- package/src/telemetry/__tests__/live-voice-funnel.test.ts +32 -0
- package/src/telemetry/live-voice-funnel.ts +33 -0
- package/src/tools/acp/list-agents.test.ts +1 -1
- package/src/tools/browser/__tests__/browser-status.test.ts +3 -0
- package/src/tools/browser/browser-execution.ts +117 -53
- package/src/tools/browser/browser-status-constants.ts +6 -6
- package/src/tools/capability-offer.test.ts +87 -0
- package/src/tools/capability-offer.ts +93 -0
- package/src/tools/computer-use/definitions.ts +6 -0
- package/src/tools/computer-use/skill-proxy-bridge.ts +10 -0
- package/src/tools/terminal/safe-env.ts +2 -0
- package/src/watch/__tests__/watch-retro.test.ts +11 -10
- package/src/watch/__tests__/watch-session-manager.test.ts +75 -1
- package/src/watch/watch-retro.ts +10 -9
- package/src/watch/watch-session-manager.ts +17 -0
- package/src/runtime/routes/__tests__/sight-frame-routes.test.ts +0 -487
- package/src/runtime/routes/sight-frame-routes.ts +0 -136
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import type { LoopToolExecutor } from "../agent/loop.js";
|
|
15
15
|
import type { AssistantEvent } from "../api/index.js";
|
|
16
|
+
import { stripInjectionsForCompaction } from "../context/strip-injections.js";
|
|
16
17
|
import {
|
|
17
18
|
queueConversationNotice,
|
|
18
19
|
resetConversationNoticesForTests,
|
|
@@ -338,6 +339,7 @@ let mockStoredMessages: unknown[] = [];
|
|
|
338
339
|
const updateMessageContentMock = mock(() => {});
|
|
339
340
|
const finalizeMessageContentMock = mock(() => {});
|
|
340
341
|
const addMessageMock = mock(() => ({ id: "mock-msg-id" }));
|
|
342
|
+
const updateConversationContextWindowMock = mock(() => {});
|
|
341
343
|
mock.module("../persistence/conversation-crud.js", () => ({
|
|
342
344
|
setConversationProcessingStartedAt: () => {},
|
|
343
345
|
isConversationProcessing: () => false,
|
|
@@ -358,7 +360,7 @@ mock.module("../persistence/conversation-crud.js", () => ({
|
|
|
358
360
|
getConversationOriginInterface: () => null,
|
|
359
361
|
addMessage: addMessageMock,
|
|
360
362
|
deleteMessageById: deleteMessageByIdMock,
|
|
361
|
-
updateConversationContextWindow:
|
|
363
|
+
updateConversationContextWindow: updateConversationContextWindowMock,
|
|
362
364
|
updateConversationSlackContextWatermark:
|
|
363
365
|
updateConversationSlackContextWatermarkMock,
|
|
364
366
|
updateConversationTitle: () => {},
|
|
@@ -504,7 +506,11 @@ const getSlackCompactionWatermarkForPrefixMock = mock(
|
|
|
504
506
|
);
|
|
505
507
|
mock.module("../daemon/conversation-runtime-assembly.js", () => ({
|
|
506
508
|
applyRuntimeInjections: applyRuntimeInjectionsMock,
|
|
507
|
-
|
|
509
|
+
// The real strip, not a pass-through: this module re-exports it, and a
|
|
510
|
+
// module mock overrides the re-exported binding at its source, so a stub
|
|
511
|
+
// here would turn the compaction strip the loop and the event dispatcher
|
|
512
|
+
// import from `context/strip-injections.js` into a no-op as well.
|
|
513
|
+
stripInjectionsForCompaction,
|
|
508
514
|
isSlackChannelConversation: () => false,
|
|
509
515
|
getSlackCompactionWatermarkForPrefix:
|
|
510
516
|
getSlackCompactionWatermarkForPrefixMock,
|
|
@@ -683,6 +689,16 @@ import {
|
|
|
683
689
|
} from "../daemon/conversation-agent-loop.js";
|
|
684
690
|
import type { QueueDrainReason } from "../daemon/conversation-queue-manager.js";
|
|
685
691
|
import { settleTurnTail } from "../daemon/turn-tail-chain.js";
|
|
692
|
+
import type { PostCompactContext } from "../hooks/types.js";
|
|
693
|
+
import { ConversationGraphMemory } from "../plugins/defaults/memory/graph/conversation-graph-memory.js";
|
|
694
|
+
import {
|
|
695
|
+
wrapMemoryBlock,
|
|
696
|
+
wrapMemoryPointerBlock,
|
|
697
|
+
} from "../plugins/defaults/memory/memory-marker.js";
|
|
698
|
+
import {
|
|
699
|
+
getActiveSections as getV3ActiveSections,
|
|
700
|
+
recordInjected as recordV3Injected,
|
|
701
|
+
} from "../plugins/defaults/memory/v3/ever-injected-store.js";
|
|
686
702
|
import { asConversation } from "./helpers/mock-conversation.js";
|
|
687
703
|
import {
|
|
688
704
|
createMockProvider,
|
|
@@ -838,7 +854,7 @@ function makeCtx(
|
|
|
838
854
|
modelOverride: undefined,
|
|
839
855
|
|
|
840
856
|
graphMemory: {
|
|
841
|
-
onCompacted: async () =>
|
|
857
|
+
onCompacted: async () => true,
|
|
842
858
|
prepareMemory: async () => ({
|
|
843
859
|
runMessages: [],
|
|
844
860
|
injectedTokens: 0,
|
|
@@ -909,6 +925,40 @@ function makeCompactionResult(
|
|
|
909
925
|
};
|
|
910
926
|
}
|
|
911
927
|
|
|
928
|
+
/**
|
|
929
|
+
* `makeCtx` overrides for a real loop that appends a tool turn, is rejected as
|
|
930
|
+
* context-too-large on the following call, and recovers on the retry, so the
|
|
931
|
+
* reactive overflow ladder runs between the rejection and the recovery.
|
|
932
|
+
*/
|
|
933
|
+
function overflowAfterToolTurnScenario(): NonNullable<
|
|
934
|
+
Parameters<typeof makeCtx>[0]
|
|
935
|
+
> {
|
|
936
|
+
return {
|
|
937
|
+
providerResponses: [
|
|
938
|
+
toolUseResponse("t1", "file_read", {}),
|
|
939
|
+
new ContextOverflowError(
|
|
940
|
+
"context_length_exceeded: 250000 tokens > 200000 maximum",
|
|
941
|
+
"mock-provider",
|
|
942
|
+
{ actualTokens: 250_000, maxTokens: 200_000 },
|
|
943
|
+
),
|
|
944
|
+
textResponse("recovered"),
|
|
945
|
+
],
|
|
946
|
+
loopTools: [
|
|
947
|
+
{
|
|
948
|
+
name: "file_read",
|
|
949
|
+
description: "Read a file",
|
|
950
|
+
input_schema: { type: "object", properties: {} },
|
|
951
|
+
},
|
|
952
|
+
],
|
|
953
|
+
toolExecutor: async () => ({ content: "ok", isError: false }),
|
|
954
|
+
contextWindowManager: {
|
|
955
|
+
updateConfig: () => {},
|
|
956
|
+
shouldCompact: () => ({ needed: false, estimatedTokens: 0 }),
|
|
957
|
+
maybeCompact: async () => ({ compacted: false }),
|
|
958
|
+
} as unknown as Conversation["contextWindowManager"],
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
|
|
912
962
|
// ── Tests ────────────────────────────────────────────────────────────
|
|
913
963
|
|
|
914
964
|
beforeEach(() => {
|
|
@@ -4429,30 +4479,7 @@ describe("session-agent-loop", () => {
|
|
|
4429
4479
|
// context-too-large error on the following call — reactive overflow
|
|
4430
4480
|
// recovery strips that appended history when it compacts before a final
|
|
4431
4481
|
// call recovers.
|
|
4432
|
-
const ctx = makeCtx(
|
|
4433
|
-
providerResponses: [
|
|
4434
|
-
toolUseResponse("t1", "file_read", {}),
|
|
4435
|
-
new ContextOverflowError(
|
|
4436
|
-
"context_length_exceeded: 250000 tokens > 200000 maximum",
|
|
4437
|
-
"mock-provider",
|
|
4438
|
-
{ actualTokens: 250_000, maxTokens: 200_000 },
|
|
4439
|
-
),
|
|
4440
|
-
textResponse("recovered"),
|
|
4441
|
-
],
|
|
4442
|
-
loopTools: [
|
|
4443
|
-
{
|
|
4444
|
-
name: "file_read",
|
|
4445
|
-
description: "Read a file",
|
|
4446
|
-
input_schema: { type: "object", properties: {} },
|
|
4447
|
-
},
|
|
4448
|
-
],
|
|
4449
|
-
toolExecutor: async () => ({ content: "ok", isError: false }),
|
|
4450
|
-
contextWindowManager: {
|
|
4451
|
-
updateConfig: () => {},
|
|
4452
|
-
shouldCompact: () => ({ needed: false, estimatedTokens: 0 }),
|
|
4453
|
-
maybeCompact: async () => ({ compacted: false }),
|
|
4454
|
-
} as unknown as Conversation["contextWindowManager"],
|
|
4455
|
-
});
|
|
4482
|
+
const ctx = makeCtx(overflowAfterToolTurnScenario());
|
|
4456
4483
|
|
|
4457
4484
|
// WHEN the loop runs the turn to completion
|
|
4458
4485
|
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
@@ -4483,35 +4510,648 @@ describe("session-agent-loop", () => {
|
|
|
4483
4510
|
// context-too-large error on the following call, driving the
|
|
4484
4511
|
// overflow-recovery strip whose marker-write helper is stubbed to throw,
|
|
4485
4512
|
// before a final call recovers.
|
|
4513
|
+
const ctx = makeCtx(overflowAfterToolTurnScenario());
|
|
4514
|
+
|
|
4515
|
+
// Must not throw: the strip-site marker write is wrapped in try/catch.
|
|
4516
|
+
await expect(
|
|
4517
|
+
runAgentLoopImpl(ctx, "hello", "msg-1", () => {}),
|
|
4518
|
+
).resolves.toBeUndefined();
|
|
4519
|
+
});
|
|
4520
|
+
});
|
|
4521
|
+
|
|
4522
|
+
describe("injection ledger reset after an injection strip", () => {
|
|
4523
|
+
// The durable base is injection-stripped on every pipeline run, so the
|
|
4524
|
+
// frozen memory blocks the ledgers claim leave history whether or not a
|
|
4525
|
+
// summary lands. The ledgers must reset either way, and before the
|
|
4526
|
+
// post-compaction hook re-injects onto the stripped base; otherwise the
|
|
4527
|
+
// next turn classifies a re-selected section as resident and points at a
|
|
4528
|
+
// block that is gone. The reset is gated on the history-stripped marker:
|
|
4529
|
+
// without it a restart rehydrates the stripped blocks, so cleared ledgers
|
|
4530
|
+
// would inject each section again beside its rehydrated copy.
|
|
4531
|
+
|
|
4532
|
+
/** Seed the real memory-v3 section store with one resident section (and
|
|
4533
|
+
* prove the store is live in this process, so an empty read after the
|
|
4534
|
+
* run is a reset rather than a degraded store), then arrange a real
|
|
4535
|
+
* graph memory whose `onCompacted` records its position in `order`
|
|
4536
|
+
* before running for real, and a post-compact hook that records when
|
|
4537
|
+
* re-injection ran. */
|
|
4538
|
+
function arrangeResidentSectionAndObservers(conversationId: string) {
|
|
4539
|
+
recordV3Injected(conversationId, [
|
|
4540
|
+
{ slug: "page-a", key: "", bytes: 100 },
|
|
4541
|
+
]);
|
|
4542
|
+
expect(getV3ActiveSections(conversationId)).toEqual(
|
|
4543
|
+
new Map([["page-a", new Set([""])]]),
|
|
4544
|
+
);
|
|
4545
|
+
const order: string[] = [];
|
|
4546
|
+
const graphMemory = new ConversationGraphMemory(conversationId);
|
|
4547
|
+
const original = graphMemory.onCompacted.bind(graphMemory);
|
|
4548
|
+
const onCompacted = spyOn(graphMemory, "onCompacted").mockImplementation(
|
|
4549
|
+
async (count: number) => {
|
|
4550
|
+
order.push("reset");
|
|
4551
|
+
return await original(count);
|
|
4552
|
+
},
|
|
4553
|
+
);
|
|
4554
|
+
registerPlugin({
|
|
4555
|
+
manifest: { name: "test-observe-post-compact", version: "1.0.0" },
|
|
4556
|
+
hooks: {
|
|
4557
|
+
"post-compact": async () => {
|
|
4558
|
+
order.push("post_compact");
|
|
4559
|
+
},
|
|
4560
|
+
},
|
|
4561
|
+
});
|
|
4562
|
+
return { graphMemory, onCompacted, order };
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
/** A manager whose pipeline runs (recorded in `order`) and finds nothing
|
|
4566
|
+
* eligible to summarize, dropping the estimate back under budget so the
|
|
4567
|
+
* provider call proceeds. */
|
|
4568
|
+
function noopPipelineManager(
|
|
4569
|
+
order: string[],
|
|
4570
|
+
): Conversation["contextWindowManager"] {
|
|
4571
|
+
return {
|
|
4572
|
+
updateConfig: () => {},
|
|
4573
|
+
shouldCompact: () => ({ needed: false, estimatedTokens: 0 }),
|
|
4574
|
+
maybeCompact: async (messages: Message[]) => {
|
|
4575
|
+
order.push("pipeline");
|
|
4576
|
+
mockEstimateTokens = 1000;
|
|
4577
|
+
return { compacted: false, messages };
|
|
4578
|
+
},
|
|
4579
|
+
} as unknown as Conversation["contextWindowManager"];
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
test("a budget-gate run that finds nothing to summarize resets the ledgers before re-injection", async () => {
|
|
4583
|
+
const { graphMemory, onCompacted, order } =
|
|
4584
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4585
|
+
// Above the loop's first-call gate threshold, so it compacts in place
|
|
4586
|
+
// before its first provider call.
|
|
4587
|
+
mockEstimateTokens = 90_000;
|
|
4486
4588
|
const ctx = makeCtx({
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4589
|
+
graphMemory,
|
|
4590
|
+
contextWindowManager: noopPipelineManager(order),
|
|
4591
|
+
});
|
|
4592
|
+
|
|
4593
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4594
|
+
|
|
4595
|
+
// THEN the marker written at the strip is durable, so the ledgers reset
|
|
4596
|
+
// exactly once on its strength (no second marker write), as a strip
|
|
4597
|
+
// with no summary, and before the post-compaction hook re-injected onto
|
|
4598
|
+
// the stripped base
|
|
4599
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledTimes(1);
|
|
4600
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledWith(
|
|
4601
|
+
"test-conv",
|
|
4602
|
+
expect.any(Number),
|
|
4603
|
+
);
|
|
4604
|
+
expect(onCompacted.mock.calls).toEqual([[0]]);
|
|
4605
|
+
expect(order).toEqual(["pipeline", "reset", "post_compact"]);
|
|
4606
|
+
// AND the section store no longer claims the section, so the next turn
|
|
4607
|
+
// injects it net-new instead of pointing at a block that is gone
|
|
4608
|
+
expect(getV3ActiveSections("test-conv")).toEqual(new Map());
|
|
4609
|
+
});
|
|
4610
|
+
|
|
4611
|
+
/** Stub the marker write so the first write succeeds and every later
|
|
4612
|
+
* write fails, as a transient SQLite error (SQLITE_BUSY) landing between
|
|
4613
|
+
* the strip and the reset would. */
|
|
4614
|
+
function failMarkerWritesAfterTheFirst(): void {
|
|
4615
|
+
let markerWrites = 0;
|
|
4616
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
4617
|
+
markerWrites += 1;
|
|
4618
|
+
if (markerWrites > 1) {
|
|
4619
|
+
throw new Error("SQLITE_BUSY");
|
|
4620
|
+
}
|
|
4621
|
+
});
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
/** A manager whose pipeline runs (recorded in `order`) and compacts,
|
|
4625
|
+
* summarizing two persisted messages and dropping the estimate back under
|
|
4626
|
+
* budget so the provider call proceeds. */
|
|
4627
|
+
function compactingPipelineManager(
|
|
4628
|
+
order: string[],
|
|
4629
|
+
): Conversation["contextWindowManager"] {
|
|
4630
|
+
return {
|
|
4631
|
+
updateConfig: () => {},
|
|
4632
|
+
shouldCompact: () => ({ needed: false, estimatedTokens: 0 }),
|
|
4633
|
+
maybeCompact: async (messages: Message[]) => {
|
|
4634
|
+
order.push("pipeline");
|
|
4635
|
+
mockEstimateTokens = 1000;
|
|
4636
|
+
return {
|
|
4637
|
+
...makeCompactionResult({
|
|
4638
|
+
messages: [
|
|
4639
|
+
{ role: "user", content: [{ type: "text", text: "summary" }] },
|
|
4640
|
+
messages[messages.length - 1]!,
|
|
4641
|
+
],
|
|
4642
|
+
compactedPersistedMessages: 2,
|
|
4643
|
+
compactedMessages: 2,
|
|
4644
|
+
}),
|
|
4645
|
+
compacted: true,
|
|
4646
|
+
summaryFailed: false,
|
|
4647
|
+
};
|
|
4648
|
+
},
|
|
4649
|
+
} as unknown as Conversation["contextWindowManager"];
|
|
4650
|
+
}
|
|
4651
|
+
|
|
4652
|
+
test("resets the ledgers on the strip's durable marker write when a later marker write would fail", async () => {
|
|
4653
|
+
const { graphMemory, onCompacted, order } =
|
|
4654
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4655
|
+
failMarkerWritesAfterTheFirst();
|
|
4656
|
+
mockEstimateTokens = 90_000;
|
|
4657
|
+
const ctx = makeCtx({
|
|
4658
|
+
graphMemory,
|
|
4659
|
+
contextWindowManager: noopPipelineManager(order),
|
|
4660
|
+
});
|
|
4661
|
+
|
|
4662
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4663
|
+
|
|
4664
|
+
// THEN the marker the strip wrote is durable, so the reset does not
|
|
4665
|
+
// depend on a re-attempt that would fail: the ledgers reset once,
|
|
4666
|
+
// before re-injection, and the store no longer claims the section
|
|
4667
|
+
expect(onCompacted.mock.calls).toEqual([[0]]);
|
|
4668
|
+
expect(order).toEqual(["pipeline", "reset", "post_compact"]);
|
|
4669
|
+
expect(getV3ActiveSections("test-conv")).toEqual(new Map());
|
|
4670
|
+
});
|
|
4671
|
+
|
|
4672
|
+
test("resets the ledgers on the strip's durable marker write when the pipeline compacts and a later marker write would fail", async () => {
|
|
4673
|
+
const { graphMemory, onCompacted, order } =
|
|
4674
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4675
|
+
failMarkerWritesAfterTheFirst();
|
|
4676
|
+
mockEstimateTokens = 90_000;
|
|
4677
|
+
const ctx = makeCtx({
|
|
4678
|
+
graphMemory,
|
|
4679
|
+
contextWindowManager: compactingPipelineManager(order),
|
|
4680
|
+
});
|
|
4681
|
+
|
|
4682
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4683
|
+
|
|
4684
|
+
// THEN the durable commit resets the ledgers with the summarized count
|
|
4685
|
+
// on the strip's marker, without depending on a re-attempt that fails
|
|
4686
|
+
expect(onCompacted.mock.calls).toEqual([[2]]);
|
|
4687
|
+
expect(order).toEqual(["pipeline", "reset", "post_compact"]);
|
|
4688
|
+
expect(getV3ActiveSections("test-conv")).toEqual(new Map());
|
|
4689
|
+
});
|
|
4690
|
+
|
|
4691
|
+
test("an overflow rung that reduces without summarizing resets the ledgers before re-injection", async () => {
|
|
4692
|
+
const { graphMemory, onCompacted, order } =
|
|
4693
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4694
|
+
// Reducer: a truncation rung that reduces the history with no summary.
|
|
4695
|
+
mockReducerStepFn = (msgs: Message[]) => {
|
|
4696
|
+
order.push("pipeline");
|
|
4697
|
+
return {
|
|
4698
|
+
messages: msgs,
|
|
4699
|
+
tier: "tool_result_truncation",
|
|
4700
|
+
state: {
|
|
4701
|
+
appliedTiers: ["tool_result_truncation"],
|
|
4702
|
+
injectionMode: "full",
|
|
4703
|
+
exhausted: false,
|
|
4501
4704
|
},
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4705
|
+
estimatedTokens: 5000,
|
|
4706
|
+
};
|
|
4707
|
+
};
|
|
4708
|
+
const ctx = makeCtx({ ...overflowAfterToolTurnScenario(), graphMemory });
|
|
4709
|
+
|
|
4710
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4711
|
+
|
|
4712
|
+
expect(onCompacted.mock.calls).toEqual([[0]]);
|
|
4713
|
+
expect(order).toEqual(["pipeline", "reset", "post_compact"]);
|
|
4714
|
+
expect(getV3ActiveSections("test-conv")).toEqual(new Map());
|
|
4715
|
+
});
|
|
4716
|
+
|
|
4717
|
+
/**
|
|
4718
|
+
* The resident section's frozen memory-v3 block as it sits on an earlier
|
|
4719
|
+
* turn's user message. A reset clears its residency, so re-injection
|
|
4720
|
+
* renders the section net-new; a skipped reset leaves it resident, so
|
|
4721
|
+
* re-injection points at it instead.
|
|
4722
|
+
*/
|
|
4723
|
+
const FROZEN_SECTION_BLOCK = wrapMemoryBlock("## page-a\nbody");
|
|
4724
|
+
/** The pointer re-injection emits for the section while it is resident. */
|
|
4725
|
+
const SECTION_POINTER_BLOCK = wrapMemoryPointerBlock("page-a");
|
|
4726
|
+
|
|
4727
|
+
/** Earlier turns whose user message carries the frozen section block. */
|
|
4728
|
+
function historyWithFrozenSection(): Message[] {
|
|
4729
|
+
return [
|
|
4730
|
+
{
|
|
4731
|
+
role: "user",
|
|
4732
|
+
content: [
|
|
4733
|
+
{ type: "text", text: "Earlier turn" },
|
|
4734
|
+
{ type: "text", text: FROZEN_SECTION_BLOCK },
|
|
4735
|
+
],
|
|
4736
|
+
},
|
|
4737
|
+
{
|
|
4738
|
+
role: "assistant",
|
|
4739
|
+
content: [{ type: "text", text: "Earlier reply" }],
|
|
4740
|
+
},
|
|
4741
|
+
];
|
|
4742
|
+
}
|
|
4743
|
+
|
|
4744
|
+
/** The number of text blocks across `messages` whose text is `text`. */
|
|
4745
|
+
function countTextBlocks(messages: Message[], text: string): number {
|
|
4746
|
+
return messages
|
|
4747
|
+
.flatMap((message) => message.content)
|
|
4748
|
+
.filter((block) => block.type === "text" && block.text === text).length;
|
|
4749
|
+
}
|
|
4750
|
+
|
|
4751
|
+
/**
|
|
4752
|
+
* Register a post-compact hook standing in for the memory plugin's
|
|
4753
|
+
* re-injection: it records the history it receives beside the durable
|
|
4754
|
+
* history at that moment, then partitions the section by residency the
|
|
4755
|
+
* way the real injector does (a section the store still claims gets a
|
|
4756
|
+
* pointer on the tail; one a reset left unclaimed renders net-new there)
|
|
4757
|
+
* and writes the result back onto the context, as the real hook does.
|
|
4758
|
+
*/
|
|
4759
|
+
function registerReinjectingPostCompactHook(ctx: Conversation): {
|
|
4760
|
+
received: Array<{ history: Message[]; durable: Message[] }>;
|
|
4761
|
+
} {
|
|
4762
|
+
const received: Array<{ history: Message[]; durable: Message[] }> = [];
|
|
4763
|
+
registerPlugin({
|
|
4764
|
+
manifest: { name: "test-reinject-post-compact", version: "1.0.0" },
|
|
4765
|
+
hooks: {
|
|
4766
|
+
"post-compact": async (hookCtx: PostCompactContext) => {
|
|
4767
|
+
received.push({
|
|
4768
|
+
history: hookCtx.history,
|
|
4769
|
+
durable: structuredClone(ctx.messages),
|
|
4770
|
+
});
|
|
4771
|
+
const resident = getV3ActiveSections(ctx.conversationId).has(
|
|
4772
|
+
"page-a",
|
|
4773
|
+
);
|
|
4774
|
+
const tail = hookCtx.history[hookCtx.history.length - 1]!;
|
|
4775
|
+
hookCtx.history = [
|
|
4776
|
+
...hookCtx.history.slice(0, -1),
|
|
4777
|
+
{
|
|
4778
|
+
...tail,
|
|
4779
|
+
content: [
|
|
4780
|
+
...tail.content,
|
|
4781
|
+
{
|
|
4782
|
+
type: "text",
|
|
4783
|
+
text: resident
|
|
4784
|
+
? SECTION_POINTER_BLOCK
|
|
4785
|
+
: FROZEN_SECTION_BLOCK,
|
|
4786
|
+
},
|
|
4787
|
+
],
|
|
4788
|
+
},
|
|
4789
|
+
];
|
|
4790
|
+
},
|
|
4791
|
+
},
|
|
4792
|
+
});
|
|
4793
|
+
return { received };
|
|
4794
|
+
}
|
|
4795
|
+
|
|
4796
|
+
/** Stub the marker write to fail at the strip and again at the
|
|
4797
|
+
* re-attempt that precedes the reset, as a SQLite lock held across the
|
|
4798
|
+
* compaction (SQLITE_BUSY) would. */
|
|
4799
|
+
function failEveryMarkerWrite(): void {
|
|
4800
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
4801
|
+
throw new Error("SQLITE_BUSY");
|
|
4802
|
+
});
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4805
|
+
test("continues a budget-gate run that found nothing to summarize from the stripped base, so a section re-injected after the reset reaches the provider once", async () => {
|
|
4806
|
+
// GIVEN a resident section whose frozen block sits on an earlier turn's
|
|
4807
|
+
// user message, and a pipeline run that finds nothing to summarize
|
|
4808
|
+
const { graphMemory, order } =
|
|
4809
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4810
|
+
const { provider, calls } = createMockProvider(
|
|
4811
|
+
[textResponse("response")],
|
|
4812
|
+
"mock-provider",
|
|
4813
|
+
);
|
|
4814
|
+
mockEstimateTokens = 90_000;
|
|
4815
|
+
const ctx = makeCtx({
|
|
4816
|
+
graphMemory,
|
|
4817
|
+
contextWindowManager: noopPipelineManager(order),
|
|
4818
|
+
loopProvider: provider,
|
|
4819
|
+
messages: historyWithFrozenSection(),
|
|
4820
|
+
});
|
|
4821
|
+
const { received } = registerReinjectingPostCompactHook(ctx);
|
|
4822
|
+
|
|
4823
|
+
// WHEN the loop runs the turn
|
|
4824
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4825
|
+
|
|
4826
|
+
// THEN the hook re-injected onto the history the durable commit holds:
|
|
4827
|
+
// the stripped base, with the frozen block gone from the earlier message
|
|
4828
|
+
expect(received).toHaveLength(1);
|
|
4829
|
+
const { history, durable } = received[0]!;
|
|
4830
|
+
expect(countTextBlocks(durable, FROZEN_SECTION_BLOCK)).toBe(0);
|
|
4831
|
+
expect(countTextBlocks(history, FROZEN_SECTION_BLOCK)).toBe(0);
|
|
4832
|
+
expect(history).toEqual(durable);
|
|
4833
|
+
// AND the provider call that followed carried the section exactly once,
|
|
4834
|
+
// rendered net-new on the tail
|
|
4835
|
+
expect(calls).toHaveLength(1);
|
|
4836
|
+
expect(countTextBlocks(calls[0]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4837
|
+
});
|
|
4838
|
+
|
|
4839
|
+
test("continues an overflow rung that reduced without summarizing from the stripped base, so the retry carries a re-injected section once", async () => {
|
|
4840
|
+
// GIVEN a resident section whose frozen block sits on an earlier turn's
|
|
4841
|
+
// user message, and a truncation rung that reduces with no summary
|
|
4842
|
+
const { graphMemory, order } =
|
|
4843
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4844
|
+
mockReducerStepFn = (msgs: Message[]) => {
|
|
4845
|
+
order.push("pipeline");
|
|
4846
|
+
return {
|
|
4847
|
+
messages: msgs,
|
|
4848
|
+
tier: "tool_result_truncation",
|
|
4849
|
+
state: {
|
|
4850
|
+
appliedTiers: ["tool_result_truncation"],
|
|
4851
|
+
injectionMode: "full",
|
|
4852
|
+
exhausted: false,
|
|
4853
|
+
},
|
|
4854
|
+
estimatedTokens: 5000,
|
|
4855
|
+
};
|
|
4856
|
+
};
|
|
4857
|
+
const scenario = overflowAfterToolTurnScenario();
|
|
4858
|
+
const { provider, calls } = createMockProvider(
|
|
4859
|
+
scenario.providerResponses!,
|
|
4860
|
+
"mock-provider",
|
|
4861
|
+
);
|
|
4862
|
+
const ctx = makeCtx({
|
|
4863
|
+
...scenario,
|
|
4864
|
+
graphMemory,
|
|
4865
|
+
loopProvider: provider,
|
|
4866
|
+
messages: historyWithFrozenSection(),
|
|
4867
|
+
});
|
|
4868
|
+
const { received } = registerReinjectingPostCompactHook(ctx);
|
|
4869
|
+
|
|
4870
|
+
// WHEN the loop runs the turn through the rejection and the retry
|
|
4871
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4872
|
+
|
|
4873
|
+
// THEN the hook re-injected onto the stripped base the durable commit
|
|
4874
|
+
// holds, not the rung's reduced copy of the injected history
|
|
4875
|
+
expect(received).toHaveLength(1);
|
|
4876
|
+
const { history, durable } = received[0]!;
|
|
4877
|
+
expect(countTextBlocks(durable, FROZEN_SECTION_BLOCK)).toBe(0);
|
|
4878
|
+
expect(countTextBlocks(history, FROZEN_SECTION_BLOCK)).toBe(0);
|
|
4879
|
+
expect(history).toEqual(durable);
|
|
4880
|
+
// AND the rejected call carried the frozen copy while the retry after
|
|
4881
|
+
// the rung carried the re-injected copy alone, so recovery regained no
|
|
4882
|
+
// tokens it set out to remove
|
|
4883
|
+
expect(calls).toHaveLength(3);
|
|
4884
|
+
expect(countTextBlocks(calls[1]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4885
|
+
expect(countTextBlocks(calls[2]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4886
|
+
});
|
|
4887
|
+
|
|
4888
|
+
test("continues a budget-gate run whose strip marker cannot be made durable from the injected history, so the section the intact ledgers still claim reaches the provider once", async () => {
|
|
4889
|
+
// GIVEN a resident section whose frozen block sits on an earlier turn's
|
|
4890
|
+
// user message, a pipeline run that finds nothing to summarize, and a
|
|
4891
|
+
// marker write that fails at the strip and at the re-attempt
|
|
4892
|
+
const { graphMemory, onCompacted, order } =
|
|
4893
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4894
|
+
failEveryMarkerWrite();
|
|
4895
|
+
const { provider, calls } = createMockProvider(
|
|
4896
|
+
[textResponse("response")],
|
|
4897
|
+
"mock-provider",
|
|
4898
|
+
);
|
|
4899
|
+
mockEstimateTokens = 90_000;
|
|
4900
|
+
const ctx = makeCtx({
|
|
4901
|
+
graphMemory,
|
|
4902
|
+
contextWindowManager: noopPipelineManager(order),
|
|
4903
|
+
loopProvider: provider,
|
|
4904
|
+
messages: historyWithFrozenSection(),
|
|
4905
|
+
});
|
|
4906
|
+
const { received } = registerReinjectingPostCompactHook(ctx);
|
|
4907
|
+
|
|
4908
|
+
// WHEN the loop runs the turn
|
|
4909
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4910
|
+
|
|
4911
|
+
// THEN both marker writes failed, so no reset ran and the store still
|
|
4912
|
+
// claims the section
|
|
4913
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledTimes(2);
|
|
4914
|
+
expect(onCompacted).not.toHaveBeenCalled();
|
|
4915
|
+
expect(getV3ActiveSections("test-conv")).toEqual(
|
|
4916
|
+
new Map([["page-a", new Set([""])]]),
|
|
4917
|
+
);
|
|
4918
|
+
// AND the hook re-injected onto the history the durable commit holds:
|
|
4919
|
+
// the injected history, the frozen block still on the earlier message
|
|
4920
|
+
// where the store's residency expects it
|
|
4921
|
+
expect(received).toHaveLength(1);
|
|
4922
|
+
const { history, durable } = received[0]!;
|
|
4923
|
+
expect(countTextBlocks(durable, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4924
|
+
expect(countTextBlocks(history, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4925
|
+
expect(history).toEqual(durable);
|
|
4926
|
+
// AND the provider call that followed carried the section exactly once:
|
|
4927
|
+
// the frozen copy, pointed at rather than rendered again
|
|
4928
|
+
expect(calls).toHaveLength(1);
|
|
4929
|
+
expect(countTextBlocks(calls[0]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4930
|
+
expect(countTextBlocks(calls[0]!.messages, SECTION_POINTER_BLOCK)).toBe(
|
|
4931
|
+
1,
|
|
4932
|
+
);
|
|
4933
|
+
});
|
|
4934
|
+
|
|
4935
|
+
test("continues a budget-gate run whose ledger clear fails from the injected history, so the section the ledgers still claim reaches the provider once", async () => {
|
|
4936
|
+
// GIVEN a resident section whose frozen block sits on an earlier turn's
|
|
4937
|
+
// user message, a pipeline run that finds nothing to summarize, a
|
|
4938
|
+
// marker write that succeeds, and a ledger clear that fails
|
|
4939
|
+
const { graphMemory, onCompacted, order } =
|
|
4940
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4941
|
+
onCompacted.mockImplementation(async () => {
|
|
4942
|
+
order.push("reset");
|
|
4943
|
+
return false;
|
|
4944
|
+
});
|
|
4945
|
+
const { provider, calls } = createMockProvider(
|
|
4946
|
+
[textResponse("response")],
|
|
4947
|
+
"mock-provider",
|
|
4948
|
+
);
|
|
4949
|
+
mockEstimateTokens = 90_000;
|
|
4950
|
+
const ctx = makeCtx({
|
|
4951
|
+
graphMemory,
|
|
4952
|
+
contextWindowManager: noopPipelineManager(order),
|
|
4953
|
+
loopProvider: provider,
|
|
4954
|
+
messages: historyWithFrozenSection(),
|
|
4955
|
+
});
|
|
4956
|
+
const { received } = registerReinjectingPostCompactHook(ctx);
|
|
4957
|
+
|
|
4958
|
+
// WHEN the loop runs the turn
|
|
4959
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
4960
|
+
|
|
4961
|
+
// THEN the marker landed at the strip and the reset ran but reported an
|
|
4962
|
+
// incomplete clear, so the store still claims the section
|
|
4963
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledTimes(1);
|
|
4964
|
+
expect(onCompacted.mock.calls).toEqual([[0]]);
|
|
4965
|
+
expect(order).toEqual(["pipeline", "reset", "post_compact"]);
|
|
4966
|
+
expect(getV3ActiveSections("test-conv")).toEqual(
|
|
4967
|
+
new Map([["page-a", new Set([""])]]),
|
|
4968
|
+
);
|
|
4969
|
+
// AND the hook re-injected onto the injected history the durable commit
|
|
4970
|
+
// holds, the frozen block still on the earlier message where the
|
|
4971
|
+
// store's residency expects it
|
|
4972
|
+
expect(received).toHaveLength(1);
|
|
4973
|
+
const { history, durable } = received[0]!;
|
|
4974
|
+
expect(countTextBlocks(durable, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4975
|
+
expect(countTextBlocks(history, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4976
|
+
expect(history).toEqual(durable);
|
|
4977
|
+
// AND the provider call carried the section exactly once: the frozen
|
|
4978
|
+
// copy, pointed at rather than rendered again
|
|
4979
|
+
expect(calls).toHaveLength(1);
|
|
4980
|
+
expect(countTextBlocks(calls[0]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
4981
|
+
expect(countTextBlocks(calls[0]!.messages, SECTION_POINTER_BLOCK)).toBe(
|
|
4982
|
+
1,
|
|
4983
|
+
);
|
|
4984
|
+
});
|
|
4985
|
+
|
|
4986
|
+
test("continues an overflow rung whose strip marker cannot be made durable from the rung's reduced history with its injections intact, so the retry carries the section the intact ledgers still claim once", async () => {
|
|
4987
|
+
// GIVEN a resident section whose frozen block sits on an earlier turn's
|
|
4988
|
+
// user message, a truncation rung that reduces with no summary, and a
|
|
4989
|
+
// marker write that fails at the strip and at the re-attempt
|
|
4990
|
+
const { graphMemory, onCompacted, order } =
|
|
4991
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
4992
|
+
failEveryMarkerWrite();
|
|
4993
|
+
mockReducerStepFn = (msgs: Message[]) => {
|
|
4994
|
+
order.push("pipeline");
|
|
4995
|
+
return {
|
|
4996
|
+
messages: msgs,
|
|
4997
|
+
tier: "tool_result_truncation",
|
|
4998
|
+
state: {
|
|
4999
|
+
appliedTiers: ["tool_result_truncation"],
|
|
5000
|
+
injectionMode: "full",
|
|
5001
|
+
exhausted: false,
|
|
5002
|
+
},
|
|
5003
|
+
estimatedTokens: 5000,
|
|
5004
|
+
};
|
|
5005
|
+
};
|
|
5006
|
+
const scenario = overflowAfterToolTurnScenario();
|
|
5007
|
+
const { provider, calls } = createMockProvider(
|
|
5008
|
+
scenario.providerResponses!,
|
|
5009
|
+
"mock-provider",
|
|
5010
|
+
);
|
|
5011
|
+
const ctx = makeCtx({
|
|
5012
|
+
...scenario,
|
|
5013
|
+
graphMemory,
|
|
5014
|
+
loopProvider: provider,
|
|
5015
|
+
messages: historyWithFrozenSection(),
|
|
5016
|
+
});
|
|
5017
|
+
const { received } = registerReinjectingPostCompactHook(ctx);
|
|
5018
|
+
|
|
5019
|
+
// WHEN the loop runs the turn through the rejection and the retry
|
|
5020
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
5021
|
+
|
|
5022
|
+
// THEN no reset ran and the store still claims the section
|
|
5023
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledTimes(2);
|
|
5024
|
+
expect(onCompacted).not.toHaveBeenCalled();
|
|
5025
|
+
expect(getV3ActiveSections("test-conv")).toEqual(
|
|
5026
|
+
new Map([["page-a", new Set([""])]]),
|
|
5027
|
+
);
|
|
5028
|
+
// AND the hook re-injected onto the injected history the durable commit
|
|
5029
|
+
// holds, the frozen block still on the earlier message
|
|
5030
|
+
expect(received).toHaveLength(1);
|
|
5031
|
+
const { history, durable } = received[0]!;
|
|
5032
|
+
expect(countTextBlocks(durable, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
5033
|
+
expect(countTextBlocks(history, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
5034
|
+
expect(history).toEqual(durable);
|
|
5035
|
+
// AND the retry after the rung carried the frozen copy once, pointed at
|
|
5036
|
+
// rather than rendered again
|
|
5037
|
+
expect(calls).toHaveLength(3);
|
|
5038
|
+
expect(countTextBlocks(calls[2]!.messages, FROZEN_SECTION_BLOCK)).toBe(1);
|
|
5039
|
+
expect(countTextBlocks(calls[2]!.messages, SECTION_POINTER_BLOCK)).toBe(
|
|
5040
|
+
1,
|
|
5041
|
+
);
|
|
5042
|
+
});
|
|
5043
|
+
|
|
5044
|
+
test("leaves the ledgers intact when the history-stripped marker cannot be written", async () => {
|
|
5045
|
+
const { graphMemory, onCompacted, order } =
|
|
5046
|
+
arrangeResidentSectionAndObservers("test-conv");
|
|
5047
|
+
failEveryMarkerWrite();
|
|
5048
|
+
mockEstimateTokens = 90_000;
|
|
5049
|
+
const ctx = makeCtx({
|
|
5050
|
+
graphMemory,
|
|
5051
|
+
contextWindowManager: noopPipelineManager(order),
|
|
5052
|
+
});
|
|
5053
|
+
|
|
5054
|
+
await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
|
|
5055
|
+
|
|
5056
|
+
// THEN the reset re-attempted the write (no write for the strip had
|
|
5057
|
+
// succeeded) and that failed too, so no reset ran: a restart rehydrates
|
|
5058
|
+
// the frozen blocks with no marker to skip them, so the store must keep
|
|
5059
|
+
// claiming the section
|
|
5060
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledTimes(2);
|
|
5061
|
+
expect(onCompacted).not.toHaveBeenCalled();
|
|
5062
|
+
expect(order).toEqual(["pipeline", "post_compact"]);
|
|
5063
|
+
expect(getV3ActiveSections("test-conv")).toEqual(
|
|
5064
|
+
new Map([["page-a", new Set([""])]]),
|
|
5065
|
+
);
|
|
5066
|
+
});
|
|
5067
|
+
|
|
5068
|
+
test("applyCompactionResult resets the ledgers only once the marker is written", async () => {
|
|
5069
|
+
const order: string[] = [];
|
|
5070
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
5071
|
+
order.push("marker");
|
|
5072
|
+
});
|
|
5073
|
+
const onCompacted = mock(async (_count: number) => {
|
|
5074
|
+
order.push("reset");
|
|
5075
|
+
return true;
|
|
5076
|
+
});
|
|
5077
|
+
const ctx = makeCtx({
|
|
5078
|
+
graphMemory: { onCompacted } as unknown as Conversation["graphMemory"],
|
|
5079
|
+
});
|
|
5080
|
+
|
|
5081
|
+
await applyCompactionResult(
|
|
5082
|
+
ctx,
|
|
5083
|
+
makeCompactionResult(),
|
|
5084
|
+
() => {},
|
|
5085
|
+
"req-1",
|
|
5086
|
+
);
|
|
5087
|
+
|
|
5088
|
+
expect(onCompacted.mock.calls).toEqual([[4]]);
|
|
5089
|
+
expect(order).toEqual(["marker", "reset"]);
|
|
5090
|
+
});
|
|
5091
|
+
|
|
5092
|
+
test("applyCompactionResult leaves the ledgers intact when the compaction commit throws, so a reload of the un-compacted history finds its frozen blocks still claimed", async () => {
|
|
5093
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
5094
|
+
throw new Error("db write failed");
|
|
5095
|
+
});
|
|
5096
|
+
updateConversationContextWindowMock.mockImplementationOnce(() => {
|
|
5097
|
+
throw new Error("SQLITE_READONLY");
|
|
5098
|
+
});
|
|
5099
|
+
const onCompacted = mock(async (_count: number) => true);
|
|
5100
|
+
const ctx = makeCtx({
|
|
5101
|
+
graphMemory: { onCompacted } as unknown as Conversation["graphMemory"],
|
|
4509
5102
|
});
|
|
4510
5103
|
|
|
4511
|
-
// Must not throw — the strip-site marker write is wrapped in try/catch.
|
|
4512
5104
|
await expect(
|
|
4513
|
-
|
|
5105
|
+
applyCompactionResult(ctx, makeCompactionResult(), () => {}, "req-1"),
|
|
5106
|
+
).rejects.toThrow("SQLITE_READONLY");
|
|
5107
|
+
|
|
5108
|
+
expect(onCompacted).not.toHaveBeenCalled();
|
|
5109
|
+
});
|
|
5110
|
+
|
|
5111
|
+
test("applyCompactionResult resets the ledgers even when the marker cannot be written, since the compacted history has already lost its frozen blocks", async () => {
|
|
5112
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
5113
|
+
throw new Error("db write failed");
|
|
5114
|
+
});
|
|
5115
|
+
const onCompacted = mock(async (_count: number) => true);
|
|
5116
|
+
const ctx = makeCtx({
|
|
5117
|
+
graphMemory: { onCompacted } as unknown as Conversation["graphMemory"],
|
|
5118
|
+
});
|
|
5119
|
+
|
|
5120
|
+
// The marker write is best-effort, so the durable commit still lands.
|
|
5121
|
+
await expect(
|
|
5122
|
+
applyCompactionResult(ctx, makeCompactionResult(), () => {}, "req-1"),
|
|
4514
5123
|
).resolves.toBeUndefined();
|
|
5124
|
+
|
|
5125
|
+
expect(setConversationHistoryStrippedAtMock).toHaveBeenCalledWith(
|
|
5126
|
+
"test-conv",
|
|
5127
|
+
expect.any(Number),
|
|
5128
|
+
);
|
|
5129
|
+
// The summary output carries no frozen block, so the ledgers must not
|
|
5130
|
+
// keep claiming sections whose blocks are gone.
|
|
5131
|
+
expect(onCompacted.mock.calls).toEqual([[4]]);
|
|
5132
|
+
});
|
|
5133
|
+
|
|
5134
|
+
test("applyCompactionResult resets the ledgers on an already-durable marker without a second write", async () => {
|
|
5135
|
+
setConversationHistoryStrippedAtMock.mockImplementation(() => {
|
|
5136
|
+
throw new Error("SQLITE_BUSY");
|
|
5137
|
+
});
|
|
5138
|
+
const onCompacted = mock(async (_count: number) => true);
|
|
5139
|
+
const ctx = makeCtx({
|
|
5140
|
+
graphMemory: { onCompacted } as unknown as Conversation["graphMemory"],
|
|
5141
|
+
});
|
|
5142
|
+
|
|
5143
|
+
await applyCompactionResult(
|
|
5144
|
+
ctx,
|
|
5145
|
+
makeCompactionResult(),
|
|
5146
|
+
() => {},
|
|
5147
|
+
"req-1",
|
|
5148
|
+
{ historyStripMarkerDurable: true },
|
|
5149
|
+
);
|
|
5150
|
+
|
|
5151
|
+
// The strip's marker write already succeeded, so the reset neither
|
|
5152
|
+
// needs nor attempts another write that would fail here.
|
|
5153
|
+
expect(setConversationHistoryStrippedAtMock).not.toHaveBeenCalled();
|
|
5154
|
+
expect(onCompacted.mock.calls).toEqual([[4]]);
|
|
4515
5155
|
});
|
|
4516
5156
|
});
|
|
4517
5157
|
});
|