Repository navigation
Persist status code and cause on provider error events (#674) #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Svector-anu
wants to merge
10
commits into
Twigpine:main
Choose a base branch
from
Svector-anu:fix/674-provider-error-diagnostics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+441
−17
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d3e263
Persist status code and cause on provider error events
Svector-anu 8f712b6
Address CodeRabbit review: upstream-unreachable metadata + test coverage
Svector-anu c762013
fix(zeroruntime): gofmt struct alignment in CollectedStream
Svector-anu 08e6a61
test(sessions): assert error event round-trips statusCode/cause throu…
Svector-anu ef00dd6
Merge branch 'main' into fix/674-provider-error-diagnostics
Svector-anu 031b841
Merge branch 'main' into fix/674-provider-error-diagnostics
Svector-anu ba92df9
fix(agent): keep StreamError through image-rejection recovery
Svector-anu 571675d
fix(providers): stop persisting a bucketed 500 and bound error cause
Svector-anu b7f6368
Merge remote-tracking branch 'origin/main' into fix/674-provider-erro…
Vasanthdev2004 ad8686e
fix(sessions): keep a truncated error cause within its cap
Vasanthdev2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package sessions | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/Twigpine/zero/internal/zeroruntime" | ||
| ) | ||
|
|
||
| // maxErrorCauseBytes bounds the persisted cause. Provider error bodies are read | ||
| // up to 64 KiB, which is far more than a diagnostic needs and would otherwise be | ||
| // copied whole into every error event in events.jsonl. | ||
| const maxErrorCauseBytes = 8 << 10 | ||
|
|
||
| const errorCauseTruncationMarker = "… [truncated]" | ||
|
|
||
| // ErrorEventPayload builds the payload for an EventError session event. It | ||
| // always includes the flattened message (unchanged, for backward | ||
| // compatibility with existing consumers of events.jsonl), and additionally | ||
| // persists the HTTP status code and upstream cause when err is (or wraps) a | ||
| // *zeroruntime.StreamError — the structured error a failed provider stream | ||
| // returns. Without this, a provider error left no way to diagnose *why* a | ||
| // call failed from the CLI or its logs — only the generic top-level message | ||
| // was ever recorded (#674). Cause has already been redacted for secrets by | ||
| // the provider before reaching here (see zeroruntime.StreamEvent.Cause) — it | ||
| // is never re-scrubbed or stored raw at this layer. A longer cause is cut on a | ||
| // rune boundary and marked, and the marked result, marker included, stays | ||
| // within maxErrorCauseBytes. | ||
| func ErrorEventPayload(err error) map[string]any { | ||
| payload := map[string]any{"message": err.Error()} | ||
| var streamErr *zeroruntime.StreamError | ||
| if errors.As(err, &streamErr) { | ||
| if streamErr.StatusCode != 0 { | ||
| payload["statusCode"] = streamErr.StatusCode | ||
| } | ||
| if streamErr.Cause != "" { | ||
| payload["cause"] = boundErrorCause(streamErr.Cause) | ||
| } | ||
| } | ||
| return payload | ||
| } | ||
|
|
||
| func boundErrorCause(cause string) string { | ||
| if len(cause) <= maxErrorCauseBytes { | ||
| return cause | ||
| } | ||
| // The marker counts toward the bound, so the cut leaves room for it. | ||
| return truncateUTF8(cause, maxErrorCauseBytes-len(errorCauseTruncationMarker)) + errorCauseTruncationMarker | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.