Skip to content

feat: add single-runtime prompt observations - #100

Draft
adityathebe wants to merge 4 commits into
mainfrom
feat/prompt-observe
Draft

feat: add single-runtime prompt observations#100
adityathebe wants to merge 4 commits into
mainfrom
feat/prompt-observe

Conversation

@adityathebe

@adityathebe adityathebe commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

  • add the versioned, CLI-only captain prompt observe <prompt> --runtime <selector> contract for exactly one resolved runtime
  • separate observation protocol success from execution outcome, with explicit requested/resolved/observed facts, capture completeness, full disjoint usage, cost source, and raw timing
  • capture OpenAI reasoning effort only from the fully marshaled openai-go /chat/completions request at the SDK transport boundary; failed Genkit conversion records no dispatch, while unsafe body inspection reports unknown with partial capture
  • preserve usage presence from Genkit responses and terminal provider events so omitted usage remains unknown without buckets while present all-zero usage remains known with all five zero buckets
  • capture Codex process/turn effort dispatch plus brokered permission/tool lifecycle evidence while preserving existing captain prompt run behavior

Validation

  • go test ./pkg/ai/provider/genkit -run 'TestOpenAI(ConversionFailureDoesNotRecordNativeDispatch|NativeDispatchRecordsMarshaledReasoningEffort)$' -v — passed; both cases run through Captain’s generic Genkit middleware; the conversion-failure case keeps reasoning_effort: high in generic config, proves zero transport calls and zero dispatch events, and reports observed: unknown; the success case proves the SDK HTTP doer received high and reports evidence-backed observed: known
  • focused usage-presence tests in pkg/cli, pkg/ai/provider/genkit, and pkg/ai/provider — passed; successful omitted usage stays unknown with no buckets, while native/event-present zero usage remains non-nil and emits all five zero buckets through Genkit, generic stream coalescing, Codex CLI, and Codex app-server seams
  • full observation, provider, Genkit, and CLI package tests plus targeted go vet — passed
  • golangci-lint run ./... — 0 issues
  • go build ./cmd/captain — passed
  • binary-level OpenAI transport-failure check — emitted one captain.observation/v1 document with process exit 0, execution failure separated from three SDK dispatch attempts, and evidence-backed observed: known/high; a no-effort run reported evidence-backed observed: unset
  • earlier focused API, recorder, Codex, and CLI checks plus black-box contract checks — passed, including exit-0 runtime failures, exit-0 unsupported controls, exact single-document JSON, stderr isolation/redaction, Codex dispatch evidence, and all five disjoint usage buckets
  • local go test ./... passed except the unrelated order-dependent pkg/ai/provider/cmux TestSessionStatsCacheColdCachesByMtime failure (OutputTokens after rewrite = 20, want 100); the untouched test passes in isolation

Deferred scope

Addresses #99.
Companion: flanksource/gavel#84.

Add a versioned machine-oriented prompt observation contract that resolves and executes exactly one runtime while reporting execution failures as observation data.

Capture provider-native reasoning effort at OpenAI and Codex dispatch boundaries, correlate brokered permission and tool lifecycle evidence, and preserve full disjoint usage, cost source, and raw timing without changing prompt run output.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0397c-1820-716d-9d2b-6223042c9b59
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Gavel summary

Source Pass Fail Skip Duration

Totals: 0 passed · 0 failed · 0 skipped · -

View full results

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Gavel summary

Source Pass Fail Skip Duration
agentcreds 11 0 0 561.084µs
ai 87 0 0 36ms
aichat 135 0 2 16.2s
anthropicmock 1 0 0 1ms
api 223 0 0 39ms
attachments 5 0 0 3ms
bash 4 0 0 318.599µs
callertools 10 0 0 78ms
captain 17 0 0 10.8s
claude 22 0 0 18ms
claudeagent 13 0 0 212ms
cli 239 0 0 7.2s
cmux 4 0 0 709.926µs
collections 12 0 0 343.707µs
credentials 5 0 0 31ms
credsync 11 0 0 208ms
database 20 0 0 6.3s
deploy 110 0 0 232ms
genkit 25 0 0 81ms
gitagent 122 0 0 15.4s
github.com/flanksource/captain/migrations 11 0 0 4.2s
github.com/flanksource/captain/pkg/ai 250 0 0 630ms
github.com/flanksource/captain/pkg/ai/agent 26 0 0 450ms
github.com/flanksource/captain/pkg/ai/agent/commit 56 0 0 4.3s
github.com/flanksource/captain/pkg/ai/agent/setup 16 0 0 80ms
github.com/flanksource/captain/pkg/ai/agent/verify 21 0 0 380ms
github.com/flanksource/captain/pkg/ai/agent/worktree 6 0 0 -
github.com/flanksource/captain/pkg/ai/assistanttags 15 0 0 -
github.com/flanksource/captain/pkg/ai/fixture 42 0 0 170ms
github.com/flanksource/captain/pkg/ai/fixture/kubeproxy 2 0 0 40ms
github.com/flanksource/captain/pkg/ai/fixture/mcpproxy 6 0 0 -
github.com/flanksource/captain/pkg/ai/history 54 0 0 -
github.com/flanksource/captain/pkg/ai/internal/gen-model-registry 12 0 0 -
github.com/flanksource/captain/pkg/ai/middleware 25 0 0 -
github.com/flanksource/captain/pkg/ai/observation 2 0 0 -
github.com/flanksource/captain/pkg/ai/pricing 9 0 0 10ms
github.com/flanksource/captain/pkg/ai/prompt 16 0 0 30ms
github.com/flanksource/captain/pkg/ai/provider 176 0 1 10ms
github.com/flanksource/captain/pkg/ai/provider/claudeagent 54 0 0 1.4s
github.com/flanksource/captain/pkg/ai/provider/cmux 128 0 0 850ms
github.com/flanksource/captain/pkg/ai/provider/genkit 41 0 0 -
github.com/flanksource/captain/pkg/ai/provider/jsonrpc 6 0 0 50ms
github.com/flanksource/captain/pkg/aichat 9 0 0 100ms
github.com/flanksource/captain/pkg/aimock 50 0 7 530ms
github.com/flanksource/captain/pkg/aimock/anthropicmock 14 0 0 10ms
github.com/flanksource/captain/pkg/aimock/openaimock 18 0 0 60ms
github.com/flanksource/captain/pkg/api 144 0 0 360ms
github.com/flanksource/captain/pkg/api/registry 96 0 0 -
github.com/flanksource/captain/pkg/bash 348 0 0 60ms
github.com/flanksource/captain/pkg/captainconfig 25 0 0 -
github.com/flanksource/captain/pkg/captaintoken 23 0 0 1.4s
github.com/flanksource/captain/pkg/claude 138 0 0 10ms
github.com/flanksource/captain/pkg/claude/tools 18 0 0 -
github.com/flanksource/captain/pkg/cli 783 0 1 1m10s
github.com/flanksource/captain/pkg/cmux 1 0 0 -
github.com/flanksource/captain/pkg/codexconfig 10 0 0 -
github.com/flanksource/captain/pkg/container 72 0 1 10ms
github.com/flanksource/captain/pkg/database 130 0 0 19.6s
github.com/flanksource/captain/pkg/dod 11 0 0 1m0s
github.com/flanksource/captain/pkg/gitagent 31 0 0 410ms
github.com/flanksource/captain/pkg/gitagent/proxy 12 0 0 -
github.com/flanksource/captain/pkg/monitor 60 0 0 2.8s
github.com/flanksource/captain/pkg/sandbox 13 0 0 -
github.com/flanksource/captain/pkg/sandbox/adapter 39 0 0 -
github.com/flanksource/captain/pkg/sandbox/presets 13 0 0 -
github.com/flanksource/captain/pkg/session 70 0 0 10ms
history 69 0 0 13ms
migrations 12 0 0 5.0s
openaimock 2 0 0 176.526µs
provider 12 0 0 13ms
registry 38 0 0 4ms
session 28 0 0 5ms
tools 53 0 0 6ms

Totals: 4392 passed · 0 failed · 12 skipped · 3m50s

View full results

Genkit model middleware sees generic config before conversion, so a conversion failure could previously claim provider-native evidence without any provider call.

Move OpenAI capture to the fully marshaled openai-go HTTP request, and report unknown/partial when that request cannot be inspected safely. Exercise both failed conversion with zero transport calls and successful native dispatch.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0397c-1820-716d-9d2b-6223042c9b59
Run both pinned OpenAI generator cases through Captain generic middleware. Any return to pre-conversion effort recording now makes the no-dispatch case or single-dispatch case fail.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0397c-1820-716d-9d2b-6223042c9b59
Buffered observation treated every ai.Response Usage value as present, so providers that omitted usage produced falsely known all-zero buckets.

Carry native/event usage presence through the observation recorder, preserve nil versus known-zero usage in Genkit and Codex terminal events, and keep provider-reported cost independent of usage availability.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0397c-1820-716d-9d2b-6223042c9b59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant