Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): hold the script POST to invariant 5's 200 ms budget
Felipe Neves Ricardocbdbd8c4518b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e646913..bc93e329 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,7 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0behind the next delivery that succeeds, detached from the hook so the agentnever waits. A 4xx stays a permanent rejection and is not retried. This isthe durability the generated TypeScript integrations got in #580, for the- path the docker deploy installs. The PowerShell bundle is unchanged (#NNN).+ path the docker deploy installs. The PowerShell bundle is unchanged (#719).+- The POSIX shell hook bundle's `POST /hook` now hard-timeouts at 200 ms+ rather than 500 ms, which is the budget invariant 5 documents for a script+ hook. A real loopback round trip runs about 0.3 ms, so a local install is+ unaffected; against a remote server the tighter ceiling is safe only because+ a missed window now spools instead of dropping (above). The handoff GET keeps+ its 1 s: it is fed synchronously to the agent's context, and truncating an+ almost-ready handoff costs more than it saves (#719).## [2.2.0] - 2026-09-12diff --git a/hooks/_lib.sh b/hooks/_lib.shindex 13c2b01c..d4f2fa23 100644--- a/hooks/_lib.sh+++ b/hooks/_lib.sh@@ -446,7 +446,7 @@ ai_memory_clear_session_id() {# POST stdin to "$1" as JSON. Adds an# `Authorization: Bearer` header when `AI_MEMORY_AUTH_TOKEN` is set.-# The 0.5s timeout matches the project-wide hook latency budget+# The 0.2s timeout is invariant 5's budget for a script hook# (never block the agent), and the trailing `|| true` makes the# function safe to call from `set -e` scripts. An undelivered event# (unreachable server or 5xx) is spooled for a later drain instead of@@ -465,7 +465,7 @@ ai_memory_post_hook() {_ambody=$(cat)_amhdr=$(ai_memory_auth_header_file || printf '')if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then- _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.5 -o /dev/null \+ _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.2 -o /dev/null \-w '%{http_code}' -X POST "$1" \-H "Content-Type: application/json" \-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \@@ -473,13 +473,13 @@ ai_memory_post_hook() {elif [ -n "$_amhdr" ]; then# `-H @file`: curl reads the header from disk, so the bearer never# appears in curl's argv the way an inline `-H` would (#552).- _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.5 -o /dev/null \+ _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.2 -o /dev/null \-w '%{http_code}' -X POST "$1" \-H "Content-Type: application/json" \-H @"$_amhdr" \--data-binary @- 2>/dev/null) || _amcode=000else- _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.5 -o /dev/null \+ _amcode=$(printf '%s' "$_ambody" | curl -s --max-time 0.2 -o /dev/null \-w '%{http_code}' -X POST "$1" \-H "Content-Type: application/json" \--data-binary @- 2>/dev/null) || _amcode=000