Repository navigation
Recover a failed or stalled trace output and count the spans it drops - #655
sabasiddique1 wants to merge 7 commits into
Conversation
|
This pull request's description says it closes #282, which is on the project roadmap. When it merges, GitHub closes that issue and the roadmap counts it as delivered. Please confirm the change delivers the whole issue before merging. |
c7c8524 to
e784196
Compare
rocklambros
left a comment
There was a problem hiding this comment.
Hi Saba, thank you for this. I reviewed commit e784196.
The breaker works well. A second reviewer ran a real Guardian with one output that never answers. The decisions and the latency were the same as with export off, and the file output still got every span. Seventeen injected defects each failed a test, and the exporter tests passed 97 of 97 six times under heavy load.
Two things are needed before merge.
-
This pull request conflicts with
integrationinreference-implementations/agt-go/agtbridge/testdata/ts-cases.json. #597 changed that file. A lead records that file again after the Guardian pull requests merge, so please keep theintegrationcopy:git fetch upstream(upstreamis GenAI-Security-Project/agent-control-standard)git rebase upstream/integrationgit checkout upstream/integration -- reference-implementations/agt-go/agtbridge/testdata/ts-cases.jsongit add reference-implementations/agt-go/agtbridge/testdata/ts-cases.jsonandgit rebase --continuegit push --force-with-lease
-
The span limit can cut a value that the Guardian writes, and nothing marks the cut. In
packages/guardian/src/otel-trace-exporter.ts:816, the decision attributes (attributes) are in the second argument offitSpanBytes(), so they share the cut with the request's step attributes. The session id and request id come from the request and are never cut. So a request with long ids makesacs.chain_hashshorter. I added this test next to "holds a span from a largest-size request" and ran it:exporter.end( exporter.start(largestRequest("é".repeat(4096), "\u{1F600}".repeat(2048), { sessionId: "€".repeat(4096), requestId: "€".repeat(4096) }), "steps/toolCallRequest", TRUSTED), decisionResponse(1, { ...DENY, chain_hash: "a".repeat(64) }), );
acs.chain_hashon the decision event has 63 characters, and the response sent 64. A trace reader then sees a wrong chain hash.Fix: replace line 816 with these two lines, so only request values are cut:
const decided = attributes; const [held = {}] = fitSpanBytes([stepSpan.claimed, failure ?? {}, decided], [stepSpan.held]);
Please add the test above with
expect(event?.attributes?.["acs.chain_hash"]).toBe("a".repeat(64)). I tried this fix:bun run typecheckexits 0, and the exporter tests give 98 passed, 0 failed, with the new test included.
What I ran, on integration with this pull request merged in (I took the integration copy of ts-cases.json), from reference-implementations/agt, on Bun 1.4.4:
bun run typecheck. It exits 0.bun test. Result: 1391 passed, 1 skipped, 0 failed.bun test packages/guardian/test/otel-trace-exporter.test.tsthree times. Each run: 97 passed, 0 failed.- The test above.
What I did not check: the Go suite, Windows, and a real OTLP collector.
Three follow-ups. They can go in this pull request or a later one:
- When the queue fills first, the real cause is never printed. The queue-full drop sets
failing = truewithout opening the breaker (otel-trace-exporter.ts:526). A later timeout then prints nothing, so the operator sees "queue is full" and not "no answer within 3000 ms". - A healthy output whose
shutdown()orforceFlush()rejects prints "Dropping spans until it recovers, 0 dropped so far" while the Guardian closes (otel-trace-exporter.ts:500and:507). Please print a separate line for this case. - STYLE.md allows four sentences in a paragraph. The changed paragraph at
reference-implementations/agt/README.md:299has six, and two new paragraphs inpackages/guardian/README.mdhave five.
When you push, I will review the new commit.
|
Similar to that of the 656 pull, where I think I see the same ts-cases.json conflict against integration, are we able to rebase it onto integration? This also conflicts with #656 in the trace exporter source aspect, its test, and the README as well I think. I suggest this lands first because it adds the dropped-span count, which #656's changes must preserve. Once this is in, #656 rebases on it. |
Closes GenAI-Security-Project#282 Refs GenAI-Security-Project#274 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Refs GenAI-Security-Project#282 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Refs GenAI-Security-Project#282 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Refs GenAI-Security-Project#282 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Refs GenAI-Security-Project#282 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
Refs GenAI-Security-Project#282 Signed-off-by: Saba Siddique <sabasiddiqdev@gmail.com>
e784196 to
c1b842d
Compare
|
Rebased on integration and kept its Two things I left out. There's no test for the flush line, because the SDK never calls the exporter's @DanPazlev agreed, this one lands first. I'll rebase #656 on it after. |
What changed
A trace output that failed once stayed off until the Guardian restarted, a hung write was never marked as failed, and dropped spans printed nothing an operator sees.
isolated()now keeps a breaker for each output: a failed, thrown or unanswered export opens it, and batches are dropped and counted while it is open. The next batch after a backoff (1 s, doubling to 60 s) tests the output again, and the Guardian prints each output's dropped count on stderr. One span is limited to 32 KiB of text, so a stalled output cannot grow memory without bound.Scope
Item by item against #282:
dead. Done. The output is never tested duringshutdownorforceFlush, and every timer is unref'd.SPAN_BYTE_LIMITis 32 KiB of text for one span, and only request values are cut to fit. The ids, the decision and any failure event stay whole, and arrays keep their length, so the policy and provenance columns still line up. If those alone pass 32 KiB, the span goes over, with every request value empty.docs/spec/changes too, see Specification changes.The issue's acceptance tests are in
packages/guardian/test/otel-trace-exporter.test.ts: the hung output (with the limit in item 2), recovery and no duplicates, run on both Bun versions. The hung-output test keeps memory growth under 256 MB over 1500 largest-size requests. It uses ASCII, as the issue's 0.5 MB span implies.Three things change for an operator. For a failed output the stderr line is now
failed: <reason>. Dropping spans until it recovers, where it wasdisabled after failure. A failed shutdown of one output printscould not shut down: <reason>.and drops nothing.onErroris now called for each failure that starts an outage or opens a breaker, and for each failed shutdown, where it was called at most once for each output.This conflicts with my PR #656 for #283 in
otel-trace-exporter.ts, the Guardian README and the exporter test file. DanPazlev suggested this one lands first, and I'll rebase #656 on it once it merges.Credit
The scope and the acceptance tests are rocklambros's, from #282. The findings behind them came from the review of PR #244 by rocklambros and bar-capsule, collected in #274.
Questions for the reviewer
@artmaro, two questions:
Which issue does this implement
Closes #282
Refs #274
meaning, so it needs no issue
Base branch
integration, because this touches the specification, schemas, a referenceimplementation, an adapter, tests, or CI
main, because every changed path is on the documentation lane allowlist inCONTRIBUTING.md
Type of change
Specification changes
No normative text changes. One sentence in
docs/spec/trace/extend_opentelemetry.mdchanges, where it describes what the AGT Guardian does when an output fails.Breaking for implementers? No.
I tested this
uv run pytest -vpasses on my machineuv run mkdocs build --strictpasses on my machineHow I tested
From
reference-implementations/agt, on Bun 1.3.11 and again on Bun 1.3.14:bun run typecheck bun testFrom the repo root,
uv run pytest -vgives 9376 passed, 7 skipped and 1 xfailed, anduv run mkdocs build --strictpasses. I broke the behavior each new test covers, and each went red. I ran this on macOS only.The Go recording is not changed here. As rocklambros asked, the branch keeps the
integrationcopy ofts-cases.json, and a lead records it again after the Guardian pull requests merge. Until thenTestRecordingIsCurrentfails in agt-go, because thepackages/guardian/srctree id changed.go test ./...passes.Checklist
git commit -s(required by the DCO)Security
It bounds the memory a stalled trace output can hold. A Guardian that runs out of memory fails open under the default posture.