Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_GYpmbzDG2PvTea_S4vxGI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"Cargo.toml": "Patch"
},
"note": "devup_figma_measure reads explicit nodes concurrently and lets the bridge fall back to the direct path when Figma cannot load an out-of-view node, instead of timing out",
"date": "2026-11-01T14:30:41.006295100Z"
}
6 changes: 3 additions & 3 deletions crates/devup-mcp-figma/src/plugin_scripts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const PLUGIN_SCRIPTS_HASH: &str =
"a5e954ac7dea2bf7b253b558b8821439181cf56477c0a293fa2689e18131edc0";
"9faf577eab918abe851b00ce4f1ed3e8621cf59acce3b6336b1b1a46fbe9c376";
pub const PLUGIN_PROTOCOL: u32 = 1;

/// The scripts of [`PLUGIN_SCRIPTS_HASH`] as one evaluable expression. The bridge
Expand Down Expand Up @@ -51,7 +51,7 @@ mod tests {
),
(
include_bytes!("scripts/measure_nodes.js").as_slice(),
"e898bb09c67cf86df37703b26b412f6686996211dc9ce445ba3afabdc599a810",
"de0526f016eef6478bae115d8b2ce7db46a5f37237360749d733c380215c5b5d",
),
(
include_bytes!("scripts/metadata.js").as_slice(),
Expand Down Expand Up @@ -103,7 +103,7 @@ mod tests {
),
(
include_bytes!("plugin_scripts_bundle.js").as_slice(),
"57a4c256d1001820eaddcd4aec52460ccd30d07b8b6f9f5c5ad1977bc9bf050d",
"33bc4c31a07d5968f9916a7eaac4d0d11d16afd45456dfc2a7c1c6df249b5996",
),
] {
let actual = Sha256::digest(source)
Expand Down
24 changes: 16 additions & 8 deletions crates/devup-mcp-figma/src/plugin_scripts_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2511,13 +2511,17 @@ const label = (node, key) => {
try { const value = node[key]; return typeof value === 'string' && value.length <= 32 && /^[A-Z_]+$/.test(value) ? value : null; }
catch { return null; }
};
const nodes = [];
for (const nodeId of ids) {
// Figma answers a read of data it has not loaded (an instance sublayer whose
// main component lives elsewhere, in a file out of sight) only after 10 s.
// Reading the IDs one after another made two such IDs outlast the caller's
// time limit, so they are read together and each failure keeps its cause:
// the unreachable sentence sits in `error`, where the bridge recognises it
// and re-reads through the direct path, which does not depend on the view.
const read = async nodeId => {
try {
const node = await figma.getNodeByIdAsync(nodeId);
if (!node || node.type === 'DOCUMENT' || node.type === 'PAGE') {
nodes.push({nodeId, status: 'unavailable', reason: node ? 'not-scene-node' : 'not-found'});
continue;
return {nodeId, status: 'unavailable', reason: node ? 'not-scene-node' : 'not-found'};
}
const layout = {
width: number(node, 'width'), height: number(node, 'height'),
Expand All @@ -2526,11 +2530,15 @@ for (const nodeId of ids) {
align: {primary: label(node, 'primaryAxisAlignItems'), counter: label(node, 'counterAxisAlignItems')}
};
const known = layout.width !== null && layout.height !== null;
nodes.push({nodeId, status: known ? 'measured' : 'partial', ...layout});
} catch {
nodes.push({nodeId, status: 'unavailable', reason: 'read-failed'});
return {nodeId, status: known ? 'measured' : 'partial', ...layout};
} catch (failure) {
const message = String((failure && failure.message) || failure).slice(0, 240);
return message.includes('Unable to establish connection to Figma')
? {nodeId, status: 'unavailable', reason: 'figma-unreachable', error: message}
: {nodeId, status: 'unavailable', reason: 'read-failed'};
}
}
};
const nodes = await Promise.all(ids.map(read));
return {kind: 'devup-measure', schemaVersion: 1, coordinateSpace: 'figma-logical', nodes,
partial: nodes.some(node => node.status !== 'measured'),
evidenceLimit: 'Null means unavailable or not applicable; no screenshot dimensions, descendants, theme, assets or code were read.'};
Expand Down
24 changes: 16 additions & 8 deletions crates/devup-mcp-figma/src/scripts/measure_nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ const label = (node, key) => {
try { const value = node[key]; return typeof value === 'string' && value.length <= 32 && /^[A-Z_]+$/.test(value) ? value : null; }
catch { return null; }
};
const nodes = [];
for (const nodeId of ids) {
// Figma answers a read of data it has not loaded (an instance sublayer whose
// main component lives elsewhere, in a file out of sight) only after 10 s.
// Reading the IDs one after another made two such IDs outlast the caller's
// time limit, so they are read together and each failure keeps its cause:
// the unreachable sentence sits in `error`, where the bridge recognises it
// and re-reads through the direct path, which does not depend on the view.
const read = async nodeId => {
try {
const node = await figma.getNodeByIdAsync(nodeId);
if (!node || node.type === 'DOCUMENT' || node.type === 'PAGE') {
nodes.push({nodeId, status: 'unavailable', reason: node ? 'not-scene-node' : 'not-found'});
continue;
return {nodeId, status: 'unavailable', reason: node ? 'not-scene-node' : 'not-found'};
}
const layout = {
width: number(node, 'width'), height: number(node, 'height'),
Expand All @@ -26,11 +30,15 @@ for (const nodeId of ids) {
align: {primary: label(node, 'primaryAxisAlignItems'), counter: label(node, 'counterAxisAlignItems')}
};
const known = layout.width !== null && layout.height !== null;
nodes.push({nodeId, status: known ? 'measured' : 'partial', ...layout});
} catch {
nodes.push({nodeId, status: 'unavailable', reason: 'read-failed'});
return {nodeId, status: known ? 'measured' : 'partial', ...layout};
} catch (failure) {
const message = String((failure && failure.message) || failure).slice(0, 240);
return message.includes('Unable to establish connection to Figma')
? {nodeId, status: 'unavailable', reason: 'figma-unreachable', error: message}
: {nodeId, status: 'unavailable', reason: 'read-failed'};
}
}
};
const nodes = await Promise.all(ids.map(read));
return {kind: 'devup-measure', schemaVersion: 1, coordinateSpace: 'figma-logical', nodes,
partial: nodes.some(node => node.status !== 'measured'),
evidenceLimit: 'Null means unavailable or not applicable; no screenshot dimensions, descendants, theme, assets or code were read.'};
83 changes: 73 additions & 10 deletions crates/devup-mcp/src/server/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ fn validated_node(node: &Value, id: &str) -> Result<Value, DevupError> {
));
}
if node["status"] == "unavailable" {
return Ok(json!({"nodeId":id,"status":"unavailable","reason":"node-read-unavailable"}));
// Only the script's fixed labels pass; anything else stays generic.
let reason = node["reason"]
.as_str()
.filter(|reason| {
matches!(
*reason,
"not-found" | "not-scene-node" | "read-failed" | "figma-unreachable"
)
})
.unwrap_or("node-read-unavailable");
let mut entry = json!({"nodeId":id,"status":"unavailable","reason":reason});
if reason == "figma-unreachable" {
entry["hint"] = json!(devup_mcp_figma::figma_unreachable_hint(
"Unable to establish connection to Figma"
));
}
return Ok(entry);
}
let numeric = |key: &str, v: &Value| -> Result<Value, DevupError> {
if v.is_null() {
Expand Down Expand Up @@ -76,6 +92,34 @@ fn validated_node(node: &Value, id: &str) -> Result<Value, DevupError> {
"align":{"primary":label(&node["align"]["primary"] )?,"counter":label(&node["align"]["counter"] )?}}),
)
}
async fn timed_out(server: &DevupServer, file_key: &str, ids: &[String]) -> DevupError {
let plugin = server
.services
.upstream
.bridge_path_snapshot()
.await
.and_then(|bridge| {
let only = bridge.attached_files.len() == 1;
bridge
.attached_files
.into_iter()
.find(|file| only || file.file_key.as_deref() == Some(file_key))
});
let details = json!({
"nodeIds": ids,
"limitSeconds": devup_mcp_figma::READ_TIME_LIMIT.as_secs(),
"inView": plugin.as_ref().and_then(|file| file.context.in_view),
"pluginBuild": plugin.as_ref().map(|file| file.context.plugin_build()),
"nextAction": "Bring the Figma window to the front and click this file's tab, then retry; split instance-descendant IDs into their own call if one keeps timing out.",
});
DevupError::with_details(
ErrorCode::DevupFigmaDirectUnavailable,
"Measurement timed out; no cached dimensions were substituted.",
true,
details,
)
}

pub(super) fn calibrate(result: &Value, input: &super::tools::MeasureCalibration) -> Value {
let Some(node) = result["nodes"]
.as_array()
Expand Down Expand Up @@ -161,18 +205,19 @@ pub(super) async fn run(
server.services.pacer.acquire().await;
}
// Live measurement deliberately bypasses the acquisition call bank.
let read = tokio::time::timeout(
std::time::Duration::from_secs(15),
// The limit is the bridge's own read limit: a plugin answering an
// out-of-sight file takes 10 s per unloaded node before the bridge
// re-reads it on the direct path, and a shorter limit here cut that
// re-read off and reported only "timed out".
let read = match tokio::time::timeout(
devup_mcp_figma::READ_TIME_LIMIT,
server.services.upstream.call_read_tool(call),
)
.await
.map_err(|_| {
DevupError::new(
ErrorCode::DevupFigmaDirectUnavailable,
"Measurement timed out; no cached dimensions were substituted.",
true,
)
})??;
{
Ok(read) => read?,
Err(_) => return Err(timed_out(server, &target.file_key, ids).await),
};
if let Some(error) = super::operation::upstream_error(&read.raw) {
return Err(error);
}
Expand Down Expand Up @@ -318,4 +363,22 @@ mod tests {
assert!(valid.get("image").is_none());
assert!(validated_node(&json!({"nodeId":"2:2","status":"unavailable"}), "1:1").is_err());
}
#[test]
fn unavailable_reasons_keep_only_fixed_labels() {
let unreachable = validated_node(
&json!({"nodeId":"I1:2;3:4","status":"unavailable","reason":"figma-unreachable","error":"Unable to establish connection to Figma"}),
"I1:2;3:4",
)
.unwrap();
assert_eq!(unreachable["reason"], "figma-unreachable");
assert!(unreachable["hint"].is_string());
assert!(unreachable.get("error").is_none());
let forged = validated_node(
&json!({"nodeId":"1:1","status":"unavailable","reason":"<script>"}),
"1:1",
)
.unwrap();
assert_eq!(forged["reason"], "node-read-unavailable");
assert!(forged.get("hint").is_none());
}
}
2 changes: 1 addition & 1 deletion plugin/dist/code.js

Large diffs are not rendered by default.

Loading
Loading