Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/completeness.md
Original file line number Diff line number Diff line change
Expand Up @@ -1756,3 +1756,25 @@ occur together in a stored command assessor configuration in executor
metadata. The full and ordinary responses preserve all three, including
explicit boolean presence. SQLite verification and offline JSON retain
them under the same equality rules as the surrounding metadata.

### Partial responses and verified transcripts

When agy reports more records than it returned, the reader resumes each short
list at its returned length. Verification still compares the assembled full
and presented responses with SQLite. An empty page before the advertised end,
a count overrun, or a content mismatch prevents verified publication.

For SQLite sessions whose executor metadata would exceed the cumulative
64 MiB source budget, sync can publish a smaller representation. A
`verified-transcript-v1` attestation covers the header, steps, generator
metadata, parent references, and battle-mode records. The sidecar omits
`executorMetadatas` and records the number excluded in
`agyReader.completeness.omittedExecutorMetadata`. Changes confined to those
omitted payloads are outside its digest. Both daemon envelopes must report the
source counts, and the reader checks the source again before publication.
Doctor counts these transcripts separately. Full-source exports and format
qualification still require full coverage.

The `killall1512` profile verifies the observed single-child `kill_all`
result against the child's identity in both persisted result lists. The
presented action and both ID strings must match.
2 changes: 1 addition & 1 deletion internal/cache/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func WriteVerified(sidecarPath string, t *daemon.Trajectory, verifiedAt time.Tim
if sourcePath != "" {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
snapshot, err := completeness.ReadSnapshot(ctx, sourcePath)
snapshot, err := completeness.ReadSyncSnapshot(ctx, sourcePath)
if err != nil {
return fmt.Errorf("cache: completeness unknown: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cli/audit_qualify.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ func liveQualification(sessions []discovery.Session) func(string) (string, strin
return string(completeness.Unknown), "no sidecar: ordinary sync has not verified and written this conversation"
}
r := session.Completeness(s)
if r.Reason == completeness.TranscriptReason {
return "transcript-only", r.Reason
}
return string(r.State), r.Reason
}
}
23 changes: 21 additions & 2 deletions internal/cli/audit_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func RunAuditSweepTo(ctx context.Context, args []string, out io.Writer) error {
returned := map[string]string{}
for _, s := range sessions {
fetchCtx, cancel := context.WithTimeout(ctx, *timeout)
t, fetchErr := client.FetchTrajectoryWithFallback(fetchCtx, s.CascadeID, s.InternalCascadeID)
t, fetchErr := fetchSweepPresentation(fetchCtx, client, s)
cancel()
if fetchErr == nil {
fetchErr = checkSweepIdentity(ctx, s, t.CascadeID, returned)
Expand Down Expand Up @@ -195,6 +195,21 @@ func RunAuditSweepTo(ctx context.Context, args []string, out io.Writer) error {
return printSweepReaderSync(out, m)
}

// Keep corpus rendering independent of qualification. If full JSON or a
// continuation exceeds the budget, use the same bounded transcript as sync
// when SQLite confirms executor records are outside the transcript scope.
func fetchSweepPresentation(ctx context.Context, c *daemon.Client, s discovery.Session) (*daemon.Trajectory, error) {
t, err := c.FetchTrajectoryWithFallback(ctx, s.CascadeID, s.InternalCascadeID)
if !errors.Is(err, daemon.ErrRecovery) || errors.Is(err, daemon.ErrAuthentication) {
return t, err
}
snap, sourceErr := completeness.ReadSyncSnapshot(ctx, s.PBPath)
if sourceErr != nil || snap.OmittedExecutors == 0 {
return nil, err
}
return c.GetTranscript(ctx, snap.CascadeID(), false, snap.StepCount, snap.GeneratorCount(), snap.OmittedExecutors)
}

func checkSweepIdentity(ctx context.Context, s discovery.Session, got string, returned map[string]string) error {
id := daemon.CanonicalCascadeID(got)
if id == "" {
Expand All @@ -217,7 +232,7 @@ func selectedSweepIdentity(ctx context.Context, s discovery.Session, id string)
if internal := daemon.CanonicalCascadeID(s.InternalCascadeID); internal != "" && id == internal {
return true
}
snapshot, err := completeness.ReadSnapshot(ctx, s.PBPath)
snapshot, err := completeness.ReadSyncSnapshot(ctx, s.PBPath)
return err == nil && id == daemon.CanonicalCascadeID(snapshot.CascadeID())
}

Expand All @@ -241,6 +256,10 @@ func qualifySweepSession(ctx context.Context, client *daemon.Client, s discovery
entry.ReaderSyncReason = t.Verification.Reason
entry.SourceDigest = t.Verification.SourceDigest
entry.Profile = t.Verification.Profile
if t.Verification.OmittedExecutors > 0 {
entry.ReaderSync = "transcript-only"
entry.ReaderSyncReason = completeness.TranscriptReason
}
}
case errors.As(err, &contentErr):
entry.ReaderSync = string(contentErr.Result.State)
Expand Down
33 changes: 33 additions & 0 deletions internal/cli/audit_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/mjacobs/agy-reader/internal/discovery"
"github.com/mjacobs/agy-reader/internal/testfixture"
"google.golang.org/protobuf/encoding/protowire"
)

const sweepTestID = "11111111-1111-1111-1111-111111111111"
Expand Down Expand Up @@ -298,3 +299,35 @@ func TestAuditSweepAcceptsStoredIdentityDiscoveryCannotRead(t *testing.T) {
t.Fatalf("bad manifest: %+v", m)
}
}

func TestSweepPublishesOversizedTranscriptWithoutQualifyingFullSource(t *testing.T) {
root, dest, _ := sweepFixture(t)
raw := "{\"cascadeId\":\"" + sweepTestID + "\",\"metadata\":{}}"
db := testfixture.Source(t, filepath.Join(root, "conversations", sweepTestID+".db"), []byte(raw))
testfixture.Exec(t, db, "INSERT INTO executor_metadata VALUES(0,zeroblob(67108865))")
header := protowire.AppendString(protowire.AppendTag(nil, 6, protowire.BytesType), sweepTestID)
header = protowire.AppendBytes(protowire.AppendTag(header, 7, protowire.BytesType), nil)
envelope := protowire.AppendBytes(protowire.AppendTag(nil, 1, protowire.BytesType), header)
envelope = protowire.AppendVarint(protowire.AppendTag(envelope, 5, protowire.VarintType), 1)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/GetCascadeTrajectory") {
if r.Header.Get("Content-Type") == "application/proto" {
_, _ = w.Write(envelope)
return
}
_, _ = w.Write([]byte(`{"trajectory":` + raw + `,"numTotalExecutorMetadata":1}`))
return
}
_, _ = w.Write([]byte("{}"))
}))
defer srv.Close()
t.Setenv("ANTIGRAVITY_DAEMON_URL", srv.URL)
var out bytes.Buffer
if err := RunAuditSweepTo(t.Context(), []string{"--root", root, "--out", dest}, &out); err != nil {
t.Fatal(err)
}
m := readSweepManifest(t, dest)
if !m.Complete || len(m.Sessions) != 1 || m.Sessions[0].ReaderSync != "transcript-only" || m.ReaderSync.Verified != 0 {
t.Fatal(m)
}
}
34 changes: 25 additions & 9 deletions internal/completeness/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ import (
// SourceOnlyReason and SourceOnly records that content; both must match the
// snapshot on every recheck.
type Attestation struct {
State string `json:"state,omitempty"`
Profile string `json:"profile"`
SourceDigest string `json:"sourceDigest"`
PayloadDigest string `json:"payloadDigest"`
Representation string `json:"representation"`
Reason string `json:"reason,omitempty"`
SourceOnly []SourceOnlyField `json:"sourceOnly,omitempty"`
OmittedExecutors int `json:"omittedExecutorMetadata,omitempty"`
State string `json:"state,omitempty"`
Profile string `json:"profile"`
SourceDigest string `json:"sourceDigest"`
PayloadDigest string `json:"payloadDigest"`
Representation string `json:"representation"`
Reason string `json:"reason,omitempty"`
SourceOnly []SourceOnlyField `json:"sourceOnly,omitempty"`
}

const representation = "supported-daemon-projection"

const TranscriptRepresentation = "verified-transcript-v1"

func (s *Snapshot) representation() string {
if s.OmittedExecutors > 0 {
return TranscriptRepresentation
}
return representation
}

func PayloadDigest(raw []byte) (string, error) {
var top map[string]any
decoder := json.NewDecoder(bytes.NewReader(raw))
Expand Down Expand Up @@ -67,11 +77,14 @@ func (s *Snapshot) Verify(fullRaw, presentation []byte) (a *Attestation, r Resul
if err != nil {
return nil, Result{Unknown, "invalid trajectory JSON"}, false
}
a = &Attestation{Profile: s.Profile, SourceDigest: s.Digest, PayloadDigest: digest, Representation: representation}
a = &Attestation{Profile: s.Profile, SourceDigest: s.Digest, PayloadDigest: digest, Representation: s.representation(), OmittedExecutors: s.OmittedExecutors}
if len(checked.sourceOnly) > 0 {
a.Reason, a.SourceOnly = SourceOnlyReason, checked.sourceOnly
r = Result{Verified, SourceOnlyReason}
}
if s.OmittedExecutors > 0 {
r.Reason = TranscriptReason
}
return a, r, false
}

Expand All @@ -97,7 +110,7 @@ func (s *Snapshot) CheckAttestation(presentation []byte, a *Attestation) Result
if s == nil {
return Result{Unknown, "source snapshot unavailable"}
}
if a == nil || a.State != "" || a.Profile != s.Profile || a.Representation != representation {
if a == nil || a.State != "" || a.Profile != s.Profile || a.Representation != s.representation() || a.OmittedExecutors != s.OmittedExecutors {
return Result{Unknown, "missing or unsupported completeness attestation"}
}
digest, err := PayloadDigest(presentation)
Expand Down Expand Up @@ -143,6 +156,9 @@ func (s *Snapshot) CheckAttestation(presentation []byte, a *Attestation) Result
if r.State == Verified && len(checked.sourceOnly) > 0 {
r.Reason = SourceOnlyReason
}
if r.State == Verified && s.OmittedExecutors > 0 {
r.Reason = TranscriptReason
}
return r
}

Expand Down
22 changes: 14 additions & 8 deletions internal/completeness/projection_subagents148.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)

// projectManageSubagents148 covers list results and one- or two-child kills. State
// projectManageSubagents148 covers list, targeted kills, and single-child kill_all results. State
// stays in the payload; only present step indices enter the metadata JSON.
func projectManageSubagents148(step, generic, result, payload protoreflect.Message) (proto.Message, error) {
unsupported := errors.New("unsupported manage_subagents 1.4.8 projection")
Expand Down Expand Up @@ -45,6 +45,10 @@ func projectManageSubagents148(step, generic, result, payload protoreflect.Messa
return nil, unsupported
}
indices[id] = state.Get(indexField).Int()
case "kill_all":
if ids.Len() != 1 || !genericArgsAllowed(generic, "Action") || state.Has(indexField) {
return nil, unsupported
}
case "kill":
if !genericArgsAllowed(generic, "Action", "ConversationIds") || state.Has(indexField) {
return nil, unsupported
Expand All @@ -61,15 +65,17 @@ func projectManageSubagents148(step, generic, result, payload protoreflect.Messa
}
metadata["subagent_step_indices"] = string(b)
} else {
arg, ok := genericArg(generic, "ConversationIds")
var requested []string
if !ok || json.Unmarshal([]byte(arg), &requested) != nil || len(requested) != len(names) {
return nil, unsupported
}
for i := range names {
if requested[i] != names[i] {
if action == "kill" {
arg, ok := genericArg(generic, "ConversationIds")
var requested []string
if !ok || json.Unmarshal([]byte(arg), &requested) != nil || len(requested) != len(names) {
return nil, unsupported
}
for i := range names {
if requested[i] != names[i] {
return nil, unsupported
}
}
}
b, err := json.Marshal(names)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/completeness/projection_subagents148_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func subagents148Pair(t *testing.T, action string) (string, string) {
state["stepIndex"] = -1
meta["subagent_step_indices"] = `{"fixture-child":-1}`
} else {
args["ConversationIds"] = []string{"fixture-child"}
genericArgs["ConversationIds"] = `["fixture-child"]`
if action == "kill" {
args["ConversationIds"] = []string{"fixture-child"}
genericArgs["ConversationIds"] = `["fixture-child"]`
}
meta["killed_conversation_ids"] = `["fixture-child"]`
}
call, _ := json.Marshal(args)
Expand All @@ -33,7 +35,7 @@ func subagents148Pair(t *testing.T, action string) (string, string) {
}

func TestSubagents148(t *testing.T) {
for _, action := range []string{"list", "kill"} {
for _, action := range []string{"list", "kill", "kill_all"} {
t.Run(action, func(t *testing.T) {
raw, shown := subagents148Pair(t, action)
s := snapshot1216(t, raw)
Expand Down
13 changes: 7 additions & 6 deletions internal/completeness/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import (
// policy1510 retains the three PolicyGuardianConfig fields observed in executor metadata.
// refs1511 retains the observed agy 1.5.11 render-reference fields.
// tools1512 projects the observed skill, file, command, timer and list results.
const Profile = "sqlite-v1-format0-agy-1.3.4-5b93565c5f04-planner50-permission2-prompt23-tools143-permission1-tools144-skill1-history2-ide225-options145-compaction146-skill146-finish147-replay147-failedread146-subagents148-media149-tools149-sendmessage149-files1411-media1410-parentmsgs1410-paths1410-denied1412-cwd1412-unrun1412-config150-skill150-frontmatter150-bgcancel150-readlines150-config152-tools153-tools154-tools155-images155-tools156-retained156-legacychoices156-runtime157-planexecute157-tools158-workflow159-schedule1510-policy1510-refs1511-tools1512"
const Profile = "sqlite-v1-format0-agy-1.3.4-5b93565c5f04-planner50-permission2-prompt23-tools143-permission1-tools144-skill1-history2-ide225-options145-compaction146-skill146-finish147-replay147-failedread146-subagents148-media149-tools149-sendmessage149-files1411-media1410-parentmsgs1410-paths1410-denied1412-cwd1412-unrun1412-config150-skill150-frontmatter150-bgcancel150-readlines150-config152-tools153-tools154-tools155-images155-tools156-retained156-legacychoices156-runtime157-planexecute157-tools158-workflow159-schedule1510-policy1510-refs1511-tools1512-killall1512"
const maxBytes = 64 << 20
const maxDepth = 100

Expand Down Expand Up @@ -356,11 +356,12 @@ func normalizeIn(m protoreflect.Message, depth int, scope sourceOnlyScope) error
// removed and recorded in sourceOnly. Legacy model choices keep their original
// fields until a complete RPC match selects the source-only alternative.
type Snapshot struct {
Profile string
Digest string
StepCount int
trajectory proto.Message
sourceOnly []SourceOnlyField
Profile string
Digest string
StepCount int
OmittedExecutors int
trajectory proto.Message
sourceOnly []SourceOnlyField
}

type State string
Expand Down
47 changes: 43 additions & 4 deletions internal/completeness/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,27 @@ func ReadSnapshot(ctx context.Context, path string) (*Snapshot, error) {
if filepath.Ext(path) == ".pb" {
return readLegacySnapshot(ctx, path)
}
s, err := readSnapshot(ctx, path)
s, err := readSnapshot(ctx, path, false)
if err != nil && notADatabase(err) {
return nil, refuse(err)
}
return s, err
}

func readSnapshot(ctx context.Context, path string) (_ *Snapshot, resultErr error) {
// ReadSyncSnapshot permits a transcript-only snapshot when executor metadata
// would exhaust the source budget. Offline exports retain their full-source contract.
func ReadSyncSnapshot(ctx context.Context, path string) (*Snapshot, error) {
if filepath.Ext(path) != ".db" {
return ReadSnapshot(ctx, path)
}
s, err := readSnapshot(ctx, path, true)
if err != nil && notADatabase(err) {
return nil, refuse(err)
}
return s, err
}

func readSnapshot(ctx context.Context, path string, allowTranscript bool) (_ *Snapshot, resultErr error) {
path, err := filepath.Abs(path)
if err != nil {
return nil, err
Expand Down Expand Up @@ -145,12 +158,12 @@ func readSnapshot(ctx context.Context, path string) (_ *Snapshot, resultErr erro
if err = readSteps(ctx, tx, out, &budget); err != nil {
return nil, err
}
omitted := 0
for _, list := range []struct {
table string
field protoreflect.Name
}{
{"gen_metadata", "generator_metadata"},
{"executor_metadata", "executor_metadatas"},
{"parent_references", "parent_references"},
{"battle_mode_infos", "battle_mode_infos"},
} {
Expand Down Expand Up @@ -195,14 +208,40 @@ func readSnapshot(ctx context.Context, path string) (_ *Snapshot, resultErr erro
if count != 1 {
return nil, refusal("source must contain one trajectory metadata record")
}
// Measure executor records without materializing their blobs. Check them
// last so the rest of the transcript has already paid its cumulative cost.
if allowTranscript {
var count, first, last int
var size int64
err = tx.QueryRowContext(ctx, "SELECT count(*), coalesce(min(idx),0), coalesce(max(idx),-1), coalesce(sum(length(data)),0) FROM executor_metadata").Scan(&count, &first, &last, &size)
if err != nil {
return nil, err
}
if size > int64(budget) {
if count < 1 || count > 100000 || first != 0 || last != count-1 {
return nil, refusal("unsupported metadata indexing")
}
omitted = count
}
}
if omitted == 0 {
if err = readList(ctx, tx, "executor_metadata", out, "executor_metadatas", &budget); err != nil {
return nil, err
}
}
if err = tx.Commit(); err != nil {
return nil, err
}
// finishSnapshot reads nothing but the content already read.
snapshot, err := finishSnapshot(m)
profile := Profile
if omitted > 0 {
profile = Profile + "/" + TranscriptRepresentation
}
snapshot, err := finishSnapshotProfile(m, profile)
if err != nil {
return nil, refuse(err)
}
snapshot.OmittedExecutors = omitted
return snapshot, nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/completeness/tools158_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func TestCurrentProfileInvalidatesPreviousAttestations(t *testing.T) {
strings.Split(Profile, "-schedule1510")[0],
strings.Split(Profile, "-policy1510")[0],
strings.Split(Profile, "-refs1511")[0],
strings.TrimSuffix(Profile, "-tools1512"),
strings.Split(Profile, "-tools1512")[0],
strings.TrimSuffix(Profile, "-killall1512"),
} {
a.Profile = previous
if a.Profile == Profile {
Expand Down
Loading
Loading