@sema-agent/core 7.69.0 → 7.69.1
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/CHANGELOG.md +583 -0
- package/dist/agents/repair-loop.js +6 -14
- package/dist/agents/subagent.js +2 -1
- package/dist/agents/verify.d.ts +1 -1
- package/dist/agents/verify.js +7 -1
- package/dist/brain/reasoning-request.d.ts +7 -0
- package/dist/brain/reasoning-request.js +6 -0
- package/dist/core/agent-config-dir.d.ts +39 -3
- package/dist/core/agent-config-dir.js +67 -11
- package/dist/core/allow-entry.d.ts +5 -5
- package/dist/core/allow-entry.js +12 -6
- package/dist/core/ask-headline.d.ts +2 -2
- package/dist/core/ask-origin.d.ts +31 -31
- package/dist/core/ask-origin.js +20 -13
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +1 -0
- package/dist/core/auto-compaction.d.ts +44 -62
- package/dist/core/auto-compaction.js +44 -103
- package/dist/core/cache-break-detector.d.ts +23 -11
- package/dist/core/cache-break-detector.js +11 -5
- package/dist/core/checkpoint-features.d.ts +1 -1
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +6 -0
- package/dist/core/checkpoint-row-verdict.js +3 -0
- package/dist/core/checkpoint-store.d.ts +13 -2
- package/dist/core/child-clamp-seats.d.ts +30 -3
- package/dist/core/child-clamp-seats.js +24 -0
- package/dist/core/compaction-retired-members.d.ts +12 -0
- package/dist/core/compaction-retired-members.js +22 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +2 -0
- package/dist/core/context-edit.d.ts +32 -17
- package/dist/core/context-edit.js +28 -0
- package/dist/core/cron.d.ts +68 -0
- package/dist/core/cron.js +259 -0
- package/dist/core/engine-attestation.d.ts +16 -0
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-capabilities.d.ts +14 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +18 -7
- package/dist/core/engine-version.js +1 -1
- package/dist/core/gate-outcome.d.ts +29 -2
- package/dist/core/gate-outcome.js +6 -0
- package/dist/core/git-read-only.d.ts +10 -0
- package/dist/core/git-read-only.js +1 -0
- package/dist/core/git-worktree-env.js +9 -8
- package/dist/core/governance-codes.d.ts +9 -2
- package/dist/core/governance-codes.js +9 -0
- package/dist/core/locked-config.js +7 -3
- package/dist/core/lsp.d.ts +3 -0
- package/dist/core/lsp.js +3 -2
- package/dist/core/memory-engine/engine.d.ts +48 -12
- package/dist/core/memory-engine/engine.js +108 -46
- package/dist/core/memory-engine/file-backend.d.ts +2 -1
- package/dist/core/memory-engine/index-copies.d.ts +47 -0
- package/dist/core/memory-engine/index-copies.js +88 -0
- package/dist/core/memory-engine/layout.d.ts +20 -3
- package/dist/core/memory-engine/layout.js +39 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +9 -7
- package/dist/core/memory-engine/origin-clearance.js +2 -4
- package/dist/core/memory-engine/types.d.ts +16 -3
- package/dist/core/mode-policy.d.ts +7 -1
- package/dist/core/mode-policy.js +9 -0
- package/dist/core/mods/session-compact.js +3 -3
- package/dist/core/mods/stations.d.ts +2 -0
- package/dist/core/mods/stations.js +2 -1
- package/dist/core/path-guard-rows.d.ts +8 -3
- package/dist/core/path-guard-rows.js +18 -5
- package/dist/core/peer-seat.d.ts +3 -0
- package/dist/core/peer-seat.js +3 -0
- package/dist/core/permission-rule-model.js +3 -2
- package/dist/core/process-identity.d.ts +11 -3
- package/dist/core/process-identity.js +26 -16
- package/dist/core/runner/assemble-result.d.ts +5 -0
- package/dist/core/runner/assemble-result.js +1 -1
- package/dist/core/runner/cleared-results-record.d.ts +33 -0
- package/dist/core/runner/cleared-results-record.js +56 -0
- package/dist/core/runner/compact-session.js +14 -9
- package/dist/core/runner/compaction-knobs.d.ts +1 -1
- package/dist/core/runner/continuation-gate.js +2 -1
- package/dist/core/runner/continues-from.d.ts +1 -1
- package/dist/core/runner/continues-from.js +1 -1
- package/dist/core/runner/contracts.d.ts +83 -31
- package/dist/core/runner/conversation-segment.d.ts +19 -12
- package/dist/core/runner/conversation-segment.js +27 -7
- package/dist/core/runner/derived-route-fallback.d.ts +2 -12
- package/dist/core/runner/derived-route-fallback.js +0 -6
- package/dist/core/runner/gate-exit.d.ts +2 -1
- package/dist/core/runner/gate-exit.js +4 -2
- package/dist/core/runner/git-status-frame.d.ts +2 -2
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/initial-run-state.js +1 -1
- package/dist/core/runner/leg-caller-places.d.ts +39 -0
- package/dist/core/runner/leg-caller-places.js +23 -0
- package/dist/core/runner/leg-frame.d.ts +8 -2
- package/dist/core/runner/leg-receipt.d.ts +29 -2
- package/dist/core/runner/leg-receipt.js +37 -6
- package/dist/core/runner/media-removed-seat.d.ts +10 -6
- package/dist/core/runner/media-removed-seat.js +6 -3
- package/dist/core/runner/messages-omitted-seat.d.ts +2 -1
- package/dist/core/runner/messages-omitted-seat.js +15 -5
- package/dist/core/runner/person-path-rows.d.ts +25 -7
- package/dist/core/runner/person-path-rows.js +16 -2
- package/dist/core/runner/prefix-ledger.d.ts +120 -0
- package/dist/core/runner/prefix-ledger.js +176 -0
- package/dist/core/runner/prepare-advisor.d.ts +2 -0
- package/dist/core/runner/prepare-advisor.js +2 -1
- package/dist/core/runner/prepare-artifact.d.ts +3 -0
- package/dist/core/runner/prepare-artifact.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +9 -8
- package/dist/core/runner/prepare-config-doors.js +15 -12
- package/dist/core/runner/prepare-context-lane.d.ts +25 -6
- package/dist/core/runner/prepare-context-lane.js +82 -27
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -2
- package/dist/core/runner/prepare-gate-stations.js +2 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +18 -5
- package/dist/core/runner/prepare-hands-readface.js +41 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -0
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory.d.ts +10 -2
- package/dist/core/runner/prepare-memory.js +51 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -0
- package/dist/core/runner/prepare-policy-chain.js +13 -2
- package/dist/core/runner/prepare-prompt-assembly.d.ts +12 -4
- package/dist/core/runner/prepare-prompt-assembly.js +10 -4
- package/dist/core/runner/prepare-prompt-inputs.d.ts +3 -7
- package/dist/core/runner/prepare-prompt-inputs.js +6 -7
- package/dist/core/runner/prepare-safety-scan.js +7 -0
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -0
- package/dist/core/runner/prepare-suspend-saga.js +3 -2
- package/dist/core/runner/prepare-task.js +59 -53
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +5 -11
- package/dist/core/runner/prepare-tool-disclosure-mount.js +7 -8
- package/dist/core/runner/prepare-turn-wiring.d.ts +16 -25
- package/dist/core/runner/prepare-turn-wiring.js +8 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prompt-suggestions.d.ts +3 -1
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/read-block-judge.d.ts +47 -0
- package/dist/core/runner/read-block-judge.js +33 -0
- package/dist/core/runner/role-resolution-table.d.ts +15 -10
- package/dist/core/runner/role-resolution-table.js +4 -5
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -4
- package/dist/core/runner/rule-store-unreadable-notice.js +4 -3
- package/dist/core/runner/run-compaction-machinery.d.ts +0 -10
- package/dist/core/runner/run-compaction-machinery.js +3 -39
- package/dist/core/runner/run-harness-handlers.js +4 -17
- package/dist/core/runner/run-identity-wiring.js +4 -1
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
- package/dist/core/runner/run-recovery-lanes.js +34 -18
- package/dist/core/runner/run-settle-and-teardown.d.ts +1 -3
- package/dist/core/runner/run-settle-and-teardown.js +14 -22
- package/dist/core/runner/run-telemetry-and-budget-seats.js +0 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
- package/dist/core/runner/run-terminal-adoption.js +5 -88
- package/dist/core/runner/run-tool-mount-facts.js +1 -5
- package/dist/core/runner/run-turn-boundary.js +56 -26
- package/dist/core/runner/runtask.js +7 -7
- package/dist/core/runner/session-hash-salt.d.ts +18 -0
- package/dist/core/runner/session-hash-salt.js +36 -0
- package/dist/core/runner/shell-env-withheld.d.ts +8 -5
- package/dist/core/runner/shell-env-withheld.js +3 -3
- package/dist/core/runner/side-call-account.d.ts +9 -1
- package/dist/core/runner/side-call-account.js +15 -4
- package/dist/core/runner/skill-mention.d.ts +12 -0
- package/dist/core/runner/skill-mention.js +50 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-table-view.d.ts +5 -9
- package/dist/core/runner/tool-table-view.js +23 -21
- package/dist/core/runner/write-protection-station.d.ts +5 -2
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +25 -27
- package/dist/core/scheduler.d.ts +13 -3
- package/dist/core/scheduler.js +0 -12
- package/dist/core/secret-env.d.ts +47 -11
- package/dist/core/secret-env.js +65 -4
- package/dist/core/sensitive-path-policy.js +4 -0
- package/dist/core/session-checkout.js +10 -9
- package/dist/core/shell-read-silence.d.ts +2 -1
- package/dist/core/shell-run-candidates.d.ts +1 -1
- package/dist/core/shell-run-candidates.js +11 -3
- package/dist/core/task-event.d.ts +32 -10
- package/dist/core/task-intake.d.ts +5 -3
- package/dist/core/task-intake.js +6 -2
- package/dist/core/task-result.d.ts +39 -0
- package/dist/core/task-spec-members.d.ts +3 -0
- package/dist/core/task-spec-members.js +2 -2
- package/dist/core/task-spec.d.ts +37 -20
- package/dist/core/tool-policy.d.ts +30 -18
- package/dist/core/tool-policy.js +44 -32
- package/dist/core/tool-roster.d.ts +21 -7
- package/dist/core/tool-roster.js +34 -6
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +27 -0
- package/dist/core/tools.js +1 -0
- package/dist/core/trace.d.ts +42 -19
- package/dist/core/unc-spelling.d.ts +31 -0
- package/dist/core/unc-spelling.js +51 -0
- package/dist/core/wiring-manifest.d.ts +30 -3
- package/dist/core/wiring-manifest.js +10 -0
- package/dist/core/workflow-run-store-contract.js +22 -0
- package/dist/core/workflow-run-store.d.ts +17 -13
- package/dist/core/workflow-run-store.js +1 -1
- package/dist/core/write-protect.d.ts +4 -0
- package/dist/core/write-protect.js +17 -15
- package/dist/engine/compaction/compaction.d.ts +48 -98
- package/dist/engine/compaction/compaction.js +136 -216
- package/dist/engine/compaction/utils.d.ts +2 -11
- package/dist/engine/compaction/utils.js +4 -13
- package/dist/engine/execution-env/node-execution-env.js +17 -6
- package/dist/engine/harness/agent-harness.d.ts +19 -5
- package/dist/engine/harness/agent-harness.js +18 -7
- package/dist/engine/harness/types.d.ts +5 -7
- package/dist/engine/loop/agent-loop.d.ts +14 -1
- package/dist/engine/loop/agent-loop.js +31 -11
- package/dist/engine/loop/types.d.ts +8 -2
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-spec.js +7 -2
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow-park-adoption.d.ts +66 -8
- package/dist/orchestration/workflow-park-adoption.js +195 -45
- package/dist/orchestration/workflow-types.d.ts +20 -0
- package/dist/orchestration/workflow-types.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -2
- package/dist/orchestration/workflow.js +10 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/events.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/mechanism.d.ts +8 -0
- package/dist/prompt-assembly/catalog/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +1 -1
- package/dist/prompt-assembly/catalog/schema.js +1 -0
- package/dist/prompt-assembly/catalog/sections.js +8 -0
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +14 -27
- package/dist/prompt-assembly/turn-snapshot.js +6 -18
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +9 -0
- package/dist/prompts/default.js +4 -0
- package/dist/shell/lex.d.ts +75 -11
- package/dist/shell/lex.js +340 -76
- package/dist/tools/fs/bash-program-position.js +2 -6
- package/dist/tools/fs/bash-readonly-classifier.d.ts +18 -3
- package/dist/tools/fs/bash-readonly-classifier.js +19 -9
- package/dist/tools/fs/containment-face.d.ts +12 -3
- package/dist/tools/fs/containment-face.js +16 -7
- package/dist/tools/fs/file-read-check.d.ts +26 -1
- package/dist/tools/fs/file-read-check.js +20 -2
- package/dist/tools/fs/fs-bash.js +4 -4
- package/dist/tools/fs/fs-read.d.ts +3 -0
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-search-tools.d.ts +2 -2
- package/dist/tools/fs/fs-search-tools.js +4 -4
- package/dist/tools/fs/index.js +5 -3
- package/dist/tools/fs/pdf.js +12 -4
- package/dist/tools/fs/read-deny-home.d.ts +13 -2
- package/dist/tools/fs/read-deny-home.js +26 -22
- package/dist/tools/fs/read-deny.js +15 -6
- package/dist/tools/fs/removal-targets.d.ts +33 -17
- package/dist/tools/fs/removal-targets.js +160 -61
- package/dist/tools/fs/repo-map.d.ts +1 -1
- package/dist/tools/fs/repo-map.js +2 -2
- package/dist/tools/fs/safety.d.ts +28 -5
- package/dist/tools/fs/safety.js +72 -8
- package/dist/tools/fs/shell-read-bindings.d.ts +8 -2
- package/dist/tools/fs/shell-read-bindings.js +25 -6
- package/dist/tools/fs/shell-read-check.d.ts +3 -0
- package/dist/tools/fs/shell-read-check.js +22 -4
- package/dist/tools/fs/shell-read-establish.js +73 -43
- package/dist/tools/fs/shell-read-judge.d.ts +32 -14
- package/dist/tools/fs/shell-read-judge.js +13 -5
- package/dist/tools/fs/shell-read-object-path.d.ts +5 -1
- package/dist/tools/fs/shell-read-object-path.js +17 -4
- package/dist/tools/fs/shell-read-plan.d.ts +8 -2
- package/dist/tools/fs/shell-read-plan.js +36 -22
- package/dist/tools/fs/shell-read-sourced.js +12 -4
- package/dist/tools/fs/shell-read-start.d.ts +4 -2
- package/dist/tools/fs/shell-read-start.js +3 -3
- package/dist/tools/fs/shell-read-workdir.d.ts +14 -6
- package/dist/tools/fs/shell-read-workdir.js +35 -17
- package/dist/tools/scheduler-tools.d.ts +7 -17
- package/dist/tools/scheduler-tools.js +9 -85
- package/dist/tools/worktree.js +5 -4
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +47 -1
- package/wire-changes/core-stores-sql@7.68.6.json +39 -0
- package/wire-changes/core-stores-sql@7.69.1.json +39 -0
- package/wire-changes/core@7.68.6.json +125 -0
- package/wire-changes/core@7.69.1.json +2561 -0
- package/wire-changes/mods-kernel@7.68.6.json +39 -0
- package/wire-changes/mods-kernel@7.69.1.json +39 -0
- package/wire-changes/primitives@7.68.6.json +39 -0
- package/wire-changes/primitives@7.69.1.json +39 -0
- package/wire-changes/wiki-gate@7.68.6.json +39 -0
- package/wire-changes/wiki-gate@7.69.1.json +39 -0
- package/dist/core/runner/prompt-hash-salt.d.ts +0 -1
- package/dist/core/runner/prompt-hash-salt.js +0 -2
|
@@ -2,7 +2,7 @@ import { compactionKindOf } from "../task-notification.js";
|
|
|
2
2
|
import { planRejectionClears } from "../context-edit.js";
|
|
3
3
|
import { rosterToolName } from "../tool-roster.js";
|
|
4
4
|
import { landStaleResultClears } from "./prepare-context-lane.js";
|
|
5
|
-
import { compactionFailureCause, compactionFailureReason, compactionPassReport,
|
|
5
|
+
import { compactionFailureCause, compactionFailureReason, compactionPassReport, compactionCutOf, DEFAULT_COMPACTION_INSTRUCTIONS, maybeCompact, mintCompactedEvent, turnCutWhileLegRuns } from "../auto-compaction.js";
|
|
6
6
|
import { emitTrace } from "../trace.js";
|
|
7
7
|
import { isDegenerateCutMessage } from "../../brain/terminal-cause.js";
|
|
8
8
|
import { rebaseCadenceWindows } from "./turn-attachments.js";
|
|
@@ -14,15 +14,16 @@ import { COMPACTION_FREED_EPSILON, COMPACTION_REGROWTH_FACTOR, MAX_CONSECUTIVE_C
|
|
|
14
14
|
import { compactionHookOptions, recordCompactionReuse, seamCCompactionOptions } from "./compaction-seams.js";
|
|
15
15
|
import { asThrownError } from "../thrown-value.js";
|
|
16
16
|
export function runRecoveryLanes(input) {
|
|
17
|
-
const { spec, prepared, queue, rs, ident, compactionBrain, compactionBreaker,
|
|
17
|
+
const { spec, prepared, queue, rs, ident, compactionBrain, compactionBreaker, callerStop, runner } = input;
|
|
18
18
|
const runForcedCompactionPass = async (lane, turnSignal) => {
|
|
19
19
|
if (!compactionEnabled("autoCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay))
|
|
20
|
-
return
|
|
20
|
+
return "off";
|
|
21
21
|
if (compactionBreaker.failures >= MAX_CONSECUTIVE_COMPACTION_FAILURES)
|
|
22
|
-
return
|
|
22
|
+
return "paused";
|
|
23
23
|
if (callerStop.signal.aborted)
|
|
24
|
-
return
|
|
24
|
+
return "cut";
|
|
25
25
|
const passSignal = AbortSignal.any([prepared.abortController.signal, callerStop.signal, ...(turnSignal !== undefined ? [turnSignal] : [])]);
|
|
26
|
+
const withdrawal = turnSignal !== undefined ? AbortSignal.any([callerStop.signal, turnCutWhileLegRuns(turnSignal, prepared.abortController.signal)]) : callerStop.signal;
|
|
26
27
|
const passReport = compactionPassReport(queue, ident);
|
|
27
28
|
try {
|
|
28
29
|
const comp = await prepared.compactStation.compact({
|
|
@@ -32,7 +33,6 @@ export function runRecoveryLanes(input) {
|
|
|
32
33
|
...centerAdoptionOption(prepared),
|
|
33
34
|
model: prepared.harness.getModel(),
|
|
34
35
|
...legContextOverlayOption(prepared, runner),
|
|
35
|
-
compactionModel: prepared.compModel,
|
|
36
36
|
...forkContextOption(prepared, true),
|
|
37
37
|
brain: compactionBrain,
|
|
38
38
|
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
@@ -40,7 +40,7 @@ export function runRecoveryLanes(input) {
|
|
|
40
40
|
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
|
|
41
41
|
customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
42
42
|
signal: passSignal,
|
|
43
|
-
manualCancelSignal:
|
|
43
|
+
manualCancelSignal: withdrawal,
|
|
44
44
|
minTokens: 0,
|
|
45
45
|
force: true,
|
|
46
46
|
overheadTokens: prepared.promptOverheadTokens,
|
|
@@ -50,7 +50,6 @@ export function runRecoveryLanes(input) {
|
|
|
50
50
|
...(prepared.onCompactionApplied ? { onApplied: prepared.onCompactionApplied } : {}),
|
|
51
51
|
...seamCCompactionOptions(runner, prepared),
|
|
52
52
|
...compactionRestateOptions(prepared, instructionEchoTo(queue, ident, rs.attach)),
|
|
53
|
-
...windowSafetyOptions(prepared.harness.getModel()),
|
|
54
53
|
...compactionHookOptions(runner, prepared, "forced", passSignal),
|
|
55
54
|
onStarted: passReport.onStarted,
|
|
56
55
|
}, maybeCompact);
|
|
@@ -93,19 +92,29 @@ export function runRecoveryLanes(input) {
|
|
|
93
92
|
...ident(),
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
|
-
return comp.compacted === true;
|
|
95
|
+
return comp.compacted === true ? "landed" : comp.noop ? "noop" : "failed";
|
|
97
96
|
}
|
|
98
97
|
catch (err) {
|
|
99
|
-
|
|
98
|
+
const cut = compactionCutOf(err);
|
|
99
|
+
if (cut === "cancelled") {
|
|
100
100
|
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.mooted", version: 1, taskId: rs.telemetry.taskId, reason: "cancelled", ts: Date.now() }));
|
|
101
101
|
queue.push({ type: "compaction_outcome", outcome: "mooted", trigger: "forced", reason: "cancelled", ...passReport.end, ...ident() });
|
|
102
|
-
return
|
|
102
|
+
return "cut";
|
|
103
|
+
}
|
|
104
|
+
if (cut === "task_ending") {
|
|
105
|
+
if (passReport.pass !== undefined) {
|
|
106
|
+
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.mooted", version: 1, taskId: rs.telemetry.taskId, reason: "task_ending", ts: Date.now() }));
|
|
107
|
+
queue.push({ type: "compaction_outcome", outcome: "mooted", trigger: "forced", reason: "task_ending", ...passReport.end, ...ident() });
|
|
108
|
+
}
|
|
109
|
+
return "cut";
|
|
103
110
|
}
|
|
104
111
|
compactionBreaker.failures += 1;
|
|
105
112
|
runner.deps.onError?.(asThrownError(err), { phase: "compaction", sessionId: prepared.sessionId });
|
|
106
113
|
const cause = compactionFailureCause(err);
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
const failReason = compactionFailureReason(err);
|
|
115
|
+
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.failed", version: 1, taskId: rs.telemetry.taskId, trigger: "forced", reason: failReason, ts: Date.now() }));
|
|
116
|
+
queue.push({ type: "compaction_outcome", outcome: "failed", trigger: "forced", reason: failReason, ...(cause !== undefined ? { cause } : {}), ...passReport.end, ...ident() });
|
|
117
|
+
return "failed";
|
|
109
118
|
}
|
|
110
119
|
};
|
|
111
120
|
prepared.harness.setLoopRecovery({
|
|
@@ -114,7 +123,7 @@ export function runRecoveryLanes(input) {
|
|
|
114
123
|
thinkingOnly: {},
|
|
115
124
|
degenerateOutput: { detect: (m) => isDegenerateCutMessage(m) },
|
|
116
125
|
promptTooLong: {
|
|
117
|
-
recover: async (attempt, turnSignal) => {
|
|
126
|
+
recover: async (attempt, turnSignal, refused) => {
|
|
118
127
|
if (prepared.abortController.signal.aborted || prepared.pausedRef.current !== undefined)
|
|
119
128
|
return false;
|
|
120
129
|
if (turnSignal?.aborted === true)
|
|
@@ -159,20 +168,27 @@ export function runRecoveryLanes(input) {
|
|
|
159
168
|
return true;
|
|
160
169
|
}
|
|
161
170
|
}
|
|
162
|
-
|
|
171
|
+
const pass = await runForcedCompactionPass("rejection", turnSignal);
|
|
172
|
+
if (pass !== "noop")
|
|
173
|
+
return pass === "landed";
|
|
174
|
+
const line = prepared.microCompact.projectionRef.current?.lineAfterRefusal(refused?.errorMessage);
|
|
175
|
+
if (line === undefined || prepared.abortController.signal.aborted || (turnSignal?.aborted ?? false))
|
|
176
|
+
return false;
|
|
177
|
+
prepared.microCompact.projectionRef.resendLine = { line, turn: turnSignal };
|
|
178
|
+
return true;
|
|
163
179
|
},
|
|
164
180
|
},
|
|
165
181
|
});
|
|
166
182
|
prepared.microCompact.inTurnCompactionRef.current = async (turnSignal, anchoredEstimate) => {
|
|
167
183
|
if (prepared.abortController.signal.aborted || prepared.pausedRef.current !== undefined)
|
|
168
|
-
return
|
|
184
|
+
return "cut";
|
|
169
185
|
if (turnSignal?.aborted === true)
|
|
170
|
-
return
|
|
186
|
+
return "cut";
|
|
171
187
|
if (anchoredEstimate !== undefined && rs.counters.compactionFloor > 0 && anchoredEstimate < rs.counters.compactionFloor) {
|
|
172
188
|
const floor = rs.counters.compactionFloor;
|
|
173
189
|
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.suppressed", version: 1, taskId: rs.telemetry.taskId, estTokens: anchoredEstimate, floor, ts: Date.now() }));
|
|
174
190
|
queue.push({ type: "compaction_outcome", outcome: "suppressed", trigger: "forced", ...ident() });
|
|
175
|
-
return
|
|
191
|
+
return "suppressed";
|
|
176
192
|
}
|
|
177
193
|
return runForcedCompactionPass("guard", turnSignal);
|
|
178
194
|
};
|
|
@@ -6,7 +6,7 @@ import { type CompactOutcome, type DelegationLifecycleEvent, type OwedUserInputA
|
|
|
6
6
|
import { type Stats } from "./assemble-result.js";
|
|
7
7
|
import { type DeliveryObligations } from "../task-notification.js";
|
|
8
8
|
import type { MessageDisplay } from "../mods/message-display.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { InstallingPhaseResult, LegWrites, ManualCompactRef, Prepared, ResumeRun, RunInternals, RunnerDepsSeat, RunState, SuspendReap, TaskIdRef } from "./contracts.js";
|
|
10
10
|
export interface RunSettleAndTeardownInput {
|
|
11
11
|
/** borrowed-readonly — the task spec: the hooks slot, the suggestion opt-in, the retain / forward flags, the task id. */
|
|
12
12
|
spec: TaskSpec;
|
|
@@ -70,8 +70,6 @@ export interface RunSettleAndTeardownInput {
|
|
|
70
70
|
reasoningResolution: {
|
|
71
71
|
readonly current: ResolvedReasoning | undefined;
|
|
72
72
|
};
|
|
73
|
-
/** borrowed-readonly — the end-of-task compaction's outcome (the terminal-adoption lane's `finish` call). */
|
|
74
|
-
comp: EndOfTaskCompaction;
|
|
75
73
|
/** borrowed-readonly — the terminal frames this leg's lane is still owed (the notification lane's book, the one a one-shot ending
|
|
76
74
|
* waits on): the tail-stop notice names what a one-shot ending still waited for, read when the notice is built. */
|
|
77
75
|
deliveryObligations: DeliveryObligations;
|
|
@@ -27,28 +27,20 @@ import { generatePromptSuggestions } from "./prompt-suggestions.js";
|
|
|
27
27
|
import { raceTeardownLegOr, settleTeardownLeg, teardownLegBudget } from "./teardown-bounded.js";
|
|
28
28
|
import { autoRunConsolidationFromRecommendation, autoRunOnRecommendationEffective, scopeHasUnconsumedRecommendation } from "./memory-consolidation-driver.js";
|
|
29
29
|
import { amendTerminal, terminalProjection } from "./terminal-projection.js";
|
|
30
|
-
import { mintCompactedEvent } from "../auto-compaction.js";
|
|
31
30
|
import { legEndRecords, settleBound, settledContinuesFrom } from "./continues-from.js";
|
|
32
31
|
import { modelLaneBrainOf } from "./model-lane-seat.js";
|
|
32
|
+
import { observingBrain } from "./prefix-ledger.js";
|
|
33
|
+
import { emitSuggestionsRow } from "./side-call-account.js";
|
|
33
34
|
import { cacheHitExclusionsOf, cacheHitOperandsOf, mainCacheLaneComplete } from "./cache-hit-account.js";
|
|
34
35
|
import { humanReviewSnapshot } from "./park-commit.js";
|
|
35
36
|
import { projectRequestCopies } from "../request-copy-projection.js";
|
|
36
37
|
export async function runSettleAndTeardown(input) {
|
|
37
|
-
const { spec, queue, prepared, resume, internals, rs, stats, ident, loopLatch, timeout, ownCommittedTailRef, legWrites, emitDelegationLifecycle, taskIdRef, manualCompactRef, drainManualCompact, final, threw, abortedLive, userInterruptedLive, answerSettled, strandedHumanAnswers, reasoningResolution,
|
|
38
|
+
const { spec, queue, prepared, resume, internals, rs, stats, ident, loopLatch, timeout, ownCommittedTailRef, legWrites, emitDelegationLifecycle, taskIdRef, manualCompactRef, drainManualCompact, final, threw, abortedLive, userInterruptedLive, answerSettled, strandedHumanAnswers, reasoningResolution, deliveryObligations, compactionBreaker, owedUserInput, setResult, onSuggestions, onSuspend, runner, sessions, display } = input;
|
|
38
39
|
const bound = settleBound(), writeOwedSessionRecords = legEndRecords(prepared, rs, runner, bound);
|
|
39
40
|
try {
|
|
40
41
|
const shown = display?.settled();
|
|
41
42
|
if (shown !== undefined)
|
|
42
43
|
await shown;
|
|
43
|
-
if (comp?.compacted) {
|
|
44
|
-
queue.push(mintCompactedEvent(comp, "auto", ident()));
|
|
45
|
-
if (comp.phaseDurations !== undefined && comp.durationMs !== undefined) {
|
|
46
|
-
const pd = comp.phaseDurations;
|
|
47
|
-
const pdDur = comp.durationMs;
|
|
48
|
-
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.phase_timings", version: 1, taskId: rs.telemetry.taskId, ...pd, durationMs: pdDur, ts: Date.now() }));
|
|
49
|
-
}
|
|
50
|
-
prepared.turnSnapshot?.declare({ cause: "compaction" });
|
|
51
|
-
}
|
|
52
44
|
if (prepared.nestedStats.tasks > 0) {
|
|
53
45
|
stats.nested = {
|
|
54
46
|
tokens: prepared.nestedStats.tokens,
|
|
@@ -67,14 +59,9 @@ export async function runSettleAndTeardown(input) {
|
|
|
67
59
|
runner.deps.onError?.(new Error(`prompt-cache: usage/api mismatch — cachedTokens (${stats.cachedTokens}) > totalInputTokens (${stats.totalInputTokens}); the cache family is likely wrong. Does model.api match the brain serving it? Override with model.params.promptCacheFamily = "input-includes-cached" | "input-excludes-cached".`), { phase: "prompt-cache", sessionId: prepared.sessionId });
|
|
68
60
|
}
|
|
69
61
|
stats.cacheHitRate = Math.min(1, rawHit);
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
? `a mid-task model switch (${rs.degrade.degraded.from} → ${rs.degrade.degraded.to}, degradation) reset the prefix cache — this is the likely cause`
|
|
74
|
-
: cacheWritten > 0
|
|
75
|
-
? `this task reported ${cacheWritten} cache-write tokens across its calls (compaction and the classifier's included) but served almost none back as reads — consistent with a prompt prefix that CHANGES between turns (client-side: volatile content up front, or per-turn tool churn/reorder) and, less often, with server-side eviction. Keep volatile content (memory/timestamps/ids) out of the prefix and the tool list stable in membership AND order`
|
|
76
|
-
: `no call in this task reported any cache-write tokens — and this API family may not report them at all (an openai-shaped usage row carries cached READS only), so the write side is no evidence here; check that the prompt prefix (system prompt + tool list, membership AND order) is byte-stable across turns and that this route caches this model`;
|
|
77
|
-
runner.deps.onError?.(new Error(`prompt-cache: low prefix-cache hit rate ${(stats.cacheHitRate * 100).toFixed(0)}% over ${stats.turns} turns (${cacheOperands.totalInputTokens} prompt tokens${cacheExcludes.length > 0 ? `; the ${cacheExcludes.map((e) => e.lane).join(" / ")} calls are left out — they did not report the cache counts` : ""}) — ${cause}. See design/09.`), { phase: "prompt-cache", sessionId: prepared.sessionId });
|
|
62
|
+
if (prepared.prefixChanges.published === 0 && mainCacheLaneComplete(stats.cacheLanes) && stats.turns >= 2 && cacheOperands.totalInputTokens >= 8000 && stats.cacheHitRate < 0.15) {
|
|
63
|
+
const switched = rs.degrade.degraded !== undefined ? `; the run switched models mid-task (${rs.degrade.degraded.from} → ${rs.degrade.degraded.to})` : "";
|
|
64
|
+
runner.deps.onError?.(new Error(`prompt-cache: low prefix-cache hit rate ${(stats.cacheHitRate * 100).toFixed(0)}% over ${stats.turns} turns (${cacheOperands.totalInputTokens} prompt tokens, ${stats.cachedTokens} read from the cache, ${stats.cacheWriteTokens} reported written${cacheExcludes.length > 0 ? `; the ${cacheExcludes.map((e) => e.lane).join(" / ")} calls are left out — they did not report the cache counts` : ""}${switched})${runner.deps.cacheBreakDetection === false ? "" : "; the engine published no prefix change this run (each request's reading is its brain.call row's `request`)"}.`), { phase: "prompt-cache", sessionId: prepared.sessionId });
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
67
|
if (prepared.resourceLedger &&
|
|
@@ -116,6 +103,9 @@ export async function runSettleAndTeardown(input) {
|
|
|
116
103
|
effectiveReadFace: prepared.effectiveReadFace,
|
|
117
104
|
effectiveWriteFace: prepared.effectiveWriteFace,
|
|
118
105
|
effectiveReadDenyPatterns: prepared.effectiveReadDenyPatterns,
|
|
106
|
+
readDenyFloorUnkept: prepared.readFloorUnkept.current,
|
|
107
|
+
effectiveAgentConfigDirs: prepared.callerPlaces?.configRoots.carried,
|
|
108
|
+
effectiveAgentHomeDirs: prepared.callerPlaces?.homes.carried,
|
|
119
109
|
effectiveMemoryScopes: prepared.effectiveMemoryScopes,
|
|
120
110
|
placementRoot: prepared.placementRoot,
|
|
121
111
|
effectiveReasoning: reasoningResolution.current,
|
|
@@ -303,7 +293,7 @@ export async function runSettleAndTeardown(input) {
|
|
|
303
293
|
queue.close();
|
|
304
294
|
await prepared.fileHistoryBoundary?.settle();
|
|
305
295
|
if (spec.suggestNextPrompts && result.terminal.kind === "completed" && !abortedLive) {
|
|
306
|
-
onSuggestions(suggestNextPrompts(spec, prepared, result, runner));
|
|
296
|
+
onSuggestions(suggestNextPrompts(spec, prepared, result, runner, rs.telemetry));
|
|
307
297
|
}
|
|
308
298
|
}
|
|
309
299
|
finally {
|
|
@@ -382,7 +372,7 @@ const SUGGESTIONS_DEFAULT_COUNT = 3;
|
|
|
382
372
|
const SUGGESTIONS_MAX_COUNT = 8;
|
|
383
373
|
const SUGGESTIONS_TIMEOUT_MS = 30_000;
|
|
384
374
|
const SUGGESTIONS_TRANSCRIPT_MESSAGES = 12;
|
|
385
|
-
async function suggestNextPrompts(spec, prepared, result, runner) {
|
|
375
|
+
async function suggestNextPrompts(spec, prepared, result, runner, telemetry) {
|
|
386
376
|
const cfg = typeof spec.suggestNextPrompts === "object" ? spec.suggestNextPrompts : {};
|
|
387
377
|
const count = cfg.count && cfg.count > 0 ? Math.min(cfg.count, SUGGESTIONS_MAX_COUNT) : SUGGESTIONS_DEFAULT_COUNT;
|
|
388
378
|
const ac = new AbortController();
|
|
@@ -425,7 +415,9 @@ async function suggestNextPrompts(spec, prepared, result, runner) {
|
|
|
425
415
|
const pricing = priceTableOf(model, runner.deps.pricing).table;
|
|
426
416
|
const ctx = await prepared.session.buildContext();
|
|
427
417
|
const transcript = projectRequestCopies(ctx.messages.filter((m) => !isSyntheticApiErrorMessage(m)).slice(-SUGGESTIONS_TRANSCRIPT_MESSAGES));
|
|
428
|
-
const out = await generatePromptSuggestions({ brain: modelLaneBrainOf(runner.deps), model, pricing, thinking, getApiKeyAndHeaders: spec.getApiKeyAndHeaders, signal: ac.signal, fastMode: prepared.fastMode.callFor() }, transcript, count);
|
|
418
|
+
const out = await generatePromptSuggestions({ brain: observingBrain(modelLaneBrainOf(runner.deps), prepared.observeSideRequest), model, pricing, thinking, getApiKeyAndHeaders: spec.getApiKeyAndHeaders, signal: ac.signal, fastMode: prepared.fastMode.callFor() }, transcript, count);
|
|
419
|
+
if (out.reply !== undefined)
|
|
420
|
+
emitSuggestionsRow(telemetry, out.reply, model, runner.deps.pricing);
|
|
429
421
|
if (out.tokens > 0 || out.costMicroUsd > 0) {
|
|
430
422
|
result.stats.suggestions = { tokens: out.tokens, costMicroUsd: out.costMicroUsd };
|
|
431
423
|
if (result.stats.costBreakdown) {
|
|
@@ -61,7 +61,6 @@ export function runTelemetryAndBudgetSeats(input) {
|
|
|
61
61
|
rs.limits.turnsExceeded = false;
|
|
62
62
|
rs.degrade.outputErrorStreak = 0;
|
|
63
63
|
rs.degrade.outputInvalid = false;
|
|
64
|
-
rs.telemetry.cacheBreakReported = false;
|
|
65
64
|
rs.limits.outputRetryCap = resolveOutputRetries(spec.outputRetries);
|
|
66
65
|
rs.limits.effectiveMaxTurns = resolveMaxTurns(spec.limits);
|
|
67
66
|
rs.telemetry.tracer = entryTracer !== undefined ? entryTracer.tracer : (spec.tracer ?? runner.deps.tracer);
|
|
@@ -4,29 +4,22 @@
|
|
|
4
4
|
* stop, the platform lane's external cause — which alone overrides a real throw), the usage ledger's FINAL charge with its
|
|
5
5
|
* slow-charge disclosure, the live-abort orphan reconcile and its synthetic `tool_end` frames, the held session-write
|
|
6
6
|
* drain, the user-interruption marker, the durable park's carried caller input and the held agent_end account's settle,
|
|
7
|
-
* the dropped post-compact announce disclosure, and the
|
|
8
|
-
*
|
|
9
|
-
* lane-to-lane reach, the S6 legs' reading).
|
|
7
|
+
* the dropped post-compact announce disclosure, and the teardown legs (`finish`, the lane's own module-private function:
|
|
8
|
+
* it has one caller, and a sibling file would be a lane-to-lane reach, the S6 legs' reading). It runs no compaction.
|
|
10
9
|
*
|
|
11
|
-
* Async
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* facts are consumed here.
|
|
10
|
+
* Async. It ends by entering the settle lane (`next`) in its LAST continuation — the settle's first read sits on the tick
|
|
11
|
+
* `finish` resolved on, as it did in the one-function body — and returns what it returns. What crosses the boundary is
|
|
12
|
+
* exactly what the settle reads of this lane's work: the ADOPTED cause (`threw`, possibly lifted here), the answer-settled
|
|
13
|
+
* verdict and the owed-input account; the pause / interruption / reconcile facts are consumed here.
|
|
16
14
|
*/
|
|
17
15
|
import type { AssistantMessage } from "../../internal/llm.js";
|
|
18
|
-
import type { Model } from "../../internal/llm.js";
|
|
19
|
-
import { type MaybeCompactOptions } from "../auto-compaction.js";
|
|
20
16
|
import type { SessionStore } from "../session.js";
|
|
21
17
|
import type { PushQueue } from "../push-queue.js";
|
|
22
|
-
import { type
|
|
18
|
+
import { type HeldUserInputs, type OwedUserInputAccount, type TaskEvent } from "../types.js";
|
|
23
19
|
import { type Stats } from "./assemble-result.js";
|
|
24
|
-
import type { EmitCommitted,
|
|
25
|
-
import type { CallerStopGate } from "./caller-stop-gate.js";
|
|
20
|
+
import type { EmitCommitted, Prepared, RunnerDepsSeat, RunState } from "./contracts.js";
|
|
26
21
|
export interface RunTerminalAdoptionInput<R> {
|
|
27
|
-
/** borrowed-
|
|
28
|
-
spec: TaskSpec;
|
|
29
|
-
/** borrowed-mutable — the run's event queue: the reconcile's synthetic `tool_end` frames and the end-of-task compaction's failure frame. */
|
|
22
|
+
/** borrowed-mutable — the run's event queue: the reconcile's synthetic `tool_end` frames. */
|
|
30
23
|
queue: PushQueue<TaskEvent>;
|
|
31
24
|
/** borrowed-mutable — the leg's prepared seat: the guardrail / gate-stop / paused refs are read, the usage ledger charged, the session
|
|
32
25
|
* reconciled and the marker appended, the harness's parkable inputs read and dropped. */
|
|
@@ -51,14 +44,6 @@ export interface RunTerminalAdoptionInput<R> {
|
|
|
51
44
|
timeout: {
|
|
52
45
|
readonly fired: boolean;
|
|
53
46
|
};
|
|
54
|
-
/** borrowed-readonly — the compaction machinery's accounted brain (the end-of-task summary call is accounted too). */
|
|
55
|
-
compactionBrain: Brain;
|
|
56
|
-
/** borrowed-readonly — the shared compaction breaker: an open breaker skips the end-of-task attempt. */
|
|
57
|
-
compactionBreaker: {
|
|
58
|
-
readonly failures: number;
|
|
59
|
-
};
|
|
60
|
-
/** borrowed-readonly — the window-safety builder the end-of-task lane shares with the boundary / PTL lanes. */
|
|
61
|
-
windowSafetyOptions: (mainModel: Model) => Pick<MaybeCompactOptions, "fallbackBudget" | "onWindowSafety">;
|
|
62
47
|
/** borrowed-readonly — the held agent_end account, as the read face on the identity lane's Result. */
|
|
63
48
|
undrainedUserAtEnd: {
|
|
64
49
|
readonly current: HeldUserInputs | undefined;
|
|
@@ -76,22 +61,18 @@ export interface RunTerminalAdoptionInput<R> {
|
|
|
76
61
|
abortedLive: boolean;
|
|
77
62
|
/** borrowed-readonly — the leg's snapshot of `loopLatch.userInterrupted` (gates the interruption marker). */
|
|
78
63
|
userInterruptedLive: boolean;
|
|
79
|
-
/** borrowed-readonly — the run's caller-stop gate: the end-of-task pass admits on it and carries it (read LIVE, never snapshot). */
|
|
80
|
-
callerStop: CallerStopGate;
|
|
81
64
|
/** borrowed-readonly — the Runner's deployment deps, read LIVE (`onError`, `checkpointStore`, `onNotice`, `mediaBudgetBase64Chars`); the one home of why it is
|
|
82
65
|
* a seat and not a captured object is {@link RunnerDepsSeat}. */
|
|
83
66
|
runner: RunnerDepsSeat;
|
|
84
|
-
/** borrowed-readonly — the session store:
|
|
67
|
+
/** borrowed-readonly — the session store: `finish`'s teardown legs touch the leg's session through it. */
|
|
85
68
|
sessions: SessionStore;
|
|
86
|
-
/** borrowed-readonly — the settle lane, entered in this lane's last continuation with the adopted cause
|
|
69
|
+
/** borrowed-readonly — the settle lane, entered in this lane's last continuation with the adopted cause. */
|
|
87
70
|
next: (adopted: RunTerminalAdoptionResult) => Promise<R>;
|
|
88
71
|
}
|
|
89
72
|
/** What the settle reads of this lane's work. */
|
|
90
73
|
export interface RunTerminalAdoptionResult {
|
|
91
74
|
/** The ADOPTED terminal cause: the leg's throw, or the typed cause lifted over it here (guardrail stall / gate stop / platform terminal). */
|
|
92
75
|
threw: unknown;
|
|
93
|
-
/** The end-of-task compaction pass's outcome. */
|
|
94
|
-
comp: EndOfTaskCompaction;
|
|
95
76
|
/** This lane's ONE evaluation of {@link answerSettled}: a clean `"stop"` final with no queued continuation lost. The
|
|
96
77
|
* settle lane hands it to the arbitration (`ResultFlags.answerSettled`), the teardown attribution and the notice. */
|
|
97
78
|
answerSettled: boolean;
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import { compactionFailureCause, compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, maybeCompact } from "../auto-compaction.js";
|
|
2
1
|
import { eventDefaultOn } from "../../prompt-assembly/event-registry.js";
|
|
3
2
|
import { appendInterruptionMarker, reconcileInterruptedSession } from "../session-reconcile.js";
|
|
4
3
|
import { emitTrace } from "../trace.js";
|
|
5
4
|
import { parkedInputIdsOf } from "../types.js";
|
|
6
5
|
import { answerSettled } from "./assemble-result.js";
|
|
7
6
|
import { errorCodeOf } from "./terminal-account.js";
|
|
8
|
-
import { awaitChargeWithSlowDisclosure
|
|
9
|
-
import { buildWorkingFileAttachments, centerAdoptionOption, emitInputTruncated, forkContextOption, legCompactionSettings, legContextOverlayOption } from "./compaction-call-options.js";
|
|
10
|
-
import { compactionHookOptions, recordCompactionReuse, seamCCompactionOptions } from "./compaction-seams.js";
|
|
11
|
-
import { compactionRestateOptions } from "./compaction-restate.js";
|
|
12
|
-
import { instructionEchoTo } from "./nested-memory-lane.js";
|
|
13
|
-
import { MAX_CONSECUTIVE_COMPACTION_FAILURES } from "./compaction-knobs.js";
|
|
7
|
+
import { awaitChargeWithSlowDisclosure } from "./clock-and-limits.js";
|
|
14
8
|
import { emitSettled, reconciledEnd } from "./tool-end-body.js";
|
|
15
9
|
import { costFigureOf } from "./side-call-account.js";
|
|
16
10
|
import { isApprovalWordsFrame } from "./approval-feedback.js";
|
|
17
11
|
import { asThrownError } from "../thrown-value.js";
|
|
18
|
-
import { modelLaneBrainOf } from "./model-lane-seat.js";
|
|
19
12
|
import { raceTeardownLeg } from "./teardown-bounded.js";
|
|
20
13
|
export async function runTerminalAdoption(input) {
|
|
21
|
-
const {
|
|
14
|
+
const { queue, prepared, rs, stats, ident, emitCommitted, startedToolCallIds, toolLabels, timeout, undrainedUserAtEnd, userInputLostAtEnd, final, abortedLive, userInterruptedLive, runner, sessions, next } = input;
|
|
22
15
|
let { threw } = input;
|
|
23
16
|
const settled = answerSettled(final, userInputLostAtEnd.current || prepared.undeliveredContinuationRef.current.parkedSteers.length > 0 || prepared.workCutRef.continuation || prepared.workCutRef.abortedBeforeTurnEnd);
|
|
24
17
|
if (threw === undefined && prepared.brainCallGuardrailRef.timedOut !== undefined) {
|
|
@@ -144,85 +137,10 @@ export async function runTerminalAdoption(input) {
|
|
|
144
137
|
if (rs.attach.attachState?.postCompactPending === true && (rs.attach.attachmentsCfg?.backgroundTasks ?? eventDefaultOn("background_tasks")) === true) {
|
|
145
138
|
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.announce_dropped", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
|
|
146
139
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
skipCompaction: durablyPaused || (abortedLive && settled) || callerStop.signal.aborted || compactionBreaker.failures >= MAX_CONSECUTIVE_COMPACTION_FAILURES,
|
|
150
|
-
callerStop,
|
|
151
|
-
minTokens: rs.counters.compactionFloor,
|
|
152
|
-
brain: compactionBrain,
|
|
153
|
-
windowSafety: windowSafetyOptions(prepared.harness.getModel()),
|
|
154
|
-
passReport: compactionPassReport(queue, ident),
|
|
155
|
-
instructionEcho: instructionEchoTo(queue, ident, rs.attach),
|
|
156
|
-
onCompactionOutcome: (outcome, reason, end, cause) => queue.push({ type: "compaction_outcome", outcome, trigger: "auto", reason, ...(cause !== undefined ? { cause } : {}), ...end, ...ident() }),
|
|
157
|
-
}, runner, sessions);
|
|
158
|
-
return await next({ threw, comp, answerSettled: settled, owedUserInput });
|
|
140
|
+
await finish(prepared, runner, sessions);
|
|
141
|
+
return await next({ threw, answerSettled: settled, owedUserInput });
|
|
159
142
|
}
|
|
160
|
-
async function finish(
|
|
161
|
-
let comp;
|
|
162
|
-
if (!opts?.skipCompaction) {
|
|
163
|
-
try {
|
|
164
|
-
const finishComp = await prepared.compactStation.compact({
|
|
165
|
-
session: prepared.session,
|
|
166
|
-
admitRows: prepared.admitRows,
|
|
167
|
-
promptIdentity: prepared.promptIdentity,
|
|
168
|
-
...centerAdoptionOption(prepared),
|
|
169
|
-
model: prepared.harness.getModel(),
|
|
170
|
-
...legContextOverlayOption(prepared, runner),
|
|
171
|
-
compactionModel: prepared.compModel,
|
|
172
|
-
...forkContextOption(prepared, false),
|
|
173
|
-
brain: opts?.brain ?? modelLaneBrainOf(runner.deps),
|
|
174
|
-
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
175
|
-
thinking: prepared.thinking,
|
|
176
|
-
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
|
|
177
|
-
customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
178
|
-
signal: opts.callerStop.signal,
|
|
179
|
-
manualCancelSignal: opts.callerStop.signal,
|
|
180
|
-
minTokens: opts?.minTokens,
|
|
181
|
-
overheadTokens: prepared.promptOverheadTokens,
|
|
182
|
-
...(prepared.activeTools.size > 0 ? { activeTools: [...prepared.activeTools] } : {}),
|
|
183
|
-
onInputTruncated: emitInputTruncated(opts?.telemetry?.tracer ?? spec.tracer ?? runner.deps.tracer, prepared.taskId),
|
|
184
|
-
...(opts?.windowSafety ?? {}),
|
|
185
|
-
workingFileAttachments: buildWorkingFileAttachments(spec, prepared),
|
|
186
|
-
...(prepared.onCompactionApplied ? { onApplied: prepared.onCompactionApplied } : {}),
|
|
187
|
-
...seamCCompactionOptions(runner, prepared),
|
|
188
|
-
...compactionRestateOptions(prepared, opts.instructionEcho),
|
|
189
|
-
...compactionHookOptions(runner, prepared, "auto", opts.callerStop.signal), onStarted: opts.passReport.onStarted,
|
|
190
|
-
}, maybeCompact);
|
|
191
|
-
recordCompactionReuse(runner, prepared, finishComp);
|
|
192
|
-
if (finishComp.unevaluableWindow) {
|
|
193
|
-
discloseUnevaluableWindow(finishComp.unevaluableWindow, prepared, opts?.telemetry?.tracer ?? spec.tracer ?? runner.deps.tracer, prepared.taskId, runner.deps.onError);
|
|
194
|
-
}
|
|
195
|
-
if (finishComp.windowBelowOverhead) {
|
|
196
|
-
discloseWindowBelowOverhead(finishComp.windowBelowOverhead, prepared, runner.deps.onError, (reason) => opts?.onCompactionOutcome?.("disabled", reason, {}));
|
|
197
|
-
}
|
|
198
|
-
comp = finishComp;
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
if (isCompactionManualCancel(err)) {
|
|
202
|
-
emitTrace(opts?.telemetry?.tracer ?? spec.tracer ?? runner.deps.tracer, () => ({
|
|
203
|
-
kind: "compaction.mooted",
|
|
204
|
-
version: 1,
|
|
205
|
-
taskId: prepared.taskId,
|
|
206
|
-
reason: "cancelled",
|
|
207
|
-
ts: Date.now(),
|
|
208
|
-
}));
|
|
209
|
-
opts?.onCompactionOutcome?.("mooted", "cancelled", opts.passReport.end);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
const failReason = compactionFailureReason(err);
|
|
213
|
-
emitTrace(opts?.telemetry?.tracer ?? spec.tracer ?? runner.deps.tracer, () => ({
|
|
214
|
-
kind: "compaction.failed",
|
|
215
|
-
version: 1,
|
|
216
|
-
taskId: prepared.taskId,
|
|
217
|
-
trigger: "auto",
|
|
218
|
-
reason: failReason,
|
|
219
|
-
ts: Date.now(),
|
|
220
|
-
}));
|
|
221
|
-
opts?.onCompactionOutcome?.("failed", failReason, opts.passReport.end, compactionFailureCause(err));
|
|
222
|
-
runner.deps.onError?.(err, { phase: "compaction", sessionId: prepared.sessionId });
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
143
|
+
async function finish(prepared, runner, sessions) {
|
|
226
144
|
await raceTeardownLeg(() => sessions.touch(prepared.sessionId), "sessions.touch (settle leg)").catch((err) => runner.deps.onError?.(err, { phase: "config", sessionId: prepared.sessionId }));
|
|
227
145
|
try {
|
|
228
146
|
await prepared.mcp.dispose();
|
|
@@ -238,5 +156,4 @@ async function finish(spec, prepared, opts, runner, sessions) {
|
|
|
238
156
|
runner.deps.onError?.(err, { phase: "a2a", sessionId: prepared.sessionId });
|
|
239
157
|
}
|
|
240
158
|
}
|
|
241
|
-
return comp;
|
|
242
159
|
}
|
|
@@ -26,6 +26,7 @@ export function runToolMountFacts(input) {
|
|
|
26
26
|
identity: prepared.promptManifest.identity,
|
|
27
27
|
selectors: prepared.promptManifest.selectors,
|
|
28
28
|
blocks: prepared.promptManifest.blocks,
|
|
29
|
+
hashScope: prepared.promptManifest.hashScope,
|
|
29
30
|
sections: prepared.promptManifest.sections,
|
|
30
31
|
...(prepared.promptManifest.superseded ? { superseded: prepared.promptManifest.superseded } : {}),
|
|
31
32
|
...(prepared.promptManifest.tools ? { tools: prepared.promptManifest.tools } : {}),
|
|
@@ -47,10 +48,5 @@ export function runToolMountFacts(input) {
|
|
|
47
48
|
ts: rs.telemetry.taskStart,
|
|
48
49
|
};
|
|
49
50
|
});
|
|
50
|
-
const snapshotChanged = (snap, change) => emitTrace(rs.telemetry.tracer, () => ({ kind: "prompt.snapshot_changed", version: 1, taskId: rs.telemetry.taskId, snapshot: { cacheIdentity: snap.cacheIdentity, elements: { ...snap.elements } }, ...change, ts: Date.now() }));
|
|
51
|
-
if (prepared.turnSnapshot?.legStart !== undefined)
|
|
52
|
-
snapshotChanged(prepared.turnSnapshot, prepared.turnSnapshot.legStart);
|
|
53
|
-
if (prepared.turnSnapshot !== undefined)
|
|
54
|
-
prepared.turnSnapshot.onChange = snapshotChanged;
|
|
55
51
|
return { todoToolMounted, taskToolsMounted, writeFamilyOf, toolStartAt, startedToolCallIds };
|
|
56
52
|
}
|