Skip to content

Phase E: Harness and Log Schema #223

Description

@Cho-Geer

Description

Add E2E tests for double-dispatch, exact lease, and shell bypass. Add structured log events for the full dispatch lifecycle. Fail framework self-test if regression conditions are detected.

Code References (§6 Phase E)

Files to Modify

  • .opencode/scripts/framework-self-test.ts
  • .opencode/lib/__tests__/dispatch-db.test.ts
  • .opencode/scripts/e2e/dispatch-exact-lease.e2e-test.ts
  • .opencode/scripts/e2e/shell-backup-bypass.e2e-test.ts

New E2E Tests (from §5.6)

  1. Single-call harness: One dispatch_subagent tool call creates one DB queue row and one prompt ref
  2. Duplicate guard: Same task/hash is idempotent; different hash is rejected
  3. Exact lease harness: Returned prompt leases the row whose dag_task_id and hash match the token
  4. Agent-only lease regression: Preload an older Super-Admin pending row; new Super-Admin Task must not lease the older row
  5. DB/file split regression: rg ".pending.json|.auto-dispatch.json|ctx/" .opencode/plugins .opencode/tools .opencode/scripts/command-tools finds no runtime writer except migration/doctor code
  6. DISPATCH_TOKEN tests: Missing token blocks, tampered prompt blocks, exact prompt passes
  7. Temp-script bypass tests: cat > /tmp/x.ts with workspace writes blocks; bun /tmp/x.ts blocks; python3 <<EOF open(...).write() blocks
  8. Backup tests: safe_edit creates backup row; shell write paths have no write effect and log a block
  9. Concurrency tests: Parallel same/different agent dispatches use DB locks and do not overwrite context

Log Schema

Add structured log events required by §5.9:

Event Producer Key Fields
DISPATCH-CREATE-REQUEST dispatch_subagent.ts sessionID, callID, agent, target_agent, dag_task_id, description_sha256
DISPATCH-DB-CREATED dispatch-db.ts queue_id, dispatch_key, prompt_ref_id, prompt_sha256
DISPATCH-PROMPT-RETURNED dispatch_subagent.ts queue_id, dispatch_key, file_path, size_bytes
DISPATCH-INTEGRITY-PASS task-before.ts dispatch_key, prompt_sha256, agent_type, dag_task_id
DISPATCH-QUEUE-EXACT-LEASE task-before.ts queue_id, lease_owner, lease_expiry
DISPATCH-QUEUE-EXACT-MISS task-before.ts attempted tuple and pending counts
SHELL-WRITE-BLOCKED scope-before.ts / safe-bash-core.ts agent, command_kind, targets, reason
BACKUP-CREATED backup-manager.ts backup_uuid, file, agent, sessionID, dag_task_id

Self-Test Checks

  • Fail if duplicate dispatch rows exist for same active tuple
  • Fail if runtime writers still touch .pending.json
  • Fail if a log event misses the required identity tuple

Acceptance Criteria

  • The harness reproduces today's double-dispatch bug before the fix
  • The harness passes after Phases A-D are implemented

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requesttesting

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions