# Telegram Dropbear Context Engineering RCA Work Order

Date: 2026-07-01

Observed run: `/home/roko/Documents/Projects/Adjacent/telegram_test/.omnius`, run id `1782873796963-i5r7mv`.

Task under observation: get a meaningful gear-sonic training run with observed progress on the Dropbear MJCF/URDF after addressing closed-loop knee components.

## Evidence Snapshot

- The run made one successful mutation: `dropbear_mjcf/dropbear_mjcf.xml` changed `RL_Revolute28` to `<joint name="RL_Revolute28" type="weld" />`.
- Immediately afterward, the model retried the pre-mutation `old_string` and received repeated `old_string not found` failures.
- The focus supervisor then forced `required_next_action=update_todos`, which blocked useful recovery reads, patches, and verification attempts.
- The run kept emitting blocked edits, sed/python rewrites, a partial `task_complete`, and more blocked reads through at least turn 28.
- Main context grew from about 73k estimated tokens after the successful edit to about 92.7k estimated tokens by turn 28.
- System prompt content grew from about 142k chars to about 230k chars.
- The final main dump had dozens of `[RUN EVIDENCE]` and focus-supervisor system messages, including repeated synthetic failures.
- The workboard existed but had no cards, decisions, or diagnostics.
- The completion ledger remained `open`; no meaningful gear-sonic training verification was run.

## Work Orders

### WO-TD-01: Stale Edit Recovery Must Read Current Truth, Not Replan Forever

Status: implemented

Root cause: repeated stale edit failures currently force `update_todos` for non-shell tools. For an `old_string not found` family, this is the wrong recovery state.

Anchors:
- `packages/orchestrator/src/focusSupervisor.ts`
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/tests/focusSupervisor.test.ts`

Implementation:
- Classify stale edit failure samples in the focus supervisor.
- Repeated stale `file_edit`, `file_patch`, or `batch_edit` failures must set `requiredNextAction=read_authoritative_target`.
- After the authoritative read succeeds, clear that directive and permit a fresh target-specific edit or verification.
- Do not use `update_todos` as the default escape hatch for stale edit families.

Acceptance:
- Two `old_string not found` failures produce a `read_authoritative_target` directive.
- A `file_read` of the target satisfies the directive.
- A different edit target in the same file is not blocked just because an old edit target failed.

Verification:
- Covered by `tests/focusSupervisor.test.ts`.

### WO-TD-02: Directive Escalation Must Terminate Cleanly After Repeated Ignoring

Status: implemented

Root cause: the observed run ignored 27 focus directives and kept accumulating blocked tool calls. The supervisor continued asking for the same action without forcing a terminal incomplete/blocker path.

Anchors:
- `packages/orchestrator/src/focusSupervisor.ts`
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/tests/focusSupervisor.test.ts`

Implementation:
- Add an ignored-directive escalation threshold.
- Once the threshold is crossed with no satisfying mutation/read/verification, force `requiredNextAction=report_incomplete`.
- In terminal incomplete state, permit `task_complete` only as an incomplete/blocker report.
- Stop appending broad blocked-family lists indefinitely.

Acceptance:
- Repeatedly ignoring a recovery directive transitions to `terminal_incomplete`.
- After terminal incomplete, edit/read/shell variants are blocked.
- A reporting tool is allowed so the run can end truthfully.

Verification:
- Covered by `tests/focusSupervisor.test.ts`.

### WO-TD-03: Focus Action Families Must Be Target-Specific For Edits

Status: implemented

Root cause: focus supervisor action families collapse all edits to `tool:path`. In the observed run, a stale `RL_Revolute28` edit contaminated later distinct joint edits and line patches in the same XML.

Anchors:
- `packages/orchestrator/src/focusSupervisor.ts`
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/tests/focusSupervisor.test.ts`

Implementation:
- Build edit action families from tool name, path, normalized edit target, patch mode/offset/limit, and error class where available.
- Keep shell action families command-based, but trim and hash long commands rather than injecting huge command prefixes.
- Preserve a separate coarse path lock only for full-file overwrite repair blocks.

Acceptance:
- A repeated stale edit for `RL_Revolute28` blocks only that edit family.
- A fresh `file_patch` for a different offset/target in the same XML can pass after the required authoritative read.
- The directive frame no longer grows with long sed/python command bodies.

Verification:
- Covered by `tests/focusSupervisor.test.ts`.

### WO-TD-04: Context Evidence Must Fold Repeats And Demote Synthetic Failures

Status: implemented

Root cause: the context engine injects every recorded tool event as high-authority `[RUN EVIDENCE]`, including repeated focus blocks and stale discovery reads.

Anchors:
- `packages/orchestrator/src/contextEngine.ts`
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/tests/contextEngine.test.ts`

Implementation:
- Fold tool evidence by family before rendering system evidence.
- Keep successes, latest mutations, latest verification results, and first/last unresolved failures.
- Collapse repeated focus-supervisor synthetic failures into one counted summary.
- Cap evidence injection separately from raw conversation/tool results.

Acceptance:
- Repeated identical focus blocks render as one summary with a repeat count.
- Evidence diagnostics report retained and dropped/folded counts.
- Large early discovery listings do not stay as repeated high-authority system evidence once more specific evidence exists.

Verification:
- Covered by `tests/contextEngine.test.ts`.

### WO-TD-05: Context Engine Compaction Must Affect Live Requests

Status: implemented

Root cause: `AgenticRunner` calls `contextEngine.compact()` but discards its output, while `contextEngine.build()` still prepends extra evidence to the live request.

Anchors:
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/src/contextEngine.ts`
- `packages/orchestrator/tests/agenticRunner-context-behavior.test.ts`
- `packages/orchestrator/tests/contextEngine.test.ts`

Implementation:
- Apply context-engine compaction output to the live message list when it actually compacts.
- Avoid duplicating engine-added evidence already present in the active context.
- Carry latest SNR/evidence metrics into focus-supervisor proposed-call snapshots.

Acceptance:
- A compacted context-engine output reduces the live message list before backend calls.
- `_buildFocusContextSnapshot()` includes raw discovery chars, active evidence chars, active frame chars, and signal-to-noise ratio.
- Context dumps and focus decisions see the same pressure/noise picture.

Verification:
- Covered by `tests/contextEngine.test.ts`, `tests/agenticRunner-context-behavior.test.ts`, and package build.

### WO-TD-06: Completion Ledger Must Finalize Open Failure Runs Truthfully

Status: implemented

Root cause: the ledger contained evidence of mutation, stale edit failures, and no final verification, but stayed `open`.

Anchors:
- `packages/orchestrator/src/completionLedger.ts`
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/orchestrator/tests/completionLedger.test.ts`

Implementation:
- Finalize open ledgers using evidence when a run exits or hits a terminal incomplete state.
- Treat unresolved stale edit families, mutations after last verification, and missing verification after code mutations as incomplete verification.
- Record focus terminal-incomplete events as unresolved ledger evidence.

Acceptance:
- A ledger with an unverified code mutation finalizes as `incomplete_verification`.
- A ledger with unresolved stale edit blocks finalizes as `incomplete_verification`.
- A run that reaches terminal incomplete writes the ledger status before exit.

Verification:
- Covered by `tests/completionLedger.test.ts`; runner bridge typechecked by package build.

### WO-TD-07: Complex Tasks Must Seed A Durable Workboard Or Todo Tree

Status: implemented

Root cause: this robotics/training task had an empty workboard despite requiring discovery, model repair, integration, training, and verification.

Anchors:
- `packages/orchestrator/src/agenticRunner.ts`
- `packages/execution/src/tools/workboard.ts`
- `packages/execution/tests/workboard.test.ts`
- `packages/orchestrator/tests/agenticRunner-context-behavior.test.ts`

Implementation:
- Detect complex implementation/training tasks and seed a minimal board or nested todo skeleton before freeform tool use.
- Require cards or nested todos for repair, integration, training run, and observed verification.
- Attach tool evidence to active cards so completion review has structured state.

Acceptance:
- A multi-step training/robotics task starts with non-empty durable decomposition.
- Workboard cards or nested todos update as evidence is collected.
- Completion review sees unresolved cards/blockers when verification has not happened.

Verification:
- Runner seed-card path guarded by `tests/agenticRunner-context-behavior.test.ts`.

## Verification Checklist

- [x] `pnpm --filter @omnius/orchestrator test -- tests/focusSupervisor.test.ts`
- [x] `pnpm --filter @omnius/orchestrator test -- tests/contextEngine.test.ts`
- [x] `pnpm --filter @omnius/orchestrator test -- tests/completionLedger.test.ts`
- [x] `pnpm --filter @omnius/orchestrator test -- tests/agenticRunner-context-behavior.test.ts`
- [x] `pnpm --filter @omnius/orchestrator build`
