Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4e1d15f
feat(api): wire cancellation and timeouts through the OpenAI provider…
easonLiangWorldedtech Nov 19, 2026
99decd4
fix(api): keep both abort contracts in the openai merge resolution
easonLiangWorldedtech Nov 23, 2026
9552368
test(api): pin the cause chain on completePrompt's abort re-wrap
easonLiangWorldedtech Nov 23, 2026
bec0067
docs(api): name the abort guard by what the routes do with the signal
easonLiangWorldedtech Nov 23, 2026
0c85ad7
fix(api): publish a recorded usage chunk before the abort verdict in …
easonLiangWorldedtech Nov 23, 2026
27e3e8e
fix(integrations): count sign-outs so the kimi refresh fence cannot o…
easonLiangWorldedtech Nov 23, 2026
87cf26e
docs(api): name the row that keeps a caller cancellation an abort
easonLiangWorldedtech Nov 23, 2026
8fd7f3b
test(api): pin the abort contract for a caller that stops after a rea…
easonLiangWorldedtech Nov 23, 2026
24f4b49
fix(api): answer the 2026-11-29 review rows on the abort paths
easonLiangWorldedtech Dec 1, 2026
d53d7eb
fix(integrations): key the kimi refresh commit marker to its own refresh
easonLiangWorldedtech Dec 1, 2026
9e4a493
fix(integrations): queue the shared refresh abort so a settled POST c…
easonLiangWorldedtech Dec 1, 2026
e08c03b
fix(integrations): recheck the waiter set inside the queued refresh a…
easonLiangWorldedtech Dec 1, 2026
66e0e5b
test(integrations): share one rotation response fixture in the kimi o…
easonLiangWorldedtech Dec 1, 2026
b0bdbb9
fix(integrations): keep the refresh commit marker under the mutation …
easonLiangWorldedtech Dec 1, 2026
9f63250
fix(integrations): simplify the signal-less waiter cleanup so the gat…
easonLiangWorldedtech Dec 1, 2026
9109771
fix(integrations): keep the rotated pair when a caller stops during t…
easonLiangWorldedtech Dec 1, 2026
75f3eb4
refactor(integrations): read every answered kimi body under the reque…
easonLiangWorldedtech Dec 1, 2026
3a0c160
refactor(integrations): detach the caller inside postForm once the se…
easonLiangWorldedtech Dec 1, 2026
cd6c8b4
fix(integrations): serialize the kimi credential writes on one chain
easonLiangWorldedtech Dec 1, 2026
bb99287
refactor(integrations): trim the kimi write chain to fit the mutation…
easonLiangWorldedtech Dec 1, 2026
ffaea4c
refactor(integrations): compact the kimi write chain to the mutation …
easonLiangWorldedtech Dec 1, 2026
90a7c84
fix(integrations): never abort the kimi token POST once the caller ha…
easonLiangWorldedtech Dec 1, 2026
266fa34
docs(tla): model the shared kimi oauth refresh
easonLiangWorldedtech Dec 1, 2026
49f57b0
fix(integrations): order the kimi verdict clear on the write chain an…
easonLiangWorldedtech Dec 2, 2026
eb34dcd
fix(api): keep usage, HTTP status and deadlines on the abort paths
easonLiangWorldedtech Dec 2, 2026
a440365
test(integrations): pin the queued ordering and model a second waiter
easonLiangWorldedtech Dec 2, 2026
06a9d28
fix(api): settle the retry waits, keep the deadlines armed and type t…
easonLiangWorldedtech Dec 2, 2026
822ed3e
test(api): cancel after the answer wins the request race
easonLiangWorldedtech Dec 2, 2026
c4ea3f3
Merge branch 'main' into feat/abort-r2-openai-family
easonLiangWorldedtech Dec 2, 2026
321d57f
fix(integrations): a canceled kimi store failure installs nothing [cr…
easonLiangWorldedtech Dec 2, 2026
8a7a4aa
fix(integrations): correct the kimi shared-POST abort comment [cr 477…
easonLiangWorldedtech Dec 2, 2026
d6cce79
fix(api): detach the caller's abort listener per request [cr 4773886021]
easonLiangWorldedtech Dec 3, 2026
db8cfc4
fix(api): carry the abort reason as the cause on fast-fail guards
easonLiangWorldedtech Dec 3, 2026
2078551
fix(integrations): describe the kimi POST contract at the headers, no…
easonLiangWorldedtech Dec 3, 2026
a14e3b0
fix(tests): make the kimi rollback row answer its reads from storage
easonLiangWorldedtech Dec 3, 2026
c11a4bd
fix(tests): run the kimi sign-out row through the host's secret queue
easonLiangWorldedtech Dec 3, 2026
203eb88
fix(tests): check caller cancellation on the first kimi completion at…
easonLiangWorldedtech Dec 3, 2026
e0f7a5b
fix(integrations): surface the kimi oauth deadline as its own error
easonLiangWorldedtech Dec 3, 2026
c2f7737
fix(api): give each completePrompt request its own abort signal
easonLiangWorldedtech Dec 3, 2026
f1744b2
merge: main into the abort-plumbing chain for the glm-5.4 thinking pr…
easonLiangWorldedtech Dec 3, 2026
dc50f70
docs(tla): model the abort bridge a completePrompt request keeps
easonLiangWorldedtech Dec 3, 2026
6ef3300
test(api): teach the glm-5.4 thinking row the family's two-argument call
easonLiangWorldedtech Dec 3, 2026
cff2d56
test(api): make the late glm-5.3 answer win the abort race
easonLiangWorldedtech Dec 3, 2026
756860e
test(integrations): read the kimi rollback from real storage
easonLiangWorldedtech Dec 3, 2026
10708f7
fix(api): give each chat completions request its own abort signal
easonLiangWorldedtech Dec 3, 2026
f7f0393
docs(tla): model a newer credential install in the kimi refresh
easonLiangWorldedtech Dec 3, 2026
201178a
docs(tla): split the kimi refresh pair into memory and storage
easonLiangWorldedtech Dec 3, 2026
5501ecb
fix(integrations): capture the kimi refresh generation with its pair
easonLiangWorldedtech Dec 3, 2026
39d64a9
fix(api): read the stream usage record before the abort guard
easonLiangWorldedtech Dec 3, 2026
538a0bb
test(api): make the three cancellation rows fail for the right reasons
easonLiangWorldedtech Dec 3, 2026
d032600
fix(api): reject a Responses completion the caller stopped before rea…
easonLiangWorldedtech Dec 3, 2026
28847bf
docs(api): repoint the cross-file comment anchors that drifted
easonLiangWorldedtech Dec 4, 2026
8916d43
refactor(api): drop the baseURL field that no provider reads
easonLiangWorldedtech Dec 4, 2026
26f625a
refactor(api): share the abort and request-config helpers
easonLiangWorldedtech Dec 4, 2026
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions docs/architecture/tla/KimiCredentialCapture.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 142 additions & 0 deletions docs/architecture/tla/KimiCredentialCapture.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---- MODULE KimiCredentialCapture ----
EXTENDS Naturals
\* Models when a forced token refresh reads the credential pair and when it reads the
\* generation that owns it, in src/integrations/kimi-code/oauth.ts (getAccessToken reads the
\* pair across loadCredentials' await; startRefresh owns persisted state through
\* generation === credentialsGeneration). The pair and the storage answer of a settled refresh
\* are modelled in KimiOAuthRefresh.tla; this spec is only about the capture order.
\* Failure: a device sign-in installs pair B between the two reads. The refresh then posts the
\* pair A it snapshotted while holding B's generation, so every ownership check below reads as
\* current: its invalid_grant verdict deletes B, or its accepted rotation A2 replaces B.
\* Invariant: Safe - once the sign-in installed and the refresh settled, B is what remains.
\* Expected before any run: with the generation captured with the pair, Safe holds even though
\* the interleaving is reachable; with the generation captured after the pair read it must fail,
\* and it must also fail when either the clear or the store stops checking the generation.
\* Actual findings after the run: the plain config holds, 18 states generated and 13 distinct,
\* depth 5. CaptureAfterPair.cfg violates Safe after 14 generated and 12 distinct along ReadPair,
\* InstallSignIn, CaptureGenerationLate, VerdictReject: the pair read, the sign-in installing
\* during it, then the generation read that the reviewed code does inside startRefresh, which
\* hands the older refresh B's generation and lets its rejection delete B. ClearNoGuard.cfg
\* violates Safe after 11 generated and 11 distinct along CaptureGeneration, ReadPair,
\* InstallSignIn, VerdictReject, and StoreNoGuard.cfg after 12 and 12 along CaptureGeneration,
\* ReadPair, InstallSignIn, VerdictAccept - the accepted rotation A2 landing on top of B. Two
\* scratch probes kept outside the repo show Safe is not being satisfied by an empty set: the
\* interleaving (step = post, snap = A, installed) is reachable in the plain shape after 7
\* generated and 7 distinct, and settled states with the install present are reachable after 11
\* and 11, so the invariant is checked where it can fail. Beyond TypeOK and Safe the plain run
\* found nothing new: a null result, and a null result is data.
\* What this model does not carry: the pair the endpoint issues. The fixed code can still drop a
\* rotation. The generation is captured before the await and the pair is read across it, so a
\* sign-in installing between the two leaves the refresh holding the current pair under the
\* older generation; its own save then refuses the rotation it earned and the caller is answered
\* with null although the newer pair is valid. A row in __tests__/oauth.spec.ts pins that, and so
\* does the review's own note about the forced caller. It is not an invariant here because the
\* plain shape would fail it, and this folder's gate requires every variant config to fail and
\* not to pass.
\* Checker status: TLA_JAR=<jar> ./check.sh KimiCredentialCapture, run from this folder through WSL
\* bash, exits 0: ok KimiCredentialCapture.cfg (pass, 13 distinct states found), ok
\* KimiCredentialCapture.CaptureAfterPair.cfg (fail, 12), ok KimiCredentialCapture.ClearNoGuard.cfg
\* (fail, 11), ok KimiCredentialCapture.StoreNoGuard.cfg (fail, 12). Each config matched its
\* expectation, so no WRONG line was printed. ./check.sh all was not run: this commit adds one
\* spec and does not touch the gate script.
\* Toolchain: this Windows install has no java; the runs went through WSL bash against tla2tools.jar
\* 2.19 of 08 August 2024, sha256 936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88,
\* kept outside the repo. Reproduce with TLA_JAR=<jar> ./check.sh KimiCredentialCapture in any
\* shell that has a JVM. No CI step runs it yet.
\* Cost: 7 actions, 3 constants, 7 variables, 4 committed configs and 2 scratch probes. Each run
\* above finished in well under two seconds, with java start-up most of that wall clock. Agent
\* time, as a wall-clock estimate: about twenty minutes - reading getAccessToken and startRefresh
\* first, then the model, then the four configs. The first candidate failed TLC's completeness
\* check because InstallSignIn left done unassigned; that is recorded, not quietly fixed.
\* Review counts for this spec: 0 covered, 1 added, 0 gap. The added row is PR 1311 thread
\* 4789519822: this spec did not exist before the review, so nothing in it could have caught the
\* finding. Stance caveat, stated plainly: the ratchet follows the review instead of preceding
\* it, so it counts as added and not covered.
\* Replay on the code, measured rather than asserted: vitest 4.1.12 with
\* --config vitest.misc.config.ts on integrations/kimi-code/__tests__/oauth.spec.ts collects 57
\* and fails 0 on the fixed code. Passing the current generation at the call site instead of the
\* captured one - which is the reviewed shape - fails exactly the 3 rows this unit adds and no
\* other row. Dropping the clear's re-check fails this finding's row plus 2 rows that already
\* pinned that check; dropping the generation half of the ownership closure fails this finding's
\* 2 rows plus 4 existing rows. All three mutants were reverted byte-identically.
\*
\* Constants - each config assigns all three, so no config can pass because a constant defaulted.
CONSTANT GenerationCapturedWithSnapshot \* TRUE: the generation is read with the pair
CONSTANT ClearChecksGeneration \* TRUE: the invalid_grant clear re-checks it inside the queued write
CONSTANT StoreChecksGeneration \* TRUE: the save refuses a pair whose generation moved on

VARIABLE pair \* "A": the cached pair, "B": the pair the sign-in installed, "A2": the rotation
\* the endpoint issued for A, "none": nothing stored
VARIABLE gen \* credentialsGeneration, 0 before the install and 1 after
VARIABLE snap \* the pair this refresh read and will post: "A" or "B"
VARIABLE capGen \* the generation this refresh recorded as its own
VARIABLE step \* "pre": neither read done, "gen": generation read, "pair": pair read,
\* "post": both read, so the POST is in flight
VARIABLE installed \* TRUE once the sign-in's install step has run
VARIABLE done \* TRUE once the refresh settled

vars == <<pair, gen, snap, capGen, step, installed, done>>

TypeOK == /\ pair \in {"A", "A2", "B", "none"}
/\ gen \in 0..1
/\ snap \in {"A", "B"}
/\ capGen \in 0..1
/\ step \in {"pre", "gen", "pair", "post"}
/\ installed \in BOOLEAN
/\ done \in BOOLEAN

Init == /\ pair = "A" /\ gen = 0 /\ snap = "A" /\ capGen = 0
/\ step = "pre" /\ installed = FALSE /\ done = FALSE

\* The generation is read first, before the await, and the pair read is what follows across it.
CaptureGeneration == GenerationCapturedWithSnapshot /\ step = "pre" /\ ~done
/\ capGen' = gen /\ step' = "gen"
/\ UNCHANGED <<pair, gen, snap, installed, done>>

\* The pair read itself. It is the read that can span an install.
ReadPair == /\ step \in (IF GenerationCapturedWithSnapshot THEN {"gen"} ELSE {"pre"})
/\ ~done
/\ snap' = pair
/\ step' = (IF GenerationCapturedWithSnapshot THEN "post" ELSE "pair")
/\ UNCHANGED <<pair, gen, capGen, installed, done>>

\* The reviewed shape: the generation is read afterwards, inside startRefresh.
CaptureGenerationLate == ~GenerationCapturedWithSnapshot /\ step = "pair" /\ ~done
/\ capGen' = gen /\ step' = "post"
/\ UNCHANGED <<pair, gen, snap, installed, done>>

\* The sign-in's store resolves and its install step runs: a new pair under a new generation.
InstallSignIn == pair = "A" /\ ~installed /\ ~done
/\ pair' = "B" /\ gen' = gen + 1 /\ installed' = TRUE
/\ UNCHANGED <<snap, capGen, step, done>>

\* The endpoint rejects the pair this refresh posted. The clear that verdict triggers runs on the
\* credential chain and re-checks the generation inside it; only a config may drop that check.
\* A superseded pair is the only pair this endpoint answers with invalid_grant here: the model
\* does not spend states on the current pair dying of old age, which KimiOAuthRefresh covers.
VerdictReject == /\ step = "post" /\ snap # pair /\ ~done
/\ done' = TRUE
/\ pair' = IF (IF ClearChecksGeneration THEN capGen = gen ELSE TRUE)
THEN "none" ELSE pair
/\ UNCHANGED <<gen, snap, capGen, step, installed>>

\* The endpoint accepts it and rotates it. The save owns its write only while the generation it
\* captured is still current. A rotation of B is not modelled: accepting the current pair leaves
\* the pair it came from, which is all this spec needs to talk about.
VerdictAccept == /\ step = "post" /\ ~done
/\ done' = TRUE
/\ pair' = IF (IF StoreChecksGeneration THEN capGen = gen ELSE TRUE) /\ snap = "A"
THEN "A2" ELSE pair
/\ UNCHANGED <<gen, snap, capGen, step, installed>>

Done == done /\ UNCHANGED vars

Next == CaptureGeneration \/ ReadPair \/ CaptureGenerationLate \/ InstallSignIn
\/ VerdictReject \/ VerdictAccept \/ Done

Spec == Init /\ [][Next]_vars

\* Once the sign-in installed and the refresh settled, its pair is what the manager holds.
Safe == done /\ installed => pair = "B"

====

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/KimiOAuthRefresh.PersistFirst.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/KimiOAuthRefresh.ReadBack.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/KimiOAuthRefresh.StaleWrite.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/KimiOAuthRefresh.Variant.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/KimiOAuthRefresh.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading