Skip to content
Draft
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
56 changes: 29 additions & 27 deletions AUTOLITH.org
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,40 @@ a user-local init.lisp change, or a private image commit.

- Problem: a changed prompt fingerprint discarded valid measured history after
restart, inflating estimates for serialized encrypted reasoning.
- Behavior: validate retained history and provider/model/reasoning/endpoint
identity, then charge changed prompt and tool components separately. Store
fingerprint-only format-two evidence; require exact headers for legacy samples.
- Behavior: a sample stays usable while its policy (class, model, model-provider,
endpoint) and its measured history prefix are unchanged.
Prompt, tool header, retained history additions and request-local input are
charged as signed character differences against the measured request, so a
rewritten covered prefix is the only rejection. When no sample is usable, the
estimate starts from the newest recorded measurement taken under the same
policy and charges only the history added after it, so evidence of an older
shape still bounds a reloaded conversation.
- Scope and location: tracked provider admission, agent context and conversation
storage in =e8a8b625= and =73babdcc=. Nine functions and their declarations
were installed live and persisted in private image commit
=b1620f5e-2077-4652-9d9e-c5f8aefb446e=, private Git =f56a6ae9=;
papercut =Q3TfMSy=.
- Verification: 24 focused cases with 248 checks passed. Real active traffic
produced valid format-two evidence. Active checks covered persistence reload,
history and policy validation, component charging, admission and tamper
rejection. Clean-process private replay passed.
- Removal condition: discard the private accounting definitions after booting
the equivalent tracked implementation.
storage in =src/provider/context-admission.lisp=, =src/agent/context.lisp= and
=src/conversation/store.lisp=. Samples store format-three evidence;
conversation storage validates that shape only and keeps the recorded token
count and history length beside it, and prefix digests decide usability.
- Verification: focused cases in =tests/context-admission-tests.lisp= cover
component charging, request-local differences, policy invalidation, effort switches that keep the anchor, replaced
history, wire-field compatibility and estimates that resume from an older
recorded measurement; =./script/check= runs the repository check.
- Removal condition: none. The tracked implementation owns the accounting and
supersedes private image commit =b1620f5e-2077-4652-9d9e-c5f8aefb446e=.

** Measured context through failed compaction

- Problem: side-channel compaction metering erased the ordinary context sample
even when compaction failed without replacing retained history.
- Behavior: retain the ordinary sample during compaction requests; invalidate it
when publishing replacement history or changing ownership or configuration.
- Scope and location: tracked =src/conversation/store.lisp= in =d0085f7c=;
the single invalidator definition was installed live and persisted in private
image commit =ad5fa7b4-6e5a-4830-ba2f-b114f8137a24=, private Git =dce50286=;
papercut =H4RdvUE=.
- Verification: source checks, 24 context-admission cases with 254 checks and
the rejected-summary case with four checks passed. Historical replay retained
the original valid sample through the failed attempt and subsequent paste,
with identical retained history. Active boundary assertions and clean-process
private replay passed; running and selected private commits are synchronized.
- Removal condition: omit the private invalidator after booting the equivalent
tracked implementation.
- Behavior: the ordinary sample survives compaction requests. A published
summary or native compaction replaces the covered history prefix, and the
prefix digest then rejects the sample on the next request; a configuration or
ownership change rejects it through the policy and conversation identity.
- Scope and location: tracked =src/conversation/store.lisp= and
=src/provider/context-admission.lisp=; conversation storage validates sample
shape only and admission decides usability.
- Verification: the context-admission cases covering summary publication,
native compaction metadata and configuration invalidation.
- Removal condition: none.

** Default child-agent depth

Expand Down Expand Up @@ -396,7 +398,7 @@ a user-local init.lisp change, or a private image commit.
** Lower-cost delegated inference

- Problem: General task children and unqualified RLM calls inherited the primary
model and reasoning effort, consuming the user's subscription allowance on
model and consuming the user's subscription allowance on
routine delegated work.
- Behavior: Top-level RLM calls default to =gpt-5.6-luna= at =low= effort.
Explicit model/effort arguments override those defaults; supplied Lisp
Expand Down
77 changes: 53 additions & 24 deletions src/agent/context.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -544,32 +544,61 @@ stays cached across midnight; this separate block carries the change instead."
(configuration conversation &key tool-registry hurry-up-p family provider)
"Return shared input accounting and whether no unmeasured history was added.

A matched measurement already includes request-local guidance. Charge only
new retained history here; admission replaces temporary context when encoding."
(let* ((tools (if tool-registry (tool-registry-provider-schemas tool-registry) #()))
(items (conversation-input-items-for-family
conversation
(or family (model-family (config :model configuration)
(config :model-provider configuration)))))
(sample (conversation-context-usage-sample conversation))
(components (and provider (provider-context--header-components provider tools))))
(when (and provider
(null (conversation-ephemeral-input-entries conversation))
A matched measurement already includes request-local guidance. Charge new
retained history, prompt and tool changes, and request-local character changes
here; admission charges the encoded request instead.

Without a usable sample the estimate starts from the newest recorded measurement
and charges only the history added after it, so a conversation reloaded with
evidence of an older shape is not priced as if nothing had been measured."
(let* ((tools (if tool-registry (tool-registry-provider-schemas tool-registry) #()))
(family (or family (model-family (config :model configuration)
(config :model-provider configuration))))
(items (conversation-input-items-for-family
conversation family :include-ephemeral-p nil))
(sample (conversation-context-usage-sample conversation))
(policy (and provider (provider-context--request-policy provider))))
(when (and policy
(provider-context--sample-matches-p
sample (provider-context--soft-header provider tools)
(mapcar #'provider-cache-prefix--entry items) :components components))
(let* ((new (nthcdr (getf sample :history-count) items))
(charge (if (= 2 (getf sample :format))
(provider-context--header-charge sample components) 0)))
sample policy (mapcar #'provider-cache-prefix--entry items)))
(let* ((count (getf sample :history-count))
(added (when (< count (length items)) (subseq items count)))
(ephemera (- (provider-context--ephemera-characters conversation)
(getf sample :ephemera-characters 0)))
(header (provider-context--header-charge
(getf sample :chargeables)
(provider-context--request-chargeables provider tools))))
(multiple-value-bind (characters)
(if added
(provider-context--request-characters (coerce added 'vector))
(values 0))
(return-from context-estimate-known-tokens
(values
(provider-context--input-tokens
sample nil
:additional-characters (+ characters ephemera header))
(and (null added) (zerop ephemera) (zerop header)))))))
(let ((baseline (conversation-context-usage-baseline conversation)))
(when (and baseline
(equal (getf baseline :policy) policy)
(<= (getf baseline :history-count) (length items)))
(return-from context-estimate-known-tokens
(values (+ charge (provider-context--input-tokens sample (and new (coerce new 'vector))))
(and (null new) (zerop charge))))))
(values
(provider-context--input-tokens
nil (vector (system-prompt configuration)
(request-context-session-state configuration :hurry-up-p hurry-up-p)
(coerce items 'vector) tools))
nil)))
(values
(provider-context--input-tokens
baseline nil
:additional-characters
(let ((added (nthcdr (getf baseline :history-count) items)))
(if added
(provider-context--request-characters (coerce added 'vector))
0)))
nil)))
(values
(provider-context--input-tokens
nil (vector (system-prompt configuration)
(request-context-session-state configuration :hurry-up-p hurry-up-p)
(coerce (conversation-input-items-for-family conversation family) 'vector)
tools))
nil))))

(-> context--render (list) (option string))
(defun context--render (contributions)
Expand Down
13 changes: 6 additions & 7 deletions src/agent/runtime.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,12 @@ retries stay auditable next to the request they belong to."
':durable))))
(conversation-append-provider-metadata
conversation
(append (list :request-number request-number
:context-usage-pending t
:response-id (provider-result-response-id result)
:usage (agent--portable-value
(provider-usage-normalize
(provider-result-usage result)))
:request-identity (conversation-request-identity conversation))
(append (list :request-number request-number
:response-id (provider-result-response-id result)
:usage (agent--portable-value
(provider-usage-normalize
(provider-result-usage result)))
:request-identity (conversation-request-identity conversation))
;; The service's effective retention mode, when it reports one.
(let ((context (agent--result-reasoning-context result)))
(and context (list :reasoning-context context))))))
Expand Down
94 changes: 42 additions & 52 deletions src/conversation/store.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ not yet been told that work from the previous process is gone.")
:accessor conversation-context-usage-sample
:type list
:documentation "Portable ordinary usage evidence, revalidated against retained history and encoded request fingerprints before reuse.")
(context-usage-baseline
:initform nil
:accessor conversation-context-usage-baseline
:type (option list)
:documentation
"The token count and history length of the newest measurement, whatever

shape its evidence had.")
(last-total-tokens
:initform 0
:accessor conversation-last-total-tokens
Expand Down Expand Up @@ -3128,31 +3136,6 @@ later picker searches read it without scanning the log."
(:method ((kind t) conversation properties)
nil))

(-> conversation--invalidate-context-usage (conversation keyword &optional list) null)
(defun conversation--invalidate-context-usage (conversation kind &optional properties)
"Discard measured context evidence when KIND replaces its coverage.

PROPERTIES is the durable record property list when available. Provider usage
metadata preserves coverage; published compaction, ownership changes and pending
ordinary responses replace it."
(let ((metadata (getf properties :metadata)))
(when (or (member kind '(:summary :native-compaction :context-adoption
:configuration :precompaction))
(and (eq kind :provider)
(or (getf metadata :context-adoption)
(getf metadata :context-usage-pending))))
(setf (conversation-context-usage-sample conversation) nil)))
nil)

(defmethod conversation-append-record :after ((conversation conversation) (record list))
"Invalidate measured coverage consistently for live appends and durable replay."
(conversation--invalidate-context-usage conversation (first record) (rest record)))

(defmethod conversation--project-record :before (kind conversation properties)
"Invalidate earlier measured coverage before projecting a durable change."
(conversation--invalidate-context-usage conversation kind properties)
nil)

(-> conversation--context-fingerprint-p (t) boolean)
(defun conversation--context-fingerprint-p (value)
"Recognize a portable SHA-256 digest and serialized character count."
Expand All @@ -3165,45 +3148,52 @@ ordinary responses replace it."
(defun conversation-context-usage-sample-p (sample)
"Validate bounded fingerprint-only measured context evidence loaded from storage."
(and (proper-list-p sample)
(evenp (length sample))
(= 18 (length sample))
(loop for tail on sample by (partial #'nthcdr 2)
always (keywordp (first tail)))
(case (getf sample :format)
(1
(member (length sample) '(16 18)))
(2
(and (= 26 (length sample))
(every (lambda (key) (get-properties sample (list key)))
'(:format :soft-header :policy :prompt :tool-header
:history-count :history-digest :wire-fields :encoder-fields
:wire-count :wire-digest :tokens :temporary-characters))
(every #'conversation--context-fingerprint-p
(list (getf sample :policy) (getf sample :prompt)
(getf sample :tool-header))))))
(typep (getf sample :temporary-characters 0) '(integer 0))
(eql 3 (getf sample :format))
(typep (getf sample :tokens) '(integer 1))
(typep (getf sample :history-count) '(integer 0))
(typep (getf sample :wire-count) '(integer 0))
(typep (getf sample :wire-characters) '(integer 0))
(typep (getf sample :ephemera-characters) '(integer 0))
(every #'conversation--context-fingerprint-p
(list (getf sample :soft-header) (getf sample :history-digest)
(getf sample :wire-digest)))
(every (lambda (fields)
(and (proper-list-p fields)
(every (lambda (field)
(and (consp field) (stringp (first field))
(conversation--context-fingerprint-p (rest field))))
fields)))
(if (= 2 (getf sample :format))
(list (getf sample :wire-fields) (getf sample :encoder-fields))
(list (getf sample :wire-fields))))
(list (getf sample :policy) (getf sample :history-digest)))
(proper-list-p (getf sample :chargeables))
(every (lambda (component)
(and (consp component) (keywordp (first component))
(conversation--context-fingerprint-p (rest component))))
(getf sample :chargeables))
(proper-list-p (getf sample :wire-fields))
(every (lambda (field)
(and (consp field) (stringp (first field))
(conversation--context-fingerprint-p (rest field))))
(getf sample :wire-fields))
t))

(defmethod conversation--project-record
((kind (eql :context-usage)) conversation properties)
"Restore portable evidence without treating its historical token count as verified."
(let ((sample (getf properties :sample)))
(setf (conversation-context-usage-sample conversation)
(when (conversation-context-usage-sample-p sample) sample))))
(when (conversation-context-usage-sample-p sample) sample)
(conversation-context-usage-baseline conversation)
(conversation--context-usage-baseline sample))))

(-> conversation--context-usage-baseline (t) (option list))
(defun conversation--context-usage-baseline (sample)
"Return the recorded total, history length and tokenizer identity of SAMPLE.

Evidence of an older shape no longer prices components, but the total it measured
still bounds the estimate a cold conversation would otherwise compute from the
stored characters of every retained item. The policy fingerprint keeps that
total from being reused under a different tokenizer."
(when (and (proper-list-p sample) (evenp (length sample)))
(let ((tokens (getf sample :tokens))
(count (getf sample :history-count))
(policy (getf sample :policy)))
(when (and (typep tokens '(integer 1)) (typep count '(integer 0))
(conversation--context-fingerprint-p policy))
(list :tokens tokens :history-count count :policy policy)))))

(defmethod conversation--project-record
((kind (eql :message)) conversation properties)
Expand Down
Loading
Loading