Skip to content
Merged
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
5 changes: 4 additions & 1 deletion pkgs/fleet/crates/fleet-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,10 @@ fn unbound_append(worker: &str, row: &Value, trigger: &str) {
/// #9046: fleet session ids are `ses_` + alphanumerics — the
/// shape every session surface mints. Anything else is not a
/// session id and must never reach a route_attempt SQL string.
fn valid_session_id(s: &str) -> bool {
/// #8287: this is the crate's one session-id predicate — the
/// broker's bind verb (turso_queue::verb_bind) validates against
/// it too; do not fork a second definition.
pub(crate) fn valid_session_id(s: &str) -> bool {
s.len() > 4 && s.starts_with("ses_") && s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
}

Expand Down
56 changes: 56 additions & 0 deletions pkgs/fleet/crates/fleet-queue/src/turso_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5305,6 +5305,20 @@ fn verb_bind(t: &TursoBackend, req: &Value) -> Value {
let launched_by = req_str(req, "launched_by")
.unwrap_or("opencode-claimant")
.to_string();
// #8287: a malformed session id refuses here, as a usage
// error, before any state is touched — binding a ghost id
// strands the task until stuck-bound supervision recovers
// it. The predicate is the one the client/claim paths keep
// (client::valid_session_id); do not fork a second one.
if !crate::client::valid_session_id(&session_id) {
return fail(
2,
format!(
"bind_repo_task_lane_session: invalid session_id {session_id:?} \
(expected ses_ + alphanumeric/underscore)"
),
);
}
// #9046: a bind may carry the bound session's own model (the
// claimant derives it from the session record, #8176); when
// it does, the bind stamps it via stamp_claim_model below.
Expand Down Expand Up @@ -8745,6 +8759,48 @@ mod tests {
assert_eq!(out["task"]["max_attempts"], 1000, "{out}");
}

#[test]
fn bind_rejects_malformed_session_id_8287() {
// #8287 oracle: verb_bind refuses a malformed session id
// as a usage error (exit 2) before any store access, so
// the task is left unbound — the dummy backend proves the
// refusal happens pre-store (any store touch would fail
// differently). A well-formed id must NOT produce the
// invalid-session refusal (it proceeds to the store path
// and fails there against this backend, or on the task).
let backend = TursoBackend::new(
"http://127.0.0.1:0".to_string(),
"test".to_string(),
ureq::agent(),
);
for bad in ["not-a-session", "", "ses_", "ses_a'; DROP TABLE tasks; --"] {
let out = verb_bind(
&backend,
&json!({"task_id": 1, "worker": "w", "session_id": bad}),
);
assert_eq!(out["ok"], false, "{bad}: {out}");
assert_eq!(out["exit"], 2, "{bad}: {out}");
assert!(
out["error"]
.as_str()
.unwrap_or("")
.contains("invalid session_id"),
"{bad}: {out}"
);
}
let out = verb_bind(
&backend,
&json!({"task_id": 1, "worker": "w", "session_id": "ses_e5e37addeb0ffeumu1UPO2bI8G"}),
);
assert!(
!out["error"]
.as_str()
.unwrap_or("")
.contains("invalid session_id"),
"well-formed id refused as invalid: {out}"
);
}

#[test]
fn model_stamp_detail_9046_carries_session_and_trigger() {
// #9046 oracle: a stamp detail names the session it
Expand Down