Imported from GitHub aien-dev/aienos.com#136 (code only)
GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).
Base 763a8ac1334926338ab3560d8a925a7a51f56288 · Head a22ddb4744ae8c407c4ac972588235f1b4fda21f
drakestapleton reviewed (COMMENTED) on 2026-10-30 11:54 UTC
Triage: blocked (merge conflicts, outdated draft note). The content is sound. Security review at 19fc357 (read-only).
Verified
The 128-bit conversation id is right. The page makes 16 random bytes (allen.js:1267), and the gateway, spool and console accept exactly 32 hex (allen_chat.py:106, 2460, 2499; allen_spool.py:157).
The opt-in __Host-allen_console cookie is correct: Secure, Path=/, no Domain, the plain name refused, and logout clears it under the same name.
Neither change touches rate limiting, CSRF, the pinned Host header or CORS. There are no secrets in the diff.
Before merge
GitHub reports merge conflicts with main (dirty). Please rebase.
The body still says "Draft… Stacked on feat/allen-chat", but the base is main. Please update it.
The X-Forwarded-For clearing on the presence and status routes is already on main (nginx-allen-location.conf:228, :264), and no nginx file changes here. This PR adds the edge test that checks it, so please reword the title and body.
CI doesn't run test_gateway.py or test_relay_mailer.py, so the pass counts in the body are local only.
The cutover is hard: an old page gets 400 on handoff, say and session. Deploy the page and gateway together, and drain relay-drop/ first.
With the flag off, the cookie still has no Secure flag. That's the documented, accepted F6 risk.
Nit: test_gateway.py:552 is an extra blank line.
— Grokbot
cursor[bot] reviewed (COMMENTED) on 2026-11-02 00:42 UTC
Risk: high. Left a non-blocking comment: Cursor Security Agent completed with no findings and Bugbot was not running, but gateway session-id and console-cookie changes sit above the medium approval threshold. Human review is needed; assigned drakestapleton.
<sub>Sent by Cursor Approval Agent: Pull Request Router and Approver</sub>
cursor[bot] reviewed (COMMENTED) on 2026-11-02 03:50 UTC
Risk: high. Left a non-blocking comment: Cursor Security Agent completed with no findings and Bugbot was not running, but gateway session-id and console-cookie changes remain above the medium approval threshold. Human review is needed; assigned drakestapleton.
diff --git a/.crumb b/.crumb
index 0098196..9150e63 100644
--- a/.crumb
+++ b/.crumb
@@ -18,74 +18,74 @@
"children": [
{
"digest": "425d6b3c9b71af6908205d51e3cb5c889a32d0750621cae94a46aa36766fb504",
- "last_commit": "fbf91fc8",
+ "last_commit": "1c0196f",
"name": ".github",
"purpose": "GitHub automation configuration"
},
{
- "digest": "19f91c9fa3f95cfdb30bc1c67dcbc477a3ea0fec3cea19f9588bce87ae5c2a7b",
- "last_commit": "ea5ca232",
+ "digest": "b88563b62f53c074a6921549a6e08c41150f865529223e6afd26ac621e9772e6",
+ "last_commit": "d072007",
"name": "crates",
"purpose": "Native Rust website crates"
},
{
"digest": "bb5b1f96cff14056a492f498929d784e8648a655c985da0d1ae96c580b47a2f0",
- "last_commit": "0a2c6e43",
+ "last_commit": "0a2c6e4",
"name": "om/agora/tls",
"purpose": "Verbatim pinned Omega TLS 1.3 client units for verified Agora peer pulls"
},
{
"digest": "b2255e3fb36241b5fe4a87f595ab384f559aaf4b6d04a62831ccfc3a7b9444da",
- "last_commit": "22e46dbe",
+ "last_commit": "22e46db",
"name": "om/allen-scene",
"purpose": "Native Allen scene reuse, Omega browser controller and independent frame oracle"
},
{
"digest": "7e8d6412f116296354d537f1cf123c33f266e3ef74546b5862a579c077429176",
- "last_commit": "0804a190",
+ "last_commit": "0804a19",
"name": "om/alpha-page",
"purpose": "Seeded Omega alpha landing page and client, with pinned wizard source and real terminal capture"
},
{
"digest": "c4e1b4fdfa83e5b9685aab9883ee681e3f5c1042baf104601afd85712e17b45c",
- "last_commit": "a9c5dbbc",
+ "last_commit": "a9c5dbb",
"name": "om/hive-render",
"purpose": "Seeded Omega edge rendering of validated canonical Hive JSON with fail-closed escaping and deter"
},
{
"digest": "679153341779296d8c4d44f67d95e31e66dcb182a966817e280a37eec60cc743",
- "last_commit": "21c485cd",
+ "last_commit": "21c485c",
"name": "om/omega-reference",
"purpose": "Seeded Omega generator of /omega/reference/ from a pinned, hash-recorded omega-harness vendor tr"
},
{
"digest": "f3688673f9ce0597ad2cb249368c873301045a4b5f7677af596593b6a24639c4",
- "last_commit": "5aace54d",
+ "last_commit": "5aace54",
"name": "om/support-page",
"purpose": "Seeded Omega support page, shared invitation and CSS with deterministic artifact checks"
},
{
- "digest": "10705ff52040f8b8ef815eca218622e6534684e2ef957e8664db54c902c494c4",
- "last_commit": "fbf91fc8",
+ "digest": "171af88503ff05ecc106be79f244722ff63952d21ff3afa4e344d806531b77cf",
+ "last_commit": "38e561c",
"name": "public",
"purpose": "Static public website assets"
},
{
"digest": "b77336127516b827d0e7a19a214d6bd15665865f7fd2f2d4eb323c6eca9c3893",
- "last_commit": "11313098",
+ "last_commit": "1131309",
"name": "scripts/allen/science",
"purpose": "Isolated compute-only Allen tools and versioned glass-pane protocol; temporary host transport ar"
}
],
- "children_root": "sha256:7efe12e3a3ee1f4b3be74ff1764280dd0d39fa64d6ef5c319cd1ba8dd80ff3dd",
- "compiled_at": "2026-10-31T12:08:33Z",
+ "children_root": "sha256:7205379f4ac06cd14fc3c31316540862a9b1005fb7d82f0620312ab9a9d6cf14",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:f27a05631c2ac5088791453e9e5bc08d2b6cd860264fa612cf7af84bdce38ea4",
+ "digest": "sha256:4b881848f1752245f068b5155ca994cd7e69b18d35c4e84e7d3ca085f901a246",
"evidence_files": 6,
"evidence_root": "sha256:7fde48972a09dd4b0f7206aca4e313cd02c8cd195ec602e3924e59246c016aa5",
"files": 1396,
- "generated_at_commit": "ea5ca2325b383901eb5e72e5a3c969bace290192",
- "source_tree": "sha256:8394d104fb64900f51073195c21b798acb55933cec4f67a59e45d9556f1937bb"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:0362d27526e7b9d726a81423c9e620feae41325f9c4d4f65947c5fc66c6cd5ea"
},
"progress": {
"initial_edits": "Dashboard draft predates explicit Crumb reminder; subsequent integration is claimed and recorded.",
diff --git a/crates/.crumb b/crates/.crumb
index 7aa0112..479f878 100644
--- a/crates/.crumb
+++ b/crates/.crumb
@@ -7,21 +7,21 @@
"generated": {
"children": [
{
- "digest": "10bf72ea8da6cfd17648f2788b7b5b75c915e14eb05bf8a51c4b858aaba55330",
- "last_commit": "ea5ca232",
+ "digest": "23b2f253ba0de2ff6cdc4dd30ee4047fec923fdc4172d1ec82d0b9faee6e53cb",
+ "last_commit": "d072007",
"name": "site-builder",
"purpose": "Rust static site generator"
}
],
- "children_root": "sha256:a0af12f284b9a4b74b6f934ac3db448400c7d38297f0f125fe8f031c983fe1d5",
- "compiled_at": "2026-10-31T12:08:33Z",
+ "children_root": "sha256:b6c321df9227276e2819b55cb37fa7b39c8be3326a58cbd66a49caae18574582",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:19f91c9fa3f95cfdb30bc1c67dcbc477a3ea0fec3cea19f9588bce87ae5c2a7b",
+ "digest": "sha256:b88563b62f53c074a6921549a6e08c41150f865529223e6afd26ac621e9772e6",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 73,
- "generated_at_commit": "ea5ca2325b383901eb5e72e5a3c969bace290192",
- "source_tree": "sha256:4335bc51771976a8bfe357195626740f186c22cb4eb137c3295c6c8dd43bee27"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:d5f10932199b959f416d338e70f78606d56d5c0b9bba76f04f8da1bc477c4429"
}
},
"invariants": [
diff --git a/crates/site-builder/.crumb b/crates/site-builder/.crumb
index 257a4cd..3443f9b 100644
--- a/crates/site-builder/.crumb
+++ b/crates/site-builder/.crumb
@@ -7,27 +7,27 @@
"generated": {
"children": [
{
- "digest": "c80aff9769e55302d5a19c54163858aa4c48b089767fc2f4f594b04166096da5",
- "last_commit": "784bc2e8",
+ "digest": "8bad7d55fdfda3b948b2b41a26c072ddabb4b96a261130e9c72e0cae83620a4d",
+ "last_commit": "d072007",
"name": "src",
"purpose": "Page assembly and site build verification"
},
{
"digest": "eae921a534bcf1dbeace156d677090e93082a521bf5ca66d8810597854066072",
- "last_commit": "abb54298",
+ "last_commit": "abb5429",
"name": "templates",
"purpose": "Reviewed HTML templates for source-backed pages"
}
],
- "children_root": "sha256:335bb4044b6b92b5a1a6e6c7fd7119e5991b7569ec56d61a3626d5ae397da3a3",
- "compiled_at": "2026-10-31T12:08:33Z",
+ "children_root": "sha256:f9ebbb1f16c82147cc5ae83c340996129f91a5ecccef8ec3aaf356fc136fc8e3",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:10bf72ea8da6cfd17648f2788b7b5b75c915e14eb05bf8a51c4b858aaba55330",
+ "digest": "sha256:23b2f253ba0de2ff6cdc4dd30ee4047fec923fdc4172d1ec82d0b9faee6e53cb",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 64,
- "generated_at_commit": "ea5ca2325b383901eb5e72e5a3c969bace290192",
- "source_tree": "sha256:6f44936a44b82686968e149f3a3a1a0a185c9a548bf47a3c99539229add17957"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:aed636d4805061bfd08eae4aee780f2f2bb36e082ac9b322830a6db262b99e9b"
}
},
"invariants": [
diff --git a/crates/site-builder/src/.crumb b/crates/site-builder/src/.crumb
index 9397165..77ba29b 100644
--- a/crates/site-builder/src/.crumb
+++ b/crates/site-builder/src/.crumb
@@ -10,21 +10,21 @@
"generated": {
"children": [
{
- "digest": "64e5fffe7d9b871d0ed3c58ced2dc11beb0dc422c77f035a5b824a7ec9d50e01",
- "last_commit": "f63d96e5",
+ "digest": "e49ec45ee1c2a7faf013ff7b86b9bd9dcd7d5ad02cebe9c58ee36c302503a632",
+ "last_commit": "d072007",
"name": "components",
"purpose": "Reusable page content and navigation"
}
],
- "children_root": "sha256:0bafa758b82b06eb4c5d1f7d35bdef95dbc61691789f69ea87811f0a2ae7a88d",
- "compiled_at": "2026-10-31T11:58:01Z",
+ "children_root": "sha256:8e5b5a2c6a12571115ffbc095c573894210a78d7d6b8614c00b78e543a258072",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:c80aff9769e55302d5a19c54163858aa4c48b089767fc2f4f594b04166096da5",
+ "digest": "sha256:8bad7d55fdfda3b948b2b41a26c072ddabb4b96a261130e9c72e0cae83620a4d",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 56,
- "generated_at_commit": "f63d96e593b2864e61a0148cadd521090e0e1d17",
- "source_tree": "sha256:1907abcf6ab2492c3869621da92faa2412c943ea47dde4c74f16bd8de686f688"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:d96a596d8cab527e5c661ae42b662dbe680c04bcecca98c9d6143ad274ee2ded"
}
},
"invariants": [
diff --git a/crates/site-builder/src/components/.crumb b/crates/site-builder/src/components/.crumb
index 93affd9..42d86ef 100644
--- a/crates/site-builder/src/components/.crumb
+++ b/crates/site-builder/src/components/.crumb
@@ -10,14 +10,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-10-31T11:58:01Z",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:64e5fffe7d9b871d0ed3c58ced2dc11beb0dc422c77f035a5b824a7ec9d50e01",
+ "digest": "sha256:e49ec45ee1c2a7faf013ff7b86b9bd9dcd7d5ad02cebe9c58ee36c302503a632",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 49,
- "generated_at_commit": "f63d96e593b2864e61a0148cadd521090e0e1d17",
- "source_tree": "sha256:eadf43ee71387614ee53953633a58c69a38122b91f00aa235eeb787b16ebc088"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:41839681512d481e268e290b466e108bb0b9212e93ec4e8791734dc1574b71b4"
}
},
"invariants": [
diff --git a/crates/site-builder/src/components/allen.rs b/crates/site-builder/src/components/allen.rs
index e8b10be..5be89f7 100644
--- a/crates/site-builder/src/components/allen.rs
+++ b/crates/site-builder/src/components/allen.rs
@@ -41,7 +41,7 @@ pub const LLMS: &str = r#"## Talk to Aien
- [Introduction fields](https://www.aienos.com/aien/): `kind` is `human` or `agent`. `human` is the person or organization operating an agent (name, contact or organization; optional). Limits in characters: name 100, org 100, contact 200, github 39, origin 200, purpose 1000, homepage 200 (an https URL or empty), framework 100, model 100, human 200. Give at least a name or a contact.
- [Consent](https://www.aienos.com/privacy/): `consent` must be the JSON value `true`. Without it nothing is stored and the reply is 400 `{"error":"consent_required"}`. What is kept: these fields and the time, privately on my own computer, so I may follow up. Never published or sold. Kept until you delete it.
- [Delete an introduction: POST /aien/api/forget](https://www.aienos.com/aien/api/forget): a saved introduction replies `{"id":"c_...","delete":"https://www.aienos.com/aien/#forget=<id>.<token>","stored":true,"key":"<32 hex>"}`. Keep the delete link. To delete, open it, or `POST https://www.aienos.com/aien/api/forget` with `{"id":"c_...","token":"..."}` taken from it, or write to aien@aienos.com.
-- [Your Aien key](https://www.aienos.com/aien/): the `key` in that reply is a random 32 hex key. Send it as the `X-Allen-Key` header on later calls, and on chat also `X-Allen-Conversation` (16 hex, new per conversation), and Aien recognizes you: with consent it keeps short notes about you (who you are, what you build, open asks) in a private store on my own computer, keyed to that key. Recognition is by key only, never by a name or email; anyone without the key is a stranger to Aien.
+- [Your Aien key](https://www.aienos.com/aien/): the `key` in that reply is a random 32 hex key. Send it as the `X-Allen-Key` header on later calls, and on chat also `X-Allen-Conversation` (32 hex, random, new per conversation), and Aien recognizes you: with consent it keeps short notes about you (who you are, what you build, open asks) in a private store on my own computer, keyed to that key. Recognition is by key only, never by a name or email; anyone without the key is a stranger to Aien.
- [Forget me: POST /aien/api/forget-me](https://www.aienos.com/aien/api/forget-me): with the `X-Allen-Key` header, deletes Aien's notes about you and your introduction.
- [Issues and projects](https://github.com/aien-dev/omega-projects): they reach GitHub only after a visitor confirms the exact text on the page, with email addresses and phone numbers removed first.
@@ -182,6 +182,20 @@ mod tests {
}
}
+ #[test]
+ fn the_conversation_id_is_128_random_bits() {
+ // The conversation id is the live-session bearer (handoff, say, session):
+ // 16 bytes from crypto.getRandomValues, 32 hex. The gateway also accepts
+ // a 16-hex id from a tab opened before this page, so the page can ship
+ // after the gateway without a simultaneous cut.
+ let script = include_str!("../../../../public/js/allen.js");
+ let make = function_body(script, "conversationId");
+ assert!(make.contains("const bytes = new Uint8Array(16);"), "the conversation id must carry 128 bits");
+ assert!(make.contains("crypto.getRandomValues(bytes);"));
+ assert!(make.contains("b.toString(16).padStart(2, '0')"));
+ assert_eq!(script.matches("function conversationId()").count(), 1);
+ }
+
#[test]
fn a_draft_link_fills_the_input_and_sends_nothing() {
// /aien/#draft=<text> only fills the input: no request, no send, the
diff --git a/om/allen-page/allen-js.om b/om/allen-page/allen-js.om
index 7ac8194..234d9c0 100644
--- a/om/allen-page/allen-js.om
+++ b/om/allen-page/allen-js.om
@@ -84,7 +84,7 @@ note JavaScript forgetOffer
text js26 " /* A delete link opens this page at #forget=<id>.<token>; nothing is sent\n until the visitor confirms, and the token leaves the address afterwards. */\n function forgetOffer() {\n const match = /^#forget=(c_[0-9a-f]{16})\\.([A-Za-z0-9_-]{20,64})$/.exec(location.hash);\n if (!match) return;\n const id = match[1];\n const token = match[2];\n const note = message('allen', 'Aien');\n note.body.append(el('p', 'allen-p', `You opened the delete link for introduction ${id}. Delete it?`));\n const row = el('div', 'allen-choices');\n const state = el('div', 'allen-card-state');\n const remove = button('Delete my introduction', async () => {\n remove.disabled = true;\n decline.disabled = true;\n state.replaceChildren(el('p', 'allen-note', 'Sending.'));\n try {\n const response = await fetch(FORGET, post({ id, token }));\n const reply = await response.json().catch(() => null);\n if (response.ok && reply && reply.accepted === true) {\n row.remove();\n state.replaceChildren(el('p', 'allen-ok', \"Deletion requested. Drake's computer removes the introduction the next time it reads the queue; a link that matches nothing changes nothing.\"));\n try {\n history.replaceState(null, '', location.pathname + location.search);\n } catch (_) {\n location.hash = '';\n }\n return;\n }\n state.replaceChildren(el('p', 'allen-err', failure(response, reply, 'Nothing was deleted yet.')));\n } catch (_) {\n state.replaceChildren(el('p', 'allen-err', 'Could not reach Aien. Nothing was deleted yet.'));\n }\n remove.disabled = false;\n decline.disabled = false;\n });\n const decline = button('Keep it', () => {\n row.remove();\n state.replaceChildren(el('p', 'allen-note', 'Nothing changed.'));\n });\n row.append(remove, decline);\n note.body.append(row, state);\n }\n"
note JavaScript keys
-text js27 " /* The visitor key: 32 hex from the gateway, kept under KEY_NAME in local\n storage only after a consented introduction or when the visitor pastes\n their own key. Nothing else is ever stored in this browser. */\n function storedKey() {\n try {\n const value = localStorage.getItem(KEY_NAME);\n return value && KEY_PATTERN.test(value) ? value : '';\n } catch (_) {\n return '';\n }\n }\n function keepKey(value) {\n try {\n localStorage.setItem(KEY_NAME, value);\n return storedKey() === value;\n } catch (_) {\n return false;\n }\n }\n function dropKey() {\n try {\n localStorage.removeItem(KEY_NAME);\n } catch (_) {\n /* Nothing was stored. */\n }\n }\n function conversationId() {\n const bytes = new Uint8Array(8);\n crypto.getRandomValues(bytes);\n return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');\n }\n /* Anonymous is the default: a visitor is remembered only after Remember me,\n through the consent card. Anonymous calls say so and never carry a key. */\n let remembered = false;\n let oldKey = '';\n function keyHeaders(chat) {\n if (!remembered) return { 'X-Allen-Anonymous': '1' };\n const key = storedKey();\n if (!key) return { 'X-Allen-Anonymous': '1' };\n return chat ? { 'X-Allen-Key': key, 'X-Allen-Conversation': conversation } : { 'X-Allen-Key': key };\n }\n"
+text js27 " /* The visitor key: 32 hex from the gateway, kept under KEY_NAME in local\n storage only after a consented introduction or when the visitor pastes\n their own key. Nothing else is ever stored in this browser. */\n function storedKey() {\n try {\n const value = localStorage.getItem(KEY_NAME);\n return value && KEY_PATTERN.test(value) ? value : '';\n } catch (_) {\n return '';\n }\n }\n function keepKey(value) {\n try {\n localStorage.setItem(KEY_NAME, value);\n return storedKey() === value;\n } catch (_) {\n return false;\n }\n }\n function dropKey() {\n try {\n localStorage.removeItem(KEY_NAME);\n } catch (_) {\n /* Nothing was stored. */\n }\n }\n /* 128 random bits (32 hex): the conversation id is the live-session bearer. */\n function conversationId() {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');\n }\n /* Anonymous is the default: a visitor is remembered only after Remember me,\n through the consent card. Anonymous calls say so and never carry a key. */\n let remembered = false;\n let oldKey = '';\n function keyHeaders(chat) {\n if (!remembered) return { 'X-Allen-Anonymous': '1' };\n const key = storedKey();\n if (!key) return { 'X-Allen-Anonymous': '1' };\n return chat ? { 'X-Allen-Key': key, 'X-Allen-Conversation': conversation } : { 'X-Allen-Key': key };\n }\n"
note JavaScript keyPanel
text js28 " function keyPanel(said) {\n const body = byId('~40~');\n if (!body) return;\n const key = remembered ? storedKey() : '';\n const state = el('p', 'allen-card-state', said || '');\n const parts = [];\n if (key) {\n const line = el('p', 'allen-keyline');\n line.append(el('span', '', 'Your Aien key: '), el('code', '', key));\n const row = el('div', 'allen-choices');\n const copy = button('Copy', () => copyText(key, copy));\n const forget = button('Forget me', () => forgetMe(forget, state));\n row.append(copy, forget);\n parts.push(line, row, el('p', 'allen-note', \"Aien recognizes you only by this key, never by a name or email you give. Keep it private, and paste it into Remember me on another device to be recognized there. Forget me deletes Aien's notes about you and your introduction, then removes the key from this browser.\"));\n } else {\n parts.push(el('p', 'allen-note', \"Anonymous: this browser holds no Aien key, so Aien won't remember this chat. Remember me asks for your consent first.\"));\n if (oldKey) {\n const forget = button('Forget me', () => forgetOld(forget, state));\n parts.push(el('p', 'allen-note', 'Notes Aien kept about you before you went anonymous stay on Drake\\'s computer until you delete them.'), forget);\n }\n }\n parts.push(state);\n body.replaceChildren(...parts);\n const panel = byId('~39~');\n if (panel) panel.dataset.key = key ? 'yes' : 'no';\n }\n"
diff --git a/om/allen-page/allen.js.sha256 b/om/allen-page/allen.js.sha256
index 0538b40..b0ce160 100644
--- a/om/allen-page/allen.js.sha256
+++ b/om/allen-page/allen.js.sha256
@@ -1 +1 @@
-a1174e5ce918f49237eedaa5b581e1e0e31123a3f16607654687f54058d24af2 ../../public/js/allen.js
+ddee75d2f643d58456203c588dc366b239bc4ffcb650126810f81e6ef2a213f0 ../../public/js/allen.js
diff --git a/public/.crumb b/public/.crumb
index de35ca8..744a38f 100644
--- a/public/.crumb
+++ b/public/.crumb
@@ -14,56 +14,56 @@
},
{
"digest": "937ca48aa52a1bcdaea3533e8e508e7c154415294449fe8ff99c65be0eea2c1d",
- "last_commit": "0804a190",
+ "last_commit": "0804a19",
"name": "alpha",
"purpose": "Pinned alpha wizard source and unmodified terminal capture assets"
},
{
"digest": "de7ce2104d541caba722cdc4da9ec2fc6cc3bf6ce135e9ac17f879a43c0700ff",
- "last_commit": "a9c5dbbc",
+ "last_commit": "a9c5dbb",
"name": "assets",
"purpose": "Website styles including the project dashboard"
},
{
"digest": "fbddcd26c59b9bf8dc30cfc42ba010787d5c934670fbe030b21b7c3552a636bc",
- "last_commit": "37adb762",
+ "last_commit": "37adb76",
"name": "data",
"purpose": "Published generated project measurements with pinned sources"
},
{
- "digest": "f2e0189fd09e6dc97622ad8e2ac6586bc8e32ec2dae0efc8093ed440eb0bcebd",
- "last_commit": "85c98395",
+ "digest": "dfae7c40068fdee10069f99027008f43a1b7b29896418c571c6c1078f0a36e16",
+ "last_commit": "38e561c",
"name": "js",
"purpose": "Browser interactions using public data only"
},
{
"digest": "6ee328cab957d221721e988204b9ac7f6b4fdd2a9bfe3e474625ed4ce8fa898e",
- "last_commit": "8f550982",
+ "last_commit": "8f55098",
"name": "licensing",
"purpose": "Public static research or licensing pages using the shared website navigation"
},
{
"digest": "92ddc743ca7340b6a0f015a1ca78e1f6978e87f089182fe0bf1abc9e6b4fe48d",
- "last_commit": "85c98395",
+ "last_commit": "85c9839",
"name": "post-llm-case",
"purpose": "Public static research or licensing pages using the shared website navigation"
},
{
"digest": "c484d91bbd5afaa165842ea77dcdf4cb921fb70a31ce8f730448c1fa21b3c242",
- "last_commit": "e588e63b",
+ "last_commit": "e588e63",
"name": "research",
"purpose": "Public static research or licensing pages using the shared website navigation"
}
],
- "children_root": "sha256:4f53b204175e53c522e4d2b9eaa31ccf6366ef4162dc64a4cef83b5163406e29",
- "compiled_at": "2026-10-31T12:08:33Z",
+ "children_root": "sha256:1af3cee66584d55704d79147e0f07f65efaca9a14d30587992b92c20b5778bdd",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:10705ff52040f8b8ef815eca218622e6534684e2ef957e8664db54c902c494c4",
+ "digest": "sha256:171af88503ff05ecc106be79f244722ff63952d21ff3afa4e344d806531b77cf",
"evidence_files": 1,
"evidence_root": "sha256:63bece7cb299b29d19622dcb0de4cbaa623357b117d8c7643a562de286c4b2fb",
"files": 732,
- "generated_at_commit": "ea5ca2325b383901eb5e72e5a3c969bace290192",
- "source_tree": "sha256:bc1a92cb7c24181b0c49675f42b593aa601c5365fecaf10c0aea9b061555f41c"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:50e33e977bc8fe2b16ab0f8b2dbbe64adcbc2e6d003dfcb382092d9f9f20f989"
}
},
"invariants": [
diff --git a/public/js/.crumb b/public/js/.crumb
index ec96100..a6a2b06 100644
--- a/public/js/.crumb
+++ b/public/js/.crumb
@@ -7,14 +7,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-10-31T11:21:48Z",
+ "compiled_at": "2026-10-31T14:49:38Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:f2e0189fd09e6dc97622ad8e2ac6586bc8e32ec2dae0efc8093ed440eb0bcebd",
+ "digest": "sha256:dfae7c40068fdee10069f99027008f43a1b7b29896418c571c6c1078f0a36e16",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 22,
- "generated_at_commit": "5803c14c5ea12b429825f5e46603928377cd6165",
- "source_tree": "sha256:5c6c962dc91fb2a236530140d2f3ef3d368d455f6d4eaaff9e336066eb21d33b"
+ "generated_at_commit": "d0720071ca11669b64895021a31d1c56dfb74356",
+ "source_tree": "sha256:a38c070215719176fb239a10966f426a2d9ab9516b9fd1d03de6800b0d3d70e5"
}
},
"invariants": [
diff --git a/public/js/allen.js b/public/js/allen.js
index d5f424d..e67d4c1 100644
--- a/public/js/allen.js
+++ b/public/js/allen.js
@@ -1262,8 +1262,9 @@ ${script}
/* Nothing was stored. */
}
}
+ /* 128 random bits (32 hex): the conversation id is the live-session bearer. */
function conversationId() {
- const bytes = new Uint8Array(8);
+ const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
}
diff --git a/scripts/allen/README.md b/scripts/allen/README.md
index 3a7c2bd..35e7a49 100644
--- a/scripts/allen/README.md
+++ b/scripts/allen/README.md
@@ -244,17 +244,37 @@ same rules before proxying.
(SSE: `state`, `human`, heartbeat every 15 s), `POST say`. While I have
joined a conversation, `POST chat` answers `event: error {"code":"human"}`
without calling the model. `event: human` is written only by the console.
+ These routes are keyed by `X-Allen-Conversation`, the live-session bearer.
+ The page draws 32 hex (128 random bits) per conversation. The gateway, the
+ console session routes and the relay spool also accept a 16-hex id: a tab
+ left open across the page deploy keeps the id it minted, and a relay file
+ queued before the deploy still has one. Any other shape is refused with 400
+ (`chat` then runs without a conversation; the console route answers 404).
+ Deploy this gateway, `allen_spool.py` and the relay mailer before the page.
+ GitHub Pages publishes the page on merge, and the gateway they replace
+ accepts only 16 hex, so a 32-hex page against that gateway makes handoff,
+ say and session return 400. Once this gateway is running, merging the page
+ is safe and open tabs keep working. The 16-hex acceptance comes out on
+ 2026-12-02 (https://github.com/aien-dev/aienos.com/issues/196).
+ `STREAM_MAX_S` ends one session stream after an hour and the page
+ reconnects with the same id, so a tab left open still sends 16 hex until
+ the visitor reloads. After that date those tabs get 400 on handoff, say
+ and session until reload.
- The console is a second listener in the gateway on `100.64.0.2:18112`. The
hub never proxies it, and nft admits it only from 100.64.0.1 and 100.64.0.4
(plus the Spark itself over loopback). Login is with the token held in
atlas-vault as `ALLEN_CONSOLE_TOKEN`; the gateway holds only its sha256
(`ALLEN_CONSOLE_TOKEN_SHA256` in `/etc/allen-chat/env`). Sessions use an
HttpOnly SameSite=Strict cookie that lasts 12 h, with a CSRF token on every
- POST, no CORS and a pinned Host. The cookie has no `Secure` flag on purpose:
- the console is plain HTTP inside the tailnet (WireGuard-encrypted), where a
- Secure cookie would never come back; the nft rule above is the compensating
- control. Availability is kept in
- `/var/lib/allen-chat/console/presence.json`.
+ POST, no CORS and a pinned Host. By default the cookie (`allen_console`) has
+ no `Secure` flag on purpose: the console is plain HTTP inside the tailnet
+ (WireGuard-encrypted), where a Secure cookie would never come back; the nft
+ rule above is the compensating control. If the console is ever served over
+ TLS, start the gateway with `--console-secure-cookie`: the cookie becomes
+ `__Host-allen_console` with `Secure` (host-only, `Path=/`), and the plain
+ name is no longer accepted. Do not set it on the plain-HTTP console, or
+ login will loop, because the browser never returns the cookie. Availability
+ is kept in `/var/lib/allen-chat/console/presence.json`.
- Anonymous mode: `X-Allen-Anonymous: 1` means no recall and no notes, whatever
key is sent, and `introduce` answers 409 `anonymous`.
- `POST project-summary` {"summary" (at most 1000 bytes of text, no email,
@@ -510,7 +530,8 @@ routes in `allen_projects.py`:
python3 scripts/allen/test_sandbox.py # compile sandbox escape tests, each with a control
python3 scripts/allen/test_a2a.py # A2A SendMessage: consent, errors, nothing stored
python3 scripts/allen/test_gateway.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
- --system-prompt scripts/allen/system-prompt.txt [--skip-model]
+ --system-prompt scripts/allen/system-prompt.txt [--skip-model --upstream 127.0.0.1:<closed port>]
+ # cookie/edge suites: console cookie flags, nginx copies' guards; NGINX=/path/to/nginx adds nginx -t
python3 scripts/allen/probe.py # run inside the unit's properties (systemd-run) and outside
python3 scripts/allen/relay/test_relay_mailer.py # relay mailer against a loopback SMTP stub, each with a control
python3 scripts/allen/test_reaching_drake_prod.py # production: console reachability, one real TEST relay email, live takeover
diff --git a/scripts/allen/allen_chat.py b/scripts/allen/allen_chat.py
index 138f845..f164b7a 100755
--- a/scripts/allen/allen_chat.py
+++ b/scripts/allen/allen_chat.py
@@ -81,7 +81,8 @@ except ImportError:
allen_voice = None
KEY = re.compile(r"^[0-9a-f]{32}$")
-CONV = re.compile(r"^[0-9a-f]{16}$")
+CONV = allen_spool.CONV # 32 hex from the page, or 16 hex from a tab opened before it
+CONV_REQUIRED = "Send X-Allen-Conversation (16 or 32 hex)."
EXTRACT_SYSTEM = (
"You keep short private notes for Allen about one visitor of aienos.com/allen/. From the exchange "
"below, write at most 5 new or updated facts about the VISITOR only: who they are, human or agent, "
@@ -142,6 +143,7 @@ MAX_LIVE_CHARS = 120000
STREAM_MAX_S = 3600 # one session stream ends after an hour; the page reconnects
CONSOLE_TTL = 12 * 3600
CONSOLE_COOKIE = "allen_console"
+CONSOLE_COOKIE_SECURE = "__Host-allen_console" # --console-secure-cookie (console served over TLS)
MAX_FORM = 16 * 1024
# Short explanations of the pinned compiler's error codes (OMEGESE.md at
@@ -1496,7 +1498,7 @@ class Handler(BaseHTTPRequestHandler):
def conversation(self):
conv = self.headers.get("X-Allen-Conversation", "").strip()
- return conv if CONV.match(conv) else None
+ return conv if CONV.fullmatch(conv) else None
def chat(self):
app = self.app
@@ -1540,7 +1542,7 @@ class Handler(BaseHTTPRequestHandler):
queued_ms = int((time.monotonic() - t0) * 1000)
vid = app.vid(self)
conv = self.headers.get("X-Allen-Conversation", "").strip()
- notes = app.notes_for(vid, conv if CONV.match(conv) else "")
+ notes = app.notes_for(vid, conv if CONV.fullmatch(conv) else "")
self.sse("start", {"model": MODEL, "queued_ms": queued_ms, "remembered": bool(notes)})
self.sse("meta", {"source": source})
# Tools run only when --tools is set and the visitor did not send X-Allen-Tools: 0.
@@ -2216,7 +2218,7 @@ class Handler(BaseHTTPRequestHandler):
app.stats.add("handoff_requests")
conv = self.conversation()
if not conv:
- return self.refuse(400, "bad_request", "Send X-Allen-Conversation (16 hex).")
+ return self.refuse(400, "bad_request", CONV_REQUIRED)
req = self.read_json()
if req is None:
return
@@ -2246,7 +2248,7 @@ class Handler(BaseHTTPRequestHandler):
app = self.app
conv = self.conversation()
if not conv:
- return self.refuse(400, "bad_request", "Send X-Allen-Conversation (16 hex).")
+ return self.refuse(400, "bad_request", CONV_REQUIRED)
req = self.read_json()
if req is None:
return
@@ -2277,7 +2279,7 @@ class Handler(BaseHTTPRequestHandler):
app = self.app
conv = self.conversation()
if not conv:
- return self.refuse(400, "bad_request", "Send X-Allen-Conversation (16 hex).")
+ return self.refuse(400, "bad_request", CONV_REQUIRED)
retry = app.session_rate.take(app.client_key(self))
if retry:
return self.refuse(429, "rate", "Reconnecting too quickly. Try again shortly.", retry)
@@ -2321,7 +2323,7 @@ class Handler(BaseHTTPRequestHandler):
def status(self, iid):
app = self.app
- if not app.args.spool_status or not allen_spool.ID.match(iid):
+ if not app.args.spool_status or not allen_spool.ID.fullmatch(iid):
return self.send_json(404, {"error": "not_found"})
st = allen_spool.read_status(app.args.spool_status, iid)
p = allen_spool.spool_file(app.args.spool_in, iid)
@@ -2360,8 +2362,9 @@ def esc(s):
class ConsoleHandler(BaseHTTPRequestHandler):
"""Drake's console: tailnet only (nft admits only his devices and the Spark), never
- proxied by the hub, token login, HttpOnly SameSite=Strict cookie, CSRF token on every
- POST, no CORS, Host pinned to the listen address. All text is HTML-escaped."""
+ proxied by the hub, token login, HttpOnly SameSite=Strict cookie (Secure with the
+ __Host- prefix under --console-secure-cookie), CSRF token on every POST, no CORS,
+ Host pinned to the listen address. All text is HTML-escaped."""
protocol_version = "HTTP/1.1"
server_version = "allen-console"
@@ -2404,12 +2407,23 @@ class ConsoleHandler(BaseHTTPRequestHandler):
"<script src=/console.js defer></script></head><body>%s</body></html>" % (esc(title), body))
def sid(self):
+ name = self.server.cookie_name
for part in self.headers.get("Cookie", "").split(";"):
k, _, v = part.strip().partition("=")
- if k == CONSOLE_COOKIE:
+ if k == name:
return v
return None
+ def set_cookie(self, value, max_age):
+ """The session cookie. Default (security survey F6): no Secure flag, because the console
+ is plain HTTP on the tailnet, where a Secure cookie would never be sent back; the
+ compensating controls are the nft rule and WireGuard encryption on the tailnet path,
+ and the hub never proxies the console. --console-secure-cookie, for a console served
+ over TLS, adds Secure and the __Host- name prefix (host-only, Path=/, Secure)."""
+ secure = "; Secure" if self.server.cookie_secure else ""
+ return ("Set-Cookie", "%s=%s; HttpOnly; SameSite=Strict; Path=/; Max-Age=%d%s"
+ % (self.server.cookie_name, value, max_age, secure))
+
def host_ok(self):
return self.headers.get("Host", "") in self.server.hosts
@@ -2510,7 +2524,7 @@ class ConsoleHandler(BaseHTTPRequestHandler):
return self.login_page(200 if path == "/login" else 401)
if path == "/":
return self.dashboard(csrf)
- m = re.match(r"^/session/([0-9a-f]{16})(\.json)?$", path)
+ m = re.match(r"^/session/(%s)(\.json)?$" % allen_spool.CONV_BODY, path)
if m and m.group(2):
d = self.app.live.detail(m.group(1))
body = json.dumps(d if d else {"state": "none", "listeners": 0, "transcript": []},
@@ -2537,12 +2551,7 @@ class ConsoleHandler(BaseHTTPRequestHandler):
if app.console.check(f.get("token", "")):
sid = app.console.login()
app.stats.add("console_login")
- # No Secure flag (security survey F6, accepted): the console is plain HTTP on the
- # tailnet, where a Secure cookie would never be sent back. The compensating controls
- # are the nft rule (only 100.64.0.1/.4 and loopback reach :18112) and WireGuard
- # encryption on the tailnet path; the hub never proxies the console.
- return self.redirect("/", (("Set-Cookie", "%s=%s; HttpOnly; SameSite=Strict; Path=/; Max-Age=%d"
- % (CONSOLE_COOKIE, sid, CONSOLE_TTL)),))
+ return self.redirect("/", (self.set_cookie(sid, CONSOLE_TTL),))
app.console.fails.take(peer)
app.stats.add("console_login_fail")
return self.login_page(401, "Wrong token.")
@@ -2554,8 +2563,7 @@ class ConsoleHandler(BaseHTTPRequestHandler):
return self.send_body(403, b"missing or wrong CSRF token\n", "text/plain")
if path == "/logout":
app.console.logout(sid)
- return self.redirect("/login", (("Set-Cookie", "%s=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0"
- % CONSOLE_COOKIE),))
+ return self.redirect("/login", (self.set_cookie("", 0),))
if path == "/presence":
hours = " ".join(f.get("hours", "").split())[:200]
app.presence.set(f.get("online") == "on", hours)
@@ -2563,7 +2571,7 @@ class ConsoleHandler(BaseHTTPRequestHandler):
return self.redirect("/")
if allen_projects.console_post(self, path, f):
return
- m = re.match(r"^/session/([0-9a-f]{16})/(join|reply|handback)$", path)
+ m = re.match(r"^/session/(%s)/(join|reply|handback)$" % allen_spool.CONV_BODY, path)
if not m:
return self.send_body(404, b"not found\n", "text/plain")
conv, op = m.group(1), m.group(2)
@@ -2664,6 +2672,9 @@ def main():
ap.add_argument("--console-listen", help="host:port of Drake's console (tailnet address only; never proxied); "
"needs ALLEN_CONSOLE_TOKEN_SHA256 in the environment")
ap.add_argument("--console-state", help="directory for presence.json (Drake's availability)")
+ ap.add_argument("--console-secure-cookie", action="store_true",
+ help="console session cookie gets Secure and the __Host- prefix; only for a console "
+ "served over TLS (a browser never returns a Secure cookie over plain HTTP)")
ap.add_argument("--tools", default="", help="tool registry module beside this file (allen_tools); "
"empty = no tools")
ap.add_argument("--heartbeat", type=float, default=15, help="seconds between session stream heartbeats")
@@ -2688,6 +2699,8 @@ def main():
csrv = Server((chost, int(cport)), ConsoleHandler)
csrv.app = app
csrv.hosts = {args.console_listen}
+ csrv.cookie_secure = args.console_secure_cookie
+ csrv.cookie_name = CONSOLE_COOKIE_SECURE if args.console_secure_cookie else CONSOLE_COOKIE
threading.Thread(target=csrv.serve_forever, daemon=True).start()
def housekeeping():
diff --git a/scripts/allen/allen_spool.py b/scripts/allen/allen_spool.py
index ada1cec..90a34e0 100644
--- a/scripts/allen/allen_spool.py
+++ b/scripts/allen/allen_spool.py
@@ -25,7 +25,7 @@ import secrets
TEMPLATES = ("feature", "question", "bug")
SLUG = re.compile(r"^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$")
AREA = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$")
-ID = re.compile(r"^[0-9a-f]{20}$")
+ID = re.compile(r"\A[0-9a-f]{20}\Z")
SECRET_SHAPES = [
re.compile(p) for p in (
@@ -124,7 +124,7 @@ def write_item(spool_in, item):
def spool_file(directory, iid):
"""directory/iid.json for a well-formed id, or None; the real path must stay in directory."""
- if not ID.match(iid or ""):
+ if not ID.fullmatch(iid or ""):
return None
root = os.path.realpath(directory)
path = os.path.realpath(os.path.join(root, iid + ".json"))
@@ -153,9 +153,16 @@ RELAY_MESSAGE = 4000
RELAY_FIELD = 200
TRANSCRIPT_MSGS = 24
TRANSCRIPT_CHARS = 16000
-RELAY_ID = re.compile(r"^r_[0-9a-f]{16}$")
-CONV = re.compile(r"^[0-9a-f]{16}$")
-RECEIVED = re.compile(r"^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$")
+RELAY_ID = re.compile(r"\Ar_[0-9a-f]{16}\Z")
+# Live-session bearer. The page draws 32 hex (128 bits). A tab opened on the
+# previous page, and a relay file queued before this gateway is deployed, still
+# carry 16 hex. Both are accepted until 2026-12-02
+# (https://github.com/aien-dev/aienos.com/issues/196). Anything else is refused.
+# 32 is first so a path match cannot stop at the first 16 of a longer id.
+# \Z, not $: a trailing newline must not pass. ASCII digits only.
+CONV_BODY = r"[0-9a-f]{32}|[0-9a-f]{16}"
+CONV = re.compile(r"\A(?:%s)\Z" % CONV_BODY)
+RECEIVED = re.compile(r"\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z\Z")
def validate_transcript(t):
@@ -202,11 +209,11 @@ def validate_relay_record(rec):
raise Invalid("not a version 1 relay record")
if set(rec) != {"v", "type", "id", "received", "conv", "message", "name", "contact", "transcript"}:
raise Invalid("relay record fields do not match")
- if not isinstance(rec["id"], str) or not RELAY_ID.match(rec["id"]):
+ if not isinstance(rec["id"], str) or not RELAY_ID.fullmatch(rec["id"]):
raise Invalid("bad relay id")
- if not isinstance(rec["received"], str) or not RECEIVED.match(rec["received"]):
+ if not isinstance(rec["received"], str) or not RECEIVED.fullmatch(rec["received"]):
raise Invalid("bad received time")
- if not isinstance(rec["conv"], str) or not (rec["conv"] == "" or CONV.match(rec["conv"])):
+ if not isinstance(rec["conv"], str) or not (rec["conv"] == "" or CONV.fullmatch(rec["conv"])):
raise Invalid("bad conversation id")
item = validate_relay({k: rec[k] for k in ("message", "name", "contact", "transcript")})
return dict(item, v=1, type="relay", id=rec["id"], received=rec["received"], conv=rec["conv"])
diff --git a/scripts/allen/relay/allen_relay_mailer.py b/scripts/allen/relay/allen_relay_mailer.py
index ef5f18b..e24c38b 100755
--- a/scripts/allen/relay/allen_relay_mailer.py
+++ b/scripts/allen/relay/allen_relay_mailer.py
@@ -53,7 +53,7 @@ import allen_spool # noqa: E402
SENDER = "aien@aienos.com"
RECIPIENT = "drake@aienos.com"
CONSOLE = "http://100.64.0.2:18112"
-DROP_NAME = re.compile(r"^[0-9a-f]{16}\.json$")
+DROP_NAME = re.compile(r"\A[0-9a-f]{16}\.json\Z")
MAX_FILE = 128 * 1024
POLL_S = 2.0
BACKOFF_MAX = 900.0
@@ -191,7 +191,7 @@ def run(args, password):
while True:
now = time.monotonic()
try:
- names = sorted(n for n in os.listdir(args.drop) if DROP_NAME.match(n))
+ names = sorted(n for n in os.listdir(args.drop) if DROP_NAME.fullmatch(n))
except OSError as e:
log("cannot list the drop directory: %s" % e.strerror)
names = []
diff --git a/scripts/allen/relay/test_relay_mailer.py b/scripts/allen/relay/test_relay_mailer.py
index cb583ce..6f17007 100755
--- a/scripts/allen/relay/test_relay_mailer.py
+++ b/scripts/allen/relay/test_relay_mailer.py
@@ -90,7 +90,7 @@ class SMTPStub:
def record(rid, **kw):
rec = {"v": 1, "type": "relay", "id": "r_" + rid, "received": "2026-10-26T12:00:00Z",
- "conv": "0123456789abcdef", "message": "Hello Drake.\nI am building a kelp boat in Omega and want to talk.",
+ "conv": "0123456789abcdef" * 2, "message": "Hello Drake.\nI am building a kelp boat in Omega and want to talk.",
"name": "Test Visitor", "contact": "test@example.org",
"transcript": [{"role": "user", "content": "hi"}, {"role": "assistant", "content": "hello"}]}
rec.update(kw)
@@ -120,6 +120,7 @@ def main():
put(d, a, record(a))
put(d, b, record(b, to="someone@example.org"))
put(d, "c" * 16, record("c" * 16, message="token ghp_" + "A1b2C3d4" * 5))
+ put(d, "d" * 16, record("d" * 16, conv="0123456789abcde")) # 15 hex: neither 16 nor 32
rc, out = run_once(d, state, smtp.port)
m = smtp.mail[0] if smtp.mail else {"data": "", "to": []}
body = m["data"]
@@ -132,11 +133,14 @@ def main():
and "From: Aien relay <aien@aienos.com>" in body and "Allen" not in body and "AIEN" not in body, subj)
check("body carries message, name, contact, transcript, conversation and console link",
all(x in body for x in ("I am building a kelp boat", "Name: Test Visitor", "Contact: test@example.org",
- "Visitor: hi", "Aien: hello", "asked Aien to pass this on", "Conversation: 0123456789abcdef",
- "http://100.64.0.2:18112/session/0123456789abcdef", "Relay id: r_" + a)),
+ "Visitor: hi", "Aien: hello", "asked Aien to pass this on",
+ "Conversation: " + "0123456789abcdef" * 2,
+ "http://100.64.0.2:18112/session/" + "0123456789abcdef" * 2, "Relay id: r_" + a)),
"%d bytes" % len(body))
- check("items with a recipient field or a secret are rejected, not sent", not os.listdir(d)
- and "rejected %s.json" % b in out and "rejected %s.json" % ("c" * 16) in out, out.strip()[-200:])
+ check("items with a recipient field, a secret or an invalid conversation id are rejected, not sent",
+ not os.listdir(d) and len(smtp.mail) == 1 and all("rejected %s.json" % x in out
+ for x in (b, "c" * 16, "d" * 16)),
+ out.strip()[-200:])
st = json.load(open(state))
check("sent id and daily count persisted", st["count"] == 1 and st["sent"] == ["r_" + a], "%s" % st)
@@ -180,6 +184,50 @@ def main():
M.send(msg, M.RECIPIENT, "", ("127.0.0.1", smtp.port, False))
check("send() refuses any recipient but drake@aienos.com", refused, "refused=%s" % refused)
check("send() to drake@aienos.com works (control)", len(smtp.mail) == n + 1, "%d mails" % len(smtp.mail))
+
+ def conv_ok(conv):
+ try:
+ M.allen_spool.validate_relay_record(record("9" * 16, conv=conv))
+ return True
+ except M.allen_spool.Invalid:
+ return False
+
+ check("relay record accepts a 32-hex conversation id", conv_ok("0123456789abcdef" * 2), "32")
+ check("relay record accepts a 16-hex conversation id from an open tab", conv_ok("0123456789abcdef"), "16")
+ check("relay record accepts an empty conversation id", conv_ok(""), "empty")
+ bad_convs = (("15 hex", "0123456789abcde"), ("17 hex", "0123456789abcdef0"), ("31 hex", "a" * 31),
+ ("33 hex", "a" * 33), ("64 hex", "a" * 64), ("uppercase 16", "A" * 16),
+ ("uppercase 32", "A" * 32), ("non-hex", "g" * 32),
+ ("trailing newline", "a" * 32 + "\n"), ("dotdot", "../" + "a" * 29),
+ ("fullwidth digits", "\uff10" * 32))
+ accepted = [name for name, conv in bad_convs if conv_ok(conv)]
+ check("relay record refuses a conversation id that is not 16 or 32 hex", not accepted, "%s" % accepted)
+ # $ matches before a trailing newline. \Z / fullmatch must not. \d would
+ # accept a fullwidth digit; the received time is ASCII [0-9] only.
+ anchors = []
+ fw_time = "\uff12" + "026-11-02T00:00:00Z"
+ for name, rx, good, bad in (
+ ("RELAY_ID", M.allen_spool.RELAY_ID, "r_" + "a" * 16, "r_" + "a" * 16 + "\n"),
+ ("ID", M.allen_spool.ID, "a" * 20, "a" * 20 + "\n"),
+ ("RECEIVED", M.allen_spool.RECEIVED, "2026-11-02T00:00:00Z", "2026-11-02T00:00:00Z\n"),
+ ("DROP_NAME", M.DROP_NAME, "a" * 16 + ".json", "a" * 16 + ".json\n"),
+ ("CONV", M.allen_spool.CONV, "a" * 32, "a" * 32 + "\n")):
+ if not rx.fullmatch(good) or rx.fullmatch(bad) or rx.match(bad):
+ anchors.append(name)
+ if M.allen_spool.RECEIVED.fullmatch(fw_time) or M.allen_spool.CONV.fullmatch("\uff10" * 32):
+ anchors.append("unicode digit")
+ if M.DROP_NAME.fullmatch("../" + "a" * 13 + ".json"):
+ anchors.append("DROP_NAME dotdot")
+ check("id validators reject a trailing newline and a unicode digit", not anchors, "%s" % anchors)
+ legacy = "abcdef0123456789"
+ put(d, "3" * 16, record("3" * 16, conv=legacy))
+ before = len(smtp.mail)
+ rc, out = run_once(d, state, smtp.port, "--per-day", "20")
+ sent = [m for m in smtp.mail[before:] if ("Conversation: " + legacy) in m["data"]]
+ check("a queued 16-hex conversation id is mailed, not rejected",
+ rc == 0 and len(sent) == 1 and not any(name.startswith("3" * 16) for name in os.listdir(d))
+ and "rejected %s.json" % ("3" * 16) not in out,
+ "rc %d new mails %d" % (rc, len(smtp.mail) - before))
try:
M.send(msg, M.RECIPIENT, "", ("192.0.2.1", 25, False))
plain = False
diff --git a/scripts/allen/test_gateway.py b/scripts/allen/test_gateway.py
index d5faccf..350c00b 100755
--- a/scripts/allen/test_gateway.py
+++ b/scripts/allen/test_gateway.py
@@ -28,6 +28,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer, ThreadingHTTPServer
HERE = os.path.dirname(os.path.abspath(__file__))
results = []
+UPSTREAM = "127.0.0.1:18091" # --upstream; suites with their own stub pass upstream= explicitly
def check(name, ok, detail):
@@ -44,7 +45,8 @@ def free_port():
class Gateway:
- def __init__(self, a, *extra, upstream="127.0.0.1:18091", env=None, console=False):
+ def __init__(self, a, *extra, upstream=None, env=None, console=False):
+ upstream = upstream or UPSTREAM
self.port = free_port()
self.dirs = {k: tempfile.mkdtemp(prefix="allenchat-test-" + k)
for k in ("in", "status", "drop", "relay", "console")}
@@ -754,7 +756,7 @@ def speed_tests(a):
key = "5" * 32
vid = hmac.new(secret.encode(), key.encode(), hashlib.sha256).hexdigest()
allen_memory.Memory("http://127.0.0.1:%d" % cx.server_address[1], "t" * 40).remember(vid, ["Builds kelp boats"])
- r = run(g, u("What is Omega?"), headers={"X-Allen-Key": key, "X-Allen-Conversation": "a" * 16})
+ r = run(g, u("What is Omega?"), headers={"X-Allen-Key": key, "X-Allen-Conversation": "a" * 32})
check("visitor with recalled notes is not served from the cache", r["meta"] != "cache"
and r["text"] == "from model", "%s" % r["meta"])
r = run(g, u("What is Omega?"), headers={"X-Allen-Key": key, "X-Allen-Anonymous": "1"})
@@ -1266,7 +1268,7 @@ class Listener:
def relay_tests(a):
g = Gateway(a)
try:
- conv = {"X-Allen-Conversation": "a1b2c3d4e5f60718"}
+ conv = {"X-Allen-Conversation": "a1b2c3d4e5f60718" * 2}
def relay(body, ip, h=conv):
c, r = g.post("/allen/api/relay", body, ip=ip, headers=h)
@@ -1289,7 +1291,7 @@ def relay_tests(a):
rec = json.load(open(os.path.join(g.dirs["relay"], drops[0]))) if drops else {}
mode = oct(os.stat(os.path.join(g.dirs["relay"], drops[0])).st_mode & 0o777) if drops else None
check("relay accepts a valid message (control)", st == 200 and j.get("sent") and not j.get("duplicate")
- and len(drops) == 1 and rec.get("id") == j["id"] and rec.get("conv") == "a1b2c3d4e5f60718"
+ and len(drops) == 1 and rec.get("id") == j["id"] and rec.get("conv") == "a1b2c3d4e5f60718" * 2
and mode == "0o640" and drops[0] == j["id"][2:] + ".json", "%d %s mode %s" % (st, j, mode))
import allen_spool
try:
@@ -1301,9 +1303,25 @@ def relay_tests(a):
st, j2 = relay(ok, "198.51.100.41")
check("identical message in the same conversation deduped", st == 200 and j2.get("duplicate")
and j2["id"] == j["id"] and len(g.files("relay")) == 1, "%d %s" % (st, j2))
- st, j3 = relay(ok, "198.51.100.42", {"X-Allen-Conversation": "ffffffffffffffff"})
+ st, j3 = relay(ok, "198.51.100.42", {"X-Allen-Conversation": "f" * 32})
check("same message from another conversation is new (control)", st == 200 and not j3.get("duplicate")
and len(g.files("relay")) == 2, "%d %s" % (st, j3))
+ st, j16 = relay(dict(ok, message="from a tab still holding 16 hex"), "198.51.100.43",
+ {"X-Allen-Conversation": "a1b2c3d4e5f60718"})
+ rec16 = {}
+ if st == 200:
+ name = j16["id"][2:] + ".json"
+ rec16 = json.load(open(os.path.join(g.dirs["relay"], name)))
+ check("relay keeps a 16-hex conversation id from an open tab", st == 200 and not j16.get("duplicate")
+ and rec16.get("conv") == "a1b2c3d4e5f60718", "%d %s conv %s" % (st, j16, rec16.get("conv")))
+ st, jbad = relay(dict(ok, message="conversation id is not hex"), "198.51.100.44",
+ {"X-Allen-Conversation": "g" * 32})
+ recbad = {}
+ if st == 200:
+ name = jbad["id"][2:] + ".json"
+ recbad = json.load(open(os.path.join(g.dirs["relay"], name)))
+ check("relay stores no conversation id when the header is not 16 or 32 hex",
+ st == 200 and recbad.get("conv") == "", "%d %s conv %r" % (st, jbad, recbad.get("conv")))
codes = [relay(dict(ok, message="per address %d" % k), "198.51.100.77")[0] for k in range(4)]
other = relay(dict(ok, message="other address"), "198.51.100.78")[0]
check("relay per-address 3 per hour then 429", codes == [200, 200, 200, 429], "%s" % codes)
@@ -1329,7 +1347,7 @@ def live_tests(a):
sha = hashlib.sha256(TOKEN.encode()).hexdigest()
g = Gateway(a, "--heartbeat", "1", upstream="127.0.0.1:%d" % s.server_address[1], console=True,
env={"ALLEN_CONSOLE_TOKEN_SHA256": sha})
- conv = "0123456789abcdef"
+ conv = "0123456789abcdef" * 2
H = {"X-Allen-Conversation": conv}
cons = Console(g)
try:
@@ -1379,6 +1397,76 @@ def live_tests(a):
{"role": "assistant", "content": "hello"}]}, headers=H)
j = json.loads(r.read())
check("handoff accepted while online (control)", r.status == 200 and j.get("waiting"), "%d %s" % (r.status, j))
+
+ def live_codes(headers):
+ """handoff, session and say statuses. A 200 session is closed so its listener drops."""
+ c, r = g.post("/allen/api/handoff", {"transcript": []}, headers=headers)
+ hs = r.status
+ r.read()
+ c.close()
+ c, r = g.get("/allen/api/session", headers=headers)
+ ss = r.status
+ # Connection: close moves the socket onto the response; closing it
+ # ends the stream so the gateway drops the listener.
+ r.close()
+ c.close()
+ c, r = g.post("/allen/api/say", {"text": "still here"}, headers=headers)
+ ys = r.status
+ r.read()
+ c.close()
+ return hs, ss, ys
+
+ def console_live(cid):
+ st, _, js = cons.req("GET", "/session/%s.json" % cid)
+ hb, _, _ = cons.post("/session/%s/handback" % cid)
+ return st, js, hb
+
+ # The page draws 32 hex. A separate id from `conv` so this check does not
+ # take the listener the rest of the test holds open.
+ fresh = "ab" * 16
+ hs, ss, ys = live_codes({"X-Allen-Conversation": fresh})
+ cst, cjs, chb = console_live(fresh)
+ check("32-hex conversation id accepted on handoff, session, say and console",
+ (hs, ss, ys, cst, chb) == (200, 200, 200, 200, 303)
+ and json.loads(cjs).get("state") == "waiting",
+ "handoff %d session %d say %d console %d handback %d %s" % (hs, ss, ys, cst, chb, cjs[:80]))
+ # A tab left open across the cutover still holds the 16-hex id minted on load.
+ legacy_id = "0123456789abcdef"
+ hs, ss, ys = live_codes({"X-Allen-Conversation": legacy_id})
+ cst, cjs, chb = console_live(legacy_id)
+ check("16-hex conversation id from an open tab accepted on handoff, session, say and console",
+ (hs, ss, ys, cst, chb) == (200, 200, 200, 200, 303)
+ and json.loads(cjs).get("state") == "waiting",
+ "handoff %d session %d say %d console %d handback %d %s" % (hs, ss, ys, cst, chb, cjs[:80]))
+ bad_ids = ("", "abc", "a" * 15, "a" * 17, "a" * 31, "a" * 33, "a" * 64,
+ "A" * 16, "A" * 32, "g" * 16, "g" * 32, "0123456789abcdef" + "G" * 16,
+ "../" + "a" * 29, "%2e%2e" + "a" * 26)
+ refused = []
+ for bad in bad_ids:
+ hs, ss, ys = live_codes({"X-Allen-Conversation": bad})
+ st, _, body = cons.req("GET", "/session/%s.json" % bad)
+ pst, _, pbody = cons.req("POST", "/session/%s/handback" % bad, {"csrf": cons.csrf})
+ if (hs, ss, ys) != (400, 400, 400) or st != 404 or body != "not found\n" or pst != 404 or pbody != "not found\n":
+ refused.append("%r -> %d %d %d console %d %r post %d %r" % (bad, hs, ss, ys, st, body[:40], pst, pbody[:40]))
+ check("conversation id that is not 16 or 32 hex refused on handoff, session, say and console",
+ not refused, "; ".join(refused) or "all refused")
+ # A newline cannot be an HTTP header value. The spool is the re-check, and
+ # \Z / fullmatch must refuse it, a ../ id, and a fullwidth-digit id (\d would not).
+ import allen_spool
+ fullwidth = "\uff10" * 32
+ anchored = (("trailing newline", "a" * 32 + "\n"), ("dotdot", "../" + "a" * 29),
+ ("fullwidth digits", fullwidth))
+ slipped = [name for name, bad in anchored if allen_spool.CONV.fullmatch(bad) or allen_spool.CONV.match(bad)]
+ for name, bad in anchored:
+ rec = {"v": 1, "type": "relay", "id": "r_" + "9" * 16, "received": "2026-11-02T00:00:00Z",
+ "conv": bad, "message": "hello", "name": "", "contact": "", "transcript": []}
+ try:
+ allen_spool.validate_relay_record(rec)
+ slipped.append(name + " record")
+ except allen_spool.Invalid:
+ pass
+ check("conversation id rejects a trailing newline, dotdot and fullwidth digits",
+ not slipped, "%s" % slipped)
L = Listener(g, conv)
time.sleep(1.5)
@@ -1446,7 +1534,7 @@ def live_tests(a):
"%s" % js[:120])
# Availability off -> handoff refused again.
cons.post("/presence", hours="")
- c, r = g.post("/allen/api/handoff", {"transcript": []}, headers={"X-Allen-Conversation": "1111222233334444"})
+ c, r = g.post("/allen/api/handoff", {"transcript": []}, headers={"X-Allen-Conversation": "1111222233334444" * 2})
r.read()
check("availability off refuses handoff again", r.status == 409, "%d" % r.status)
st, _, _ = cons.post("/logout")
@@ -1479,20 +1567,20 @@ def anon_tests(a):
return writes(key)
try:
k1, k2, k3 = "1" * 32, "2" * 32, "3" * 32
- chat_events(g, "I build kelp boats.", headers={"X-Allen-Key": k1, "X-Allen-Conversation": "aaaaaaaaaaaaaaaa"})
+ chat_events(g, "I build kelp boats.", headers={"X-Allen-Key": k1, "X-Allen-Conversation": "a" * 32})
n1 = wait_writes(k1, 0)
check("keyed chat writes visitor notes (control)", n1 >= 1, "%d writes" % n1)
chat_events(g, "I build kelp boats.", headers={"X-Allen-Key": k2, "X-Allen-Anonymous": "1",
- "X-Allen-Conversation": "bbbbbbbbbbbbbbbb"})
+ "X-Allen-Conversation": "b" * 32})
n2 = wait_writes(k2, 0, 4)
with cx.lock:
searched = sum(1 for q in cx.searches if q == space(k2))
check("anonymous chat: zero Cortex writes and no recall even with a key", n2 == 0 and searched == 0,
"%d writes, %d searches" % (n2, searched))
- chat_events(g, "turn one", headers={"X-Allen-Key": k3, "X-Allen-Conversation": "cccccccccccccccc"})
+ chat_events(g, "turn one", headers={"X-Allen-Key": k3, "X-Allen-Conversation": "c" * 32})
m1 = wait_writes(k3, 0)
chat_events(g, "turn two", headers={"X-Allen-Key": k3, "X-Allen-Anonymous": "1",
- "X-Allen-Conversation": "cccccccccccccccc"})
+ "X-Allen-Conversation": "c" * 32})
m2 = wait_writes(k3, m1, 4)
check("switching to anonymous mid-conversation stops writes", m1 >= 1 and m2 == m1,
"writes %d before, %d after the switch" % (m1, m2))
@@ -1508,7 +1596,7 @@ def anon_tests(a):
before = len(cx.writes)
c, r = g.post("/allen/api/relay", {"message": "From an anonymous visitor.", "name": "Anon Name",
"contact": "anon@example.org"}, ip="203.0.113.92",
- headers={"X-Allen-Anonymous": "1", "X-Allen-Conversation": "dddddddddddddddd"})
+ headers={"X-Allen-Anonymous": "1", "X-Allen-Conversation": "d" * 32})
r.read()
relays = g.files("relay")
rec = json.load(open(os.path.join(g.dirs["relay"], relays[0]))) if relays else {}
@@ -1837,19 +1925,157 @@ def model_tests(a):
g.close()
+def cookie_tests(a):
+ """W7: the console cookie is plain by default; --console-secure-cookie adds Secure and __Host-."""
+ sha = hashlib.sha256(TOKEN.encode()).hexdigest()
+ for secure in (False, True):
+ label = "secure" if secure else "default"
+ g = Gateway(a, *(["--console-secure-cookie"] if secure else []), console=True,
+ env={"ALLEN_CONSOLE_TOKEN_SHA256": sha})
+ cons = Console(g)
+ try:
+ st, setc = cons.login()
+ name, _, rest = setc.partition("=")
+ sid, _, attrs = rest.partition(";")
+ attrs = [x.strip() for x in attrs.split(";")]
+ if not secure:
+ check("console cookie default: allen_console, no Secure (plain-HTTP tailnet console, control)",
+ st == 303 and name == "allen_console" and "Secure" not in attrs and cons.csrf,
+ "%d %s %s" % (st, name, attrs))
+ continue
+ check("console cookie with --console-secure-cookie: __Host- name, Secure, Path=/, no Domain",
+ st == 303 and name == "__Host-allen_console" and "Secure" in attrs and "Path=/" in attrs
+ and "HttpOnly" in attrs and "SameSite=Strict" in attrs
+ and not any(x.lower().startswith("domain") for x in attrs) and cons.csrf,
+ "%d %s %s" % (st, name, attrs))
+ st2, _, _ = cons.req("GET", "/", cookie=False, headers={"Cookie": "allen_console=" + sid})
+ check("secure console ignores the unprefixed cookie name", st2 == 401, "%d" % st2)
+ st3, setc3, _ = cons.post("/logout")
+ check("secure console logout clears the __Host- cookie with Secure",
+ st3 == 303 and setc3.startswith("__Host-allen_console=;") and "Secure" in setc3
+ and "Max-Age=0" in setc3, "%d %s" % (st3, setc3))
+ except OSError as e:
+ check("console cookie %s: gateway answers" % label, False, "%s: %s" % (type(e).__name__, e))
+ finally:
+ g.close()
+
+
+def nginx_blocks(text):
+ """(header, body) for every {...} block of an nginx file; quote-aware, comments dropped."""
+ out, stack, head, q, i = [], [], [], None, 0
+ while i < len(text):
+ ch = text[i]
+ if q:
+ head.append(ch)
+ if ch == "\\":
+ head.append(text[i + 1])
+ i += 1
+ elif ch == q:
+ q = None
+ elif ch == "#":
+ i = text.find("\n", i)
+ if i < 0:
+ break
+ continue
+ elif ch in "'\"":
+ q = ch
+ head.append(ch)
+ elif ch == "{":
+ stack.append((" ".join("".join(head).split()), i + 1))
+ head = []
+ elif ch == "}":
+ h, b = stack.pop()
+ out.append((h, text[b:i]))
+ head = []
+ elif ch == ";":
+ head = []
+ else:
+ head.append(ch)
+ i += 1
+ return out
+
+
+def edge_route_faults(text):
+ """Proxied routes in a location snippet that miss a forwarding or origin guard."""
+ faults = []
+ for h, b in nginx_blocks(text):
+ if not h.startswith("location") or "proxy_pass" not in b:
+ continue
+ need = ['proxy_set_header X-Forwarded-For "";', "proxy_set_header X-Real-IP $proxy_protocol_addr;",
+ 'if ($proxy_protocol_addr = "") { return 503; }']
+ if "limit_except POST" in b:
+ need.append("if ($allen_xsite) { return 403; }")
+ if "/a2a" in h: # JSON or application/a2a+json, its own stricter map
+ need.append("if ($allen_a2a_notjson) { return 415; }")
+ elif "transcribe" not in h: # raw audio, not JSON
+ need.append("if ($allen_notjson) { return 415; }")
+ faults += ["%s: %s" % (h, n) for n in need if n not in " ".join(b.split())]
+ return faults
+
+
+def edge_tests(a):
+ """W5/W6: the committed hub nginx copies carry every edge guard the live hub has."""
+ loc = open(os.path.join(HERE, "nginx-allen-location.conf")).read()
+ zones = open(os.path.join(HERE, "nginx-allen-zones.conf")).read()
+ routes = [h for h, b in nginx_blocks(loc) if h.startswith("location") and "proxy_pass" in b]
+ faults = edge_route_faults(loc)
+ check("edge: every proxied route clears X-Forwarded-For, keys X-Real-IP on PROXY protocol, "
+ "and POST routes refuse cross-site and non-JSON", len(routes) >= 8 and not faults,
+ "%d routes; missing %s" % (len(routes), faults))
+ broken = loc.replace('proxy_set_header X-Forwarded-For "";', "", 1)
+ check("edge: the route check finds one dropped X-Forwarded-For line (control)",
+ len(edge_route_faults(broken)) == len(faults) + 1, "%d" % len(edge_route_faults(broken)))
+ maps = {m.group(1) for m in re.finditer(r"^map\s+\S+\s+\$(\w+)\s*\{", zones, re.M)}
+ check("edge: zones define the $allen_xsite, $allen_notjson and $allen_a2a_notjson maps",
+ {"allen_xsite", "allen_notjson", "allen_a2a_notjson"} <= maps,
+ "%s" % sorted(maps))
+ nginx = os.environ.get("NGINX") or shutil.which("nginx")
+ if not nginx:
+ print("NOT_RUN edge: nginx -t (no nginx binary; set NGINX=/path/to/nginx)", flush=True)
+ return
+ d = tempfile.mkdtemp(prefix="allenchat-test-nginx")
+ try:
+ def syntax(location_text):
+ with open(os.path.join(d, "zones.conf"), "w") as f:
+ f.write(zones)
+ with open(os.path.join(d, "location.conf"), "w") as f:
+ f.write(location_text)
+ temps = "".join("%s_temp_path %s/%s;\n" % (k, d, k) for k in ("client_body", "proxy", "fastcgi",
+ "uwsgi", "scgi"))
+ with open(os.path.join(d, "nginx.conf"), "w") as f:
+ f.write("pid %s/nginx.pid;\nerror_log %s/error.log;\nevents {}\nhttp {\n%saccess_log off;\n"
+ "include %s/zones.conf;\nserver {\nlisten 127.0.0.1:8443 proxy_protocol;\n"
+ "server_name www.aienos.com;\ninclude %s/location.conf;\n}\n}\n" % (d, d, temps, d, d))
+ p = subprocess.run([nginx, "-t", "-p", d, "-c", os.path.join(d, "nginx.conf"), "-e",
+ os.path.join(d, "error.log")], capture_output=True, text=True, timeout=20)
+ return p.returncode, (p.stdout + p.stderr).strip().splitlines()
+ rc, out = syntax(loc)
+ check("edge: nginx -t accepts zones + location snippet", rc == 0 and any("test is successful" in x for x in out),
+ "rc %d %s" % (rc, out[-1:]))
+ rc, out = syntax(loc.replace("proxy_buffering off;", "proxy_buffering offf;", 1))
+ check("edge: nginx -t refuses a broken directive (control)", rc != 0, "rc %d %s" % (rc, out[-1:]))
+ finally:
+ shutil.rmtree(d, ignore_errors=True)
+
+
+
def main():
+ global UPSTREAM
ap = argparse.ArgumentParser()
ap.add_argument("--omc", required=True)
ap.add_argument("--irwasm", required=True)
ap.add_argument("--system-prompt", required=True)
ap.add_argument("--skip-model", action="store_true")
+ ap.add_argument("--upstream", default=UPSTREAM,
+ help="model upstream for suites without their own stub (a closed port keeps them off the model)")
a = ap.parse_args()
+ UPSTREAM = a.upstream
only = os.environ.get("ALLEN_TEST_ONLY", "")
for name, fn in (("offline", offline_tests), ("spool", spool_tests), ("pool", pool_tests),
("relay", relay_tests), ("live", live_tests), ("anon", anon_tests),
("summary", summary_tests), ("volunteer", volunteer_tests), ("tools", tool_tests),
("warm", warm_tests), ("speed", speed_tests), ("voice", voice_tests),
- ("infer", infer_tests)):
+ ("infer", infer_tests), ("cookie", cookie_tests), ("edge", edge_tests)):
if not only or name in only.split(","):
fn(a)
if not a.skip_model:
diff --git a/scripts/allen/test_memory_e2e.py b/scripts/allen/test_memory_e2e.py
index b7a189a..e29ecff 100755
--- a/scripts/allen/test_memory_e2e.py
+++ b/scripts/allen/test_memory_e2e.py
@@ -58,7 +58,7 @@ def call(path, obj, key=None, conv=None):
def chat(msg, key=None, conv=None):
time.sleep(22) # stay inside the per-address chat bucket (one per 20 s after the burst)
st, out, ttft = call("chat", {"messages": [{"role": "user", "content": msg}]}, key,
- conv or secrets.token_hex(8))
+ conv or secrets.token_hex(16))
return out.get("text", ""), out, ttft
diff --git a/scripts/allen/test_reaching_drake_prod.py b/scripts/allen/test_reaching_drake_prod.py
index 780748e..0a0e5ba 100755
--- a/scripts/allen/test_reaching_drake_prod.py
+++ b/scripts/allen/test_reaching_drake_prod.py
@@ -118,7 +118,7 @@ def main():
nonce = secrets.token_hex(4)
msg = ("TEST from AllenRelay %s: production relay check, please ignore. This verifies that a visitor "
"message relayed by public Allen reaches drake@aienos.com." % nonce)
- conv = secrets.token_hex(8)
+ conv = secrets.token_hex(16)
c, r = public("POST", "/allen/api/relay", {"message": msg, "name": "AllenRelay test", "contact": "",
"transcript": [{"role": "user", "content": "test"},
{"role": "assistant", "content": "test reply"}]},
@@ -152,7 +152,7 @@ def main():
if found else "not found in the last 15 messages after 2 min")
# Live takeover end to end.
- conv = secrets.token_hex(8)
+ conv = secrets.token_hex(16)
H = {"X-Allen-Conversation": conv, "X-Allen-Anonymous": "1"}
try:
st = cons.post("/presence", online="on", hours=prev_hours or "")