Commit Graph
83 Commits
Author SHA1 Message Date
sausheong a5f21d3a2c fix(bash): treat background & as a command separator in allowlist mode (S1) 2026-06-13 16:23:51 +08:00
sausheong 34435736c5 Merge branch 'cleanup/low-batch': low-priority sweep (L1/L3/L4/L5/L10)
tokens image accounting, Qwen usage stats, one-time degraded-persistence
warning (AppendEntry+Rewrite), RunSync abort surfacing, retry classifier
bounded 429/529 forms + typed Gemini APIError path.
2026-06-13 15:57:04 +08:00
sausheong 3da8fe8ed3 fix(llm): recognize Gemini 429/5xx as retryable via typed APIError path 2026-06-13 15:52:33 +08:00
sausheong 9292731d79 fix(llm): scope retry classifier to bounded 429/529 forms 2026-06-13 15:34:19 +08:00
sausheong 04f02c56d6 fix(runtime): RunSync returns context.Canceled on aborted run 2026-06-13 15:33:02 +08:00
sausheong 3eb9596ee6 fix(session): extend degraded-persistence warning to Rewrite path 2026-06-13 15:31:27 +08:00
sausheong 275636ed20 fix(session): emit one-time warning when persistence is degraded 2026-06-13 15:29:57 +08:00
sausheong 754721bc30 fix(qwen): request usage stats (IncludeUsage) and use MaxCompletionTokens
no request-capture seam; covered by build + openai sibling parity
2026-06-13 15:28:29 +08:00
sausheong 22f4329f44 fix(tokens): count attached images in Estimate (~1500 tokens each) 2026-06-13 15:27:43 +08:00
sausheong 8c9bc2963d Merge branch 'correctness/round5': provider stream + file correctness (R7/N11/N12) 2026-06-13 13:42:59 +08:00
sausheong 1752cbf2fb fix(file): honor ctx cancellation in read_file/edit_file (N12) 2026-06-13 12:51:30 +08:00
sausheong e133f97e1e fix(web): decode all HTML entities via html.UnescapeString (N11) 2026-06-13 12:50:07 +08:00
sausheong 373e44b9c7 fix(anthropic): surface in-band stream error + Builder accumulation (R7c) 2026-06-13 12:48:10 +08:00
sausheong d0cd0989a9 fix(gemini): emit a single EventDone with final usage (R7b) 2026-06-13 12:45:56 +08:00
sausheong 385cd26e4b fix(openai): strings.Builder for tool-arg accumulation (R7c) 2026-06-13 12:44:06 +08:00
sausheong 79a69e5dce fix(qwen): index-order tool emit + strings.Builder accumulation (R7a/R7c) 2026-06-13 12:42:41 +08:00
sausheong e40733145f fix(openai): emit tool calls in index order for prompt-cache determinism (R7a) 2026-06-13 12:40:57 +08:00
sausheong b85ffeac69 Merge branch 'security/round4': SSRF + file-size hardening (S2/N4/S3/N5) 2026-06-13 12:06:50 +08:00
sausheong d6db565d7c fix(web): dial all validated IPs for dual-stack fallback (I1); fix live SSRF test to await fetch (M1) 2026-06-13 11:56:30 +08:00
sausheong fb5103fb87 feat(file): cap read_file/edit_file size to prevent OOM (N5) 2026-06-13 11:27:34 +08:00
sausheong 01b55a1446 fix(browser): block private-IP resolution via host-resolver-rules (S3) 2026-06-13 11:25:22 +08:00
sausheong 7d85074509 fix(web): all web_search backends use SafeHTTPClient (N4) 2026-06-13 11:22:15 +08:00
sausheong d7777f7c89 fix(web): web_fetch uses SafeHTTPClient — pins validated IP (S2) 2026-06-13 11:20:12 +08:00
sausheong 1e00916a82 fix(web): block 0.0.0.0/8, CGNAT, and reserved ranges in isPrivateIP (S2 hardening) 2026-06-13 11:19:03 +08:00
sausheong 083122a81f feat(web): add SafeHTTPClient with IP-pinning transport (S2) 2026-06-13 11:15:26 +08:00
sausheong 5d5dcd1902 Merge branch 'perf/round3': agent hot-path performance (P2/P3/P8/P1/P5)
Drop dead O(n^2) message-assembly work and a never-read tool-result map;
hoist tool-def normalization out of the turn loop; debounce calibrator
persistence to once per Run; skip re-writing spilled tool results each
turn; move the session disk write off the session lock (order-preserving
via lock-coupling). Zero observable behavior change.
2026-06-13 10:29:52 +08:00
sausheong 34ebfc5e95 fix(session): lock-couple writeMu to preserve disk order under concurrent Append (P5)
The earlier P5 change released s.mu before the store write, which let
concurrent appends on one Session reach the disk writer out of in-memory
order. Acquire a dedicated writeMu while still holding s.mu, then release
s.mu before the disk write — disk latency stays off s.mu while on-disk
order still matches append order. Adds a disk-order regression test.
2026-06-13 10:29:07 +08:00
sausheong e1fd4dc689 fix(runtime): recompute calibrator estimate at EventDone (P8 stale-estimate bug)
The earlier P8 change reused the pre-compaction turnEstimate at EventDone,
but mid-turn compaction reassembles msgs without recomputing it — so the
persisted calibration ratio diverged from main whenever compaction fired,
changing future compaction timing. Recompute fresh at EventDone exactly as
the pre-debounce code did; keep only the disk-write debounce (the real win).
2026-06-13 10:27:53 +08:00
sausheong 25b2e9163f perf(session): persist entry after releasing the session lock (P5) 2026-06-13 10:06:43 +08:00
sausheong c710ea5a94 perf(runtime): track spilled tool-call IDs to skip re-writing spills each turn (P1) 2026-06-13 10:04:46 +08:00
sausheong 671c10e89a perf(runtime): persist calibrator once per Run; reuse per-turn estimate (P8) 2026-06-13 10:00:52 +08:00
sausheong 1da0584530 perf(runtime): hoist tool-def filter/sort/normalize out of the turn loop (P3) 2026-06-13 09:57:39 +08:00
sausheong 7151562d99 perf(runtime): drop dead resultIDs map and mid-loop tool-result injection (P2) 2026-06-13 09:55:58 +08:00
sausheong 86ad622144 Merge branch 'reliability/round2': pre-first-token stream-error recovery (R1)
EventError delivered before the first token now runs the same reactive
compaction + fallback-model recovery as the synchronous ChatStream-error
path, via recoverFromPreTokenError (single-shot per turn). Fixes the
primary Anthropic/Gemini path where 429/overflow aborted the turn.
2026-06-13 01:52:25 +08:00
sausheong 7052a66e38 fix(runtime): recover from pre-first-token stream errors (compaction/fallback) — R1 2026-06-13 01:46:38 +08:00
sausheong de23ad986a Merge branch 'harden/safe-defaults': atomic file writes + 0600 perms
WriteFileAtomic helper; write_file/edit_file atomic + restrictive perms;
spill files 0600. Part of the cross-repo safe-by-default hardening.
2026-06-13 01:13:06 +08:00
sausheong 27fecf4588 feat(runtime): spill files 0600 via atomic write 2026-06-13 00:53:22 +08:00
sausheong 87f77c76ba feat(tools/file): edit_file atomic + preserve existing mode 2026-06-13 00:51:57 +08:00
sausheong 7ae944f0eb feat(tools/file): write_file atomic + 0600 2026-06-13 00:50:46 +08:00
sausheong c4750347e6 feat(tool): add WriteFileAtomic helper 2026-06-13 00:49:50 +08:00
sausheong 7fa3e75ad1 feat(llm): PromptCachingProvider capability — cache on renamed providers
providerSupportsCaching gated on the provider NAME being literally
'anthropic', so an Anthropic-shaped provider registered under a custom
config name (platformai, bedrock, any relay) never set
CacheLastMessage — every turn re-processed the full conversation
history uncached (~120K input tokens and 4-6s TTFT per turn on a
large session).

Add llm.PromptCachingProvider capability interface; AnthropicProvider
declares it; runtime gates providerSupportsCaching and
providerSupportsMidLoopCompaction on the capability first, with the
name check kept as legacy fallback for custom impls.
2026-06-11 22:02:37 +08:00
sausheong d5e8abf492 feat(runtime): surface and recover from model refusals
Claude Fable 5 safety classifiers decline requests with HTTP 200 +
stop_reason=refusal and empty content. The Anthropic stream parser
never read stop_reason, so a refused turn looked like a successful
empty response — the UI showed nothing and the agent appeared hung.

- llm: ChatEvent carries StopReason/StopCategory on EventDone;
  StopReasonRefusal constant
- anthropic: parse stop_reason + stop_details.category from
  message_delta (streaming) and the message (non-streaming); WARN log
  on refusal
- runtime Run + RunTurn: on refusal, retry the turn once on
  FallbackModel (refusals are model-specific; Opus-tier has no
  bio/cyber classifiers), discarding any partial output; without a
  fallback (or if the fallback also refuses) synthesize a visible
  'model declined this request' message with the policy category
  instead of silent emptiness
2026-06-10 21:13:48 +08:00
sausheong 3064a0da14 fix(tokens): 1M context window for Fable 5 / Mythos 5 / Opus 4.6+ / Sonnet 4.6
The blanket claude→200k rule predates the 1M-window generation. With
a 200k detected window, preventive compaction (threshold 0.6) fired
at ~120k tokens on models that actually hold 1M — 5x too early.

Match the 1M family explicitly (claude-fable, claude-mythos,
claude-opus-4-6/7/8/9, claude-sonnet-4-6) before the 200k fallback;
older Claude models (3.x, 4.0-4.5 era, Haiku 4.5) keep 200k.
2026-06-10 19:32:09 +08:00
sausheong cf47b2fca8 feat(mcp): expose session Ping on Client
Gateway supervisors need a cheap liveness probe to detect mid-flight
upstream death (crashed stdio child, restarted HTTP server). Client.Ping
forwards to the SDK session's MCP ping; a non-nil error means the
session is no longer usable.

Also moves examples/minimal's keep-import-live statement above the REPL
loop — it sat after an infinite for loop, tripping go vet's unreachable
code check.
2026-06-10 12:44:21 +08:00
sausheong 6f0040f606 fix(anthropic): adaptive thinking for Fable 5 / Mythos 5 / Opus 4.7+
These models reject the legacy thinking config — sending
{type:"enabled", budget_tokens:N} returns HTTP 400
("thinking.type.enabled is not supported for this model"), and
sampling params (temperature) are removed too.

For adaptive-only models (matched by substring so gateway model-group
names like claude-fable-5-global and Bedrock-style IDs are covered):
- emit thinking: {type:"adaptive"} plus output_config.effort
  (low/medium/high mapped from the unified ReasoningMode)
- omit thinking entirely when reasoning is off (Fable 5 also rejects
  an explicit {type:"disabled"})
- drop temperature

Pre-4.7 models keep the existing enabled+budget_tokens behavior.
2026-06-10 12:41:01 +08:00
sausheong 0341628068 Merge: wire KnowledgeGraph (recall+ingest) into RunTurn
RunTurn now consults r.KG — bounded-synchronous semantic recall folded into
the prompt on the first round of an exchange, async auto-ingest on the
completing round. Fixes the gap where the KG seam was inert on the runtime's
serve path (RunTurn never read r.KG). Interface + BuildRuntime unchanged.
2026-06-10 00:23:53 +08:00
sausheong 5d6326981e docs(runtime): update RunTurn contract — it now does KG recall/ingest 2026-06-09 23:58:21 +08:00
sausheong b7cbfc584c docs(runtime): note IngestSource/growth-gate rationale at RunTurn ingest 2026-06-09 23:42:58 +08:00
sausheong 8f8d75cd06 feat(runtime): KG ingest on RunTurn exchange completion 2026-06-09 23:39:26 +08:00
sausheong fe71e7b36d feat(runtime): bounded-synchronous KG recall in RunTurn 2026-06-09 23:34:44 +08:00